简体   繁体   中英

Multi tasking CNN model early stop with validation loss

I am trying to fit a multitasking model with validation data and tracing validation loss for early stopping. Is there any way to trace and early stop with validation loss? My demo code is following it shows a warning that validation loss is not available.


    def main_model(height, width): 
            input_img = Input(shape = (height, width, 1))
            conv01_1 = Conv2D(64, (3, 3), activation='relu', padding='same')(input_img)
            pool01_1 = AveragePooling2D(pool_size=(2, 2),strides=None, padding="same")( conv01_1)
            batch_nor01_1= BatchNormalization()(pool01_1)
            drout01_1= Dropout(0.1)(batch_nor01_1)
            flatten_layer = Flatten()(drout01_1)
            x1_dense = Dense(512,activation='relu')( flatten_layer )
            out_1=Dense(6,activation = "softmax",name='activity_output')( x1_dense)
            out_2=Dense(1,activation='linear',name='energy_output')( x1_dense)
            model = Model(inputs=input_img,outputs = [out_1,out_2])
            model.compile(optimizer=SGD(lr=0.001,momentum=0.9),loss={'activity_output':'categorical_crossentropy', 'energy_output': 'mse'},loss_weights={'activity_output': 0.5, 'energy_output': 0.5},metrics=['accuracy','mae'])
            model.summary()
            return model
    
    model_name=s+'_best_model.h5'
    mc = ModelCheckpoint(model_name, monitor='validation_loss', mode='auto', verbose=1, save_best_only=True)
    es = EarlyStopping(monitor='validation_loss',min_delta=0,patience=20,verbose=0, mode='auto')
    ```
    
    batch_size=500
    epochs=1
    model=main_model(height, width)
    History = model.fit(x_train,[y_train,y_train_1],epochs = epochs, validation_data = (x_valid,y_valid,y_valid_1),verbose = 1,callbacks=[callback_test,es,lrs,mc,])

'''


        

I have got the solution. Basically, I have replaced the validation_loss with val_loss so the code is now:

mc = ModelCheckpoint(model_name, monitor='val_loss', mode='min', verbose=1, 
                     save_best_only=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM