Skip to main content

Posts

Showing posts from March, 2024

PyTorch Code for Simple Neural Networks for MNIST Dataset

PyTorch Introduction To Install PyTorch in Linux (Ubuntu), here is the step: $ sudo apt install python3-pip python3 python3-dev $ pip3 install torch torchvision torchaudio notebook MNIST Dataset (0 to 9 handwritten characters) as given below MNIST Dataset Given the dataset of MNIST, do the accuracy analysis of the dataset based on the following hyperparameters using Deep Learning with PyTorch 1. Number of epochs is 4,5,6 and 7 2. batch_size is 64 and 128 3. Number of Hidden layers is 1 and 2 4. Learning rate is 0.001, 0.002 and 0.003 Compute the accuracy in each case. Run the following code either using the Jupyter Notebook or Google Colab . To run the notebook, the command is  $ python3 -m notebook import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader, TensorDataset from torchvision import datasets, transforms from torch.autograd import Variable # Define a simple neural network model class SimpleNN(nn.Module): def __init__(self, i...