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

RuntimeError: Input and output sizes should be greater than 0, but got input (W: 0) and output (W: 128) #8

Closed
MaxTeselkin opened this issue Oct 9, 2023 · 2 comments

Comments

@MaxTeselkin
Copy link

Hi! I am trying to run model inference on custom data, I was able to successfully create category space with corresponding .pth file, but when I tried running demo.py on my image I got the following error:

File "/workspaces/devit/my_demo.py", line 235, in main
    output = model(batched_inputs)[0]
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/devit/detectron2/modeling/meta_arch/devit.py", line 1168, in forward
    other_classes = interpolate(other_classes, self.T, mode='linear') # (Nxclasses) x spatial x T
  File "/devit/detectron2/modeling/meta_arch/devit.py", line 86, in interpolate
    return F.interpolate(seq, T, mode=mode) 
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/functional.py", line 3945, in interpolate
    return torch._C._nn.upsample_linear1d(input, output_size, align_corners, scale_factors)
RuntimeError: Input and output sizes should be greater than 0, but got input (W: 0) and output (W: 128)

Can it be because of the fact that I have only 1 class?

@mlzxy
Copy link
Owner

mlzxy commented Oct 9, 2023

Yes. If you only have one class, consider setting the other class to all zeros instead of interpolating them.

@MaxTeselkin
Copy link
Author

Thanks for help, I added "blank" class to category space using the following code:

if category_space is not None:
        category_space = torch.load(category_space)
        if len(category_space["label_names"]) < 2:
            category_space["label_names"].append("_blank_")
            real_prototypes = category_space["prototypes"]
            blank_prototypes = torch.zeros(1, 1024)
            category_space["prototypes"] = torch.cat((real_prototypes, blank_prototypes), 0)
        model.label_names = category_space["label_names"]
        model.test_class_weight = category_space["prototypes"].to(device)

and it worked

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

2 participants