我正在构建一个多输出 keras 模型
model1 = Model(input=ip, output=[main, aux])
model1.compile(optimizer='sgd', loss={'main':cutom_loss, 'aux':'mean_squared error'}, metrics='accuracy')
model1.fit(input_data, [main_output, aux_output], nb_epoch=epochs, batch_size=batch_size, verbose=2, shuffle=True, validation_split=0.1, callbacks=[checkpointer])
我的custom_loss
功能:`
def custom_loss(y_true, y_pred):
main_pred = y_pred[0]
main_true = y_true[0]
loss = K.mean(K.square(main_true - main_pred), axis=-1)
return loss
但我的网络没有收敛
Epoch 1/10
Epoch 00000: val_loss improved from inf to 0.39544, saving model to ./testAE/testAE_best_weights.h5
18s - loss: 0.3896 - main_loss: 0.0449 - aux_loss: 0.3446 - main_acc: 0.0441 - val_loss: 0.3954 - val_main_loss: 0.0510 - val_aux_loss: 0.3445 - val_main_acc: 0.0402
Epoch 2/10
Epoch 00001: val_loss did not improve
18s - loss: 0.3896 - main_loss: 0.0449 - aux_loss: 0.3446 - main_acc: 0.0441 - val_loss: 0.3954 - val_main_loss: 0.0510 - val_aux_loss: 0.3445 - val_main_acc: 0.0402
Epoch 3/10
Epoch 00002: val_loss did not improve
18s - loss: 0.3896 - main_loss: 0.0449 - aux_loss: 0.3446 - main_acc: 0.0441 - val_loss: 0.3954 - val_main_loss: 0.0510 - val_aux_loss: 0.3445 - val_main_acc: 0.0402
Epoch 4/10
Epoch 00003: val_loss did not improve
18s - loss: 0.3896 - main_loss: 0.0449 - aux_loss: 0.3446 - main_acc: 0.0441 - val_loss: 0.3954 - val_main_loss: 0.0510 - val_aux_loss: 0.3445 - val_main_acc: 0.0402
我只想训练主要输出。辅助输出将用于测试。