6.9 KiB
Executable File
6.9 KiB
Executable File
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Common commands
- Install editable package:
pip install -e . - Install a CI-like local test environment:
uv pip install --system -e ".[export,solutions]" pytest-cov --extra-index-url https://download.pytorch.org/whl/cpu --index-strategy unsafe-best-match - Install docs/lint dependencies:
uv pip install --system -e ".[dev]" ruff black --extra-index-url https://download.pytorch.org/whl/cpu - Sanity check the environment:
yolo checks
Lint and docs
- Lint with the same Ruff rules used in CI:
ruff check --extend-select F,I,D,UP,RUF,FA --target-version py39 --ignore D100,D104,D203,D205,D212,D213,D401,D406,D407,D413,RUF001,RUF002,RUF012 . - Apply the same Ruff autofixes used in docs CI:
ruff check --fix --unsafe-fixes --extend-select F,I,D,UP,RUF,FA --target-version py39 --ignore D100,D104,D203,D205,D212,D213,D401,D406,D407,D413,RUF001,RUF002,RUF012 . - Rebuild autogenerated API reference docs:
python docs/build_reference.py - Build docs locally:
python docs/build_docs.py
Tests
- Run the default test suite:
pytest --cov=ultralytics/ --cov-report=xml tests/ - Run slow tests too:
pytest --slow --cov=ultralytics/ --cov-report=xml tests/ - Run one test file:
pytest tests/test_engine.py -v -s - Run one test by node id:
pytest tests/test_engine.py::test_name -v -s - Run the GPU-focused test file:
pytest tests/test_cuda.py -sv
Repo-specific training entry points
- Ground 2D training:
python train_mono2d.py --model yolo26s.pt --data ultralytics/cfg/datasets/mono2d_ground.yaml --epochs 100 --device 0 - Ground 2D DDP training:
python -m torch.distributed.run --nproc_per_node 4 train_mono2d.py --model yolo26s.pt --data ultralytics/cfg/datasets/mono2d_ground.yaml --epochs 100 - Ground 3D training from pretrained 2D weights:
python train_mono3d.py --pretrained yolo26s-pretrain.pt --epochs 100 --device 0 - Ground 3D DDP training from pretrained 2D weights:
python -m torch.distributed.run --nproc_per_node 4 train_mono3d.py --pretrained yolo26s-pretrain.pt --epochs 100 - Resume 3D training:
python train_mono3d.py --resume runs/detect/train_mono3d/weights/last.pt
Big-picture architecture
- This repo still uses the standard Ultralytics split of
cfg -> engine -> task package -> nn/data/utils, but this checkout adds a substantial custom ground-detection branch for 2D and 3D training on top of the upstream abstractions instead of replacing them. - CLI entry is
ultralytics.cfg:entrypoint.ultralytics/cfg/__init__.pydefines supported tasks/modes and default task-to-model/data mappings. - The public Python orchestration layer is
ultralytics/engine/model.py.Model.train(),val(),predict(),track(), andexport()all route into task-specific trainer/validator/predictor classes. - Task binding lives in
ultralytics/models/yolo/model.pyviatask_map. That is the main switchboard from a high-levelYOLO(...)object to the task-specific model/trainer/validator/predictor implementations. - Model YAMLs under
ultralytics/cfg/models/are converted into PyTorch graphs byultralytics/nn/tasks.py. Standard heads live inultralytics/nn/modules/head.py; this fork addsDetect3Dthere. - Shared runtime loops are in
ultralytics/engine/trainer.py,ultralytics/engine/validator.py, andultralytics/engine/predictor.py. Most repo-specific behavior plugs in by subclassing these rather than rewriting the loops. - Dataset selection and dataloader wiring are in
ultralytics/data/build.py. Core dataset classes are inultralytics/data/dataset.py.
Ground 2D custom path
train_mono2d.pyis the practical entry point for the custom ground 2D workflow.ultralytics/models/yolo/detect/train.pydefinesGroundDetectionModel,GroundDetectionTrainer, andGroundDetectionValidator.ultralytics/data/dataset.pyaddsYOLOGroundDataset, which extends the normal YOLO dataset flow with class mapping, difficulty-aware targets, min-box filtering, and optional YUV444 support.- Dataset YAMLs that include
class_mapare routed intoYOLOGroundDatasetbyultralytics/data/build.py. - Ground-specific losses live in
ultralytics/utils/loss.py(v8DetectionLossGround/E2EGroundLoss). - YUV444 images are not converted in the loader; they are converted to BGR in trainer/validator preprocessing. If image colors or TensorBoard examples look wrong, inspect
GroundDetectionTrainer.preprocess_batch()andGroundDetectionValidator.preprocess()before touching the dataset loader.
Ground 3D custom path
train_mono3d.pyis the main entry point for the joint 2D+3D workflow.ultralytics/models/yolo/detect/train.pyalso definesGround3DDetectionModel,Ground3DDetectionTrainer, andGround3DDetectionValidator.- The 3D model config is
ultralytics/cfg/models/26/yolo26-3d.yaml; it usesDetect3Dfromultralytics/nn/modules/head.py, which extends the normal detection head with a dedicated 3D branch. ultralytics/data/dataset.pyaddsYOLOGround3DDataset, which loads mixed 2D/3D labels, performs ROI crop or virtual-camera transforms, and returns standard 2D fields pluslabels_3dand calibration data.- Geometry-heavy preprocessing lives in
ultralytics/data/ground3d_augment.py. That file is the source of truth for ROI cropping, virtual-camera simulation, calibration updates, cut-in/cut-out handling, and depth scaling. - 3D loss, validation metrics, and visualization are split across
ultralytics/utils/loss.py,ultralytics/utils/metrics_3d.py, andultralytics/utils/plotting_3d.py. - 3D metrics and TensorBoard visualizations depend on calibration stored in
batch["calib"]. Do not re-read calibration from disk inside callbacks or validators.
Fast navigation hints
- If a command or API call is being routed somewhere unexpected, start with
ultralytics/cfg/__init__.py, thenultralytics/engine/model.py, thenultralytics/models/yolo/model.py. - If a model YAML change is not taking effect, inspect
ultralytics/nn/tasks.pyand the relevant head inultralytics/nn/modules/. - If a batch field looks wrong, trace
ultralytics/data/dataset.py->ultralytics/data/build.py-> the relevant trainerpreprocess_batch(). - If 3D training, metrics, or TensorBoard visualizations look inconsistent, trace
YOLOGround3DDataset.get_image_and_label()->Ground3DDetectionTrainer/Ground3DDetectionValidator->Detect3D->ultralytics/utils/loss.py/ultralytics/utils/metrics_3d.py/ultralytics/utils/plotting_3d.py.
Repository notes
- There is no
Makefileor committed.pre-commit-config.yamlin this repo. The most authoritative local commands come frompyproject.toml,train_mono2d.py,train_mono3d.py, and the GitHub Actions workflows. - API reference docs under
docs/en/reference/are generated; if source signatures or docstrings change, rebuild them withpython docs/build_reference.py.