Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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
Tensorflow ValueError:无法为张量“ResizeBilinear:0”提供形状(1,26,38,3)的值,该张量具有形状“(1,299,299,3)”_Tensorflow_Object Detection_Imagenet - Fatal编程技术网

Tensorflow ValueError:无法为张量“ResizeBilinear:0”提供形状(1,26,38,3)的值,该张量具有形状“(1,299,299,3)”

Tensorflow ValueError:无法为张量“ResizeBilinear:0”提供形状(1,26,38,3)的值,该张量具有形状“(1,299,299,3)”,tensorflow,object-detection,imagenet,Tensorflow,Object Detection,Imagenet,我尝试了使用inceptionv3 train pb文件的对象检测教程,但发现以下错误: ValueError Traceback (most recent call last) <ipython-input-41-1cfc370a11f2> in <module>() 8 image_np_expanded = np.expand_dims(image_np, axis=0) 9 # Actu

我尝试了使用inceptionv3 train pb文件的对象检测教程,但发现以下错误:

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)'
但是图像仍然不能传递给重定尺寸的线性张量

我刚刚更改了此代码:

#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
如何修复此错误? 谢谢你的帮助

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

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

您需要的是在加载到所需的299 x 299像素后调整图像的大小,例如,未测试:

image = array( img.resize( (299, 299) ) ).reshape(1, 299,299,3)
当然,您仍然需要保持重塑,以便在前面添加额外的尺寸,您也可以使用“展开”dims

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