问题描述

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

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐