0

I'm using keras.callbacks.callbacks.EarlyStopping for my deep learning project.
It's a VGG19 model for image classification.

Problem:

When settingrestore_best_weights=True,

TypeError: 'NoneType' object is not subscriptable

Stack trace:

Epoch 00003: saving model to ./output/2020-02-17_17-06-25_nomura/vgg19_weights.03-1.099-0.34.hdf5
Restoring model weights from the end of the best epoch  
Traceback (most recent call last):  
  File "wb-det_nomura_nobn.py", line 824, in <module>
    dynamic_train(path, _model)  
  File "wb-det_nomura_nobn.py", line 542, in dynamic_train
    verbose=1)  
  File "C:\Users\owner\Anaconda3\lib\site-packages\keras\engine\training.py", line 1039, in fit
    validation_steps=validation_steps)  
  File "C:\Users\owner\Anaconda3\lib\site-packages\keras\engine\training_arrays.py", line 217, in fit_loop  
    callbacks.on_epoch_end(epoch, epoch_logs)  
  File "C:\Users\owner\Anaconda3\lib\site-packages\keras\callbacks.py", line 79, in on_epoch_end
    callback.on_epoch_end(epoch, logs)  
  File "C:\Users\owner\Anaconda3\lib\site-packages\keras\callbacks.py", line 557, in on_epoch_end
    self.model.set_weights(self.best_weights)  
  File "C:\Users\owner\Anaconda3\lib\site-packages\keras\engine\network.py", line 504, in set_weights  
    layer_weights = weights[:num_param]  
TypeError: 'NoneType' object is not subscriptable

And when python restore_best_weights=False, no problem.

System information
- keras 2.2.4
- python 3.7.3
installed within Anaconda.

The code is simple as follows.

es_cb = EarlyStopping(monitor='val_loss', patience=0, verbose=1,
                      mode='auto', baseline=0.05,
                      restore_best_weights=True)
Penny Liu
  • 15,447
  • 5
  • 79
  • 98
guttentag_liu
  • 45
  • 1
  • 7
  • [Could this be the droid you're looking for?](https://stackoverflow.com/questions/52466932/restore-best-weights-issue-keras-early-stopping) – jgk_iles Feb 17 '20 at 15:16
  • @jgk_iles Actually, I've read it before. Not the same problem and the Keras I'm using is version 2.2.4. – guttentag_liu Feb 17 '20 at 15:43

0 Answers0