Thank you for your patient and time, you are teaching me a lot. After those changes i run my code and then i get the following error:
File “C:/Users/user/.spyder-py3/original_cnn.py”, line 115, in 
loss.backward()
File “C:\Users\user\Anaconda3\lib\site-packages\torch\tensor.py”, line 166, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph)
File “C:\Users\user\Anaconda3\lib\site-packages\torch\autograd_init_.py”, line 99, in backward
allow_unreachable=True)  # allow_unreachable flag
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
Loop code:
for epoch in range(num_epochs):
   for data in train_loader: 
       img, label= data
       label = Variable(label).cuda()
       img = Variable(img).cuda()
       nova=to_img(img)
       
       st = time.time()

       optimizer.zero_grad()

       output = model(img)

       label=torch.Tensor([0,1,2])
       output=torch.Tensor(3,3)
       loss=criterion(label,torch.argmax(output,dim=1).type(torch.FloatTensor))

       loss.backward()

       optimizer.step()

       iter += 1

I searched about this and tried a few changes in my code, like loss.backward(requires_grad=True) but still not working: TypeError: backward() got an unexpected keyword argument ‘requires_grad’
Or this : label.requires_grad=True
(torch.argmax(output,dim=1).type(torch.FloatTensor)).requires_grad=True
But i can´t find a solution, can you help me in this?