Thank you Dwight for been still there.
This is my whole “best” code right now:
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import Dataset
from torch.utils.data.sampler import SubsetRandomSampler, BatchSampler, SequentialSampler
import torch.optim as optim
from operator import itemgetter
class CNNModel1():#(nn.Module):
def init(self, fully_layer_1=512, fully_layer_2=256, drop_rate=0.5):
super(CNNModel1, self).init()
self.conv1 = nn.Conv2d(3, 32, 2)
self.bn1 = nn.BatchNorm2d(32)
self.conv2 = nn.Conv2d(32, 64, 2)
self.bn2 = nn.BatchNorm2d(64)
self.conv3 = nn.Conv2d(64, 128, 2)
self.bn3 = nn.BatchNorm2d(128)
self.conv4 = nn.Conv2d(128, 64, 2)
self.bn4 = nn.BatchNorm2d(64)
self.conv5 = nn.Conv2d(64, 32, 2)
self.bn5 = nn.BatchNorm2d(32)
self.pool = nn.MaxPool2d(2, 2)
self.drop_rate = drop_rate
self.fc1 = nn.Linear(32*5*5, fully_layer_1)
self.fc2 = nn.Linear(fully_layer_1, fully_layer_2)
self.fc3 = nn.Linear(fully_layer_2, 2)
def forward(self, x):
# print(x.shape)
x = self.pool(F.relu(self.bn1(self.conv1(x))))
# print(x.shape)
x = self.pool(F.relu(self.bn2(self.conv2(x))))
# print(x.shape)
x = self.pool(F.relu(self.bn3(self.conv3(x))))
# print(x.shape)
x = self.pool(F.relu(self.bn4(self.conv4(x))))
# print(x.shape)
x = self.pool(F.relu(self.bn5(self.conv5(x))))
# print(x.shape)
x = x.view(-1, 32*5*5)
x = F.dropout(F.relu(self.fc1(x)), self.drop_rate)
x = F.dropout(F.relu(self.fc2(x)), self.drop_rate)
x = self.fc3(x)
return x
model = CNNModel1(fully_layer_1=512, fully_layer_2=256, drop_rate=0.5)
model.load_state_dict(torch.load(‘VA2.pth’))
output = model(input)
Terminal answer:--------------------------------------------------------------------------
runfile(‘C:/- DOCKING/Macros/py/inouts/pthModels/pthModels.py’, wdir=‘C:/- DOCKING/Macros/py/inouts/pthModels’)
Traceback (most recent call last):
File “C:- DOCKING\Macros\py\inouts\pthModels\pthModels.py”, line 57, in
model.load_state_dict(torch.load(‘VA2.pth’))
AttributeError: ‘CNNModel1’ object has no attribute ‘load_state_dict’