簡體   English   中英

多任務 CNN model 提前停止,帶有驗證損失

[英]Multi tasking CNN model early stop with validation loss

我正在嘗試為多任務 model 安裝驗證數據並跟蹤驗證損失以提前停止。 有什么方法可以追蹤驗證損失並提前停止? 我的演示代碼緊隨其后,它顯示了驗證丟失不可用的警告。


    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,])

'''


        

我有解決辦法。 基本上,我已經用val_loss替換了validation_loss ,所以現在的代碼是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM