Repository navigation
feat(cli): add headless LabGym workflows - #358
Conversation
…nd validate media extensions
…alidate test categorizer parameters
…tings, and harden detector annotations
…nd correct stream documentation
btmlnsn
left a comment
There was a problem hiding this comment.
I completed a quick integration re-review of the headless CLI surface and our follow-up changes.
I checked the console-entry-point behavior, headless GUI isolation, configuration validation, inference-output parity with the GUI workflow, Python 3.9 dependency compatibility, focused CLI coverage, and the fresh-install smoke check.
| return deduped | ||
|
|
||
|
|
||
| def rollup_behavior_summaries(result_path, behaviornames_and_colors, use_detector=False, animal_kinds=None): |
There was a problem hiding this comment.
Reviewed against the GUI inference workflow. The CLI intentionally follows the GUI’s per-video summary layout, sorted result-folder scan, root workbook naming, and overwrite behavior so Mine Results can consume the same outputs.
| * `--ex-end` (`ex_end`): Extraction end frame number | ||
| * `--decode-extraction` / `--no-decode-extraction`: Extract start/end frames from filenames | ||
| * `--stable-illumination` / `--no-stable-illumination`: Illumination stability flag (default: True) | ||
| * `--animal-vs-bg` (`animal_vs_bg`): Animal-to-background contrast for background-subtraction inference: `0` = animal brighter than background, `1` = animal darker than background, `2` = hard to tell. Default: `0`. This option is not used with `--use-detector`; a nonzero value in Detector mode is rejected. |
There was a problem hiding this comment.
Reviewed this against the GUI background-subtraction control. Values 0, 1, and 2 preserve the existing brighter, darker, and hard-to-tell contrast choices; nonzero values remain invalid for detector inference.
| 'PyYAML', | ||
| 'tomli', | ||
| 'reportlab>=5.0.0', | ||
| 'reportlab>=5.0.0,<5.1', |
There was a problem hiding this comment.
This preserves LabGym’s existing Python 3.9 support. ReportLab 5.1.0 resolves on Python 3.9 but fails during import because it now requires Python 3.10; the upper bound keeps CI on the last Python 3.9-importable release line.
|
|
||
| [project.scripts] | ||
| LabGym='LabGym.__main__:main' | ||
| labgym-cli='LabGym.cli:main' |
There was a problem hiding this comment.
Reviewed the entry-point split. LabGym remains the GUI command, while labgym-cli is the headless command. This avoids the case-insensitive filename collision between LabGym and labgym on macOS and Windows. I also verified both installed as distinct wrappers in a fresh macOS environment.
Summary
Primary implementation: Alexander Chumak
Follow-up CLI integration, compatibility, testing, and documentation: Bobby Tomlinson
This PR adds a dedicated headless command-line interface (
labgym-cli) to LabGym for training, evaluating, and running behavioral inference without launching or importing the desktop GUI (wxPython). It supports reproducible batch workflows through a three-tier configuration contract (built-in defaults -> workflow YAML -> inline CLI flags), strict pre-execution schema validation, and GUI-compatible analysis outputs.Changes
Dedicated Headless Entry Point & Command Hierarchy
Problem
Previously, LabGym’s console entry point launched the desktop
wxPythonGUI, preventing users from running training, evaluation, or inference jobs directly in headless terminal environments, remote SSH sessions, or cluster batch scripts (sbatch). Additionally, usinglabgymas the CLI command collided with theLabGymGUI entry point on case-insensitive macOS and Windows filesystems.Implementation
Added the
labgym-clientry point inpyproject.tomlandcli.pywhile preservingLabGymas the desktop GUI command. Structured the CLI into explicit action/target subcommands (labgym-cli train categorizer,labgym-cli train detector,labgym-cli test categorizer,labgym-cli test detector, andlabgym-cli infer). Running barelabgym-clior--helpprints usage information tostdoutand exits cleanly (0) without importing or launchingwx.Impact
Researchers can execute LabGym workflows in headless and HPC environments without display servers (
DISPLAY/ Xvfb) while keeping the existingLabGymdesktop workflow unchanged.Three-Tier Configuration Precedence & Fail-Fast Validation
Problem
Batch and cluster workflows require reusable baseline configuration files combined with per-job inline overrides (such as array-task output directories or hyperparameter sweeps). Without strict schema validation, mistyped YAML keys, missing paths, or incompatible parameter combinations could be silently ignored or fail late after initializing GPU resources.
Implementation
Implemented a three-tier configuration merger (
built-in defaults -> optional --config YAML -> explicit inline CLI flags) incli.pyusing sentinel parser defaults so unspecified flags never overwrite YAML values. Added kebab-case inline flags mapped to snake_case YAML/Python keys, paired boolean flags (--flag/--no-flag), and platform-appropriate home-directory (~) path expansion. Enforced pre-execution validation that rejects unknown YAML keys, unreadable configuration files, invalid parameter values, missing dataset/model files, invalid COCO JSON annotations, and incompatible mode combinations with clear messages onstderrand exit code2before starting compute.Impact
Users can combine shared YAML workflow files with targeted inline CLI overrides, and invalid configurations fail immediately with predictable exit codes (
0success,1runtime error,2configuration/usage error) suitable for automated scripts.Headless Training, Evaluation, & GUI-Compatible Inference
Problem
Headless workflows needed to support both Categorizer and Detector pipelines while protecting trained model architecture settings during inference and producing output artifacts compatible with downstream LabGym analysis tools such as Mine Results.
Implementation
Wired
trainandtestsubcommands for Categorizers and Detectors (TrainingandDetectorincore.pyanddetectors.py), and implemented headless video/image inference viaAnalyzeAnimalinanalyzebehavior.pyandAnalyzeAnimalDetectorinanalyzebehavior_dt.py. During inference, trained Categorizer metadata (model_parameters.txt) is read as authoritative so incompatible architecture overrides are rejected, structuredanimal_numberkind-to-count mappings are restricted to detector inference,animal_vs_bgcontrast selection is supported for non-detector background subtraction, and root*_summary.xlsxroll-ups are generated from per-video summaries when requested analysis parameters produce those summaries. UpdatedLabGym_CLI_Guide.md,README.md, anddocs/installation/index.md.Impact
Users can train, test, and run inference headlessly from start to finish while preserving full compatibility with trained LabGym models and downstream GUI analysis workflows.
Python 3.9 ReportLab Compatibility
Problem
LabGym supports Python 3.9, but ReportLab 5.1.0 can be installed under Python 3.9 and then fails at import time because it requires Python 3.10 or newer.
Implementation
Pinned ReportLab to
>=5.0.0,<5.1and updated the packaging assertion for that dependency declaration.Impact
Keeps the supported Python 3.9 environment able to import ReportLab and restores the Python 3.9 CI path without changing LabGym’s supported Python-version policy.
Testing
Focused automated validation and package checks passed:
LabGym/tests/test_cli.py(python -m pytest LabGym/tests/test_cli.py -q --tb=short -p no:cacheprovider).LabGymvslabgym-cli) and clean bare/--helpexecution without importingwx.defaults -> YAML -> CLI), paired boolean flags, home-directory (~) expansion, and structuredanimal_number/ID_colors/specific_behaviorsparsing.2validation for missing/unreadable--configfiles, unknown YAML keys, invalid parameter ranges, incompatible training/inference combinations, invalid COCO annotations, and missing model artifacts without leaving partial output directories.model_parameters.txtmetadata inheritance and protection during inference.animal_vs_bgbackground contrast selection (0,1,2) for non-detector inference.*_summary.xlsxinference roll-ups across videos and result-directory reuse behavior.wximports.LabGymandlabgym-cliinstall as distinct wrappers andlabgym-cli --helpexits0.Known limitations
labgym-clicovers training, testing, and inference workflows; interactive preprocessing utilities (such as interactive video cropping/trimming and drawing environment landmarks) and post-hoc statistical data-mining dialogs remain part of theLabGymdesktop GUI.