Beginner with Keras -- I'm attempting to train a very simple neural network on a series of images from my local folder, but getting an error when I try to use fit_generator
.
From
model.fit_generator(train_batches,steps_per_epoch=33, validation_data=valid_batches,validation_steps=50,epochs=10,verbose=2)`
I get the error
RuntimeError: You must compile your model before using it.
despite the fact that I compile the model in the line immediately about it with
model.compile(Adam(0.01),loss="categorical_crossentropy",metrics=["accuracy"])
which runs without errors. (see pictures).
This can be a rare case where pictures are more useful than code sample.
The image says, the compile cell got number [206]
, and fit cell is [210]
. In between them, you have recreated the model at [209]
, which deletes the previously compiled model and creates a new one.
I think it will run (unless there is another bug) if you execute the cells from top to bottom again.
I ran into the same issue. There is a bug: https://github.com/tensorflow/tensorflow/issues/18287
Unfortunately the fix is not yet released.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.