It seems that my model loads the wrong file.
The error states that the program is trying to load the wrong architecture: Loading torchvision\models\mobilenet.py, but I trained MobileNetV2.
How to fix this and what did i do wrong?
I used the following to load the model:
model = torch.load("models/MobileNetV2_CLEF_Small10/MobileNetV2_model_29.pt")
This is the creation of the model:
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
# Load pretrained MOBILENET Model
model = models.mobilenet_v2(pretrained=True)
model = model.to(device)
# Freeze model parameters
for param in model.parameters():
param.requires_grad = False
# Change the classifier of the model for Transfer Learning
model.classifier = nn.Sequential(
nn.Dropout(0.2),
nn.Linear(model.last_channel, num_classes),
)
Full error code:
Traceback (most recent call last):
File "C:/Users/faxxe/PycharmProjects/NextGrow/MobileNetV2_metrics.py", line 69, in <module>
model = torch.load("models/MobileNetV3_CLEF_Small10/MobileNetV3_model_29.pt")
File "C:\Users\faxxe\anaconda3\envs\NextGrow\lib\site-packages\torch\serialization.py", line 607, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "C:\Users\faxxe\anaconda3\envs\NextGrow\lib\site-packages\torch\serialization.py", line 882, in _load
result = unpickler.load()
File "C:\Users\faxxe\anaconda3\envs\NextGrow\lib\site-packages\torch\serialization.py", line 875, in find_class
return super().find_class(mod_name, name)
AttributeError: Can't get attribute 'ConvBNReLU' on <module 'torchvision.models.mobilenet' from 'C:\\Users\\faxxe\\anaconda3\\envs\\NextGrow\\lib\\site-packages\\torchvision\\models\\mobilenet.py'>