EarlyStopping (керас) не работает при помещении в метод - PullRequest
0 голосов
/ 30 января 2020

EarlyStopping не работает при размещении внутри метода.

EarlyStopping работает не при работе:

def model_training():

    # model, train_images, val_images, train_labels, val_images DEFINED HERE


    train_it =  ImageDataGenerator().flow(train_images, y=train_labels, batch_size=32)
    val_it =  ImageDataGenerator().flow(val_images, y=val_labels, batch_size=32)

    mc = ModelCheckpoint('model_name.h5', monitor='val_acc', save_best_only=True)

    es = EarlyStopping(monitor='val_loss',patience=1)

    history = model.fit_generator(train_it, steps_per_epoch=len(train_it),
                                  validation_data=val_it, validation_steps=len(val_it), 
                                  epochs=50, callbacks=[es, mc])

    _, acc = model.evaluate_generator(val_it, steps=len(val_it), verbose=1)


model_training()

EarlyStopping работает при запуске:

# model, train_images, val_images, train_labels, val_images DEFINED HERE

train_it =  ImageDataGenerator().flow(train_images, y=train_labels, batch_size=32)
val_it =  ImageDataGenerator().flow(val_images, y=val_labels, batch_size=32)

mc = ModelCheckpoint('model_name.h5', monitor='val_acc', save_best_only=True)

es = EarlyStopping(monitor='val_loss',patience=1)

history = model.fit_generator(train_it, steps_per_epoch=len(train_it),
                              validation_data=val_it, validation_steps=len(val_it), 
                              epochs=50, callbacks=[es, mc])

_, acc = model.evaluate_generator(val_it, steps=len(val_it), verbose=1)

Есть идеи почему?


UPDATE: EarlyStopping только работает когда patience=1.

...