Skip to content Skip to sidebar Skip to footer

Keras Tuner - Model-building Function Did Not Return A Valid Keras Model Instance

I'm trying to search Hyperparameters for a model using Keras Tuner, but I'm getting this error when I run the code: 'RuntimeError: Model-building function did not return a valid Ke

Solution 1:

If you import module members from keras, you must import from tensorflow.keras instead of keras. For example, if you write:

from keras.modelsimportSequentialfrom keras.layersimportDense, Activation, Dropoutfrom keras.optimizersimportAdam

Then change them to:

from tensorflow.keras.modelsimportSequentialfrom tensorflow.keras.layersimportDense, Activation, Dropoutfrom tensorflow.keras.optimizersimportAdam

Solution 2:

I know what's wrong and is not the code, my model have 6 neurons on the last layer and I've used the loss as 'categorical_crossentropy', but this only works when the labels are 0 and 1, so I've changed the loss to 'sparse_categorical_crossentropy' and metrics to 'accuracy' and it worked. Thanks everyone for the reply, I appreciate the help.

Post a Comment for "Keras Tuner - Model-building Function Did Not Return A Valid Keras Model Instance"