mnist-cnn

pytorchv1.0.0

A PyTorch convolutional neural network for handwritten digit recognition. Uses two Conv2d layers with max pooling, dropout regularization, and fully connected classification head. Trains on synthetically generated MNIST-like data with configurable epochs, learning rate, and batch size.

Computer Visionimage-classificationcnndeep-learningbeginner

Install

1openmodelstudio install mnist-cnn

SDK Usage

1import openmodelstudio as oms
2
3model = oms.use_model("mnist-cnn")
4handle = oms.register_model("my-mnist-cnn", model=model)
5job = oms.start_training(handle.model_id, wait=True)

Source Preview(112 lines)

View full source
1"""MNIST digit classification with a simple CNN."""
2
3import torch
4import torch.nn as nn
5import torch.nn.functional as F
6
7class MNISTNet(nn.Module):
8 def __init__(self):
9 super().__init__()
10 self.conv1 = nn.Conv2d(1, 32, 3, padding=1)
11 self.conv2 = nn.Conv2d(32, 64, 3, padding=1)
12 self.pool = nn.MaxPool2d(2, 2)
13 self.fc1 = nn.Linear(64 * 7 * 7, 128)
14 self.fc2 = nn.Linear(128, 10)
15
16 def forward(self, x):
17 x = self.pool(F.relu(self.conv1(x)))
18 x = self.pool(F.relu(self.conv2(x)))
19 x = x.view(-1, 64 * 7 * 7)
20 return self.fc2(F.relu(self.fc1(x)))

Details

Author
openmodelstudio
License
MIT
Source
112 lines
Version
1.0.0

Dependencies

torch>=2.0
torchvision>=0.15
numpy>=1.24

Hyperparameters

epochs5

Number of training epochs

lr0.001

Learning rate

batch_size64

Training batch size

View on GitHub