Save the date! Google I/O returns May 18-20 Register now

tf.contrib.eager.metrics.BinaryAccuracy

View source on GitHub

Calculates how often predictions matches labels.

Inherits From: Mean

This class is compatible with tf.keras.losses.binary_crossentropy, tf.compat.v1.losses.sigmoid_cross_entropy, tf.nn.sigmoid_cross_entropy_with_logits. If there is more than one label, this will become multi-label classification.

name name of the accuracy object.
threshold Used for rounding off the predictions. If the predictions are,

  1. probabilities then set the threshold to 0.5.
  2. logits then set the threshold to 0. You can set the threshold appropriately, to trade off with precision and recall.
dtype data type of tensor.
variables

Methods

add_variable

View source

Only for use by descendants of Metric.

aggregate

View source

Adds in the state from a list of metrics.

Default implementation sums all the metric variables.

Args
metrics A list of metrics with the same type as self.

Raises
ValueError If metrics contains invalid data.

build

View source

Method to create variables.

Called by __call__() before call() for the first time.

Args
*args

**kwargs The arguments to the first invocation of __call__(). build() may use the shape and/or dtype of these arguments when deciding how to create variables.

call

View source

Accumulate accuracy statistics.

labels and predictions should have the same shape and type.

Args
labels Binary Tensor(containing 0 or 1).
predictions Tensor with probabilities or logits.
weights Optional weighting of each example. Defaults to 1.

Returns
The arguments, for easy chaining.

init_variables

View source

Initializes this Metric's variables.

Should be called after variables are created in the first execution of __call__(). If using graph execution, the return value should be run() in a session before running the op returned by __call__(). (See example above.)

Returns
If using graph execution, this returns an op to perform the initialization. Under eager execution, the variables are reset to their initial values as a side effect and this function returns None.

result

View source

Returns the result of the Metric.

Args
write_summary bool indicating whether to feed the result to the summary before returning.

Returns
aggregated metric as float.

Raises
ValueError if the optional argument is not bool

value

View source

In graph mode returns the result Tensor while in eager the callable.

__call__

View source

Returns op to execute to update this metric for these inputs.

Returns None if eager execution is enabled. Returns a graph-mode function if graph execution is enabled.

Args
*args

**kwargs A mini-batch of inputs to the Metric, passed on to call().