-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
227 lines (197 loc) · 8.01 KB
/
Makefile
File metadata and controls
227 lines (197 loc) · 8.01 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
.PHONY: help setup explore label train inference analyze clean
# Python interpreter
PYTHON = ./venv/bin/python
help:
@echo "Printer-Offline Detection Model - Available Commands"
@echo ""
@echo "Setup:"
@echo " make setup - Create venv and install dependencies"
@echo ""
@echo "Data Exploration:"
@echo " make explore - Show dataset statistics"
@echo " make explore-visual - Visualize random samples"
@echo " make explore-time - View temporal sequence"
@echo ""
@echo "Labeling:"
@echo " make label - Label 100 images (interactive)"
@echo " make label-50 - Label 50 images"
@echo " make label-200 - Label 200 images"
@echo ""
@echo "Training:"
@echo " make train - Train model (20 epochs)"
@echo " make train-quick - Quick training (10 epochs)"
@echo " make train-long - Extended training (30 epochs)"
@echo ""
@echo "Inference:"
@echo " make inference - Run inference on all images"
@echo " make inference-org - Run inference and organize images"
@echo ""
@echo "Analysis:"
@echo " make analyze - Analyze labels and predictions"
@echo " make analyze-conf - Plot confidence distribution"
@echo " make analyze-uncertain - Find uncertain predictions"
@echo ""
@echo "Phase 2 - Failed Print Detection:"
@echo " make label-failed - Label active images as good/failed"
@echo " make train-failed - Train failed print detection model"
@echo " make status-failed - Show failed print detection status"
@echo ""
@echo "Real-time Monitoring (tail -f style):"
@echo " make monitor - Monitor today's prints (30s poll)"
@echo " make monitor-fast - Monitor with 10s poll"
@echo " make monitor-date DATE=YYYYMMDD - Monitor specific date"
@echo " ./demo_monitor.sh - Demo with existing images"
@echo ""
@echo "Correct Mislabeled Predictions:"
@echo " make correct-time DATE=YYYYMMDD TIME=HH:MM-HH:MM - Correct time range"
@echo " make correct-images IMAGES='path1.jpg path2.jpg' - Correct specific images"
@echo " make correct-retrain DATE=YYYYMMDD TIME=HH:MM-HH:MM - Correct & auto-retrain"
@echo " See QUICK_CORRECTION_GUIDE.md for examples"
@echo ""
@echo "Utilities:"
@echo " make clean - Remove generated files (keep labels)"
@echo " make clean-all - Remove all generated files"
@echo " make status - Show project status"
setup:
python3 -m venv venv
./venv/bin/pip install -r requirements.txt
@echo "Setup complete! Activate with: source venv/bin/activate"
explore:
./venv/bin/python src/explore_images.py --mode stats
explore-visual:
./venv/bin/python src/explore_images.py --mode random --num-samples 12
explore-time:
./venv/bin/python src/explore_images.py --mode temporal --date 20251110
label:
./venv/bin/python src/label_images.py --sample-size 100
label-50:
./venv/bin/python src/label_images.py --sample-size 50
label-200:
./venv/bin/python src/label_images.py --sample-size 200
train:
./venv/bin/python src/train_model.py --epochs 20 --batch-size 32
train-quick:
./venv/bin/python src/train_model.py --epochs 10 --batch-size 32
train-long:
./venv/bin/python src/train_model.py --epochs 30 --batch-size 32
inference:
./venv/bin/python src/inference.py
inference-org:
./venv/bin/python src/inference.py --organize --filter-active
analyze:
./venv/bin/python src/analyze_results.py --mode all
analyze-conf:
./venv/bin/python src/analyze_results.py --mode predictions --plot-confidence
analyze-uncertain:
./venv/bin/python src/analyze_results.py --find-uncertain --uncertainty-threshold 0.6
# Phase 2: Failed Print Detection
label-failed:
./venv/bin/python src/label_failed_prints.py
train-failed:
./venv/bin/python src/train_failed_print_model.py --epochs 20 --batch-size 32
status-failed:
@echo "=== Failed Print Detection Status ==="
@echo ""
@if [ -f "data/active_images.txt" ]; then \
echo "✓ Active images list exists"; \
echo " Total active images: $$(wc -l < data/active_images.txt)"; \
else \
echo "✗ No active images list (run: make inference-org)"; \
fi
@if [ -f "data/failed_print_labels.json" ]; then \
echo "✓ Failed print labels exist"; \
echo " Labeled images: $$(cat data/failed_print_labels.json | grep -o '"good"' | wc -l | xargs echo -n) good, $$(cat data/failed_print_labels.json | grep -o '"failed"' | wc -l | xargs echo -n) failed"; \
else \
echo "✗ No failed print labels yet (run: make label-failed)"; \
fi
@if [ -f "models/failed_print_detector.pth" ]; then echo "✓ Failed print model exists"; else echo "✗ No failed print model (run: make train-failed)"; fi
@echo ""
# Real-time Monitoring
monitor:
@TODAY=$$(date +%Y%m%d); \
if [ -d "printer-timelapses/$$TODAY" ]; then \
./venv/bin/python src/monitor_print.py --image-dir printer-timelapses/$$TODAY --interval 30; \
else \
echo "Error: Directory printer-timelapses/$$TODAY not found"; \
echo "Available dates:"; \
ls -1 printer-timelapses/ | grep -E '^[0-9]{8}$$' | tail -5; \
fi
monitor-fast:
@TODAY=$$(date +%Y%m%d); \
if [ -d "printer-timelapses/$$TODAY" ]; then \
./venv/bin/python src/monitor_print.py --image-dir printer-timelapses/$$TODAY --interval 10; \
else \
echo "Error: Directory printer-timelapses/$$TODAY not found"; \
echo "Available dates:"; \
ls -1 printer-timelapses/ | grep -E '^[0-9]{8}$$' | tail -5; \
fi
monitor-date:
@if [ -z "$(DATE)" ]; then \
echo "Error: DATE parameter required"; \
echo "Usage: make monitor-date DATE=20251110"; \
echo "Available dates:"; \
ls -1 printer-timelapses/ | grep -E '^[0-9]{8}$$' | tail -5; \
elif [ -d "printer-timelapses/$(DATE)" ]; then \
./venv/bin/python src/monitor_print.py --image-dir printer-timelapses/$(DATE) --interval 30; \
else \
echo "Error: Directory printer-timelapses/$(DATE) not found"; \
echo "Available dates:"; \
ls -1 printer-timelapses/ | grep -E '^[0-9]{8}$$' | tail -5; \
fi
# Correct mislabeled predictions
correct-time:
@if [ -z "$(DATE)" ] || [ -z "$(TIME)" ]; then \
echo "Error: DATE and TIME required."; \
echo "Usage: make correct-time DATE=20251111 TIME=08:54-09:25"; \
exit 1; \
fi
$(PYTHON) src/correct_labels.py --date $(DATE) --time-range $(TIME)
correct-images:
@if [ -z "$(IMAGES)" ]; then \
echo "Error: IMAGES required."; \
echo "Usage: make correct-images IMAGES='path1.jpg path2.jpg'"; \
exit 1; \
fi
$(PYTHON) src/correct_labels.py --image-paths $(IMAGES)
correct-retrain:
@if [ -z "$(DATE)" ] || [ -z "$(TIME)" ]; then \
echo "Error: DATE and TIME required."; \
echo "Usage: make correct-retrain DATE=20251111 TIME=08:54-09:25"; \
exit 1; \
fi
$(PYTHON) src/correct_labels.py --date $(DATE) --time-range $(TIME) --auto-retrain
status:
@echo "=== Project Status ==="
@echo ""
@if [ -d "venv" ]; then echo "✓ Virtual environment exists"; else echo "✗ Virtual environment missing (run: make setup)"; fi
@if [ -f "data/labels.json" ]; then \
echo "✓ Labels file exists"; \
echo " Labeled images: $$(cat data/labels.json | grep -o '"offline"' | wc -l | xargs echo -n) offline, $$(cat data/labels.json | grep -o '"active"' | wc -l | xargs echo -n) active"; \
else \
echo "✗ No labels yet (run: make label)"; \
fi
@if [ -f "models/printer_offline_detector.pth" ]; then echo "✓ Trained model exists"; else echo "✗ No trained model (run: make train)"; fi
@if [ -f "data/predictions.json" ]; then \
echo "✓ Predictions exist"; \
echo " Total predictions: $$(cat data/predictions.json | grep -o '"label"' | wc -l)"; \
else \
echo "✗ No predictions yet (run: make inference)"; \
fi
@echo ""
@if [ -L "printer-timelapses" ]; then \
echo "Dataset: $$(find -L printer-timelapses -name '*.jpg' 2>/dev/null | wc -l) images"; \
else \
echo "Dataset: $$(find printer-timelapses -name '*.jpg' 2>/dev/null | wc -l) images"; \
fi
clean:
rm -rf data/organized/
rm -f data/predictions.json
rm -f data/active_images.txt
rm -f data/uncertain_images.txt
rm -f data/*.png
rm -f models/training_history.png
@echo "Cleaned generated files (kept labels and model)"
clean-all: clean
rm -f data/labels.json
rm -f models/*.pth
@echo "Cleaned all generated files"