CategoricalCrossentropy

public class CategoricalCrossentropy

A Metric that computes the categorical cross-entropy loss between true labels and predicted labels.

This is the crossentropy metric class to be used when there are multiple label classes (2 or more). The labels should be given as a one_hot representation. eg., When labels values are [2, 0, 1], the labels Operand contains = [[0, 0, 1], [1, 0, 0], [0, 1, 0]] .

Inherited Constants

org.tensorflow.framework.metrics.impl.Reduce
String COUNT
String TOTAL

Public Constructors

CategoricalCrossentropy(Ops tf, String name, boolean fromLogits, float labelSmoothing, long seed, Class<T> type)
Creates a CategoricalCrossentropy metric that computes the crossentropy metric between the labels and predictions.
CategoricalCrossentropy(Ops tf, String name, boolean fromLogits, float labelSmoothing, int axis, long seed, Class<T> type)
Creates a CategoricalCrossentropy metric that computes the crossentropy metric between the labels and predictions.

Public Methods

Operand<T>
call(Operand<? extends TNumber> labels, Operand<? extends TNumber> predictions)
Calculates the weighted loss between labels and predictions

Inherited Methods

org.tensorflow.framework.metrics.impl.MeanMetricWrapper
LossMetric<T>
getLoss()
Gets the loss function.
List<Op>
updateStateList(Operand<? extends TNumber> labels, Operand<? extends TNumber> predictions, Operand<? extends TNumber> sampleWeights)
Creates Operations that update the state of the mean metric, by calling the loss function and passing the loss to the Mean metric to calculate the weighted mean of the loss over many iterations.
org.tensorflow.framework.metrics.impl.Reduce
Variable<T>
getCount()
Gets the count variable
Class<T>
getResultType()
Gets the type for the variables
Variable<T>
getTotal()
Gets the total variable
Op
resetStates()
Resets any state variables to their initial values
Operand<T>
result()
Gets the current result of the metric
List<Op>
updateStateList(Operand<? extends TNumber> values, Operand<? extends TNumber> sampleWeights)
Updates the metric variables based on the inputs.
org.tensorflow.framework.metrics.Metric
final Operand<T>
callOnce(Operand<? extends TNumber> values, Operand<? extends TNumber> sampleWeights)
Calls update state once, followed by a call to get the result
String
getName()
Gets the name of this metric.
long
getSeed()
Gets the random number generator seed value
Ops
getTF()
Gets the TensorFlow Ops
abstract Op
resetStates()
Resets any state variables to their initial values
abstract Operand<T>
result()
Gets the current result of the metric
final Op
updateState(Operand<? extends TNumber> labels, Operand<? extends TNumber> predictions, Operand<? extends TNumber> sampleWeights)
Creates a NoOp Operation with control dependencies to update the metric state
final Op
updateState(Operand<? extends TNumber> values, Operand<? extends TNumber> sampleWeights)
Creates a NoOp Operation with control dependencies to update the metric state
List<Op>
updateStateList(Operand<? extends TNumber> labels, Operand<? extends TNumber> predictions, Operand<? extends TNumber> sampleWeights)
Creates a List of Operations to update the metric state based on labels and predictions.
List<Op>
updateStateList(Operand<? extends TNumber> values, Operand<? extends TNumber> sampleWeights)
Creates a List of Operations to update the metric state based on input values.
boolean
equals(Object arg0)
final Class<?>
getClass()
int
hashCode()
final void
notify()
final void
notifyAll()
String
toString()
final void
wait(long arg0, int arg1)
final void
wait(long arg0)
final void
wait()
org.tensorflow.framework.metrics.impl.LossMetric
abstract Operand<T>
call(Operand<? extends TNumber> labels, Operand<? extends TNumber> predictions)
Calculates the weighted loss between labels and predictions

Public Constructors

public CategoricalCrossentropy (Ops tf, String name, boolean fromLogits, float labelSmoothing, long seed, Class<T> type)

Creates a CategoricalCrossentropy metric that computes the crossentropy metric between the labels and predictions.

Uses a CHANNELS_LAST for the channel axis.

Parameters
tf the TensorFlow Ops
name the name of this metric, if null then metric name is getSimpleName().
fromLogits Whether to interpret predictions as a tensor of logit values oras opposed to a probability distribution.
labelSmoothing value used to smooth labels, When > 0, label values are smoothed, meaning the confidence on label values are relaxed. e.g. labelSmoothing=0.2 means that we will use a value of 0.1 for label 0 and 0.9 for label 1
seed the seed for random number generation. An initializer created with a given seed will always produce the same random tensor for a given shape and data type.
type the type for the variables and result

public CategoricalCrossentropy (Ops tf, String name, boolean fromLogits, float labelSmoothing, int axis, long seed, Class<T> type)

Creates a CategoricalCrossentropy metric that computes the crossentropy metric between the labels and predictions.

Parameters
tf the TensorFlow Ops
name the name of this metric, if null then metric name is getSimpleName().
fromLogits Whether to interpret predictions as a tensor of logit values as opposed to a probability distribution.
labelSmoothing value used to smooth labels, When > 0, label values are smoothed, meaning the confidence on label values are relaxed. e.g. labelSmoothing=0.2 means that we will use a value of 0.1 for label 0 and 0.9 for label 1
axis Int specifying the channels axis. axis=CHANNELS_LAST corresponds to data format channels_last, and axis=CHANNELS_FIRST corresponds to data format channels_first.
seed the seed for random number generation. An initializer created with a given seed will always produce the same random tensor for a given shape and data type.
type the type for the variables and result

Public Methods

public Operand<T> call (Operand<? extends TNumber> labels, Operand<? extends TNumber> predictions)

Calculates the weighted loss between labels and predictions

Parameters
labels the truth values or labels
predictions the predictions
Returns
  • the loss