View_classify in helper is not defined

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 =, 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.Linear(256, 64),
nn.Linear(64, 10),
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)

    output = model.forward(images)
    loss = criterian(output, labels)



    running_loss += loss.item()

    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)

Could you check your current working directory via !ls, if you are using IPython?
I guess you might have copied the file to a different location?
Also, did you include the necessary methods or classes to use view_classify?

1 Like

hello , thank you so much for helping

i read the helper module i downloaded it didn’t contain view_classify in it

sorry but i didn’t understand your last sentence

im not good at drawing in python i just downloaded helper and wrote the code i saw in instructon . im coding with pycharm ,

can we use pyplot instead ? what should i write ?

thanks again

This file should contain the view_classify method. You could either download it again and import the method or copy-paste it to your script.

1 Like

thank you so much
it worked brilliantly

1 Like