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

TypeError: SequentialWithIdx.forward() missing 1 required positional argument: 'indices'" #7475

Open
KumoLiu opened this issue Feb 19, 2024 · 1 comment

Comments

@KumoLiu
Copy link
Contributor

KumoLiu commented Feb 19, 2024

Describe the bug
Quicknat not work as expected.

To Reproduce

from monai.networks.nets import Quicknat
import torch

model = Quicknat(
            num_classes=1,
            num_channels=1,
            num_filters=64,
            se_block=None
        ).to("cuda:0")
data = torch.rand((1, 1, 32, 32)).to("cuda:0")

out = model(data)
Error Log

{
	"name": "TypeError",
	"message": "SequentialWithIdx.forward() missing 1 required positional argument: 'indices'",
	"stack": "---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 14
      5 model = Quicknat(
      6             num_classes=1,
      7             num_channels=1,
   (...)
     10             se_block=None
     11         ).to(\"cuda:0\")
     12 data = torch.rand((1, 1, 32, 32)).to(\"cuda:0\")
---> 14 out = model(data)
     17 # export
     18 # convert_to_onnx(model, dataloader, filename='quicknat.onnx', verify=True, use_ort=True)

File /usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py:1511, in Module._wrapped_call_impl(self, *args, **kwargs)
   1509     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1510 else:
-> 1511     return self._call_impl(*args, **kwargs)

File /usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py:1520, in Module._call_impl(self, *args, **kwargs)
   1515 # If we don't have any hooks, we want to skip the rest of the logic in
   1516 # this function, and just call forward.
   1517 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1518         or _global_backward_pre_hooks or _global_backward_hooks
   1519         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1520     return forward_call(*args, **kwargs)
   1522 try:
   1523     result = None

File /workspace/MONAI/monai/networks/nets/quicknat.py:438, in Quicknat.forward(self, input)
    437 def forward(self, input: torch.Tensor) -> torch.Tensor:
--> 438     input, _ = self.model(input, None)
    439     return input

File /usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py:1511, in Module._wrapped_call_impl(self, *args, **kwargs)
   1509     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1510 else:
-> 1511     return self._call_impl(*args, **kwargs)

File /usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py:1520, in Module._call_impl(self, *args, **kwargs)
   1515 # If we don't have any hooks, we want to skip the rest of the logic in
   1516 # this function, and just call forward.
   1517 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1518         or _global_backward_pre_hooks or _global_backward_hooks
   1519         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1520     return forward_call(*args, **kwargs)
   1522 try:
   1523     result = None

File /workspace/MONAI/monai/networks/nets/quicknat.py:62, in SequentialWithIdx.forward(self, input, indices)
     60 def forward(self, input, indices):
     61     for module in self:
---> 62         input, indices = module(input, indices)
     63     return input, indices

File /usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py:1511, in Module._wrapped_call_impl(self, *args, **kwargs)
   1509     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1510 else:
-> 1511     return self._call_impl(*args, **kwargs)

File /usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py:1520, in Module._call_impl(self, *args, **kwargs)
   1515 # If we don't have any hooks, we want to skip the rest of the logic in
   1516 # this function, and just call forward.
   1517 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1518         or _global_backward_pre_hooks or _global_backward_hooks
   1519         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1520     return forward_call(*args, **kwargs)
   1522 try:
   1523     result = None

File /workspace/MONAI/monai/networks/nets/quicknat.py:46, in SkipConnectionWithIdx.forward(self, input, indices)
     45 def forward(self, input, indices):
---> 46     return super().forward(input), indices

File /workspace/MONAI/monai/networks/layers/simplelayers.py:129, in SkipConnection.forward(self, x)
    128 def forward(self, x: torch.Tensor) -> torch.Tensor:
--> 129     y = self.submodule(x)
    131     if self.mode == \"cat\":
    132         return torch.cat([x, y], dim=self.dim)

File /usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py:1511, in Module._wrapped_call_impl(self, *args, **kwargs)
   1509     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1510 else:
-> 1511     return self._call_impl(*args, **kwargs)

File /usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py:1520, in Module._call_impl(self, *args, **kwargs)
   1515 # If we don't have any hooks, we want to skip the rest of the logic in
   1516 # this function, and just call forward.
   1517 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1518         or _global_backward_pre_hooks or _global_backward_hooks
   1519         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1520     return forward_call(*args, **kwargs)
   1522 try:
   1523     result = None

TypeError: SequentialWithIdx.forward() missing 1 required positional argument: 'indices'"
}

Quicknat is introduced by this PR.
Looks like the unit tests are always not tested since squeeze_and_excitation is not a required dependency.

@unittest.skipUnless(has_se, "squeeze_and_excitation not installed")

@KumoLiu
Copy link
Contributor Author

KumoLiu commented Feb 19, 2024

Hi @vgonzalezd, @Al3xand1a, and @ge96lip, could you please help take a look at this issue?
Thanks in advance!

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

1 participant