Keras: return_dict in evaluate() method doesn't work

Created on 12 May 2020  路  5Comments  路  Source: keras-team/keras

I'm not sure if this is a bug, is a documentation incoherence or it's just an issue with the keras version that kaggle uses.

System information

  • Have I written custom code (as opposed to using example directory): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Docker container for kaggle
  • TensorFlow backend (yes / no): yes
  • TensorFlow version: 2.1.0
  • Keras version: 2.3.1
  • Python version: 3.7.6.

Describe the current behavior

In the docs for the model.evaluate method it says you can use the argument "return_dict" to get a dictionary instead of a list for the output. However, I get an error when I specify such argument:

TypeError: evaluate() got an unexpected keyword argument 'return_dict'

Describe the expected behavior
No error an dict with the output of the evaluation.

Code to reproduce the issue
results = model.evaluate(X_test, y_test, batch_size=24, return_dict=True)

same thing if I use return_dict = False.

Other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

tensorflow buperformance

Most helpful comment

return_dict argument is introduced in tf 2.2, you cannot use it in tf 2.1

i'm using this snipped in 2.1 to convert the evaluation result to dict:

e = model.evaluate(
    x=test_inputs,
    y=test_outputs,
    verbose=1
)

e = {out: e[i] for i, out in enumerate(model.metrics_names)}

All 5 comments

return_dict argument is introduced in tf 2.2, you cannot use it in tf 2.1

i'm using this snipped in 2.1 to convert the evaluation result to dict:

e = model.evaluate(
    x=test_inputs,
    y=test_outputs,
    verbose=1
)

e = {out: e[i] for i, out in enumerate(model.metrics_names)}

I'm not sure if this is a bug, is a documentation incoherence or it's just an issue with the keras version that kaggle uses.

System information

* Have I written custom code (as opposed to using example directory): Yes

* OS Platform and Distribution (e.g., Linux Ubuntu 16.04):  Docker container for kaggle

* TensorFlow backend (yes / no):  yes

* TensorFlow version:  2.1.0

* Keras version:  2.3.1

* Python version:  3.7.6.

Describe the current behavior

In the docs for the model.evaluate method it says you can use the argument "return_dict" to get a dictionary instead of a list for the output. However, I get an error when I specify such argument:

TypeError: evaluate() got an unexpected keyword argument 'return_dict'

Describe the expected behavior
No error an dict with the output of the evaluation.

Code to reproduce the issue
results = model.evaluate(X_test, y_test, batch_size=24, return_dict=True)

same thing if I use return_dict = False.

Other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

Tensorflow 2.1 does not support this. To use this feature you must install the latest version of tensorflow(or 2.2 but why not stay updated!).

got it, thanks!

return_dict argument is introduced in tf 2.2, you cannot use it in tf 2.1

i'm using this snipped in 2.1 to convert the evaluation result to dict:

e = model.evaluate(
    x=test_inputs,
    y=test_outputs,
    verbose=1
)

e = {out: e[i] for i, out in enumerate(model.metrics_names)}

This worked perfectly for me, thank you!

I am getting this same error in tf 2.3.1 (TypeError: evaluate() got an unexpected keyword argument 'return_dict'). The docs still suggest tf.keras.Model.evaluate() takes the return_dict keyword. Any clarification on this? Thanks!

Was this page helpful?
0 / 5 - 0 ratings