我正在尝试打印张量的值但得到一个奇怪的错误。有人能告诉我如何正确打印张量的值吗?
def getCertitude1(result):
return (Z/result)*100
def getCertitude2(result):
return (result/Z)*100
result = sess.run(cost, feed_dict={X: np.matrix(np.array(reps[0][1]))})
if result is not None:
confidence = (tf.cond(tf.less(result, 0.53), lambda: getCertitude1(result), lambda: getCertitude2(result)))
print("result: " + str(result) + " confidence: "+str(confidence))
输出:
result: 0.488459 confidence: Tensor("cond/Merge:0", shape=(?, 128), dtype=float32)
所以我尝试如下:
confidence = sess.run(tf.cond(tf.less(result, 0.53), lambda: getCertitude1(result), lambda: getCertitude2(result)))
print("result: " + str(result) + " confidence: "+str(confidence))
然后输出:
2017-10-02 13:31:24.098024: W tensorflow/core/framework/op_kernel.cc:1148] Invalid argument: Shape [-1,128] has negative dimensions
2017-10-02 13:31:24.098114: E tensorflow/core/common_runtime/executor.cc:644] Executor failed to create kernel. Invalid argument: Shape [-1,128] has negative dimensions
[[Node: X = Placeholder[dtype=DT_FLOAT, shape=[?,128], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
2017-10-02 13:31:24.100074: W tensorflow/core/framework/op_kernel.cc:1148] Invalid argument: Shape [-1,128] has negative dimensions
2017-10-02 13:31:24.100207: E tensorflow/core/common_runtime/executor.cc:644] Executor failed to create kernel. Invalid argument: Shape [-1,128] has negative dimensions
[[Node: X = Placeholder[dtype=DT_FLOAT, shape=[?,128], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
2017-10-02 13:31:24.100679: W tensorflow/core/framework/op_kernel.cc:1148] Invalid argument: Shape [-1,128] has negative dimensions
2017-10-02 13:31:24.100755: E tensorflow/core/common_runtime/executor.cc:644] Executor failed to create kernel. Invalid argument: Shape [-1,128] has negative dimensions
[[Node: X = Placeholder[dtype=DT_FLOAT, shape=[?,128], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Traceback (most recent call last):
File "autoEncoder2.py", line 173, in <module>
confidence = sess.run(tf.cond(tf.less(result, 0.53), lambda: getCertitude1(result), lambda: getCertitude2(result)))
File "/home/yalishanda/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 789, in run
run_metadata_ptr)
File "/home/yalishanda/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 997, in _run
feed_dict_string, options, run_metadata)
File "/home/yalishanda/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1132, in _do_run
target_list, options, run_metadata)
File "/home/yalishanda/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1152, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape [-1,128] has negative dimensions
[[Node: X = Placeholder[dtype=DT_FLOAT, shape=[?,128], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Caused by op u'X', defined at:
File "autoEncoder2.py", line 91, in <module>
X = tf.placeholder("float", [None, n_visible], name='X')
File "/home/yalishanda/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1530, in placeholder
return gen_array_ops._placeholder(dtype=dtype, shape=shape, name=name)
File "/home/yalishanda/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1954, in _placeholder
name=name)
File "/home/yalishanda/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
op_def=op_def)
File "/home/yalishanda/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2506, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/home/yalishanda/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1269, in __init__
self._traceback = _extract_stack()
InvalidArgumentError (see above for traceback): Shape [-1,128] has negative dimensions
[[Node: X = Placeholder[dtype=DT_FLOAT, shape=[?,128], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
有人能告诉我如何纠正这个问题吗?