解决module 'tensorflow' has no attribute 'placeholder'

原代码

import tensorflow as tf
xxx
tf.placeholder(tf.float32,shape=(batch_size,4,4,16))

运行报错

module 'tensorflow' has no attribute 'placeholder'

原因分析

tensorflow2调用了tensorflow1的API

解决方案

import tensorflow.compat.v1 as tf
tf.compat.v1.disable_eager_execution()
posted @ 2021-08-16 14:35  Init0ne  阅读(1473)  评论(0编辑  收藏  举报