Refactor into standard Python package with uv

- Move all code into src/mouse_control/ following the src-layout convention,
  with model/collect/train/visualize/inference as separate modules and
  SimpleNet extracted into model.py
- Add hatchling-based pyproject.toml with three CLI entry points
  (mouse-collect, mouse-train, mouse-visualize) and bundle the trained
  ONNX model as a package resource under assets/
- Move training data to data/, delete superseded show.py, remove dead
  imports (numpy, onnxruntime, onnx, onnxsim) and the unused
  visualize_path() helper
- Fix crashes in the collector: guard against destroyed-widget access
  after the n==100 destroy(), and skip save_to_csv when recording is
  off or the path is too short to derive 10 keypoints
- Switch ONNX export to external_data=False so the model ships as a
  single self-contained 19KB file
- Bytes-load the bundled model via importlib.resources so packaging
  remains correct under zip-safe distributions
- Rewrite README around the new layout, commands, and public API
This commit is contained in:
2026-05-12 00:30:08 +08:00
parent 2c482150d4
commit de602365e9
19 changed files with 2170 additions and 299 deletions

20
data/mouse_data_test.csv Normal file
View File

@@ -0,0 +1,20 @@
"-122,-17","0,0","-3,-3","-9,-7","-19,-11","-32,-16","-51,-19","-68,-20","-84,-20","-102,-19","-114,-17"
"-115,-153","0,0","-10,-13","-34,-62","-68,-105","-74,-128","-78,-139","-82,-147","-89,-152","-98,-155","-107,-156"
"-77,193","0,0","-2,9","-12,31","-26,68","-41,106","-54,136","-63,156","-67,170","-71,178","-75,183"
"-85,-86","0,0","-5,-5","-20,-19","-47,-36","-69,-50","-80,-57","-85,-61","-85,-66","-85,-71","-85,-77"
"29,-175","0,0","9,-10","25,-51","32,-90","30,-119","30,-138","30,-146","29,-152","33,-165","36,-175"
"-201,197","0,0","-12,20","-64,77","-113,129","-130,160","-139,175","-152,178","-171,181","-184,183","-191,187"
"-124,-16","0,0","-6,-1","-20,-4","-42,-8","-67,-13","-90,-16","-109,-19","-116,-21","-119,-20","-122,-18"
"-123,53","0,0","-16,7","-47,17","-73,22","-92,24","-106,29","-109,32","-112,38","-115,45","-118,49"
"-146,-125","0,0","0,-12","-12,-40","-33,-58","-64,-84","-95,-115","-116,-123","-126,-125","-134,-122","-141,-122"
"132,49","0,0","9,5","32,11","56,18","81,30","95,36","102,39","108,41","114,44","123,48"
"157,164","0,0","9,10","36,35","72,68","107,97","132,121","146,137","149,145","151,152","154,158"
"-52,48","0,0","-5,5","-14,11","-20,18","-26,24","-29,30","-30,36","-31,41","-32,47","-40,48"
"-135,-106","0,0","-13,-15","-34,-37","-56,-61","-75,-78","-86,-90","-93,-98","-99,-104","-104,-105","-116,-107"
"197,99","0,0","3,6","23,21","62,33","111,48","157,63","177,74","181,82","184,86","192,91"
"129,-194","0,0","7,-7","19,-26","45,-55","77,-85","104,-117","117,-139","118,-149","119,-162","123,-180"
"167,-56","0,0","14,-6","42,-15","79,-23","115,-31","138,-39","149,-45","152,-48","155,-50","159,-51"
"132,143","0,0","28,4","84,24","113,57","116,77","118,88","120,98","120,107","122,124","126,135"
"-113,89","0,0","-11,8","-38,23","-71,41","-81,48","-86,56","-89,62","-92,67","-97,73","-103,79"
"-46,-8","0,0","-2,1","-4,1","-7,1","-11,0","-16,-2","-24,-4","-30,-5","-35,-7","-39,-8"
"-40,181","0,0","0,37","-11,92","-12,120","-12,133","-12,148","-14,168","-21,178","-25,184","-32,184"
1 -122,-17 0,0 -3,-3 -9,-7 -19,-11 -32,-16 -51,-19 -68,-20 -84,-20 -102,-19 -114,-17
2 -115,-153 0,0 -10,-13 -34,-62 -68,-105 -74,-128 -78,-139 -82,-147 -89,-152 -98,-155 -107,-156
3 -77,193 0,0 -2,9 -12,31 -26,68 -41,106 -54,136 -63,156 -67,170 -71,178 -75,183
4 -85,-86 0,0 -5,-5 -20,-19 -47,-36 -69,-50 -80,-57 -85,-61 -85,-66 -85,-71 -85,-77
5 29,-175 0,0 9,-10 25,-51 32,-90 30,-119 30,-138 30,-146 29,-152 33,-165 36,-175
6 -201,197 0,0 -12,20 -64,77 -113,129 -130,160 -139,175 -152,178 -171,181 -184,183 -191,187
7 -124,-16 0,0 -6,-1 -20,-4 -42,-8 -67,-13 -90,-16 -109,-19 -116,-21 -119,-20 -122,-18
8 -123,53 0,0 -16,7 -47,17 -73,22 -92,24 -106,29 -109,32 -112,38 -115,45 -118,49
9 -146,-125 0,0 0,-12 -12,-40 -33,-58 -64,-84 -95,-115 -116,-123 -126,-125 -134,-122 -141,-122
10 132,49 0,0 9,5 32,11 56,18 81,30 95,36 102,39 108,41 114,44 123,48
11 157,164 0,0 9,10 36,35 72,68 107,97 132,121 146,137 149,145 151,152 154,158
12 -52,48 0,0 -5,5 -14,11 -20,18 -26,24 -29,30 -30,36 -31,41 -32,47 -40,48
13 -135,-106 0,0 -13,-15 -34,-37 -56,-61 -75,-78 -86,-90 -93,-98 -99,-104 -104,-105 -116,-107
14 197,99 0,0 3,6 23,21 62,33 111,48 157,63 177,74 181,82 184,86 192,91
15 129,-194 0,0 7,-7 19,-26 45,-55 77,-85 104,-117 117,-139 118,-149 119,-162 123,-180
16 167,-56 0,0 14,-6 42,-15 79,-23 115,-31 138,-39 149,-45 152,-48 155,-50 159,-51
17 132,143 0,0 28,4 84,24 113,57 116,77 118,88 120,98 120,107 122,124 126,135
18 -113,89 0,0 -11,8 -38,23 -71,41 -81,48 -86,56 -89,62 -92,67 -97,73 -103,79
19 -46,-8 0,0 -2,1 -4,1 -7,1 -11,0 -16,-2 -24,-4 -30,-5 -35,-7 -39,-8
20 -40,181 0,0 0,37 -11,92 -12,120 -12,133 -12,148 -14,168 -21,178 -25,184 -32,184