This POC predicts both parabolic correction (p_corr) and Ronchi offset in inches (offset_in) from a Ronchi image, conditioning on your mirror/grating parameters (f, lpi). It uses your existing JSONL manifest unchanged.
python3.11 -m venv .venv --copies
source .venv/bin/activate
pip install --upgrade pip wheel setuptools
pip install torch torchvision opencv-python numpy tqdmIf you have one combined manifest (e.g., data/manifest.jsonl), the trainer will split it internally into train/val (80/20 by default):
python src/train.py --manifest data/manifest.jsonl --resize 320Optional split controls:
--val-ratio 0.2--split-seed 42
If you prefer to manage the split yourself:
python src/train.py --train-jsonl data/train.jsonl --val-jsonl data/val.jsonl --resize 320python src/infer.py --image data/images/ronchi_3.0_-0.5_0.0.png --f 3.0 --lpi 100 --resize 320Example output:
{
"p_corr": 0.9731,
"offset_in": -0.5123,
"offset_mm": -13.01,
"notes": "twohead-inch"
}Each line in your manifest looks like:
{"id":"ronchi_3.0_-0.5_0.0",
"image":"data/images/ronchi_3.0_-0.5_0.0.png",
"meta":{"f":3.0,"offset":-0.5,"lpi":100.0},
"labels":{"p_corr":0.0}}meta.offsetis in inches (negative = inside ROC).labels.p_corris your scalar parabolic correction.- Trainer computes normalization stats from the train split only.
| Flag | Default | Meaning |
|---|---|---|
--manifest |
— | Single JSONL; trainer auto-splits into train/val |
--train-jsonl / --val-jsonl |
— | Explicit split files (alternative to --manifest) |
--resize |
320 |
Image size used for both train and infer |
--bs |
32 |
Batch size |
--lr |
3e-4 |
Learning rate |
--epochs |
20 |
Training epochs |
--lambda_z |
0.25 |
Offset-loss weight |
--val-ratio |
0.2 |
(Only with --manifest) validation fraction |
--split-seed |
42 |
(Only with --manifest) reproducible shuffling |
- Two-head CNN (
p_corr,offset_in) with conditioning on (f,lpi). - Loss:
SmoothL1Lossfor both heads; offset head scaled by--lambda_z. - Norm stats saved to
models/label_norm.jsonandmodels/cond_norm.jsoninside the checkpoint as well. - Keep
--resizethe same for both training and inference (default 320).
src/
├─ data.py
├─ model.py
├─ train.py # supports --manifest auto-split OR explicit --train-jsonl/--val-jsonl
├─ infer.py
└─ README.md