Skip to content

Instantly share code, notes, and snippets.

@SamratSahoo
Created November 1, 2020 00:05
Show Gist options
  • Select an option

  • Save SamratSahoo/e2304f6d17a6d62b3834899aa72455bd to your computer and use it in GitHub Desktop.

Select an option

Save SamratSahoo/e2304f6d17a6d62b3834899aa72455bd to your computer and use it in GitHub Desktop.
def trainModel(self):
for epoch in range(self.epochs):
for data in self.dataLoader:
image, _ = data
image = image.view(image.size(0), -1)
image = Variable(image)
# Predictions
output = self(image)
# Calculate Loss
loss = self.criterion(output, image)
# Backpropagation
self.optimizer.zero_grad()
loss.backward()
self.optimizer.step()
print('epoch [{}/{}], loss:{:.4f}'
.format(epoch + 1, self.epochs, loss.data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment