index-v002: SD-card web trainer, vision regression (distance + confidence)

Pairs with firmware-v002.ino. Desktop Chrome or Edge. Add data, train, analyze, clean, debug; weights go back to the SD card unchanged.

1. Data source

Pick the root of the SD card (the folder that contains images/ and header/). Chrome or Edge asks for read/write permission.
Nothing loaded yet.

2. Classes and data

Firmware limit: one target per class folder. To give an image a different distance, move it to that class (inspector).
Lines to paste into the sketch (layout, distances, folder names); then reflash:
REC
Frames are square-cropped to 240x240, JPEG-encoded and decoded again like stored images. The device flips its sensor (CAM_VFLIP) to correct how the board is mounted, so the page does not flip by default. Mirror, flip and brightness need bench tuning so device images and page images look alike. Browser files are named img_w... and sort differently from device files (img_ and milliseconds), which can put the whole "last N" hold-out in one source.
step through a class, X marks a bad sample

3. Train

Browser-only training knobs (not in the firmware):
STOP keeps the model in memory and does not save.
Gradients are summed over the batch like the firmware. Training steps are bounded and a non-finite loss rolls back to the last good epoch with half the learning rate.

4. Analyze

Worst residuals (blank images ranked by false confidence)

5. Infer (live)

Start the camera, then live inference.

6. Save

Saving never happens automatically. An existing header/myWeights.bin is copied to myWeights.bin.bak first. Weights file = 6 float32 arrays (little-endian) then calibration slope and offset.

7. Console

8. Serial monitor (Web Serial)

115200 baud
Close the Arduino IDE serial monitor first. Opening the port can reboot the board. Chrome or Edge only. Debug frames over a UART bridge are about 100 times slower than native USB.

Device view

Waiting for a debug frame.