Open main menu

CDOT Wiki β

Changes

DPS921/PyTorch: Convolutional Neural Networks

663 bytes added, 15:43, 29 November 2020
Implementation of Neural Network
== Implementation of a Neural Network ==
x = self.fc4(x)
return F.log_softmax(x, dim = 1)
 
 
''' 5. Use an optimizer to train the neural network. By passing the 1-dimensional tensor of pixel maps of each image in the training
''' data set to the optimizer, it allows the optimizer to update the weight value of each of the layers in our neural network.
 
import torch.optim as optim
 
optimizer = optim.Adam(net.parameters(), lr=0.001)
 
EPOCHS = 3
 
for epoch in range(EPOCHS):
for data in trainset:
# data is a batch of featuresets and labels
X, y = data
net.zero_grad()
output = net(X.view(-1,28*28))
loss = F.nll_loss(output, y)
loss.backward()
optimizer.step()
print(loss)
== Getting Started With Jupyter ==