问题描述

AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’
tensorflow2.0 没有placeholder属性问题

解决办法1:

import tensorflow as tf

x = tf.compat.v1.placeholder(shape=[None, 2], dtype=tf.float32)

解决办法2:

import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()
x = tf.placeholder(shape=[None, 2], dtype=tf.float32)

如果方案1可以实现,尽量使用方案1;如果方案1实现的时候可能会有其他问题,则使用方案2,此时请注意:该py环境下尽量不要写tf2.0的代码。

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐