hi how are you ? thanks for helping
i wrote my network but im having difficulty in plotting the results by helper module as View_classify is not defined . can you please help me to solve the problem ?
i downloaded helper and copied to work place and it didnt work
imported everything needed
transform = transforms.Compose([transforms.ToTensor(),
transforms.Normalize((0.5,), (0.5,))])
trainset = datasets.MNIST(‘MNIST_data/’, download=True, train=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True)
def Sigmoid(x):
return 1 / (1 + torch.exp(-x)) # rewrited
def Softmax(x):
return torch.exp(x) / torch.sum(torch.exp(x), dim=1).view(-1, 1)
model = nn.Sequential(nn.Linear(784, 256),
nn.ReLU(),
nn.Linear(256, 64),
nn.ReLU(),
nn.Linear(64, 10),
nn.LogSoftmax(dim=1))
criterian = nn.NLLLoss()
optimizer = optim.SGD(model.parameters(), lr=0.1)
epochs = 1
for e in range(epochs):
running_loss = 0
for images , labels in trainloader:
images = images.view(images.shape[0], -1)
optimizer.zero_grad()
output = model.forward(images)
loss = criterian(output, labels)
loss.backward()
optimizer.step()
running_loss += loss.item()
else:
print(f"Training loss : {running_loss/ len(trainloader)}")
images , labels = next(iter(trainloader))
img = images[0].view(1 , 784)
with torch.no_grad():
output = model.forward(img)
ps = F.softmax(output , dim = 1)
helper.view_classify(img.view(1 , 28 , 28) , ps)