Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

python - `tf.keras.model.evaluate()` provides different results when fed the same data in different formats

Backgound

I am looking at the following Tensorflow time series tutorial: https://www.tensorflow.org/tutorials/structured_data/time_series#single-shot_models

For the discussion here, I am going to consider the ‘multi_linear_model’ in the Multi-step models section.

I add the following line

multi_val_performance_new['Linear'] = multi_linear_model.evaluate(next(iter(multi_window.val))[0], next(iter(multi_window.val))[1])

after this line

multi_val_performance['Linear'] = multi_linear_model.evaluate(multi_window.val).

When I inspect the loss and mean absolute errors, they are different.

Question

Why - when I feed the original tf.Dataset to model.evaluate - do I get one set of loss and mean absolute error, but when I feed its components - (next(iter(tf.Dataset))[0], next(iter(tf.Dataset)[1]) to model.evaluate - do I get a different set of loss and mean absolute errors?

NB

I have set shuffle = false in def make_dataset(self, data):.

question from:https://stackoverflow.com/questions/66069038/tf-keras-model-evaluate-provides-different-results-when-fed-the-same-data-in

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

next(iter(ds)) will only return one batch/observation. Passing the entire dataset in model.evaluate will return the metrics for the entire dataset.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...