This repository contains PyTorch implementations for training, evaluating, and deploying simple feed-forward neural networks on the MNIST and Fashion MNIST datasets. It includes:
- MNIST – Handwritten digit classification.
- Fashion MNIST (fmnist) – Clothing article classification (basic training and evaluation).
- Fashion MNIST v2 (fmnist2) – Fashion MNIST classification with extended code and testing.
- Streamlit App (appfmnist) – Interactive web app to upload images and predict Fashion MNIST classes.
.
├── mnist.py # MNIST training, evaluation, and visualization
├── fmnist.py # Fashion MNIST training, evaluation, and visualization
├── fmnist2.py # Fashion MNIST variant with additional test image visualization
├── appfmnist.py # Streamlit app for Fashion MNIST predictions
├── data/ # MNIST/Fashion MNIST datasets (downloaded automatically)
├── fashion_mnist_model.pth # Saved trained model weights (generated after training)
Install dependencies:
pip install torch torchvision streamlit pillow matplotlib numpyTrain and evaluate on MNIST:
python mnist.py- Downloads MNIST dataset automatically.
- Trains a simple feed-forward neural network.
- Prints accuracy on test dataset.
- Displays sample predictions.
Train and evaluate on Fashion MNIST:
python fmnist.py- Trains a neural network on Fashion MNIST.
- Saves trained weights to
fashion_mnist_model.pth. - Evaluates accuracy.
- Displays predictions on sample test images.
Alternate Fashion MNIST pipeline with sample/random image testing inside Streamlit:
python fmnist2.py- Loads trained weights.
- Allows testing on random Fashion MNIST images or uploaded images.
Run the web app:
streamlit run appfmnist.py- Upload your own
.jpg,.png,.jpegimages. - See predicted class in real time.
- Uses the model trained in
fmnist.py.
All models use the same simple feed-forward architecture:
Input Layer: 784 nodes (28x28 pixels)
Hidden Layer1: 128 nodes (ReLU)
Hidden Layer2: 64 nodes (ReLU)
Output Layer: 10 nodes (class scores)
- MNIST – Handwritten digits (0–9).
- Fashion MNIST – Clothing items (T-shirt/top, Trouser, Pullover, Dress, Coat, Sandal, Shirt, Sneaker, Bag, Ankle boot).
Both datasets are loaded using:
from torchvision import datasets, transformsand normalized to range [-1, 1].
Example output from MNIST/Fashion MNIST scripts:
| Image | Predicted |
|---|---|
| 🖼 Digit "7" | 7 |
| 👕 T-shirt/top | T-shirt/top |
- Add convolutional neural network (CNN) for higher accuracy.
- Support batch image predictions in the Streamlit app.
- Deploy app on cloud services (e.g., Streamlit Cloud, Heroku).
This project is licensed under the MIT License.