Tensorflow 不推荐使用Keras模型/层正则化特性
我使用Keras来定义一个模型,然后我尝试使用分布式Tensorflow来校准它,就像这样做的 我以前处理正则化器的丢失,就像在链接中一样Tensorflow 不推荐使用Keras模型/层正则化特性,tensorflow,keras,Tensorflow,Keras,我使用Keras来定义一个模型,然后我尝试使用分布式Tensorflow来校准它,就像这样做的 我以前处理正则化器的丢失,就像在链接中一样 model = Sequential() ...... #build keras model loss = tf.reduce_mean(keras.objectives.mean_squared_error(targets, preds)) # apply regularizers if any if model.regularizers: tot
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
但是现在正则化器属性已被去除润滑,并且有一条警告建议使用模型/层的损失
属性
,因此我尝试:
loss = tf.reduce_mean(keras.objectives.mean_squared_error(targets, preds))
total_loss = loss * 1. # copy tensor
for reg_loss in model.losses:
tf.assign_add(total_loss, reg_loss)
但这会导致崩溃。请提供任何帮助正确的做法是:
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
什么是撞车?有消息要发吗?