Sim-to-Real Studio: Example Videos → 3D Mouse/Fly Simulation → Colab Iteration¶
Annolid's Sim-to-Real Studio (annolid-run sim2real and AI & Models → Sim-to-Real Studio (3D Sim → Colab)…) lets you bootstrap and iteratively improve segmentation, pose, and detection models starting directly from real example videos—with zero or minimal manual labels.
End-to-End Workflow¶
- Sample & analyze real user videos (or an image folder) using
annolid-run sim2real sample/analyzeor 1. Example Videos & Match in the GUI: - Uses diverse foreground + motion coreset sampling (K-Means medoids + Farthest-Point Sampling with blur filtering) or
uniformspacing to sample representative and rare postures from one or more user videos, writingenvironment_analysis/sampled_frames/andsampled_frames_manifest.json. - Extracts clean per-video median arena backgrounds (
reference_background.png,reference_background_v02.png, …) and per-video photometric profiles so multi-video projects match every recording cleanly without ghosted cross-video background averages. - Infers species (
mouse,rat, orfly), illumination/IR profile (default,ir_night,calms_gray,dim_warm), arena geometry (10 neuroscience arenas), camera perspective, coat appearance, subject count (1–6), calibrated 3D body scale (0.75–1.35), motion activity (low/medium/high), wire-bar occluders, and optical blur/noise/vignette statistics. - Generate an environment-matched 3D synthetic dataset for body parts or pose estimation:
- Mouse 3D (
threejs_two_mice_3d): drives Annolid's bundled Three.js 3D mouse simulator via Playwright Chromium across 1–6 subjects, 10 neuroscience arenas, 6 camera perspectives, 4 lighting presets, 5 coat pairs, calibratedbody_scale, wire-bar occluders, and headstages.- Body-part segmentation (
task=yolo_seg): supportsinstances, coarse 4-partparts(head,torso,limbs,tail), pose-oriented 5-partsemantic_parts(head,snout,ear,torso,tail), 11-partfine_parts(head,snout,left_ear,right_ear,neck,torso,left_forelimb,right_forelimb,left_hindlimb,right_hindlimb,tail), andhierarchical_parts(whole-animal + semantic parts), plus densesemantic_masks/{train,val}/*.pngand optional COCO-Seg JSONs. - Pose estimation (
task=yolo_pose): exports exact 3D-projected anatomical keypoints aligned totwo_mice_scene.jsformouse13(13 landmarks including ears, spine, paws, and tail),calms7(7 CalMS21/MARS landmarks), ortopdown6(6 dorsal landmarks), complete withdata.yaml(kpt_shape,keypoint_names,flip_idx),pose_schema.json, and a synchronized COCO Keypoints dataset (coco_keypoints/train/annotations.json,valid/annotations.json,coco_spec.yaml).
- Body-part segmentation (
- Fly 3D (
flybody_mujoco) and Rat 3D (threejs_rat_ncap_3d): also supported with matching body-part and pose exports. - Applies label-preserving foreground-first photometric matching (matching 3D subject Lab color/contrast, IR desaturation, blur, and noise before compositing onto per-video real arena backgrounds with soft contact shadows so real backgrounds are never double-blurred), configurable domain randomization, and sim + real LabelMe mixing (preserving real polygons, body-part masks, and pose keypoints).
- Train / fine-tune body-part or pose estimation models on Google Colab or locally:
yolo: Ultralytics YOLO-Seg (body-part / instance segmentation), YOLO-Pose (multi-instance keypoint pose), or YOLO-Detect.dino_kpseg: DINOv3 dense-feature keypoint pose estimation trained directly on the generatedYOLO_dataset/data.yaml(keypoint_names+flip_idx).keypoint_rcnn: Torchvision ResNet-50 FPN Keypoint R-CNN trained directly on the generatedcoco_keypoints/dataset.- Automatically warm-starts Iteration 2+ from the previous iteration's best checkpoint and reuses one warm Colab GPU session across loops.
- Evaluate on real user videos & iterate:
- Runs model-appropriate inference (
yolo_labelme --save-pose-bbox,dino_kpseg, orkeypoint_rcnn) on sampled clips from your recordings. - Computes task-aware metrics: real-video detection coverage, confidence, subject-count accuracy, temporal IoU stability, pose landmark completeness & per-keypoint detection rates (plus supervised OKS / PCK when GT keypoints are supplied), and body-part completeness & per-part coverage.
- Renders skeleton + keypoint and body-part overlays and proposes automated Diagnosis & Next-Iteration Recommendations.
- Write reproducible reports:
- Produces
reports/sim2real_report.md,reports/sim2real_report.json, and self-containedreports/sim2real_report.htmlwith inline SVG metric trend charts (includingval_mask_map50,val_pose_map50,val_box_map50) and visual contact sheets.
Quick Start (CLI)¶
1. Sample user videos & match 3D Mouse simulation¶
# For 13-keypoint Mouse Pose Estimation (supports YOLO-Pose, DINOv3 KPSEG, and Keypoint R-CNN)
annolid-run sim2real sample \
--video /path/to/lab_recording_1.mp4 \
--video /path/to/lab_recording_2.mp4 \
--project ./sim2real_mouse_pose \
--species mouse \
--task yolo_pose \
--pose-schema mouse13 \
--sampling-strategy diverse \
--samples-per-video 24
# For Mouse Anatomical Body-Part Segmentation (hierarchical whole mouse + head/snout/ear/torso/tail)
annolid-run sim2real sample \
--video /path/to/lab_recording_1.mp4 \
--project ./sim2real_mouse_parts \
--species mouse \
--task yolo_seg \
--export-level hierarchical_parts \
--sampling-strategy diverse \
--export-coco
2. Generate an environment-matched synthetic dataset (optional standalone step)¶
# Mouse 3D Pose dataset (YOLO-Pose + COCO Keypoints + LabelMe + pose_schema.json)
annolid-run sim2real generate \
--project ./sim2real_mouse_pose \
--composite-bg \
--frames-per-scenario 24
# Mouse 3D Fine Body-Part Segmentation (11 anatomical parts)
annolid-run sim2real generate \
--project ./sim2real_mouse_parts \
--export-level fine_parts \
--composite-bg \
--frames-per-scenario 24
3. Train & iterate body-part or pose estimation models (Colab GPU or Local)¶
# YOLO-Pose or YOLO-Seg (body parts) on Colab T4 GPU
annolid-run sim2real iterate \
--project ./sim2real_mouse_pose \
--model yolo \
--iterations 2 \
--train-backend colab \
--gpu T4 \
--epochs 30 \
--imgsz 640
# DINOv3 KPSEG pose estimation (local or Colab)
annolid-run sim2real iterate \
--project ./sim2real_mouse_pose \
--model dino_kpseg \
--iterations 1 \
--train-backend local \
--epochs 30
# Torchvision Keypoint R-CNN pose estimation on the exported COCO Keypoints dataset
annolid-run sim2real iterate \
--project ./sim2real_mouse_pose \
--model keypoint_rcnn \
--iterations 1 \
--train-backend colab \
--gpu T4 \
--epochs 25
4. Inspect status or regenerate reports¶
annolid-run sim2real status --project ./sim2real_mouse_project
annolid-run sim2real report --project ./sim2real_mouse_project
Annolid Bot (Natural-Language & Chat Usage)¶
You can ask Annolid Bot (in the Annolid GUI AI Chat dock, CLI bot, or connected chat channels) to run the entire Sim-to-Real workflow in plain language:
- "Sample my mouse videos in
./recordings, use 3D mouse simulation to generate a matching body-parts dataset, and train a YOLO segmentation model on Colab in the background." - "Use my currently open video to generate a matching 3D mouse pose dataset (
calms7) and train adino_kpsegmodel locally." - "Check the progress of my Sim-to-Real background job and open Sim-to-Real Studio for that project."
- Type
/sim2real(or/sim2real project=/path/to/project) in the GUI chat box to open Sim-to-Real Studio directly.
Under the hood, Annolid Bot uses sim2real_workflow (with preflight readiness checks, one-shot action="run_pipeline", intent presets goal="pose"|"body_parts"|"fine_body_parts"|"hierarchical_body_parts", video_dir auto-discovery, active GUI video handoff, and persisted non-blocking background=true jobs monitored via job_status / list_jobs / cancel_job) plus gui_open_sim2real_studio in the desktop app.
GUI Usage¶
- Open AI & Models → Sim-to-Real Studio (3D Sim → Colab)… (or click Sim-to-Real Studio… in the Google Colab Studio header bar).
- Add your example videos in 1. Example Videos & Match and click Analyze Environment & Match 3D Simulation.
- Review or override simulation controls in 2. 3D Sim Dataset (Mouse 3D or FlyBody 3D, photometry matching, background compositing, optional real LabelMe frames).
- Run 1 iteration or a multi-iteration loop in 3. Train & Iterate while monitoring live training loss/mAP curves and logs.
- Compare iterations and apply advisor suggestions in 4. Iterations & Advisor, then open the visual HTML/Markdown report in 5. Report.
Notes on Renderers & Provenance¶
- Mouse 3D requires Playwright Chromium (
playwright install chromium). - Fly 3D requires FlyBody + MuJoCo (
docs/simulation_flybody.mdor.venv311). - Neither engine silently substitutes a fallback renderer. If you want to test pipelines in an environment without Chromium or MuJoCo, pass
--allow-fallback(or check the fallback option in the GUI); the manifest and reports explicitly recordprocedural_mouse_fallbackorprocedural_fly_fallback.