【TensorFlow 2.x】AttributeError: module ‘tensorflow_core.compat.v1‘ has no attribute ‘contrib‘

TensorFlow2.0之后的版本删掉了l2正则化函数tf.contrib.layers.l2_regularizer

修改建议:

 

将源码:

regularzer = tf.contrib.layers.l2_regularizer(regularzation_rate)
regularzation = regularzer(weight1) + regularzer(weight2)

 

修改为

regularzation = regularzation_rate * tf.nn.l2_loss(weight1) + regularzation_rate * tf.nn.l2_loss(weight2)

 

你可能感兴趣的:(【TensorFlow 2.x】AttributeError: module ‘tensorflow_core.compat.v1‘ has no attribute ‘contrib‘)