tensorflow2和1的一些区别

AttributeError: module 'tensorflow' has no attribute 'placeholder'

原因是在tf2的版本下使用了1的API

改正方法:

import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()

替换 import tensorflow as tf

X = tf.compat.v1.placeholder()

替换X = placeholder()

"AttributeError: module 'tensorflow' has no attribute 'random_normal'"

最新一版的random_normal方法已经换为:random.normal

直接在代码段中修改即可。

原文地址:https://www.cnblogs.com/wex1022/p/14072562.html