Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tensorflow不再知道占位符或只与cpu一起工作_Python_Tensorflow_Tensorflow2.0 - Fatal编程技术网

Python Tensorflow不再知道占位符或只与cpu一起工作

Python Tensorflow不再知道占位符或只与cpu一起工作,python,tensorflow,tensorflow2.0,Python,Tensorflow,Tensorflow2.0,您好,我的tensorflow脚本有问题。在过去的几年里,剧本没有出现任何问题。 现在我在重新安装tensorflow后发现错误: AttributeError: module 'tensorflow' has no attribute 'placeholder' 我试过: import tensorflow as tf 与 要替换,则会导致错误: AttributeError: module 'tensorflow' has no attribute 'truncated_normal'

您好,我的tensorflow脚本有问题。在过去的几年里,剧本没有出现任何问题。 现在我在重新安装tensorflow后发现错误:

AttributeError: module 'tensorflow' has no attribute 'placeholder'
我试过:

import tensorflow as tf

要替换,则会导致错误:

AttributeError: module 'tensorflow' has no attribute 'truncated_normal'
因此,我将其解压并卸载了tensorflow和:

pip3.6.exe install tensorflow == 1.9
安装。 现在脚本可以运行了,但只能在CPU上运行。 因此:

pip3.6.exe install tensorflow-gpu
输出结果如下所示:

ERROR: tensorflow 1.9.0 has requirement tensorboard <1.10.0,> = 1.9.0, but you'll have tensorboard 2.1.0 which is incompatible.
ERROR: tensorboard 2.1.0 has requirement setuptools> = 41.0.0, but you'll have setuptools 39.1.0 which is incompatible.
Installing collected packages: tensorboard, tensorflow-gpu
  Attempting uninstall: tensorboard
    Found existing installation: tensorboard 1.9.0
    Uninstalling tensorboard-1.9.0:
      Successfully uninstalled tensorboard-1.9.0
Successfully installed tensorboard-2.1.0 tensorflow-gpu-2.1.0
从中我出来了

tf.placeholder()

tf.truncated_normal()
完成了

tf.compat.v1.placeholder()

tf.random.truncated_normal()
但这导致:

File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\ops\check_ops.py", line 2101, in assert_scalar
    % (message or '', tensor.name, shape))
ValueError: Expected scalar shape for keepProb:0, saw shape: <unknown>.
文件“C:\Users\user\AppData\Local\Programs\Python36\lib\site packages\tensorflow\u core\Python\ops\check\u ops.py”,第2101行,在assert\u scalar中 %(消息或“”、张量、名称、形状)) ValueError:keepProb:0的标量形状应为,锯形:。 我该怎么办? 我必须用什么来替换占位符?或者我必须安装哪些版本的配置? 为什么没有更多的占位符


他们不赞成占位符的概念,因为它太复杂而难以理解,特别是对于初学者来说。他们将其替换为
tf.variable
。如果你以前有过这样的经历:
x=tf.placeholder(tf.float32[1227227,3])

您必须将其更改为:

x=tf.Variable(tf.zeros(shape=(1227227,3)),name='x',dtype=tf.float32)

对于
截断的\u normal
,您必须更改:

initial=tf.truncated\u normal(形状,stddev=0.1)

致:

initial=tf.random.trunched\u normal(
shape,mean=0.0,stddev=1.0,dtype=tf.dtypes.float32,seed=None,name=None
)


升级到tensorflow 2.0后。

ok,我安装了tensorflow-gpu-2.1.0并更改了以下行

旧的:

新的:


旧的:

新的:


旧的:

新的:


现在,在调用第一个“tf.Variable”时出现以下错误:


这就是版本兼容性问题。现在tensorflow的版本是2.1.0,它与1.x有很多不同。首先,最好使用下面的命令将TensorFlow python文件从1.x版转换为2.x版

tf\u升级\u v2--infle文件\u v1.py--outfile文件\u v2.py


您以后可能会遇到其他问题,但请先完成上述工作。以后的其他问题可能更容易解决。

您已经安装了
tensorflow gpu v2.1.0
尝试安装
v1.9
至于
tensorflow
脚本运行,但似乎仍然只使用CPUok以及它的功能:initial=tf.truncated\u normal(shape,stddev=0.1)
tf.compat.v1.placeholder()

tf.random.truncated_normal()
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\ops\check_ops.py", line 2101, in assert_scalar
    % (message or '', tensor.name, shape))
ValueError: Expected scalar shape for keepProb:0, saw shape: <unknown>.
x = tf.placeholder(tf.float32, [None, self._sizeX, self._sizeY, self._inputdim], name="x")
y = tf.placeholder(tf.float32, [None, self._outputdim], name="y")
x = tf.Variable(tf.zeros(shape=(self._sizeX, self._sizeY, self._inputdim)), name='x', dtype=tf.float32)
y = tf.Variable(tf.zeros(shape=(self._outputdim)), name='y', dtype=tf.float32)
keep_prob = tf.placeholder(tf.float32, name="keepProb")
keep_prob = tf.Variable(name='keepProb', dtype=tf.float32)
initial = tf.truncated_normal(shape, stddev=0.1)
initial = tf.random.truncated_normal(shape, mean=0.0, stddev=1.0, dtype=tf.dtypes.float32, seed=None, name=None)
  File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\ops\variables.py", line 262, in __call__
    return super(VariableMetaclass, cls).__call__(*args, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py", line 1411, in __init__
    distribute_strategy=distribute_strategy)
  File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py", line 1489, in _init_from_args
    raise ValueError("initial_value must be specified.")
ValueError: initial_value must be specified.