larq.metrics
¶
We add metrics specific to extremely quantized networks using a larq.context.metrics_scope
rather than through the metrics
parameter of model.compile()
, where most common metrics reside. This is because, to calculate metrics like the flip_ratio
, we need a layer's kernel or activation and not just the y_true
and y_pred
that Keras passes to metrics defined in the usual way.
FlipRatio¶
larq.metrics.FlipRatio(values_dtype="int8", name="flip_ratio", dtype=None)
Computes the mean ratio of changed values in a given tensor.
Example
m = metrics.FlipRatio()
m.update_state((1, 1)) # result: 0
m.update_state((2, 2)) # result: 1
m.update_state((1, 2)) # result: 0.75
print('Final result: ', m.result().numpy()) # Final result: 0.75
Arguments
- name: Name of the metric.
- values_dtype: Data type of the tensor for which to track changes.
- dtype: Data type of the moving mean.