Histopathology Classification and Knowledge Distillation
One question, two experiments
When a small network does well, where does its accuracy come from? I asked that twice in 2024, in two small PyTorch experiments. One sets architecture and pretraining against each other on a medical-imaging benchmark. The other asks whether a small network learns more from a larger one than from the labels alone.
Both answer it the same way: change exactly one thing, hold everything else fixed, and read the gap. Within each pair the data, the preprocessing, the optimizer, the batch size and the number of epochs are identical, so a difference in the result has one explanation rather than several. That rule shaped the code too. Each experiment is a single script that downloads its own data, builds both models, trains them under one budget defined in one place, and prints the two results side by side, with no configuration through which the two arms could drift apart and nothing carried between runs. Both scripts are in one repository under the MIT license.
Photographs and tissue
The first experiment runs on PathMNIST, small tiles of colorectal-cancer histology in nine tissue classes. On one side is SimpleCNN, two convolution blocks and a fully connected head, small enough to train from scratch in minutes. On the other is ResNet18 carrying ImageNet weights, with a new head for the nine classes and every layer fine-tuned rather than frozen. Both spend the whole budget learning this data; one starts from random weights, the other from features learned on photographs.
Stained tissue looks nothing like a photograph, so it was a fair question whether those features would be worth anything here. They were. After the same short budget, on the same data, the pretrained ResNet18 came out clearly ahead of the network trained from scratch.
What a teacher passes on
A one-hot label says which class an image belongs to and nothing more. A trained network says more: a four that leans toward nine scores nine above seven, and that ordering is knowledge about the shape of the input, learned from the whole training set. An ordinary softmax hides it, because the winning class takes nearly all the probability.
Knowledge distillation brings it out. A teacher CNN is trained on MNIST first. A student of the same design at a fraction of the width then learns from the teacher's outputs, softened by a temperature until the losing classes register, together with the ordinary labels, so it is drawn toward the teacher's judgment without drifting from the ground truth. The control is the same student, on the same data and budget, trained on the labels alone. Keeping the shape fixed and moving only the width is what makes the student's two runs comparable with each other and with the teacher.
The distilled student finished ahead of its twin and closed part of the distance to a teacher several times its size.