CRICKET / code /README.md
d9993r's picture
Add files using upload-large-folder tool
14c58d8 verified
|
Raw History Blame Contribute Delete
12.4 kB

Cricket data foundry pipeline (offline prototype, v0.4.3)

Turns the videos in datasets/ into delivery clips, a seven-event timeline, 2D measurements, reviewer-corrected labels, coach notes, SFT training pairs, Tier-1 Parquet tables and a versioned dataset release, plus a review website where people correct what the models proposed. Every path is relative to the project folder.

CRICKET-SFT-DATA/
  code/       all scripts, config.yaml, ontology.yaml, experiments/
  datasets/   your video folders
  models/     YOLO weights (auto-downloaded)
  results/    all outputs (safe to delete and rebuild)

Run

python code/tests/test_pipeline.py            # self-test, no GPU or models needed
python code/run_all.py --max-per-video 3      # quick first look
python code/run_all.py                        # everything (reuses finished work)
python code/serve.py                          # review site with editing: http://127.0.0.1:8765/web/

Opening results/web/index.html directly also works, read-only.

Stages

# Stage Script Output
1 Ingest: checksum, fps, rights record ingest.py registry/sources.json
2 Pass 1: cuts and release candidates (pose cached) segment.py segments/
3 Pass 2: events, posture, ball, QC, clips analyze.py, events.py deliveries/<id>/
4 Merge review edits, build SFT pairs review.py, pitch.py, sft.py jsonl/
5 Tier-1 tables + schema validation tables.py tables/*.parquet, qa/schema_report.json
6 Dataset release + Appendix D checklist release.py releases/<id>/
7 Review website build_web.py, web_template.html web/

Stages 4-7 take seconds and never touch video, so python code/run_all.py --stages sft,tables,release,web (which the review server runs after every save) is cheap.

What maps to which part of the standard

  1. Seven-event timeline (7.3, Fig. 3): run-up start, back-foot contact, front-foot contact, release, bounce, bat contact, follow-through end, each with clip time, video time, frame index, confidence and provenance.
  2. Review loop (9.2): drag event markers or set them at the paused frame, confirm or remove events, mark deliveries verified or expert gold. The review queue sorts the least certain deliveries first and says why.
  3. Coach layer (7.5-7.6): observation, evidence, consequence, correction, confidence and an optional counterfactual. These become expert_interpretation, expert_advice and counterfactual pairs, never mixed with measured facts.
  4. Pitch calibration (8.2): click four crease corners on a fixed-camera frame; bounce is measured in metres and line/length are derived from thresholds in ontology.yaml. Line needs the batter's handedness.
  5. Controlled vocabulary (8.1): code/ontology.yaml; the server rejects values not in it and player IDs that are not pseudonymous (P0023).
  6. Label provenance (8.3): every event, posture value and label carries source_type, source_version, created_by, confidence, review_state, created_at and parent_artifact.
  7. Tier-1 tables (Appendix B): deliveries, events, labels in Parquet with schema checks and field completeness.
  8. Release builder (13, Appendix D): split by source video; sources holding expert-gold deliveries go to test; data card; automatic readiness checklist. Today every source is training_allowed: false, so releases are labelled dev_only.
  9. Experiment spec (3): code/experiments/EXP_YT_PIPELINE_DEV_V01.yaml, recorded on every delivery and shown in the site.
  10. Dashboard (backlog #12): event detection rates, review progress, corrections per event, QC by video type, answer types, schema status.

Added in v0.4 (everything from the standard that needs no cameras)

Feature How to use Standard
Batter trigger and shot follow-through events (9 events total) automatic 7.3
Bat contact confirmed or added from the bat-on-ball sound; clips keep audio automatic (audio.contact_from_sound) 7.3
Speech transcription with timestamps (coach voice / commentary) audio.transcribe: true, pip install faster-whisper 7.5
Ball labelling tab + cricket ball detector training and evaluation Ball labels tab, then python code/train_ball.py export / train / eval; see docs/train_ball_on_colab.md 7.4, 9.2
Event timing accuracy, reviewer agreement (kappa), error by slice Dashboard, results/qa/evaluation.json 9.2, 12
Disagreements between reviewers marked disputed and queued first automatic 8.3
Calibration reused across deliveries only if the camera did not move; points moved if it panned automatic 17
Reviewer roles (reviewer / coach / system); unknown IDs rejected code/registry/people.yaml 11.3
Device and camera-config registry for Salem code/registry/devices.yaml backlog #2
Appendix A session checklist Field checklist tab 5.1, App. A
Intent sheet import for phone/academy sessions python code/import_intent.py --source ... --csv ... 5.2, 7.2
Two-camera time sync from audio (clap) python code/sync_videos.py A.mp4 B.mp4 2
Second copy with checksum verification; MinIO/S3 python code/backup.py --to DIR / --s3 URL; docs/minio_setup.md 11.2
Coach review pack for the ontology python code/make_coach_pack.py 8
First real Salem experiment spec (draft) code/experiments/EXP_PACE_LL_V01.yaml 3
Consent, rights, site survey and phone-session documents code/docs/ 10, 15
Private identity table template (never read by the pipeline) datasets/identity/ 10.3

Not included: a six-camera capture simulator (the earlier real-time package already tests sync and dropped-frame QC), and anything that needs the Basler cameras, radar or a 3D rig.

Added in v0.4.1: review points

Every delivery shows a Bowler's review point and a Batter's review point panel, each with an Expected action and a Performed action column and a ✓ / ✗ / needs-label verdict per row.

Panel Expected action Performed action Standard
Bowler the instruction: target line, length, delivery, pace band (labels or import_intent.py) actual line/length (pitch calibration or reviewer), delivery type 7.2 intended vs actual
Batter recommended response to the delivery as bowled, from the provisional expected_shots table in ontology.yaml, or a coach's per-delivery override shot type, contact, trigger timing, follow-through 7.2, 7.3
  • Verdicts become execution_review and coaching_rule_review training pairs.
  • The expected-shot table is provisional coaching opinion: review it with python code/make_coach_pack.py and edit code/ontology.yaml.
  • Coach notes (observation, evidence, consequence, correction, confidence, counterfactual) are in the "Coach notes" form of each delivery (section 7.5).
  • Nothing needs reprocessing: python code/run_all.py --stages sft,tables,evaluate,release,web.

Added in v0.4.2: bat geometry, bat movement, feet on the pitch

Bat (section 7.4). Each delivery with a tracked batter gets a bat line (handle to toe) per frame, drawn over the video ("Bat line" toggle), plus: top of backlift (time, angle, height), fastest downswing (deg/s), and bat angle at contact.

  • Now: estimated from the batter's hands and forearms, with the bat length taken from code/registry/equipment.yaml (MCC Law 5 limits and typical sizes; set each player's bat size there). Good for timing; angles are rough (2D, wrist cock and foreshortening ignored). Shown as a dashed line.
  • Better: click the top of the handle and the toe in the Bat labels tab (~150-300 frames), python code/train_bat.py export, train (Colab GPU recommended), eval, then set models.bat_weights in config.yaml and rerun analyze with --force. Shown as a solid green line.

Feet on the pitch (needs pitch calibration). Ankles are on the ground, so the same 4-point calibration measures them in metres: the bowler's front foot vs the popping crease at landing (a no-ball indicator, about 15 cm accuracy), the bowler's stride, and the batter's forward/back movement. That fills a new Movement row in the batter's review point, checked against the provisional expected_movement table (full lengths: front foot; short: back foot).

Added in v0.4.3: multi-view sessions (one delivery, several cameras)

Before, the same ball filmed from three angles became three unrelated deliveries. Now:

  1. Declare the session in code/config.yaml under multiview.sessions: an id, a reference camera, and the video file for each camera id (C1 bowler side, C2 behind the bowler, C3 batter side, C4 in front of the batter; same ids as the Salem lane).
  2. Run python code/run_all.py. Each video is analysed as usual, then the multiview step:
    • syncs the cameras from the sound (clap) and refines with the release moment;
    • matches deliveries whose releases coincide into one multi-view delivery (MV_..._D0001) and tags every per-view record and SFT row with that shared sample_id.
  3. Calibrate each camera once (Deliveries tab > Pitch calibration). Click the visible points of the 12 offered (crease corners, stump-line corners, middle-stump base and top at each end) and skip the rest. 4 ground points give length; 6+ points including a stump top give full 3D: focal length, orientation and position are solved from the clicks alone.
  4. With 2+ calibrated views the step triangulates: ball path, release point, bounce point, speed (gravity-constrained fit), length from the 3D bounce, and the bowler's 3D elbow, front knee and trunk angles at release and front-foot contact. Speed fills the Pace row of the bowler's review point; the 3D length/line replace single-view estimates.
  5. The Multi-view tab plays all views in sync (one scrubber, event chips), shows top and side plots, the 3D numbers, how well the views agree on each event, and each camera's sync and calibration error.
  6. Releases split by session, so views of one delivery never land in different splits, and sft_records.jsonl gains multi-view samples whose media lists every camera's clip.

Test it with no cameras: python code/tests/test_multiview.py (synthetic 4-camera scene; checks sync, calibration, 3D release/bounce/speed/elbow against ground truth). Record a real one with code/docs/phone_session_protocol.md (four phones).

Reviewer edits are append-only

Edits go to results/annotations/review.jsonl with reviewer ID and time, and are merged over the automatic values at build time. measurements.json is never changed, so the automatic proposal, the correction and its history are all kept. Back this file up: it is the only human work in results/.

When a video gives no deliveries

python code/diagnose.py SRC_YT_0004 explains why (frames read, people detected, wrist height and speed, rejected peaks) and saves a plot and a frame contact sheet in results/qa/.

Tuning (code/config.yaml)

Symptom Change
No deliveries found run diagnose.py; usually lower release.min_wrist_speed or min_wrist_height
Fielders' throws counted as deliveries raise release.min_wrist_speed
Run-up start too late / too early ffc.run_speed (lower = earlier)
Follow-through end too early lower ffc.followthrough_fraction
Bowler too small (batter's view) raise that category's pose_imgsz
Slow-motion timings wrong set time_scale per file under overrides:
Slow on CPU models.cpu_format: openvino

Honest limits

  • Everything is 2D from one camera. Pitch calibration only measures the bounce (on the ground plane), and only for videos where the camera does not move.
  • Bat contact is a direction change near the batter; the stock COCO ball class misses many balls at 25-60 fps until a ball detector is fine-tuned (put it in models/).
  • Length and line thresholds in ontology.yaml are provisional; review them with coaches.
  • All sources are training_allowed: false: the outputs are for building and testing the pipeline, not for training a model you will ship.