tensorflow报错

上一章做了tensorflow的踩坑发现坑不够啊,硬生生有被拉进AttributeError: module ‘tensorflow.compat.v1’ has no attribute 'XXXXXX’这类坑里,这个坑是兼容性问题,我个人觉得应该很少人的会出现这种情况吧?这类报错的原因是“模块“tensorflow”没有属性“XXXXXXXX””
先来看看第一个坑AttributeError: module ‘tensorflow’ has no attribute ‘histogram_summary’
运行:tf.histogram_summary(layer_name + '/outputs',outputs)
报错:AttributeError: module ‘tensorflow’ has no attribute ‘histogram_summary’
解决方法:将上面的tf.histogram_summary 改为:tf.summary.histogram`

第二坑AttributeError: module ‘tensorflow.compat.v1’ has no attribute ‘scalar_summary’
运行:tf.scalar_summary ('loss',cross_entropy)
报错:AttributeError: module ‘tensorflow.compat.v1’ has no attribute ‘scalar_summary’
解决方法:将 tf.scalar_summary改为 tf.summary.scalar

第三坑AttributeError:module ‘tensorflow.compat.v1’ has no attribute ‘merge_all_summaries’
运行:merged = tf.merge_all_summaries() 报错:AttributeError:module 'tensorflow.compat.v1' has no attribute 'merge_all_summaries' 解决方法: tf.merge_all_summaries()改为:tf.summary.merge_all()`

第四坑AttributeError: module ‘tensorflow._api.v2.compat.v1.train’ has no attribute ‘SummaryWriter’
运行:train_writer = tf.train.SummaryWriter'logs/train',sess.graph)
报错:AttributeError: module ‘tensorflow._api.v2.compat.v1.train’ has no attribute ‘SummaryWriter’
解决方法:train_writer = tf.summary.FileWriter('logs/train',sess.graph)

第五坑AttributeError:module ‘tensorflow.compat.v1’ has no attribute ‘initializer_all_variables’
运行:sess.run(tf.initialize_all_variables())
报错:AttributeError:module ‘tensorflow.compat.v1’ has no attribute ‘initializer_all_variables’
解决方法:tf.initialize_all_variables() 改为tf.compat.v1.global_variables_initializer()

你可能感兴趣的:(笔记,tensorflow,python,神经网络,机器学习)