Deep-Learning
Deep-Learning copied to clipboard
AttributeError: 'function' object has no attribute 'named_parameters'
I tried to pip install fastai==2.4 but couldn't as colab couldn't find 2.4 version of fastai. so i just installed pip install fastai. whenever i try to run the trained model, i get the error
AttributeError Traceback (most recent call last)
3 frames /usr/local/lib/python3.10/dist-packages/fastai/vision/learner.py in _get_first_layer(m) 32 "Access first layer of a model" 33 c,p,n = m,None,None # child, parent, name ---> 34 for n in next(m.named_parameters())[0].split('.')[:-1]: 35 p,c=c,getattr(c,n) 36 return c,p,n
AttributeError: 'function' object has no attribute 'named_parameters'
please let me know how to fix it. Thanks.
Have you tried installing the 2.4 version using directly the .whl file?
how do i install directly from the .whl file?
If you make the following modifications to the function build_res_unet
, it should work properly.
def build_res_unet(n_input=1, n_output=2, size=256):
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
body = create_body(resnet18(), pretrained=True, n_in=n_input, cut=-2)
net_G = DynamicUnet(body, n_output, (size, size)).to(device)
return net_G
If you make the following modifications to the function
build_res_unet
, it should work properly.def build_res_unet(n_input=1, n_output=2, size=256): device = torch.device("cuda" if torch.cuda.is_available() else "cpu") body = create_body(resnet18(), pretrained=True, n_in=n_input, cut=-2) net_G = DynamicUnet(body, n_output, (size, size)).to(device) return net_G
Change the import a bit like,
from torchvision.models.resnet import resnet18