我正在尝试运行一个开源推理代码来预测给定边界框的多边形,称为 Polygon-RNN++
我正在尝试运行我自己裁剪到 (224,224) 的图像,但我仍然遇到这样的断言错误。
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-8-224b99f63642> in <module>
4 image_np = skimage.transform.resize(image_np,(224,224))
5 #image_np = np.expand_dims(image_np, axis=0)
----> 6 preds = [model.do_test(polySess, image_np, top_k) for top_k in range(_FIRST_TOP_K)]
7
8 # sort predictions based on the eval score to pick the best.
<ipython-input-8-224b99f63642> in <listcomp>(.0)
4 image_np = skimage.transform.resize(image_np,(224,224))
5 #image_np = np.expand_dims(image_np, axis=0)
----> 6 preds = [model.do_test(polySess, image_np, top_k) for top_k in range(_FIRST_TOP_K)]
7
8 # sort predictions based on the eval score to pick the best.
~/Desktop/polyrnn/src/PolygonModel.py in do_test(self, sess, input_images, first_top_k)
61 Return polygon
62 """
---> 63 assert input_images.shape[1:] == (224, 224, 3), 'image must be rgb 224x224 (%s)' % str(input_images.shape)
64 pred_dict = sess.run(
65 self._prediction(),
AssertionError: image must be rgb 224x224 ((224, 224, 4))
我的图像是普通的 RGB 图像,为什么它的形状是 (224,224,4),我怎样才能将它 reshape 为 (224,224,3)?
最佳答案
由于有四个 channel ,您的源图像是 RGBA
格式,其中最后一个 channel 是 alpha/透明 channel 。您可以对数组进行切片以隔离 RGB
channel
remove_alpha_from_image = image[:,:,:3]
另一种方法是这样的
remove_alpha_from_image = cv2.cvtColor(image, cv2.COLOR_RGBA2RGB)
关于python - 断言错误 : image must be rgb 224x224 ((224, 224, 4)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56944173/