Skip to content

Instantly share code, notes, and snippets.

@AbsolutelySaurabh
Created December 22, 2018 09:08
Show Gist options
  • Save AbsolutelySaurabh/125628cb3707d8e2369524b55368e7f5 to your computer and use it in GitHub Desktop.
Save AbsolutelySaurabh/125628cb3707d8e2369524b55368e7f5 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
# Build a feed-forward network
model = nn.Sequential(nn.Linear(784, 128),
nn.ReLU(),
nn.Linear(128, 64),
nn.ReLU(),
nn.Linear(64, 10))
# Define the loss
criterion = nn.CrossEntropyLoss()
# Get our data
images, labels = next(iter(trainloader))
# Flatten images
images = images.view(images.shape[0], -1)
# Forward pass, get our logits
logits = model(images)
# Calculate the loss with the logits and the labels
loss = criterion(logits, labels)
print(loss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment