看以前机器学习课堂笔记,运行代码出现问题提示:
module 'tensorflow' has no attribute 'placeholder'
检查没什么问题,怀疑tensorflow版本兼容问题
把
import tensorflow as tf
改为
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
改完运行,出现问题提示:
AttributeError: module 'tensorflow.compat.v1' has no attribute 'contrib'
查阅多个资料都是降低tensorflow版本,参阅博客:https://blog.csdn.net/maple05/article/details/108186303,将错误提示代码:
tf.add_to_collection('losses', tf.contrib.layers.l2_regularizer(regularizer)(w))
改为:
tf.add_to_collection('losses', regularizer * tf.nn.l2_loss(w))
问题解决。