RuntimeError: Model-building function did not return a valid Keras Model instance
See original GitHub issueHi,
I followed exactly the tutorial and I got this error …
Input :
import keras
from keras import layers
from kerastuner.tuners import RandomSearch
def build_model(hp):
model = keras.Sequential()
model.add(layers.Dense(units=hp.Int('units',
min_value=32,
max_value=512,
step=32),
activation='relu'))
model.add(layers.Dense(10, activation='softmax'))
model.compile(
optimizer=keras.optimizers.Adam(
hp.Choice('learning_rate',
values=[1e-2, 1e-3, 1e-4])),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model
tuner = RandomSearch(
build_model,
objective='val_accuracy',
max_trials=5,
executions_per_trial=3,
directory='my_dir',
project_name='helloworld')
Output :
RuntimeError: Model-building function did not return a valid Keras Model instance, found <keras.engine.sequential.Sequential object at 0x7f7209a72950>
Help please ?
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Keras Tuner - Model-building function did not return a valid ...
I'm trying to search Hyperparameters for a model using Keras Tuner, but I'm getting this error when ...
Read more >Model-building function did not return a valid Keras ... - SILVER
RuntimeError : Model-building function did not return a valid Keras Model instance, found None 케라스 튜너 에러 해결 방법 !
Read more >A few pitfalls for Kerastuner beginner users and why I like and ...
RuntimeError : Model-building function did not return a valid Keras Model instance, found <keras.engine.sequential.Sequential object at 0x000001A7D79E3128>.
Read more >Keras FAQ
How can I use pre-trained models in Keras? How can I use stateful RNNs? General questions. How can I train a Keras model...
Read more >How can one apply `keras_tuner` to `xgboost`-based models?
RuntimeError : Model-building function did not return a valid Keras Model instance, found StackingRegressor(estimators=[('rnd_reg_opt', ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OKay sorry I got it on my own…
Just needed to change the import from
import keras
tofrom tensorflow import keras
Now it works !
My layers and optimizers were imported from tensorflow.keras like this
whereas Sequential and layers like Conv2D, MaxPooling etc were imported from keras like this:
Also, doing this
from tensorflow import keras
doesn’t help, because I had both, tensorflow 2.0 and keras installed.So, all I had to do was change all
from keras. import .....
tofrom tensorflow.keras. import ....
to get rid of the error.