David293836
David293836

Reputation: 1215

tensorflow TypeError: cannot unpack non-iterable float object

I am using tensorflow V2.2 and run into TyepError when I do model.evaluate. Can someone advise what the issues may be? A screenshot of the execution and error message is shown below. enter image description here

Upvotes: 7

Views: 8752

Answers (3)

Patrice Gagnon
Patrice Gagnon

Reputation: 1464

Thanks Marco. In my version of Tensorflow (2.16.2), the metrics param needs to be a list:

model.compile(
    loss = tf.keras.losses.BinaryCrossentropy(),
    optimizer = tf.keras.optimizers.Adam(learning_rate=0.01),
    metrics=['accuracy'])

Upvotes: 0

Francois Robert
Francois Robert

Reputation: 556

Actually, if you don't have metric='accuracy' in the model.compile, don't try to extract it in model.evaluate.

So, you can change:

loss, acc= model.evaluate(df, df_y, verbose=0)

to

loss = model.evaluate(df, df_y, verbose=0)

Upvotes: 5

Marco Cerliani
Marco Cerliani

Reputation: 22031

you need to define a metric when you compile the model model.compile('adam', 'binary_crossentropy', metrics='accuracy')

in this way during evaluation, loss and accuracy are returned

Upvotes: 12

Related Questions