Relative Content

Tag Archive for pythontensorflowkeras

Model.evaluate() returning a float, not a list

I have a multi-task neural network. I want to make sure that when I call Model.evaluate() on my model, that the score I see is the sum of the losses. However, it is returning a scalar rather than a list, so I am not sure what this loss is. According to the documentation, a list of scalars should be returned for multiple outputs or losses. Below is a minimal reproducible example

Tensorflow.keras import issues

I am creating a simple AI. I am using TensorFlow and Keras in python and receiving an attribute error from the imports.

Tensorflow/Keras model raises output shape errors when loaded in another system

I have a tf.keras lstm model that I trained on Google Colab and I want to load it on my laptop so I can run it to do inference.
I created a Python virtual environment on my laptop with the same versions of Tensorflow/Keras as Google Colab (2.15) and the same version of Python (3.10).
Despite this, when I load the model I get the following errors:

Error loading model in keras. Please help me

Traceback (most recent call last):
File “C:Users250004460DesktopBackupPython filesMicroservicescat_dog_classifier.py”, line 27, in
get_model()
File “C:Users250004460DesktopBackupPython filesMicroservicescat_dog_classifier.py”, line 17, in get_model
model=tf.keras.models.load_model(‘cat_dog_classifier.h5’)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:Users250004460AppDataLocalanaconda3Libsite-packageskerassrcsavingsaving_api.py”, line 183, in load_model
return legacy_h5_format.load_model_from_hdf5(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:Users250004460AppDataLocalanaconda3Libsite-packageskerassrclegacysavinglegacy_h5_format.py”, line 133, in load_model_from_hdf5
model = saving_utils.model_from_config(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:Users250004460AppDataLocalanaconda3Libsite-packageskerassrclegacysavingsaving_utils.py”, line 58, in model_from_config
batch_input_shape = config[“config”].pop(“batch_input_shape”, None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: pop expected at most 1 argument, got 2

What is the difference between tf.keras.models.Sequential() and tf.keras.Sequential()?

I have just started building neural networks with tensorflow and different online resources have different ways of creating them. One thing I have noticed is how the sequential API is implemented. Some use tf.keras.Sequential() while others use tf.keras.models.Sequential()? Can anyone tell me the difference and when to use one over the other?