How to prevent TypeError type: unsupported operand type for -: "NoneType" and "int" when using keras EarlyStopping?

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 get the following error:

TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

It does not produce this error if I do not use EarlyStopping.

Does anyone have a fix?

+4
source share
1 answer

If you think about it: you are asking to track the loss of validation without using validation during training.

Using

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 receive confirmation. It will use 20% of your data as a validation set. You will not train on these patterns, just checking your model at the end of each era.

: softmax categorical_crossentropy. binary_crossentropy .

+2

Source: https://habr.com/ru/post/1670880/


All Articles