Data — from a folder to a dataset
Until now the data simply was there: load_fashion returned ready-made
tensors. Nobody asked where they came from, whether they were balanced, or
whether something leaked from validation into training.
Your own photographs have none of that. Someone has to decide which photograph trains and which one checks, what size it is, and what range of numbers it enters the network in — and mistakes in these decisions do not raise an error. They produce a lovely number that later does not hold up.
What you get, and what this lesson honestly says
We use a stand-in dataset here. The lesson texts and numbers were measured
not on your categories but on four FashionMNIST classes saved as PNGs: tshirt,
pullover, coat, sneaker, 200 pictures each, 28 × 28 grayscale. That way
the folder layout is exactly what yours will be, and the numbers are
reproducible.
Your photographs will be harder: different lighting, backgrounds, angles. Your numbers will differ and should not be expected to match ours — what carries over is the workflow.
How much data is enough?
Our experience, not a rule:
- 200 per category (640 for training, 160 for validation) — the stand-in set used below. Validation has 160 pictures, so one picture = 0.6 points.
- 60 per category (48 for validation) — we tried that too (in step 6). It works, but the validation number "jumps" (across three seeds from 85.4 % to 93.8 %) because one picture = 2.1 points.
- Start with ~100 per category if you can. Below ~60 we did not test — with only a dozen or so validation pictures per class the number says very little.
- Set aside another ~20 per category — a test folder that you never touch while training. In lesson 11 you evaluate the final model on it.
The lesson climbs in steps
- Watch. A folder becomes batches of tensors: how many pictures, how they are split, what the numbers are. You write nothing.
- Prepare your photographs. A small
prepare.py— ready-made. - Fill in the holes. The split into training and validation, and normalisation — two lines missing.
- Write it yourself. Augmentation and class balancing — empty skeletons.
- Run it and measure — honestly.
- Two traps that data preparation sets for you without any error message.
What this lesson promises — and what it does not
It is natural to expect that better data preparation raises accuracy. We measured it and it does not, at least not on our dataset:
- augmentation almost entirely closes the gap between training and validation, but validation accuracy does not go up (92.5 % without, 91.9 % with — a tie; one picture = 0.6 points);
- class balancing does not raise overall accuracy, but it exposes a problem that the overall number hides.
Data work makes your number correct and repeatable, not necessarily bigger. That is a more modest promise, but it is a real one.
Guess before you read on
- Will augmentation (random flips, rotations, shifts) raise validation accuracy? By how much?
- Take a class with only 20 pictures when the others have 200. Will the overall accuracy be ... high or low? Will it tell you the truth about that small class?