naomiiiking commited on
Commit
3259f4e
·
verified ·
1 Parent(s): 0cc16da

Fine-tune on webcam captures; add config.json and model card

Browse files
Files changed (3) hide show
  1. README.md +38 -20
  2. config.json +13 -0
  3. model.safetensors +1 -1
README.md CHANGED
@@ -2,31 +2,49 @@
2
  license: mit
3
  tags:
4
  - pytorch
5
- - object-detection
 
6
  ---
7
  ## Paper, scissors, rock classifier
8
 
9
- A TorchVision model trained on images of hands being paper, scissors or rock. Part of my PyTorch Fundamentals (LFD2000) course. Educational use.
10
 
11
- To run:
 
12
 
13
- ```bash
14
- git clone https://github.com/naomiiiking/paper-scissors-rock-classifier.git
15
- cd paper-scissors-rock-classifier
16
- git clone https://github.com/lftraining/LFD2000-resources.git
17
 
18
- uv sync
19
- uv run pipeline.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  ```
21
 
22
- Example output:
23
- ```bash
24
- Test accuracy: 94.62%
25
- Confusion matrix:
26
- tensor([[104, 13, 7],
27
- [ 0, 124, 0],
28
- [ 0, 0, 124]])
29
- paper: precision = 1.00, recall = 0.84
30
- rock: precision = 0.91, recall = 1.00
31
- scissors: precision = 0.95, recall = 1.00
32
- ```
 
2
  license: mit
3
  tags:
4
  - pytorch
5
+ - image-classification
6
+ pipeline_tag: image-classification
7
  ---
8
  ## Paper, scissors, rock classifier
9
 
10
+ A small PyTorch CNN that classifies a hand as paper, rock or scissors. Part of my PyTorch Fundamentals (LFD2000) course. Educational use.
11
 
12
+ - Architecture: `RPSClassifier` (3 conv blocks, then AdaptiveAvgPool, Dropout and Linear), defined in the [training repo](https://github.com/naomiiiking/paper-scissors-rock-classifier).
13
+ - Input: `(N, 3, 128, 128)` RGB, float in `[0, 1]`, with no `Normalize` step. Classes (in `config.json`): `paper`, `rock`, `scissors`.
14
 
15
+ ### Versions
 
 
 
16
 
17
+ - **Current (fine-tuned for webcams):** the CGI model fine-tuned on a mix of the CGI training set and about 300 real webcam crops of a hand in front of a light wall.
18
+ - **Original (CGI only):** trained only on the CGI images (300×300, white background). It is available in this repo's commit history.
19
+
20
+ ### Results
21
+
22
+ | Test set | CGI only | Fine-tuned |
23
+ |---|---|---|
24
+ | CGI test (372 images) | 94.1% | 97.3% |
25
+ | Webcam crops held out (48) | 37.5% | 100%* |
26
+
27
+ \* The held-out webcam crops come from the same sessions as the training crops (same person, wall and lighting). Expect lower accuracy in other conditions.
28
+
29
+ ### Preprocessing (important)
30
+
31
+ A webcam sees a white wall as grey, but the model was trained on pure white backgrounds. Before the usual transform, rescale the crop so the background maps to white, as was done in fine-tuning:
32
+
33
+ ```python
34
+ import numpy as np, torch
35
+ from torchvision.transforms import v2
36
+
37
+ def whiten(rgb): # uint8 HWC RGB
38
+ ref = np.percentile(rgb.reshape(-1, 3), 90, axis=0)
39
+ return np.clip(rgb.astype(np.float32) * (255.0 / np.maximum(ref, 1.0)), 0, 255).astype(np.uint8)
40
+
41
+ transform = v2.Compose([v2.ToImage(), v2.Resize((128, 128)), v2.ToDtype(torch.float32, scale=True)])
42
+ x = transform(whiten(square_crop_rgb)).unsqueeze(0)
43
  ```
44
 
45
+ Use a square crop where the hand fills about a third of the frame, against a plain light background.
46
+
47
+ ### Limitations
48
+
49
+ - The model has no "no hand" class. An empty white image is classified as rock with high confidence, so check that a hand is present first (for example, that at least 5% of pixels are darker than 200 after whitening).
50
+ - The webcam data comes from one person, one background and one room.
 
 
 
 
 
config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "num_classes": 3,
3
+ "class_names": [
4
+ "paper",
5
+ "rock",
6
+ "scissors"
7
+ ],
8
+ "image_size": [
9
+ 128,
10
+ 128
11
+ ],
12
+ "preprocessing": "whiten() background to white before the test transform"
13
+ }
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:8466b5d92d9738da7afbef704d56d8cca6d34f8dac3f71a15a0e1842b1bcc7a7
3
  size 95748
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:acf3660a4f6c3a282304e1340c21f59ce5f87a17226324a883fc94670e16039b
3
  size 95748