LostTech.TensorFlow : API Documentation

Type Metric

Namespace tensorflow.keras.metrics

Parent Layer

Interfaces IMetric

Encapsulates metric logic and state.

Usage: Usage with tf.keras API: To be implemented by subclasses: * `__init__()`: All state variables should be created in this method by calling `self.add_weight()` like: `self.var = self.add_weight(...)` * `update_state()`: Has all updates to the state variables like: self.var.assign_add(...). * `result()`: Computes and returns a value for the metric from the state variables.

Example subclass implementation:

``` class BinaryTruePositives(tf.keras.metrics.Metric):

def __init__(self, name='binary_true_positives', **kwargs): super(BinaryTruePositives, self).__init__(name=name, **kwargs) self.true_positives = self.add_weight(name='tp', initializer='zeros')

def update_state(self, y_true, y_pred, sample_weight=None): y_true = tf.cast(y_true, tf.bool) y_pred = tf.cast(y_pred, tf.bool)

values = tf.logical_and(tf.equal(y_true, True), tf.equal(y_pred, True)) values = tf.cast(values, self.dtype) if sample_weight is not None: sample_weight = tf.cast(sample_weight, self.dtype) sample_weight = tf.broadcast_weights(sample_weight, values) values = tf.multiply(values, sample_weight) self.true_positives.assign_add(tf.reduce_sum(values))

def result(self): return self.true_positives ```
Show Example
m = SomeMetric(...)
            for input in...:
              m.update_state(input)
            print('Final result: ', m.result().numpy()) 

Methods

Properties

Public instance methods

object add_weight(string name, Dimension shape, bool aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, Dimension shape, IDictionary<object, object> aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, int shape, VariableAggregation aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, Dimension shape, DType aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, Dimension shape, VariableAggregation aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, int shape, object aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, Dimension shape, object aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, int shape, DType aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, int shape, string aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, TensorShape shape, bool aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, TensorShape shape, IDictionary<object, object> aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, TensorShape shape, DType aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, TensorShape shape, VariableAggregation aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, TensorShape shape, object aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, TensorShape shape, string aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, Dimension shape, string aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, ImplicitContainer<T> shape, bool aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, ImplicitContainer<T> shape, IDictionary<object, object> aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, IEnumerable<Nullable<int>> shape, string aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, ImplicitContainer<T> shape, DType aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, int shape, IDictionary<object, object> aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, ImplicitContainer<T> shape, VariableAggregation aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, IEnumerable<Nullable<int>> shape, IDictionary<object, object> aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, ImplicitContainer<T> shape, object aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, IEnumerable<Nullable<int>> shape, bool aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, ImplicitContainer<T> shape, string aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, IEnumerable<Nullable<int>> shape, VariableAggregation aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, int shape, bool aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, IEnumerable<Nullable<int>> shape, object aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight(string name, IEnumerable<Nullable<int>> shape, DType aggregation, ImplicitContainer<T> synchronization, object initializer, DType dtype)

Adds state variable. Only for use by subclasses.

object add_weight_dyn(object name, ImplicitContainer<T> shape, ImplicitContainer<T> aggregation, ImplicitContainer<T> synchronization, object initializer, object dtype)

Adds state variable. Only for use by subclasses.

object result()

Computes and returns the metric value tensor.

Result computation is an idempotent operation that simply calculates the metric value using the state variables.

object result_dyn()

Computes and returns the metric value tensor.

Result computation is an idempotent operation that simply calculates the metric value using the state variables.

object update_state(IGraphNodeBase[] args)

Accumulates statistics for computing the element-wise mean.
Returns
object
Update op.

object update_state(IDictionary<string, object> kwargs, IGraphNodeBase[] args)

Accumulates statistics for computing the element-wise mean.
Returns
object
Update op.

object update_state_dyn(Object[] args)

Accumulates statistics for computing the element-wise mean.
Returns
object
Update op.

object update_state_dyn(IDictionary<string, object> kwargs, Object[] args)

Accumulates statistics for computing the element-wise mean.
Returns
object
Update op.

Public properties

PythonFunctionContainer activity_regularizer get; set;

object activity_regularizer_dyn get; set;

bool built get; set;

object dtype get;

object dtype_dyn get;

bool dynamic get;

object dynamic_dyn get;

IList<Node> inbound_nodes get;

object inbound_nodes_dyn get;

IList<object> input get;

object input_dyn get;

object input_mask get;

object input_mask_dyn get;

IList<object> input_shape get;

object input_shape_dyn get;

object input_spec get; set;

object input_spec_dyn get; set;

IList<object> losses get;

object losses_dyn get;

IList<object> metrics get;

object metrics_dyn get;

object name get;

object name_dyn get;

object name_scope get;

object name_scope_dyn get;

IList<object> non_trainable_variables get;

object non_trainable_variables_dyn get;

IList<object> non_trainable_weights get;

object non_trainable_weights_dyn get;

IList<object> outbound_nodes get;

object outbound_nodes_dyn get;

IList<object> output get;

object output_dyn get;

object output_mask get;

object output_mask_dyn get;

object output_shape get;

object output_shape_dyn get;

object PythonObject get;

bool stateful get; set;

ValueTuple<object> submodules get;

object submodules_dyn get;

bool supports_masking get; set;

bool trainable get; set;

object trainable_dyn get; set;

object trainable_variables get;

object trainable_variables_dyn get;

IList<object> trainable_weights get;

object trainable_weights_dyn get;

IList<object> updates get;

object updates_dyn get;

object variables get;

object variables_dyn get;

IList<object> weights get;

object weights_dyn get;