Mask_rcnn: error: operands could not be broadcast together with shapes (1280,1280,4) (3,)

Created on 20 May 2018  路  23Comments  路  Source: matterport/Mask_RCNN

My training has gone fine, but I'm getting the following error when I try to infer from an image. I'm using the balloon template to apply a splash image. Any help would be very much appreciated.

image                    shape: (3000, 4000, 4)       min:    0.00000  max:  255.00000  uint8
Traceback (most recent call last):
  File "test.py", line 374, in <module>
    video_path=args.video)
  File "test.py", line 238, in detect_and_color_splash
    r = model.detect([image], verbose=1)[0]
  File "/scratch/df525/Mask_RCNN-master/mrcnn/model.py", line 2457, in detect
    molded_images, image_metas, windows = self.mold_inputs(images)
  File "/scratch/df525/Mask_RCNN-master/mrcnn/model.py", line 2356, in mold_inputs
    molded_image = mold_image(molded_image, self.config)
  File "/scratch/df525/Mask_RCNN-master/mrcnn/model.py", line 2757, in mold_image
    return images.astype(np.float32) - config.MEAN_PIXEL
ValueError: operands could not be broadcast together with shapes (1280,1280,4) (3,) 

Most helpful comment

@eyildiz-ugoe

# Remove alpha channel, if it has one
    if image.shape[-1] == 4:
        image = image[..., :3]

All 23 comments

I met this problem too.

Was this error solved?

Yes - You need to remove the alpha channel, because it expects just the RGB channels without the alpha. That's why it's giving the error, it's the 4 in the shape that's the problem, removing alpha makes it 3.

Thank you for the clarification.
png images do have that alpha channel. Scikit-image tends to take it whereas opencv doesn't (in default input mode).

Cool Project. I was a little surprised to learn that balloons were not part of the COCO dataset. I ran on Amazon EC2 P2 instance using the pre-trained model and got good results with both an image (small balloon) and video (giant balloons)!

splash_20180611t050521

animated gif-downsized_large

@doingRsrch I'm facing the same problem. How to remove the channel?

@eyildiz-ugoe

# Remove alpha channel, if it has one
    if image.shape[-1] == 4:
        image = image[..., :3]

Ah, thanks for the fix @doingRsrch 馃槃

Well, not really. I still get the same error.

ValueError: operands could not be broadcast together with shapes (1200,800) (1433,1075) (1433,1075)

I got the same problem, have you fixed it @eyildiz-ugoe

@chibohe No I couldn't. With or without that suggested piece of code, it gives error for me. It is true that the problem could be channels as the error appears to be related to image[:, :, c]) but I don't know what exactly is wrong.

One thing I noticed though: Every time I execute the code, depending on the image it operates, it changes the last two arrays in the error message (since these are the image resolutions) however the first message (the mask, I guess) is always the same.

For instance:

ValueError: operands could not be broadcast together with shapes (1200,800) (856,1200) (856,1200)
ValueError: operands could not be broadcast together with shapes (1200,800) (480,640) (480,640)
ValueError: operands could not be broadcast together with shapes (1200,800) (1075,1433) (1075,1433)

I don't know but it always has this (1200, 800) mask and it tries to fit on the others, and it fails.

You need to avoid PNG images as they seem to be the root of this problem. Using jpg seems fine but png breaks into this issue!

Hi All, I am facing the same issue while classification , images having channels 4 are throwing this error in broadcasting. I tried changing that channels value in IMAGE_SHAPE initialisation to 1 as suggested but that is throwing error in training itself. Is there any way around or do you suggest resizing all images to a particular dimension, not sure if that will harm classification results.Please advice.

[ValueError: operands could not be broadcast together with shapes (1024,1024,4) (3,)]. I am getting this error while I am trying to inference. Please help me out from this situation.

I've got the same problem, @bhuiyanmobasshir94 have you fixed this?

Png To Jpg

from PIL import Image
img = Image.open('path/xx.png')
img = img.convert('RGB')
img.save('path/xx.jpg')

I have got the same problem, Have anyone fixed it?

@Basma-hash have you solved the problem, I am facing the same problem?

@alikanakar the problem was from the png format of nucleus dataset, if you run the code in your custom data, it will be run.

@Basma-hash thank you for your answer but I have already used my own dataset and it doesn't contain any png images. I am still working on it

ValueError: operands could not be broadcast together with shapes (712,) (712,5) any help !

I'm getting the following error while trying to train my mask rcnn on 3 classes instead of 81:

  File "/usr/local/lib/python3.6/dist-packages/mask_rcnn-2.1-py3.6.egg/mrcnn/model.py", line 1772, in data_generator
    batch_images[b] = mold_image(image.astype(np.float32), config)
ValueError: could not broadcast input array from shape (480,640,3) into shape (427,640,3)

@MartinJensen37 i solve the problem of shapes by using
y_test=np.argmax(y_test, axis=1)
u can check my notebook tomoreunderstanding: https://github.com/imen-g/Deep-Learning/blob/master/perceptron_Titanic_kaggle.ipynb

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wadmes picture wadmes  路  4Comments

chrispolo picture chrispolo  路  4Comments

Mabinogiysk picture Mabinogiysk  路  3Comments

techjjun picture techjjun  路  4Comments

LifeBeyondExpectations picture LifeBeyondExpectations  路  4Comments