MCPcopy Create free account
hub / github.com/pytorch/tutorials / train

Function train

intermediate_source/spatial_transformer_tutorial.py:163–176  ·  view source on GitHub ↗
(epoch)

Source from the content-addressed store, hash-verified

161
162
163def train(epoch):
164 model.train()
165 for batch_idx, (data, target) in enumerate(train_loader):
166 data, target = data.to(device), target.to(device)
167
168 optimizer.zero_grad()
169 output = model(data)
170 loss = F.nll_loss(output, target)
171 loss.backward()
172 optimizer.step()
173 if batch_idx % 500 == 0:
174 print('Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}'.format(
175 epoch, batch_idx * len(data), len(train_loader.dataset),
176 100. * batch_idx / len(train_loader), loss.item()))
177#
178# A simple test procedure to measure the STN performances on MNIST.
179#

Callers 1

Calls 3

stepMethod · 0.80
modelFunction · 0.50
backwardMethod · 0.45

Tested by

no test coverage detected