This repository contains a PyTorch implementation of a neural network designed to classify images from the Fashion MNIST dataset. The dataset consists of grayscale images of various clothing items, with each image being 28x28 pixels.
The project includes the following key components:
-
Data Loading and Preprocessing: The Fashion MNIST dataset is loaded and split into training, validation, and test sets. The images are normalized and transformed into tensors for processing by the neural network.
-
Model Architecture: A simple neural network is built using PyTorch's
nn.Sequential
with layers including fully connected (linear) layers, ReLU activations, and dropout for regularization. The model outputs class probabilities usingLogSoftmax
. -
Training and Validation: The model is trained using the Adam optimizer and negative log likelihood loss (
NLLLoss
). The training and validation losses, as well as validation accuracy, are tracked and printed for each epoch. -
Visualization: The training and validation losses are plotted to observe the model's performance over time. Additionally, the model's predictions on sample images are visualized alongside the predicted class probabilities.
-
Image Prediction: Three options are provided to predict images:
- Random Image from Dataset: Use a random image from the Fashion MNIST dataset to predict the class.
- Image from URL: Preprocess and predict the class of an image from a given URL.
- Image from Local File: Upload a local file to predict the class using the trained model. The predictions are then visualized along with the input image.
- Python 3.x
- PyTorch
- torchvision
- matplotlib
- numpy
- requests
- PIL (Pillow)
You can install the required packages using:
pip install torch torchvision matplotlib numpy requests pillow
To train the model, simply run the main script. The model will train for 25 epochs, and the training and validation losses will be displayed.
python train.py
To predict the class of a random image from the Fashion MNIST dataset, use the following command:
python predict_random.py
To predict the class of an image from a URL, use the following command:
python predict_url.py --image_url "http://example.com/image.jpg"
To predict the class of an image from a local file, use the following command:
python predict_file.py --image_path "path/to/image.jpg"
The model achieves a validation accuracy of approximately 88% after 25 epochs of training. The trained model can accurately predict the class of various clothing items in the Fashion MNIST dataset.
Given an image of an Tshirt, the model predicts the class with a high probability.
This project was done in collaboration with Prajan Kannan.
This project is licensed under the MIT License - see the LICENSE file for details.
🔭 A Simple guy who does coding for fun
👯 Willing to collaborate in all types of Projects
🤝 I’m looking for help with Neural Networking
🌱 I’m currently learning ML and Deep Learning, FIGMA (In near future)
This update includes the information on the notebook's ability to use a random image from the dataset, a URL, or an uploaded image for predictions.