Skip to content

How to use a tensorflow metric function in keras? #6050

@ophiry

Description

@ophiry

using python 3.5.2 tensorflow rc 1.1

I'm trying to use a tensorflow metric function in keras. the required inteface seems to be the same, but calling:

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=[tensorflow.metrics.auc])

results with the error:

Using TensorFlow backend.
Traceback (most recent call last):
  File "/Users/ophir/dev/ophir/tf_keras_metrics.py", line 49, in <module>
    metrics=[precision, recall, tensorflow.metrics.auc]
  File "/Users/ophir/anaconda3/envs/p3/lib/python3.5/site-packages/keras/engine/training.py", line 956, in compile
    metric_result = masked_metric_fn(y_true, y_pred, mask=masks[i])
  File "/Users/ophir/anaconda3/envs/p3/lib/python3.5/site-packages/keras/engine/training.py", line 489, in masked
    return K.mean(score_array)
  File "/Users/ophir/anaconda3/envs/p3/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 1120, in mean
    axis = _normalize_axis(axis, ndim(x))
  File "/Users/ophir/anaconda3/envs/p3/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 437, in ndim
    dims = x.get_shape()._dims
AttributeError: 'tuple' object has no attribute 'get_shape'

Process finished with exit code 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions