Hey, my model is giving me around the same loss and not training. Can someone pls help me.
trainset = torchvision.datasets.CIFAR10(root='.', train=True,
download=False, transform=transform)
trainloader = torch.utils.data.Data`Preformatted text`Loader(trainset, batch_size=32,
shuffle=True, num_workers=2)
testset = torchvision.datasets.CIFAR10(root='.', train=False,
download=False, transform=transform)
testloader = torch.utils.data.DataLoader(testset, batch_size=32,
shuffle=False, num_workers=2)
classes = ('plane', 'car', 'bird', 'cat',
'deer', 'dog', 'frog', 'horse', 'ship', 'truck')
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.features = nn.Sequential(
nn.Conv2d(3, 6, 3),
nn.ReLU(inplace=True),
nn.MaxPool2d(2, 2),
nn.Conv2d(6, 16, 5),
nn.ReLU(inplace=True),
nn.Conv2d(16, 20, 5),
nn.ReLU(inplace=True),
torch.nn.Conv2d(20, 27, 3),
nn.ReLU(inplace=True)
)
self.classifier = nn.Sequential(
nn.Linear(27 * 5 * 5, 120),
nn.ReLU(inplace=True),
nn.Linear(120, 84),
nn.ReLU(inplace=True),
nn.Linear(84, 10)
)
def forward(self, x):
x = self.features(x)
x = x.view(-1, 27 * 5 * 5)
x = self.classifier(x)
return x
net = Net().cuda()
criterion = nn.CrossEntropyLoss().cuda()
init_lr=0.01
opt = torch.optim.Adam(net.parameters(), lr=init_lr)
for epoch in tqdm_notebook(range(10)):
forward_times=4
running_loss = 0.0
for i, data in tqdm_notebook(enumerate(trainloader, 0)):
# get the inputs
inputs, labels = data
if torch.cuda.is_available():
# in versions of Torch < 0.4.0 we have to wrap these into torch.autograd.Variable as well
inputs, labels = Variable(inputs).cuda(), Variable(labels).cuda()
# zero the parameter gradients
# forward + backward + optimize
outputs = net(inputs)
loss = criterion(outputs, labels)
loss.backward()
opt.step()
opt.zero_grad()
if i%100:
print(i,loss)
# print statistics
running_loss += loss.data[0]
if i % 2000 == 1999: # print every 2000 mini-batches
print('[%d, %5d] loss: %.3f' %
(epoch + 1, i + 1, running_loss / 2000))
running_loss = 0.0
print('Finished Training')