2021Experiment
clothingrecognizer
Python · Scrapy · TensorFlow · Kivy · OpenCV · rembg
Overview
The ML project that starts with writing your own fashion scraper.
clothingrecognizer is an ML project with three moving parts: a Scrapy fashion scraper written by hand for H&M, Zara and ASOS, a TensorFlow training pipeline built to turn its catches into a mobile-ready model, and a Kivy desktop app that strips photo backgrounds and files clothing into six categories. It started in 2021 as a face-verification app and was rebuilt for clothing in April 2025.
The build order was data first: the project's own research doc prescribed a real, self-collected dataset before any model work, so the scraper and its processing pipeline came before the training code. The desktop app runs fully local, and the wardrobe manager in this portfolio is its product sibling: Get Dressed stores the closet, this project recognizes what goes into it.
How did a face-verification app become a clothing recognizer?
October 2021: a Kivy desktop app that verified faces with a Siamese network, comparing a webcam frame against 50 reference images through an L1 distance layer. The rebuild kept the shell and widened the question: what is this garment, across the six categories a wardrobe actually has, tops, bottoms, dresses, outerwear, shoes and accessories.
In this portfolio's history that question belongs to the wardrobe line. Get Dressed, the wardrobe manager, catalogs clothes and plans outfits; this project was its research half, the place where the recognition got figured out. The April 2025 rebuild did the swap in one focused evening: file-based input, a new classification layer, and the background-removal work below.
Why write a scraper when Fashion-MNIST exists?
Because the project's own research doc argues for real data. model_research.md surveys Fashion-MNIST (70,000 grayscale 28-pixel images, a smoke test) and DeepFashion (800,000 images with someone else's labeling decisions) and lands on self-collected product photos from shops a real person browses. So the scraper came first, hand-written in Scrapy, one spider per site and one extraction strategy each: H&M parsed with CSS selectors, Zara read from its JSON-LD blocks, ASOS pulled out of an embedded window.asos.pdp.config blob repaired with regex until it parsed.
Under the extraction sits a politeness stack most hobby scrapers skip: robots.txt checks on every start URL, randomized one-to-three-second delays, user-agent rotation, exponential backoff, retries on 403 and 429, a 24-hour HTTP cache, and per-category caps of 100 to 1,000 items. Everything a spider catches then flows through field validation, brand-and-name dedup, image download and a resize pass to 224-pixel training squares, out the other end as JSON, CSV and TFRecord.
How does the desktop app work?
You pick an image, the app strips its background and files it. Background removal runs on rembg, a U²-Net model, with GrabCut and a color-based method as alternatives, and the alpha channel survives: saves land as transparent PNGs in the category folders, each named with its own timestamp.
Classification is layered so the app always returns an answer. The main path loads ImageNet MobileNetV2 from TensorFlow Hub, reads the top five predictions and maps them through a 36-word clothing keyword list down to the six categories; beneath it, an OpenCV HSV detector reads the dominant color as a second opinion. The app is fully local: no accounts, no API keys, and no image ever leaves the machine.
Which background remover won?
The one the numbers picked. All three methods ran on the same test shirt in the same session: rembg cut it out in 1.54 seconds, GrabCut needed 35 to 47. The four-way comparison set, color-based, GrabCut, rembg and the side-by-side, still ships in the repo's output folder, and rembg took the default slot. That comparison is the project's method in one decision: build the options, measure them on the same input, keep the winner.
How does the training side work?
Mobile-first. The dataset builder splits every category into stratified 70/15/15 train, validation and test sets on a fixed seed; the TFRecord exporter packs brand, price, materials, sizes and the image bytes into each example; and the trainer runs a frozen MobileNetV2 backbone with a Dense 256 head beneath it, early stopping, checkpointing on validation accuracy, and a TFLite export at the end so the finished model fits a phone. Transfer learning keeps the scope honest: the backbone already knows images, the head only has to learn six categories.
What carries forward from it?
The habits. Data-first ML, where the scraper and the dataset get built before anyone touches a model. A full pass through every layer of an ML product: collection, politeness, processing, training design, export, and a desktop app on top. And the working parts went straight into the family tree: the rembg pipeline and the alpha-channel handling are exactly what the wardrobe manager needs when its AI features ship. Get Dressed gives the closet; this project built the eyes.
Field notes
- 40 Python files, 8,052 lines across scraper and app: a Scrapy crawler, a TensorFlow training pipeline and a Kivy desktop app in one repo.
- Three spiders, three extraction strategies: H&M via CSS selectors, Zara via JSON-LD, ASOS via a repaired embedded config blob.
- Politeness built in: robots.txt checks on start URLs, randomized 1 to 3 s delays, user-agent rotation, exponential backoff, 403/429 retries, a 24-hour HTTP cache, 100 to 1,000 items per category.
- Every catch flows through field validation, brand-and-name dedup, image download and a 224×224 resize before export as JSON, CSV and TFRecord.
- Training design: stratified 70/15/15 splits on a fixed seed, frozen MobileNetV2 backbone, Dense 256 head, early stopping, checkpointing, TFLite export for mobile.
- Layered classification: ImageNet MobileNetV2 through a 36-word clothing keyword filter, with an OpenCV HSV detector as the second layer.
- Background removal, measured on the same shirt: rembg 1.54 s, GrabCut 35 to 47 s. The four-way comparison set still ships in the repo.
- Six filing categories: tops, bottoms, dresses, outerwear, shoes, accessories. Background-removed saves keep their transparency as PNG.
- Fully local: no accounts, no API keys, no image leaves the machine.
- Origin October 2021 (Siamese face verification against 50 reference images), rebuilt for clothing in April 2025.