Closed ghost closed 4 years ago
cost = criterion(preds, text, preds_size, length) / batch_size # crnn.zero_grad() cost.backward()
cost = criterion(preds, text, preds_size, length) / batch_size
# crnn.zero_grad()
cost.backward()
why you removed crnn.zero_grad()? we need to set the gradients to zero before starting to do backpropragation because PyTorch accumulates the gradients on subsequent backward. So crnn.zero_grad() is necessary
sorry, I made a mistake, I saw optimizer.zero_grad(), which works.
cost = criterion(preds, text, preds_size, length) / batch_size
# crnn.zero_grad()
cost.backward()
why you removed crnn.zero_grad()? we need to set the gradients to zero before starting to do backpropragation because PyTorch accumulates the gradients on subsequent backward. So crnn.zero_grad() is necessary