Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Defining gradient descent
learning_rate = 0.01
criterion = nn.NLLLoss()
optimiser = optim.SGD(model.parameters(), lr=learning_rate)
# Training the network
epochs = 5
for e in range(epochs):
for images, labels in train_loader:
# Flattening an input image to vector
images = images.view(images.shape[0], -1)
# Initialising model parameters' gradient to zero
# Propogating forward: input -> hidden -> output
output = model.forward(images)
# Calculating error at output
loss = criterion(output, labels)
# Propogating an error backward: output -> hidden -> input
# Updating weight
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.