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

Error: loading UNet xse_resnext50 #3745

Closed
peterdudfield opened this issue Jul 25, 2022 · 5 comments
Closed

Error: loading UNet xse_resnext50 #3745

peterdudfield opened this issue Jul 25, 2022 · 5 comments

Comments

@peterdudfield
Copy link

Get an error when loading an UNet xse_resnext50.

Please confirm you have the latest versions of fastai, fastcore, and nbdev prior to reporting a bug (delete one): YES

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

from fastai.vision.learner import create_unet_model
from fastai.vision.models.xresnet import xse_resnext50

kwargs = {
    "img_size": (128, 256),
    "n_in": 15,
    "n_out": 25,
    "pretrained": False,
}

model = create_unet_model(arch=xse_resnext50, **kwargs)

Expected behavior

No error and the model to load

Error with full stack trace

Traceback (most recent call last):
  File "/Users/peterdudfield/Documents/Github/nowcasting_forecast/scripts/error.py", line 16, in <module>
    model = create_unet_model(arch=xse_resnext50, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/fastai/vision/learner.py", line 243, in create_unet_model
    model = arch(pretrained)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/fastai/vision/models/xresnet.py", line 99, in xse_resnext50
    def xse_resnext50(n_out=1000, pretrained=False, **kwargs):  return XResNet(SEResNeXtBlock, 4, g1, n_out=n_out, **se_kwargs2, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/fastai/vision/models/xresnet.py", line 47, in __init__
    nn.Linear(block_szs[-1]*expansion, n_out),
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/linear.py", line 97, in __init__
    self.weight = Parameter(torch.empty((out_features, in_features), **factory_kwargs))
TypeError: empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=NoneType), but expected one of:
 * (tuple of ints size, *, tuple of names names, torch.memory_format memory_format, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
 * (tuple of ints size, *, torch.memory_format memory_format, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)


Potential Solution
By changing the line to

model = arch(pretrained=pretrained)

I can do a PR for this if you like

@peterdudfield
Copy link
Author

peterdudfield commented Aug 1, 2022

Feel like we should keep this issue open until it is fixed and released?

@jph00
Copy link
Member

jph00 commented Aug 1, 2022

It's fixed in #3746 . Please let me know if it doesn't work for you.

(We close issues when they're fixed in the repo, not when the release occurs.)

@peterdudfield
Copy link
Author

It's fixed in #3746 . Please let me know if it doesn't work for you.

(We close issues when they're fixed in the repo, not when the release occurs.)

Sorry i was / am a littel confused. #3746 says it was closed with out merging, so just trying to see where the commit is

@jph00
Copy link
Member

jph00 commented Aug 2, 2022

Oh sorry my bad! Yes you're right this is that commit that I slid into the general nbdev2 fixes. You can use git blame to find the commit that fixed it if you're curious.

https://github.com/fastai/fastai/blob/master/fastai/vision/learner.py#L240

@peterdudfield
Copy link
Author

Thanks @jph00

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