0

我尝试了使用 inceptionv3 train pb 文件的“object_detection”教程,但我遇到了以下错误:

ValueError                                Traceback (most recent call last)
<ipython-input-41-1cfc370a11f2> in <module>()
  8   image_np_expanded = np.expand_dims(image_np, axis=0)
  9   # Actual detection.
---> 10   output_dict = run_inference_for_single_image(image_np, detection_graph)
 11   # Visualization of the results of a detection.
 12   vis_util.visualize_boxes_and_labels_on_image_array(

<ipython-input-38-7704143af1b0> in run_inference_for_single_image(image, graph)
 33       # Run inference
 34       output_dict = sess.run(tensor_dict,
---> 35                              feed_dict={ResizeBilinear: np.expand_dims(image, 0)})
 36 
 37       # all outputs are float32 numpy arrays, so convert types as appropriate

~/anaconda3/lib/python3.6/site-
packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
893     try:
894       result = self._run(None, fetches, feed_dict, options_ptr,
--> 895                          run_metadata_ptr)
896       if run_metadata:
897         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

~/anaconda3/lib/python3.6/site-
packages/tensorflow/python/client/session.py in _run(self, handle, 
fetches, feed_dict, options, run_metadata)
1102                 'Cannot feed value of shape %r for Tensor %r, '
1103                 'which has shape %r'
-> 1104                 % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
1105           if not self.graph.is_feedable(subfeed_t):
1106             raise ValueError('Tensor %s may not be fed.' % subfeed_t)

ValueError: Cannot feed value of shape (1, 26, 38, 3) for Tensor 'ResizeBilinear:0', which has shape '(1, 299, 299, 3)'

因此,我尝试使用下面的代码来调整图像大小:

 image = array(img).reshape(1, 299,299,3)

但是图像仍然无法传递给resizeBilinear张量。

我刚刚更改了这段代码:

#MODEL_NAME = 'ssd_mobilenet_v1_coco_2017_11_17'
#MODEL_FILE = MODEL_NAME + '.tar.gz'
#DOWNLOAD_BASE ='http://download.tensorflow.org/models/object_detection/'
#upper code is origin model preparation 
PATH_TO_CKPT = /tmp/output_graph.pb
PATH_TO_LABELS = /tmp/output_labels.txt
NUM_CLASSES = 2

我该如何解决这个错误?谢谢您的帮助!

4

1 回答 1

1

问题是Inception V3需要一个大小为 299 x 299 像素和 3 个通道(彩色图像)的图像输入。因此它需要一个形状为 (1, 299, 299, 3) 的输入数组。

您正在尝试向其提供尺寸为 26 x 38 像素的小得多的图像。整形是一种数组操作,它沿维度重新排列数组的元素,而不改变元素的数量

您需要的是在加载到所需的 299 x 299 像素后调整图像的大小,使用类似的东西PIL.Image.resize(),像这样(未经测试):

image = array( img.resize( (299, 299) ) ).reshape(1, 299,299,3)

注意,您仍然需要保持重塑以预先添加额外的尺寸(您也可以使用 expand_dims。)

于 2018-04-26T13:30:09.607 回答