I do not know your current status, but, at least Keras accepts this.
Setting Keras metrics is really confusing, since, I believe, it merged different implementations.
Historically, Keras WAS a high level API to run on Tensorflow, PlaidML and Theano. (And, I was using PlaidML as a backend for Keras.)
Keras had default metrics to set in here. (In V1, they prepared slightly different metrics. So, for this explanation, I use V2 APIs.) Available metrics are;
binary_accuracy
categorical_accuracy
sparse_categorical_accuracy
top_k_categorical_accuracy
Of course, only 4 metrics can not cover all. So, Keras allows users to develop their own function. I think you can see this in Keras document.
def mean_pred(y_true, y_pred):
return K.mean(y_pred)
model.compile(optimizer=‘rmsprop’, loss=‘binary_crossentropy’, metrics=[‘accuracy’, mean_pred])
In those Keras default implementation, we just set a class name, not an instance. This is one type.
Then, in 2020, Keras and Tensorflow were merged. (Personally, I was very disappointed, since Keras is no longer multi-backend support API.)
The challenge for them is how to merge different types of metrics classes in here.
So, (I guess) they decided to set Tensorflow classes as an instance in metrics definition just like
tf.keras.metrics.Accuracy() in the above case.
This causes confusions, of course. Please look at this.
Both work as “categorical accuracy”, but the first one comes from Tensorflow, and the second one comes from Keras.
In net, original Keras metrics and custom metrics do not use parenthesis, but Tensorflow classes need parenthesis.
Then, additional confusions come from ‘accuracy’, ‘acc’, …
Those are special strings that Keras guess what does it mean. Then, Keras starts to look at several environment and selects one of these.
binary_accuracy
categorical_accuracy
sparse_categorical_accuracy
So, there is a chance that a metrics, that you may not expect, is selected. In this sense, it is better to set your metrics with in either Keras style or Tensorflow style. (By the way, just setting ‘accuracy’ works most of cases, though…)
That’s the whole story.