MCPcopy Create free account
hub / github.com/Sirwenhao/Deep-Learning-Notes / trainBatch

Function trainBatch

CV/Pytorch_classification/CRNN_PyTorch/train.py:173–188  ·  view source on GitHub ↗
(net, ctiterion, optimizer)

Source from the content-addressed store, hash-verified

171 print('Test loss: %f, accuracy: %f' %(loss_avg.val(), accuracy))
172
173def trainBatch(net, ctiterion, optimizer):
174 data = train_iter.next()
175 cpu_images, cpu_texts = data
176 batch_size = cpu_images.size(0)
177 utils.loadData(image, cpu_images)
178 t, l = converter.encode(cpu_texts)
179 utils.loadData(text, t)
180 utils.loadData(length, l)
181
182 preds = crnn(image)
183 preds_size = Variable(torch.IntTensor([preds.size(0)] * batch_size))
184 cost = criterion(preds, text, preds_size, length) / batch_size
185 crnn.zero_grad()
186 cost.backward()
187 optimizer.step()
188 return cost
189
190for epoch in range(opt.nepoch):
191 train_iter = iter(train_loader)

Callers 1

train.pyFile · 0.85

Calls 1

backwardMethod · 0.80

Tested by

no test coverage detected