Here is my code:
from keras.callbacks import EarlyStopping
model = Sequential()
model.add(Dense(50, input_dim=33, init='uniform', activation='relu'))
for u in range(3): #how to efficiently add more layers
model.add(Dense(33, init='uniform', activation='relu'))
model.add(Dense(122, init='uniform', activation='sigmoid'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(X_train, Y_train, nb_epoch=20, batch_size=20, callbacks=[EarlyStopping(monitor='val_loss', patience=4)])
and I'm getting the following error:
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
It doesn't produce that error when I don't use EarlyStopping
.
Anyone have a fix?
If you think about it : you ask to monitor a validation loss without using a validation during the training.
Use
model.fit(X_train, Y_train, nb_epoch=20, batch_size=20, validation_split=0.2, callbacks=[EarlyStopping(monitor='val_loss', patience=4)])
For example if you want to have a validation. It will use 20% of your data as validation set. You won't be training on those samples, just validating your model at the end of each epoch.
And as mentionned in your other question about this code : change the last activation to a softmax to use with categorical_crossentropy
. Or switch the objective to binary_crossentropy
depending on your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With