Reputation: 35
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).
Image of error, Image of generator,
Upvotes: 1
Views: 1145
Reputation: 9617
I ran into the same issue. There is a bug: https://github.com/tensorflow/tensorflow/issues/18287
Unfortunately the fix is not yet released.
Upvotes: 1
Reputation: 6740
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.
Upvotes: 3