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

今天把代码放到新服务器上跑,结果报错:“AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’”
原因是:之前代码用tf1.8,新服务器环境是tf2.5,而且代码中调用了tf1中的API,因此会报错,解决方法:
原来代码:

import tensorflow as tf

改过之后的代码:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

问题得到解决。

你可能感兴趣的:(深度学习环境,tensorflow)