This project implements a full image data pipeline so that a deep learning model can learn efficiently for image classification. It covers data loading, preprocessing, augmentation, train/val/test splitting, and training of a convolutional neural network (CNN) on image data with labels stored in MATLAB format.
The work is organized in a single Jupyter notebook, main.ipynb, which includes:
Datahandler– A custom PyTorch-style dataset that:- Loads images from a folder (
imagedata/) and labels fromimagelabels.mat - Supports optional transforms
- Validates images (corruption check, minimum size)
- Converts grayscale to RGB when needed
- Tracks loading errors for debugging
- Loads images from a folder (
- Test/inference transforms: resize, center crop,
ToTensor, normalization - Training transforms: same base pipeline plus data augmentation (e.g. random horizontal flip, random rotation, color jitter) to improve generalization
- Builds the dataset with the chosen transforms
- Splits data into train, validation, and test sets (e.g. with
random_split) - Optionally builds separate dataset instances per split with the right transform (training vs test)
DataLoaderinstances for train, validation, and test with configurable batch size and shuffling- Basic checks to verify batch counts and data flow
ImageClassificationModel– A convolutional neural network (CNN) for image classification:- Convolutional blocks (Conv2d, BatchNorm, ReLU, pooling)
- Fully connected head for class logits
- Designed to run on CPU or GPU
- Device selection (CUDA if available, else CPU)
training_function– one-epoch training loop (forward pass, loss, backward, optimizer step)- Validation loop for monitoring
- Multi-epoch training with loss tracking
- Plotting – training (and optionally validation) loss over epochs with matplotlib
Pytorch_Image_Data_processing_project/
├── main.ipynb # Full pipeline: data → transforms → model → training
├── data/ # Data directory
│ ├── imagedata/ # Images (e.g. image_00001.jpg, image_00002.jpg, ...)
│ └── imagelabels.mat # Labels (MATLAB file: 'labels' array, 1-based class indices)
├── README.md
└── requirements.txt # Python dependencies
Expected data layout:
- Images:
data/imagedata/image_00001.jpg,image_00002.jpg, … (5-digit zero-padded index). - Labels:
data/imagelabels.matwith a variablelabels(shape(1, n)or(n,)), 1-based class indices (the pipeline converts to 0-based).
cd /path/to/Pytorch_Image_Data_processing_projectpython3 -m venv venv
source venv/bin/activate # Linux/macOS
# or: venv\Scripts\activate # Windowspip install -r requirements.txtIf you use GPU, install PyTorch with CUDA from pytorch.org and then install the rest:
pip install torch torchvision # choose your CUDA version on the website
pip install pandas scipy Pillow matplotlib- Place your images in
data/imagedata/with namesimage_00001.jpg,image_00002.jpg, … - Place
imagelabels.matindata/with thelabelsarray (one label per image, 1-based).
- Update the dataset path in
main.ipynbif needed (e.g. replace/content/drive/MyDrive/...with your local path, e.g.dataor./data). - Start Jupyter:
jupyter notebook main.ipynbOr use JupyterLab, VS Code, or Cursor with the Jupyter extension, then run the cells in order.
- Python 3.8+
- PyTorch and torchvision
- pandas, scipy (for reading
imagelabels.mat) - Pillow (PIL) for image loading
- matplotlib for loss plots
- Jupyter to run the notebook
See requirements.txt for version suggestions.