-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
105 lines (89 loc) · 3.59 KB
/
Makefile
File metadata and controls
105 lines (89 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# -------- SixByFive Finish Detector — Makefile --------
# Requires: Python 3.12+, pip-installed requirements.
# On Windows, run via Git Bash (or WSL) so rm/find work.
PY ?= python
TRAIN_IMG ?= 160
EPOCHS ?= 25
# Thresholds for dataset check (tweak as you like)
MIN_CARDS_PER_CLASS ?= 20
MIN_IMAGES_PER_CARD ?= 5
MIN_TOTAL_PER_CLASS ?= 150
# Paths
RAW_DIR := datasets/finish_raw
SPLIT_DIR := datasets/finish_split
PATCH_DIR := datasets/finish_patches
PATCH_TRAIN := $(PATCH_DIR)/train
PATCH_VAL := $(PATCH_DIR)/val
ARTIFACTS := artifacts/finish_v1
# Convenient split ratios (can override at call time, e.g. make split TRAIN=0.8 VAL=0.2 TEST=0.0)
TRAIN ?= 0.8
VAL ?= 0.2
TEST ?= 0.0
.PHONY: help check split patches patches-raw patches-split train eval clean deepclean freeze
help:
@echo "Targets:"
@echo " make check - Validate dataset balance/leakage on $(RAW_DIR)"
@echo " make split - Create card-aware train/val/test splits in $(SPLIT_DIR)"
@echo " make patches - Build patches (prefers split; falls back to raw)"
@echo " make train - Train model from $(PATCH_TRAIN) and $(PATCH_VAL) -> $(ARTIFACTS)"
@echo " make eval - Evaluate exported TFLite on $(PATCH_VAL)"
@echo " make clean - Remove generated patches and current artifacts"
@echo " make deepclean - Remove ALL generated patches and artifacts"
@echo " make freeze - Write pip freeze to requirements.lock.txt"
# 1) Sanity-check raw dataset before splitting
check:
$(PY) tools/check_dataset.py \
--root $(RAW_DIR) \
--min-cards-per-class $(MIN_CARDS_PER_CLASS) \
--min-images-per-card $(MIN_IMAGES_PER_CARD) \
--min-total-per-class $(MIN_TOTAL_PER_CLASS)
# 2) Create card-aware split (never mixes the same card across splits)
split:
$(PY) tools/make_split.py \
--root $(RAW_DIR) \
--out $(SPLIT_DIR) \
--train $(TRAIN) --val $(VAL) --test $(TEST)
# 3) Build patches (auto-crops corners + bottom band)
# Prefer split dirs; if they don't exist, fall back to building from raw (single set).
patches: patches-split
# Build patches from split (train/val must exist)
patches-split:
@if [ -d "$(SPLIT_DIR)/train" ] && [ -d "$(SPLIT_DIR)/val" ]; then \
echo ">> Building patches from split..."; \
$(PY) tools/build_patches.py --src $(SPLIT_DIR)/train --dst $(PATCH_TRAIN); \
$(PY) tools/build_patches.py --src $(SPLIT_DIR)/val --dst $(PATCH_VAL); \
else \
echo "!! $(SPLIT_DIR)/train or /val not found. Falling back to raw."; \
$(MAKE) patches-raw; \
fi
# Build patches directly from raw (single directory of patches)
patches-raw:
$(PY) tools/build_patches.py --src $(RAW_DIR) --dst $(PATCH_DIR)
# 4) Train (explicit dirs). Requires patches in $(PATCH_TRAIN) and $(PATCH_VAL).
train:
@mkdir -p $(ARTIFACTS)
$(PY) tools/train_finish_classifier_explicit.py \
--train_dir $(PATCH_TRAIN) \
--val_dir $(PATCH_VAL) \
--out $(ARTIFACTS) \
--img $(TRAIN_IMG) \
--epochs $(EPOCHS)
# 5) Evaluate exported TFLite quickly on val patches
eval:
$(PY) tools/eval_tflite.py \
--data $(PATCH_VAL) \
--tflite $(ARTIFACTS)/model.int8.tflite \
--labels $(ARTIFACTS)/labels.txt \
--img $(TRAIN_IMG)
# Clean current outputs
clean:
@echo ">> Removing generated patches (train/val) and artifacts at $(ARTIFACTS)"
@rm -rf $(PATCH_TRAIN) $(PATCH_VAL) $(ARTIFACTS)
# Deep clean everything generated
deepclean:
@echo ">> Removing ALL generated patches and artifacts"
@rm -rf $(PATCH_DIR) artifacts/*
# Pin current venv state (optional)
freeze:
$(PY) -m pip freeze > requirements.lock.txt
@echo "Wrote requirements.lock.txt"