Open main menu

CDOT Wiki β

Changes

DPS921/PyTorch: Convolutional Neural Networks

627 bytes added, 12:53, 29 November 2020
Implementation of Neural Network
''' 2. Download the needed datasets from the MNIST database, partition them to into feasible data batch sizes.
train = datasets.MNIST('', train = True, download = True, transform=transforms.Compose([transforms.ToTensor()]))
''' 3. Import the necessary modules to define the structure of our the neural network
import torch.nn as nn
import torch.nn.functional as F
 
''' 4. Define the class structure of the CNN, in the following case, we have defined 4 linear layers, that output to three functions
that execute rectified linear processing as an activation method. '''
 
class Net(nn.Module):
def __init__(self):
super().__init__()
self.fc1 = nn.Linear(784, 64)
self.fc2 = nn.Linear(64, 64)
self.fc3 = nn.Linear(64, 64)
self.fc4 = nn.Linear(64, 10)
def forward(self, x):
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = F.relu(self.fc3(x))
x = self.fc4(x)
return F.log_softmax(x, dim = 1)
== Getting Started With Jupyter lab ==