Looking at the docs for tfa.metrics.CohenKappa I'm trying to figure out how to use it with a simple model.
I've written the following code:
num_features = 10
inp = Input(shape=( num_features))
out = Dense(5, activation='softmax')(inp)
model = tf.keras.models.Model(inp, out)
# model.add_metric(tfa.metrics.CohenKappa(num_classes=5)(out)) <-- problematic line
model.compile('sgd', loss='mse')
That produces the following model:
Model: "model_16"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_18 (InputLayer) [(None, 1)] 0
_________________________________________________________________
dense_51 (Dense) (None, 5) 10
=================================================================
Total params: 10
Trainable params: 10
Non-trainable params: 0
_________________________________________________________________
If I uncomment the cohenKappa line I get the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-165-d0ef1187e052> in <module>()
----> 1 get_model().summary()
4 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/metrics_utils.py in decorated(metric_obj, *args, **kwargs)
88
89 with tf_utils.graph_context_for_symbolic_tensors(*args, **kwargs):
---> 90 update_op = update_state_fn(*args, **kwargs)
91 if update_op is not None: # update_op will be None in eager execution.
92 metric_obj.add_update(update_op)
TypeError: update_state() missing 1 required positional argument: 'y_pred'
What am I missing?