Holmeyoung / crnn-pytorch

Pytorch implementation of CRNN (CNN + RNN + CTCLoss) for all language OCR.
MIT License
377 stars 105 forks source link

why crnn.zero_grad() was removed in training? #46

Closed ghost closed 4 years ago

ghost commented 4 years ago

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

ghost commented 4 years ago

sorry, I made a mistake, I saw optimizer.zero_grad(), which works.