tensorflow2.0报错没有 placeholder 属性解决方案

  • Post author:
  • Post category:其他




问题描述

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的代码。



版权声明:本文为lbj1260200629原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。