I am trying to run a custom model for UCF-101. I am having a problem while running my code:
I am able to run model.forward(input) and loss but the moment I get into loss.backward() is giving me this error:
Traceback (most recent call last):
File /home/josueortc/anaconda3/lib/python3.6/site-packages/torch/autograd/variable.py, line 156, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph, retain_variables)
File home/josueortc/anaconda3/lib/python3.6/site-packages/torch/autograd/init.py, line 98, in backward
variables, grad_variables, retain_graph)
RuntimeError: element 0 of variables tuple is volatile
The code is:
# compute output for the number of timesteps selected by train loader
optimizer.zero_grad()
output = model.forward(x=input_var)
# Calculate the loss function based on the criterion. For example, UCF-101 is CrossEntropy
loss = criterion(output, target_var)
# measure accuracy and record loss
prec1, prec5 = accuracy(output.data, target, topk=(1, 5))
losses.update(loss.data[0], input.size(0))
top1.update(prec1[0], input.size(0))
top5.update(prec5[0], input.size(0))
loss.backward()
optimizer.step()
As you can see, I am already using optimizer.zero_grad() before computing the loss, so I am not sure why is saying that the element 0 of variables is a tuple.