Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.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 检查张量是否为占位符?_Python_Tensorflow_Tensor - Fatal编程技术网

Python 检查张量是否为占位符?

Python 检查张量是否为占位符?,python,tensorflow,tensor,Python,Tensorflow,Tensor,占位符在TensorFlow中被识别为张量 isinstance(tf.placeholder(“float”),tf.Tensor)返回True 有没有办法特别检查张量是否是占位符?比如: isinstance(tf.placeholder("float", []), tf.Placeholder) 不幸的是,对于我正在构建的API,tf.Placeholder不是TensorFlow中的实际实例类型。您可以使用op.type检查它: assert tf.placeholder("float

占位符在TensorFlow中被识别为张量

isinstance(tf.placeholder(“float”),tf.Tensor)
返回
True

有没有办法特别检查张量是否是占位符?比如:

isinstance(tf.placeholder("float", []), tf.Placeholder)

不幸的是,对于我正在构建的API,
tf.Placeholder
不是TensorFlow中的实际实例类型。

您可以使用
op.type
检查它:

assert tf.placeholder("float", []).op.type == 'Placeholder'

这里有一个丑陋的方法:导入tensorflow作为tf pl=tf.placeholder(“float”),sess=tf.Session()尝试:sess.run(pl)除了tf.errors.invalidargumeinterror:print(pl.shape)@SamLerman没问题。请考虑将答案标记为接受,如果它解决了你的问题。