[BUG] Can't use different image size than what's specified in the config
jxtps opened this issue · 5 comments
If I do create_model("efficientdetv2_ds")
which has image_size=(1024, 1024)
in model_config.py and try to feed it some other image size like this:
import torch
from effdet import create_model
model = create_model("efficientdetv2_ds") # Expects (n, 3, 1024, 1024) input
data = torch.ones((1, 3, 640, 640)) # Try different input size, since useful
out = model(data)
print(f"{data.shape} -> {out.shape}")
Then I get a stack trace like:
Traceback (most recent call last):
File "C:\work\tmp\efficientdet-pytorch-master\test.py", line 5, in <module>
out = model(data)
File "C:\work\python_venvs\pt112_cu113\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "C:\work\tmp\efficientdet-pytorch-master\effdet\efficientdet.py", line 603, in forward
x = self.fpn(x)
File "C:\work\python_venvs\pt112_cu113\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "C:\work\tmp\efficientdet-pytorch-master\effdet\efficientdet.py", line 346, in forward
x = self.cell(x)
File "C:\work\python_venvs\pt112_cu113\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "C:\work\tmp\efficientdet-pytorch-master\effdet\efficientdet.py", line 36, in forward
x = module(x)
File "C:\work\python_venvs\pt112_cu113\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "C:\work\tmp\efficientdet-pytorch-master\effdet\efficientdet.py", line 279, in forward
x.append(fn(x))
File "C:\work\python_venvs\pt112_cu113\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "C:\work\tmp\efficientdet-pytorch-master\effdet\efficientdet.py", line 240, in forward
return self.after_combine(self.combine(x))
File "C:\work\python_venvs\pt112_cu113\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "C:\work\tmp\efficientdet-pytorch-master\effdet\efficientdet.py", line 220, in forward
out = torch.stack(
RuntimeError: stack expects each tensor to be equal size, but got [1, 256, 20, 20] at entry 0 and [1, 256, 32, 32] at entry 1
Superficially, this seems to be because ResampleFeatureMap doesn't create a resize op if the input_size
and output_size
are the same, but there's probably also a deeper issue since the size difference isn't 2^k.
Changing _USE_SCALE = False
to True
in efficientdet.py fixes the problem.
Reading the source a little more, the comment # FIXME not sure if scale vs size is better, leaving both in to test for now
would seem to be resolved now if you ask me ;)
Changing
_USE_SCALE = False
toTrue
in efficientdet.py fixes the problem.
Did you try with non-square images?
No, I only used square images.
Ok thanks 🙏