def custom_loss(lmbda , regularizer_value):
def loss(y_true , y_pred):
return K.categorical_crossentropy(y_true ,y_pred) + lmbda * regularizer_value
return loss
model_loss = custom_loss(lmbda= 1 , regularizer_value=regularizer_value)
model.compile(loss=model_loss,optimizer='adam',metrics=['categorical_accuracy'])
分类交叉熵的准确度约为90%,但即使在100个历元之后,现在也降至10%。