Reading an Uno table from a single photo

Year
2026

TL;DR

Problem
From one overhead photo of a game, read every player’s hand, the center card and whose turn it is, even when cards overlap, rotate and hide each other.
What we built
A lightweight (12M parameter) customized ResNet-18 with CBAM attention that counts the cards in five zones of the table, pre-trained on 10,000 synthetic two-card images, then moved to real camera photos with multi-stage fine-tuning.
Result
75% accuracy on the course’s Kaggle leaderboard. Spread-out hands are read well; cards buried deep in a fan are still missed.
Stack
Python, PyTorch, Torchvision, NumPy, Pillow, Matplotlib

With only 81 labeled photos and no pretrained weights, the network first learned on tables that never existed.

  • 75% ACCURACY · 12M PARAMS
  • PyTorch
  • Synthetic data
  • Sim-to-real
  • Attention

The approach

  1. Five zones. Each photo is cut on a fixed grid into the four hands and the center pile. Each hand is turned to face its player, and every crop is padded to a square before it is resized to 336 px, so round symbols are never squashed into ovals.
  2. Count, don’t detect. The real photos only list the cards in each hand, with no boxes. So for each of 56 classes (54 card faces and the two turn tokens), the network predicts how many copies, 0 to 5, a zone holds.
  3. Model. A ResNet-18 trained from scratch, with CBAM channel and spatial attention on its last feature map and a counting head. Focal loss keeps the many easy “zero copies” targets from swamping the few cards present.
  4. Synthetic pre-training. 10,000 images of two overlapping cards, built from 56 hand-cut cards on patches of the two real table surfaces, with colour jitter, rotation, perspective, blur, letterbox bars and sensor noise. Pairs rather than single cards, so the network learns to recognize a card by its corners when another one covers it.
  5. Multi-stage fine-tuning. The 81 labeled photos give 405 zone crops, and each training crop gets a turned, rescaled twin. First only the counting head learns from them, then the whole network, each stage with early stopping.

What it achieved

  • 75% accuracy on the course’s Kaggle leaderboard.
  • Lightweight: 12M parameters, trained without pretrained weights. It reads a table in about a quarter of a second on a laptop.
  • 0.737 mean F1 on 81 held-out real hand crops, over the 48 card classes present, counting every copy.
  • It misses rather than invents. Missed cards outnumber invented ones more than two to one, and a card buried in a fan is the typical miss.

Notes

The animation at the top is the submitted model reading a test photo it never saw: it gets 5 of the 6 cards and the turn right, and misses the red 8 in the bottom hand. The photos come from the course’s dataset; since the test labels are hidden, the cards were checked by eye.

A team of 3, as an in-class Kaggle competition; I built most of the pipeline: the synthetic data, the model, the training and the inference. Afterwards I restructured the code into a documented package that reproduces the submission exactly; the repository has the trained weights, every step of the pipeline and the scripts behind the figures on this page.