Comments (8)
@LostInDarkMath
Here the following API are technically same.
keras.metrics.Accuracy
keras.metrics.BinaryAccuracy
From doc,
keras.metrics.Accuracy(name="accuracy", ...)
keras.metrics.BinaryAccuracy(name="binary_accuracy", ...)
Calculates how often predictions equal labels.
This metric creates two local variables, total and count that are used to compute the frequency with which y_pred matches y_true. This frequency is ultimately returned as binary accuracy: an idempotent operation that simply divides total by count.
And when we use string identifier, for example [accuracy
], later it converts to the appropriate metrics based on the labels and logits, source.
When you pass the
strings 'accuracy' or 'acc', we convert this to one of
tf.keras.metrics.BinaryAccuracy
,
tf.keras.metrics.CategoricalAccuracy
,
tf.keras.metrics.SparseCategoricalAccuracy
based on the shapes
of the targets and of the model output. We do a similar
@tilakrayal
Apart from the abvove clarification, there may be potential bug. Please check this question on stack overflow. That is very similar to this issue.
from tf-keras.
@LostInDarkMath,
Apologies for the delay. Here in the code you are trying to use loss=CategoricalCrossentropy()
, where Accuracy is not the better option. Instead you can use keras.metrics.CategoricalAccuracy for the accurate result. I tried to execute with keras.metrics.CategoricalAccuracy and it provided the required output. Kindly find the gist of it here.
https://www.tensorflow.org/api_docs/python/tf/keras/metrics/CategoricalAccuracy
Thank you!
from tf-keras.
Thank your for the clarification.
That means that the string 'accuracy'
is resolved differently depending on the loss function? Or does 'accuracy'
always resolve to eras.metrics.CategoricalAccuracy
? And where is this behavior documented? Is there something like a mapping table that visualizes this mapping? Would be very nice :)
from tf-keras.
This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.
from tf-keras.
From the model.copile document:
List of metrics to be evaluated by the model during training and testing. Each of this can be a string (name of a built-in function), function or a tf.keras.metrics.Metric instance. See tf.keras.metrics. Typically you will use metrics=['accuracy']. A function is any callable with the signature result = fn(y_true,y_pred). To specify different metrics for different outputs of a multi-output model, you could also pass a dictionary, such as metrics={'output_a':'accuracy', 'output_b':['accuracy', 'mse']}. You can also pass a list to specify a metric or a list of metrics for each output, such as metrics=[['accuracy'], ['accuracy', 'mse']] or metrics=['accuracy', ['accuracy', 'mse']]. When you pass the strings 'accuracy' or 'acc', we convert this to one of tf.keras.metrics.BinaryAccuracy, tf.keras.metrics.CategoricalAccuracy, tf.keras.metrics.SparseCategoricalAccuracy based on the shapes of the targets and of the model output. We do a similar conversion for the strings 'crossentropy' and 'ce' as well. The metrics passed here are evaluated without sample weighting; if you would like sample weighting to apply, you can specify your metrics via the weighted_metrics argument instead.
from tf-keras.
When you use metrics.Accuracy, it resolves to BinaryAccuracy
as stated in the doc of Accuracy
. Whereas, when using string accuracy
it resolves to BinaryAccuracy or CategoricalAccuracy, based on the target shape. This was also explained by @innat above. This may be confusing, so we recommend either explicitly using BinaryAccuracy
or CategoricalAccuracy
if you don't want to use the string accuracy
for the metrics.
from tf-keras.
The same behavior exists in Keras 3 as well. Should we deprecate use of metrics.Accuracy
or mimic its usage to string metric of accuracy
?
from tf-keras.
The same behavior exists in Keras 3 as well. Should we deprecate use of
metrics.Accuracy
or mimic its usage to string metric ofaccuracy
?
The metrics.Accuracy
can be removed. It makes confusion, especially among the beginners a lot.
from tf-keras.
Related Issues (20)
- Calling a model and using model.predict yields different results for the same input HOT 5
- StringLookup layer never releases memory on load HOT 3
- Add a dedicated file for Keras' security policy HOT 1
- L1 penalty set small weights to 0 HOT 9
- `Cannot iterate over a scalar tensor.` with split_dataset HOT 4
- Add a dedicated file for Keras' security policy
- Feature: Flops calculation
- NotFoundError could not find registered transfer manager for platform Host -- check target linkage [Op:__inference__jit_compiled_convolution_op_26169] HOT 3
- Error importing model with both load_model (.keras) and load_weights (.h5) HOT 10
- Using Lambda layers to take different slices of a prevous layer's output causes earlier Lambda layers to be overwritten HOT 5
- Error while importing tf_keras HOT 11
- shape issue for y_pred for a custom made loss function HOT 3
- Add a target_width parameter to keras.utils.timeseries_dataset_from_array HOT 4
- UNIMPLEMENTED: Cast string to float is not supported; CANCELLED: Function was cancelled before it was started HOT 3
- TextVectorization: output_mode={multi_hot, count} promise int arrays but output floats
- Cloning a TextVectorization Layer with Split Function Doesn't Work HOT 6
- Mirrored strategy model.load_weights() failure HOT 2
- sparse_categorical_crossentropy with ignore_class=-1 makes loss to `nan` HOT 3
- Importing `tf_keras` to use Keras 2 in TensorFlow 2.16 fails HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tf-keras.