Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: operands could not be broadcast together with shapes (441,786,4) (1,1,3) (441,786,4) #599

Closed
dreamedrainbow opened this issue Jul 9, 2019 · 9 comments

Comments

@dreamedrainbow
Copy link

No description provided.

@zhengxinvip
Copy link

I got the same error as you , have you fix it? how can I do next? thanks.

@dreamedrainbow
Copy link
Author

dreamedrainbow commented Jul 20, 2019 via email

@zhengxinvip
Copy link

when I use the voc2007 dataset, there is no problem. but when I use my own dataset, I meet this problem, how did you deal with it, does your error is you don not consistent with the path of the pre-trained model?

@zhengxinvip
Copy link

before filtering, there are 8194 images...
after filtering, there are 8194 images...
8194 roidb entries
Loading pretrained weights from data/pretrained_model/resnet101_caffe.pth
Traceback (most recent call last):
File "trainval_net.py", line 310, in
data = next(data_iter)
File "/home/wuwenfu/.conda/envs/pytorch04/lib/python3.5/site-packages/torch/utils/data/dataloader.py", line 286, in next
return self._process_next_batch(batch)
File "/home/wuwenfu/.conda/envs/pytorch04/lib/python3.5/site-packages/torch/utils/data/dataloader.py", line 307, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
ValueError: Traceback (most recent call last):
File "/home/wuwenfu/.conda/envs/pytorch04/lib/python3.5/site-packages/torch/utils/data/dataloader.py", line 57, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/wuwenfu/.conda/envs/pytorch04/lib/python3.5/site-packages/torch/utils/data/dataloader.py", line 57, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/wuwenfu/faster-rcnn.pytorch-master/lib/roi_data_layer/roibatchLoader.py", line 67, in getitem
blobs = get_minibatch(minibatch_db, self._num_classes)
File "/home/wuwenfu/faster-rcnn.pytorch-master/lib/roi_data_layer/minibatch.py", line 30, in get_minibatch
im_blob, im_scales = _get_image_blob(roidb, random_scale_inds)
File "/home/wuwenfu/faster-rcnn.pytorch-master/lib/roi_data_layer/minibatch.py", line 79, in _get_image_blob
cfg.TRAIN.MAX_SIZE)
File "/home/wuwenfu/faster-rcnn.pytorch-master/lib/model/utils/blob.py", line 39, in prep_im_for_blob
im -= pixel_means
ValueError: operands could not be broadcast together with shapes (181,106,4) (1,1,3) (181,106,4)

this is my error.

@matonix
Copy link

matonix commented Nov 25, 2019

I was encountered nearly this (and #616) problem.
This problem may come from a difference of color channel (expected 3 (rgb), but got 4 (rgba)).
So, I was removed alpha channel following issue comments (as just a workaround).

#527 (comment)

I changed lib/model/utils/blob.py line 38-39 to followings.

    im = im.astype(np.float32, copy=False)
    if im.shape[2] == 4:
        # in the event you have an image with alpha channels, drop it for now
        im = im[:, :, :3]
    im -= pixel_means

@matonix
Copy link

matonix commented Dec 6, 2019

Update: I found above code has another issue.
It removes not alpha channel but another color channel (maybe green).
So, here is the fixed one.

    im = im.astype(np.float32, copy=False)
    if im.shape[2] == 4:
        # in the event you have an image with alpha channels, drop it for now
        im = im[:, :, 1:4]
    im -= pixel_means

@peach1995
Copy link

在$lib\model\util\blob.py的P39行前插入: if im.shape[2] == 4: im = im[:, :, :3]

@sjytker
Copy link

sjytker commented Nov 30, 2021

在$lib\model\util\blob.py的P39行前插入: if im.shape[2] == 4: im = im[:, :, :3]

Greate job buddy.

@Lyhour-Chhay
Copy link

@matonix @peach1995 I have 5 channel and I meet this problem as well. This is my error: ValueError: operands could not be broadcast together with shapes (373,548,5) (1,1,3) (373,548,5). How can I solve this problem. Thank you very much sir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants