Skip to content

Instantly share code, notes, and snippets.

@llSourcell
Created February 6, 2020 19:10
Show Gist options
  • Select an option

  • Save llSourcell/a0c1185e1b426ae598bde2be8c321a95 to your computer and use it in GitHub Desktop.

Select an option

Save llSourcell/a0c1185e1b426ae598bde2be8c321a95 to your computer and use it in GitHub Desktop.
#pytorch team
for epoch in range(2): # loop over the dataset multiple times
running_loss = 0.0
for i, data in enumerate(trainloader, 0):
# get the inputs; data is a list of [inputs, labels]
inputs, labels = data
# zero the parameter gradients
optimizer.zero_grad()
# forward + backward + optimize
outputs = net(inputs)
loss = criterion(outputs, labels)
loss.backward()
optimizer.step()
# print statistics
running_loss += loss.item()
if i % 2000 == 1999: # print every 2000 mini-batches
print('[%d, %5d] loss: %.3f' %
(epoch + 1, i + 1, running_loss / 2000))
running_loss = 0.0
print('Finished Training')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment