我正在使用Keras来定义模型,然后我尝试使用Distributed Tensorflow进行校准,就像here一样。
我曾经在链接
中处理正规化损失model = Sequential()
...... #build keras model
loss = tf.reduce_mean(keras.objectives.mean_squared_error(targets, preds))
# apply regularizers if any
if model.regularizers:
total_loss = loss * 1. # copy tensor
for regularizer in model.regularizers:
total_loss = regularizer(total_loss)
else:
total_loss = loss
但是现在正规制定者的财产已被删除,并且警告建议使用losses
的{{1}}属性,所以我尝试了:
model/layer
但这会导致崩溃。请帮忙
答案 0 :(得分:0)
正确的做法是:
loss = tf.reduce_mean(keras.objectives.mean_squared_error(targets, preds))
total_loss = loss * 1. # copy tensor
for reg_loss in model.losses:
total_loss = total8loss + reg_loss