错误 运行 label_image 与 output_layer=pool_3
Error running label_image with output_layer=pool_3
图像识别教程中的tensorflow练习建议运行 c++示例与
--output_layer=pool_3
。我试过 运行 这个,但出现错误:
$ bazel-bin/tensorflow/examples/label_image/label_image --output_layer=pool_3
I tensorflow/core/common_runtime/local_device.cc:40] Local device intra op parallelism threads: 4
I tensorflow/core/common_runtime/direct_session.cc:58] Direct session inter op parallelism threads: 4
W tensorflow/core/common_runtime/executor.cc:1076] 0x558ae6a5d210 Compute status: Invalid argument: input must be 2-dimensional
[[Node: top_k = TopK[T=DT_FLOAT, k=5, _device="/job:localhost/replica:0/task:0/cpu:0"](Const/_0)]]
E tensorflow/examples/label_image/main.cc:311] Running print failed: Invalid argument: input must be 2-dimensional
[[Node: top_k = TopK[T=DT_FLOAT, k=5, _device="/job:localhost/replica:0/task:0/cpu:0"](Const/_0)]]
我错过了什么?
这里的问题是 image recognition tutorial 中的 TensorFlow 代码需要额外修改才能使 --output_layer=pool_3
选项生效:
One can specify this by setting --output_layer=pool_3
in the C++ API example and then changing the output tensor handling.
要更改输出张量处理,您需要修改代码 below this line in label_image/main.cc
. The PrintTopLabels()
function calls GetTopLabels()
, which takes a single 2-D (batch x classes) tensor—assumed to be the output of a tf.nn.softmax()
containing a probability distribution for the labels in a batch of images—and builds a small TensorFlow graph using the tf.nn.top_k()
op 。 pool_3
层输出一个four-dimensional(batch x height x width x depth)张量,需要额外处理。
附加处理留作 reader 的练习。但是,您可以尝试一些操作:
将输出重塑为two-dimensional(batch x features)矩阵,并训练一个(或更多)全连接层来识别你自己训练数据中的特征。
通过沿深度维度对其进行切片来可视化池化层的输出,并使用 tf.image.encode_png()
操作将切片编码为图像。
N.B. 由于文档更好,我提供了指向 Python 文档的链接,而不是相应的 C++ API.您可能会发现修改 Python code for Inception inference 更容易(多了!)。
图像识别教程中的tensorflow练习建议运行 c++示例与
--output_layer=pool_3
。我试过 运行 这个,但出现错误:
$ bazel-bin/tensorflow/examples/label_image/label_image --output_layer=pool_3
I tensorflow/core/common_runtime/local_device.cc:40] Local device intra op parallelism threads: 4
I tensorflow/core/common_runtime/direct_session.cc:58] Direct session inter op parallelism threads: 4
W tensorflow/core/common_runtime/executor.cc:1076] 0x558ae6a5d210 Compute status: Invalid argument: input must be 2-dimensional
[[Node: top_k = TopK[T=DT_FLOAT, k=5, _device="/job:localhost/replica:0/task:0/cpu:0"](Const/_0)]]
E tensorflow/examples/label_image/main.cc:311] Running print failed: Invalid argument: input must be 2-dimensional
[[Node: top_k = TopK[T=DT_FLOAT, k=5, _device="/job:localhost/replica:0/task:0/cpu:0"](Const/_0)]]
我错过了什么?
这里的问题是 image recognition tutorial 中的 TensorFlow 代码需要额外修改才能使 --output_layer=pool_3
选项生效:
One can specify this by setting
--output_layer=pool_3
in the C++ API example and then changing the output tensor handling.
要更改输出张量处理,您需要修改代码 below this line in label_image/main.cc
. The PrintTopLabels()
function calls GetTopLabels()
, which takes a single 2-D (batch x classes) tensor—assumed to be the output of a tf.nn.softmax()
containing a probability distribution for the labels in a batch of images—and builds a small TensorFlow graph using the tf.nn.top_k()
op 。 pool_3
层输出一个four-dimensional(batch x height x width x depth)张量,需要额外处理。
附加处理留作 reader 的练习。但是,您可以尝试一些操作:
将输出重塑为two-dimensional(batch x features)矩阵,并训练一个(或更多)全连接层来识别你自己训练数据中的特征。
通过沿深度维度对其进行切片来可视化池化层的输出,并使用
tf.image.encode_png()
操作将切片编码为图像。
N.B. 由于文档更好,我提供了指向 Python 文档的链接,而不是相应的 C++ API.您可能会发现修改 Python code for Inception inference 更容易(多了!)。