在Tensorflow中打印张量的值

以下是我完整代码的链接:

https://github.com/roshanDD/YAD2K/blob/master/yad2k/models/keras_yolo.py#L253

我只想打印出名为true_areas的张量的值。我运行了以下代码:

sess = tf.InteractiveSession()true_areas = true_wh[..., 0] * true_wh[..., 1]tf.Print(true_areas, [true_areas], message = "This is True Areas: ")b = tf.add(true_areas, true_areas).eval()

但它返回了以下错误:

Caused by op 'input_2', defined at:  File "learning.py", line 358, in <module>    _main(args)  File "learning.py", line 66, in _main    model_body, model = create_model(anchors, class_names)  File "learning.py", line 185, in create_model    boxes_input = Input(shape=(None, 5))  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/keras/engine/topology.py", line 1388, in Input    input_tensor=tensor)  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/keras/engine/topology.py", line 1299, in __init__    name=self.name)  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 349, in placeholder    x = tf.placeholder(dtype, shape=shape, name=name)  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/ops/array_ops.py", line 1507, in placeholder    name=name)  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1997, in _placeholder    name=name)  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op    op_def=op_def)  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2336, in create_op    original_op=self._default_original_op, op_def=op_def)  File "/home/ubuntu/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1228, in __init__    self._traceback = _extract_stack()InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'input_2' with dtype float     [[Node: input_2 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

它提到的那个占位符是什么?


回答:

错误消息告诉你,你的代码中某个地方定义了一个名为input_2tf.placeholder()

当你想要评估依赖于这个占位符的图时,你需要提供值给这个占位符。应该看起来像这样:

b = tf.add(true_areas, true_areas).eval({input_2: someInputValues})

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注