osmr / imgclsmob

Sandbox for training deep learning networks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in PSPBlock while running inference with ICNet

platvlad opened this issue · comments

Hi!
I am still trying to run ICNet with the following code:

import torch
from pytorch.pytorchcv.model_provider import get_model as ptcv_get_model


net = ptcv_get_model('icnet_resnetd50b_cityscapes', pretrained=True).eval().cuda()
x = torch.rand((1, 3, 224, 224), dtype=torch.float).cuda()
net(x)

I am getting the following error:


File "/home/oem/repo/libs/imgclsmob/examples/play.py", line 7, in 
    net(x)
  File "/home/oem/repo/libs/ML/venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/oem/repo/libs/imgclsmob/pytorch/pytorchcv/models/icnet.py", line 264, in forward
    y3, y2 = self.branch2(x)
  File "/home/oem/repo/libs/ML/venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/oem/repo/libs/imgclsmob/pytorch/pytorchcv/models/common.py", line 2192, in forward
    x = module(x)
  File "/home/oem/repo/libs/ML/venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/oem/repo/libs/imgclsmob/pytorch/pytorchcv/models/icnet.py", line 83, in forward
    x = self.pool(x)
  File "/home/oem/repo/libs/ML/venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/oem/repo/libs/imgclsmob/pytorch/pytorchcv/models/pspnet.py", line 121, in forward
    x = self.branches(x)
  File "/home/oem/repo/libs/ML/venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/oem/repo/libs/imgclsmob/pytorch/pytorchcv/models/common.py", line 1947, in forward
    out = torch.cat(tuple(out), dim=self.axis)
RuntimeError: Sizes of tensors must match except in dimension 2. Got 15 and 7 (The offending index is 0)

Debugging indicates that the error happens when running ICNet PSPBlock.

Use in_size argument for this model:

net = ptcv_get_model('icnet_resnetd50b_cityscapes', in_size=(224, 224), pretrained=True).eval().cuda()

@osmr Thank you so much! Now it works.