Skip to content

RuntimeError: The shape of the mask [32, 8732] at index 0 does not match the shape of the indexed tensor [279424, 1] at index 0 #173

Open
@17764591637

Description

@17764591637

rps@rps:~/桌面/ssd.pytorch$ python3 train.py
/home/rps/桌面/ssd.pytorch/ssd.py:34: UserWarning: volatile was removed and now has no effect. Use with torch.no_grad(): instead.
self.priors = Variable(self.priorbox.forward(), volatile=True)
/home/rps/桌面/ssd.pytorch/layers/modules/l2norm.py:17: UserWarning: nn.init.constant is now deprecated in favor of nn.init.constant_.
init.constant(self.weight,self.gamma)
Loading base network...
Initializing weights...
train.py:214: UserWarning: nn.init.xavier_uniform is now deprecated in favor of nn.init.xavier_uniform_.
init.xavier_uniform(param)
Loading the dataset...
Training SSD on: VOC0712
Using the specified args:
Namespace(basenet='vgg16_reducedfc.pth', batch_size=32, cuda=True, dataset='VOC', dataset_root='/home/rps/data/VOCdevkit/', gamma=0.1, lr=0.001, momentum=0.9, num_workers=4, resume=None, save_folder='weights/', start_iter=0, visdom=False, weight_decay=0.0005)
train.py:169: UserWarning: volatile was removed and now has no effect. Use with torch.no_grad(): instead.
targets = [Variable(ann.cuda(), volatile=True) for ann in targets]
Traceback (most recent call last):
File "train.py", line 255, in
train()
File "train.py", line 178, in train
loss_l, loss_c = criterion(out, targets)
File "/home/rps/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in call
result = self.forward(*input, **kwargs)
File "/home/rps/桌面/ssd.pytorch/layers/modules/multibox_loss.py", line 97, in forward
loss_c[pos] = 0 # filter out pos boxes for now
RuntimeError: The shape of the mask [32, 8732] at index 0 does not match the shape of the indexed tensor [279424, 1] at index 0

anyone helps,please...

Activity

isaactalx

isaactalx commented on Jun 4, 2018

@isaactalx

I have the same error.Using Pytorch0.4+python3.5.

bobo0810

bobo0810 commented on Jun 7, 2018

@bobo0810

python3.5 and pytorch 0.3.0 no problem

xscjun

xscjun commented on Jun 7, 2018

@xscjun

I have the same error,if I switch the lines 96,97
loss_c = loss_c.view(num, -1)
loss_c[pos] = 0
in multibox_loss.py, this error disappear.
But come with another error :
"File "/home/.../ssd.pytorch/layers/modules/multibox_loss.py", line 115, in forward
loss_l /= N
RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.cuda.LongTensor for argument #3 'other'"
The type of tensor is not match, how can I fix it ?

slomrafgrav

slomrafgrav commented on Jun 8, 2018

@slomrafgrav

@xscjun change line:
N = num_pos.data.sum()
to:
N = num_pos.data.sum().double()
loss_l = loss_l.double()
loss_c = loss_c.double()
this should work

gtwell

gtwell commented on Jul 25, 2018

@gtwell

Anyone has solved this problem? help me tks.

Lin-Zhipeng

Lin-Zhipeng commented on Sep 27, 2018

@Lin-Zhipeng

I have the same error,if I switch the lines 96,97
loss_c = loss_c.view(num, -1)
loss_c[pos] = 0
in multibox_loss.py, this error disappear.
But come with another error :
"File "/home/.../ssd.pytorch/layers/modules/multibox_loss.py", line 115, in forward
loss_l /= N
RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.cuda.LongTensor for argument #3 'other'"
The type of tensor is not match, how can I fix it ?

The “pos” -> torch.Size([32, 8732])
The “loss_c ” ->torch.Size([279424, 1])
when I add one line as :

        loss_c = loss_c.view(pos.size()[0], pos.size()[1]) #add line 
        loss_c[pos] = 0  # filter out pos boxes for now
        loss_c = loss_c.view(num, -1)

Then it worked.

zxt-triumph

zxt-triumph commented on Nov 1, 2018

@zxt-triumph

I have the same error,if I switch the lines 96,97
loss_c = loss_c.view(num, -1)
loss_c[pos] = 0
in multibox_loss.py, this error disappear.
But come with another error :
"File "/home/.../ssd.pytorch/layers/modules/multibox_loss.py", line 115, in forward
loss_l /= N
RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.cuda.LongTensor for argument #3 'other'"
The type of tensor is not match, how can I fix it ?

i have the same error, and how did you solve it finally?

zxt-triumph

zxt-triumph commented on Nov 1, 2018

@zxt-triumph

I have the same error,if I switch the lines 96,97
loss_c = loss_c.view(num, -1)
loss_c[pos] = 0
in multibox_loss.py, this error disappear.
But come with another error :
"File "/home/.../ssd.pytorch/layers/modules/multibox_loss.py", line 115, in forward
loss_l /= N
RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.cuda.LongTensor for argument #3 'other'"
The type of tensor is not match, how can I fix it ?

i have the same error, so how could you figure it out finally?

matthewarthur

matthewarthur commented on Nov 7, 2018

@matthewarthur

What file should be updated?

queryor

queryor commented on Nov 12, 2018

@queryor

I have the same error,if I switch the lines 96,97
loss_c = loss_c.view(num, -1)
loss_c[pos] = 0
in multibox_loss.py, this error disappear.
But come with another error :
"File "/home/.../ssd.pytorch/layers/modules/multibox_loss.py", line 115, in forward
loss_l /= N
RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.cuda.LongTensor for argument #3 'other'"
The type of tensor is not match, how can I fix it ?

change the data type of N to FloatTensor.

usherbob

usherbob commented on Nov 12, 2018

@usherbob

What file should be updated?

You may try to update your file /home/.../ssd.pytorch/layers/modules/multibox_loss.py, and add one line as @LZP4GitHub said above.

subicWang

subicWang commented on Nov 13, 2018

@subicWang

@usherbob python3.6+pytorch0.4.1, I added "loss_c = loss_c.view(pos.size()[0], pos.size()[1]) #add line", but I have another issue. RuntimeError: copy_if failed to synchronize: device-side assert triggered

subicWang

subicWang commented on Nov 14, 2018

@subicWang

Finally, I succeeded.
step1: switch the two lines 97,98:
loss_c = loss_c.view(num, -1)
loss_c[pos] = 0 # filter out pos boxes for now

step2: change the line144 N = num_pos.data.sum() to
N = num_pos.data.sum().double()
loss_l = loss_l.double()
loss_c = loss_c.double()

48 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @leaf918@ashleylid@ynjiun@blueardour@SalahAdDin

        Issue actions

          RuntimeError: The shape of the mask [32, 8732] at index 0 does not match the shape of the indexed tensor [279424, 1] at index 0 · Issue #173 · amdegroot/ssd.pytorch