Skip to content

Blake Rayvid

Menu
  • About
  • Portfolio
Menu

Deep Learning for Clothing Classification

Posted on July 23, 2026July 31, 2026 by Blake

To practice convolutional neural network (CNN) design, I worked on a classification problem that was more challenging than toy datasets but still lightweight enough to train quickly on my local machine.

The following details the design of a 3-block CNN architecture and the lessons I learned from training it on clothing image data.

Dataset Characteristics

Clothing classification with the Fashion-MNIST dataset (28×28 grayscale images) is an excellent deep learning project for several reasons:

  • High inter-class similarity: Items like shirts, coats, and pullovers share similar silhouettes. The model cannot rely solely on outlines; it must learn to distinguish subtle features such as collar shapes, zippers, and fabric textures.
  • Fast iteration: The small image size allows training to complete in a few minutes on a standard laptop. This makes it easier to prototype, test changes, and debug the training pipeline quickly.
  • Regularization requirements: Because the images are small and the class boundaries are close, models can easily overfit by memorizing noise in the training set. This makes the dataset highly sensitive to regularization choices.

Fashion-MNIST examples

CNN Architecture Design

The network uses three sequential convolutional blocks to extract features hierarchically:

  • Block 1 (1 to 32 channels): Captures low-level features such as edges and basic boundaries.
  • Block 2 (32 to 64 channels): Combines these edges into local shapes and textures.
  • Block 3 (64 to 128 channels): Extracts more complex structural patterns.

Max-pooling layers halve the spatial dimensions after each block, reducing the representation from 28×28 down to 3×3 while the channel depth doubles.

To stabilize training, I applied several design decisions:

  • Batch Normalization: I added BatchNorm2d to every convolutional block. Normalizing the activations across the batch kept the gradients stable and improved convergence speed.
  • Spatial Dropout (Dropout2d): Standard dropout randomly zeroes out individual pixels. Because neighboring pixels in an image are highly correlated, the network can easily work around pixel-level dropout. I used 2D Spatial Dropout in the convolutional blocks instead. This drops entire feature channels, forcing the network to learn distributed representations rather than relying on specific feature maps.
  • Classifier Regularization: After the final convolutional block, the remaining 3×3 feature maps are flattened and passed to a dense layer with 256 units. This fully connected layer is regulated by a 40% dropout rate to reduce overfitting before the final classification layer.

Architecture schematic

Training Configuration

The training setup incorporated several adjustments to improve generalization:

  • Data Augmentation: I applied random horizontal flips and minor random rotations (up to 10 degrees) to the training images to make the model less sensitive to slight variations in orientation.
  • Optimizer: I used AdamW instead of standard Adam. AdamW decouples weight decay from the gradient updates, which handles L2 regularization more effectively and helps keep the model weights small.
  • Learning Rate Schedule: A Cosine Annealing scheduler was used to smoothly decay the learning rate over 15 epochs, helping the model settle into a stable local minimum toward the end of training.

Performance Analysis

To evaluate the model’s performance beyond overall accuracy, I calculated class-specific precision, recall, F1-score, and specificity.

Class NamePrecisionRecall (Sens)F1-ScoreSpecificity
T-shirt/top0.87450.88500.87970.9859
Trouser0.99500.98700.99100.9994
Pullover0.88470.88200.88330.9872
Dress0.91630.94100.92850.9904
Coat0.86730.88900.87800.9849
Sandal0.99090.97500.98290.9990
Shirt0.78820.74800.76760.9777
Sneaker0.94520.98400.96420.9937
Bag0.98990.98500.98750.9989
Ankle boot0.98360.96200.97270.9982
  • Overall Accuracy: 92.38%
  • Macro Precision: 0.9236
  • Macro Recall: 0.9238
  • Macro F1-Score: 0.9235
  • Macro Specificity: 0.9915

Observations

The class-by-class metrics highlight the specific structural challenges of the dataset:

  • Distinct Classes: The model achieved high F1-scores on classes with distinct shapes, such as Trousers (0.9910) and Bags (0.9875).
  • Ambiguous Classes: The model struggled most with Shirts (F1-score of 0.7676), which were frequently misclassified as Coats or T-shirts. This is a common issue given the structural overlap between these categories in low-resolution grayscale images.

Analyzing these metrics helped clarify where the 3-block architecture reaches its limits and demonstrated how spatial regularization and data augmentation affect classification performance across similar categories.

🔗 View on GitHub

Tags: NumPy, Python, PyTorch
Categories: Data Science

Post navigation

Java Elevator Simulator →

Categories

  • Data Science
  • Exploration
  • Finance
  • Health
  • Interactive
  • Optimization
  • Utilities

Tags

D3.js Desmos Docker Express.js FFmpeg Flask Gemini API Google Maps API HTML/CSS/JS Java Java-AWT Java-Swing MATLAB Matplotlib Netlify NetworkX Next.js NLP Node.js NumPy P5.js Pandas Pillow PostgreSQL Python PyTorch QuantConnect Railway React.js Scikit-Learn SciPy TensorFlow Tesseract WeasyPrint YFinance API

© 2026 Blake Rayvid. All rights reserved.