├── .gitignore ├── .pre-commit-config.yaml ├── CITATION.cff ├── CONTRIBUTING.md ├── KITTI.yaml ├── LICENSE ├── MANIFEST.in ├── MOT.yaml ├── MOTR ├── LICENSE ├── README.md ├── benchmark.py ├── configs │ ├── r50_deformable_detr.sh │ ├── r50_deformable_detr_plus_iterative_bbox_refinement.sh │ ├── r50_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage.sh │ ├── r50_deformable_detr_single_scale.sh │ ├── r50_deformable_detr_single_scale_dc5.sh │ ├── r50_motr_demo.sh │ ├── r50_motr_eval.sh │ ├── r50_motr_submit.sh │ ├── r50_motr_submit_dance.sh │ ├── r50_motr_train.sh │ └── r50_motr_train_dance.sh ├── demo.py ├── engine.py ├── eval.py ├── main.py ├── models │ ├── __init__.py │ ├── backbone.py │ ├── deformable_detr.py │ ├── deformable_transformer.py │ ├── deformable_transformer_plus.py │ ├── fsqm.py │ ├── matcher.py │ ├── memory_bank.py │ ├── motr.py │ ├── ops │ │ ├── functions │ │ │ ├── __init__.py │ │ │ └── ms_deform_attn_func.py │ │ ├── make.sh │ │ ├── modules │ │ │ ├── __init__.py │ │ │ └── ms_deform_attn.py │ │ ├── setup.py │ │ ├── src │ │ │ ├── cpu │ │ │ │ ├── ms_deform_attn_cpu.cpp │ │ │ │ └── ms_deform_attn_cpu.h │ │ │ ├── cuda │ │ │ │ ├── ms_deform_attn_cuda.cu │ │ │ │ ├── ms_deform_attn_cuda.h │ │ │ │ └── ms_deform_im2col_cuda.cuh │ │ │ ├── ms_deform_attn.h │ │ │ └── vision.cpp │ │ └── test.py │ ├── position_encoding.py │ ├── qim.py │ ├── relu_dropout.py │ ├── segmentation.py │ └── structures │ │ ├── __init__.py │ │ ├── boxes.py │ │ └── instances.py ├── requirements.txt ├── submit.py ├── submit_dance.py ├── tools │ ├── launch.py │ ├── run_dist_launch.sh │ └── run_dist_slurm.sh └── util │ ├── __init__.py │ ├── box_ops.py │ ├── checkpoint.py │ ├── evaluation.py │ ├── misc.py │ ├── motdet_eval.py │ ├── plot_utils.py │ └── tool.py ├── README.md ├── dancetracker.yaml ├── mkdocs.yml ├── requirements.txt ├── run_test.py ├── setup.cfg ├── setup.py ├── start_train.py ├── tests ├── conftest.py ├── test_cli.py ├── test_engine.py └── test_python.py └── ultralytics ├── __init__.py ├── assets ├── bus.jpg └── zidane.jpg ├── cfg ├── __init__.py ├── default.yaml ├── models │ ├── README.md │ ├── rt-detr │ │ ├── rtdetr-l.yaml │ │ └── rtdetr-x.yaml │ ├── v3 │ │ ├── yolov3-spp.yaml │ │ ├── yolov3-tiny.yaml │ │ └── yolov3.yaml │ ├── v5 │ │ ├── yolov5-p6.yaml │ │ └── yolov5.yaml │ ├── v6 │ │ └── yolov6.yaml │ └── v8 │ │ ├── YOLO_MOT.yaml │ │ ├── cls │ │ ├── yolov8l-cls.yaml │ │ ├── yolov8m-cls.yaml │ │ ├── yolov8n-cls.yaml │ │ ├── yolov8s-cls.yaml │ │ └── yolov8x-cls.yaml │ │ ├── detr_track.yaml │ │ ├── seg │ │ ├── yolov8l-seg.yaml │ │ ├── yolov8m-seg.yaml │ │ ├── yolov8n-seg.yaml │ │ ├── yolov8s-seg.yaml │ │ └── yolov8x-seg.yaml │ │ ├── yolo_track.yaml │ │ ├── yolo_track_rare.yaml │ │ ├── yolov8-cls.yaml │ │ ├── yolov8-p2.yaml │ │ ├── yolov8-p6.yaml │ │ ├── yolov8-pose-p6.yaml │ │ ├── yolov8-pose.yaml │ │ ├── yolov8-rtdetr.yaml │ │ ├── yolov8-seg.yaml │ │ ├── yolov8.yaml │ │ ├── yolov8l.yaml │ │ ├── yolov8m.yaml │ │ ├── yolov8m_track.yaml │ │ ├── yolov8n.yaml │ │ ├── yolov8s.yaml │ │ ├── yolov8x.yaml │ │ └── yolov8x6.yaml └── trackers │ ├── botsort.yaml │ └── bytetrack.yaml ├── data ├── __init__.py ├── annotator.py ├── augment.py ├── base.py ├── build.py ├── converter.py ├── dataloaders │ └── __init__.py ├── dataset.py ├── loaders.py ├── scripts │ ├── download_weights.sh │ ├── get_coco.sh │ ├── get_coco128.sh │ └── get_imagenet.sh └── utils.py ├── engine ├── __init__.py ├── exporter.py ├── model.py ├── predictor.py ├── results.py ├── trainer.py └── validator.py ├── hub ├── __init__.py ├── auth.py ├── session.py └── utils.py ├── models ├── MOTRtrack │ ├── __init__.py │ ├── model.py │ ├── predict.py │ ├── train.py │ └── val.py ├── __init__.py ├── fastsam │ ├── __init__.py │ ├── model.py │ ├── predict.py │ ├── prompt.py │ ├── utils.py │ └── val.py ├── nas │ ├── __init__.py │ ├── model.py │ ├── predict.py │ └── val.py ├── rtdetr │ ├── __init__.py │ ├── model.py │ ├── predict.py │ ├── train.py │ └── val.py ├── sam │ ├── __init__.py │ ├── amg.py │ ├── build.py │ ├── model.py │ ├── modules │ │ ├── __init__.py │ │ ├── decoders.py │ │ ├── encoders.py │ │ ├── sam.py │ │ ├── tiny_encoder.py │ │ └── transformer.py │ └── predict.py ├── utils │ ├── __init__.py │ ├── loss.py │ └── ops.py └── yolo │ ├── __init__.py │ ├── classify │ ├── __init__.py │ ├── predict.py │ ├── train.py │ └── val.py │ ├── detect │ ├── __init__.py │ ├── predict.py │ ├── train.py │ └── val.py │ ├── pose │ ├── __init__.py │ ├── predict.py │ ├── train.py │ └── val.py │ ├── segment │ ├── __init__.py │ ├── predict.py │ ├── train.py │ └── val.py │ └── track │ ├── __init__.py │ ├── model.py │ ├── predict.py │ ├── train.py │ └── val.py ├── nn ├── __init__.py ├── autobackend.py ├── modules │ ├── __init__.py │ ├── block.py │ ├── conv.py │ ├── head.py │ ├── ms_deform_attn.py │ ├── structures │ │ ├── __init__.py │ │ ├── boxes.py │ │ └── instances.py │ ├── transformer.py │ └── utils.py └── tasks.py ├── trackers ├── README.md ├── __init__.py ├── basetrack.py ├── bot_sort.py ├── byte_tracker.py ├── track.py └── utils │ ├── __init__.py │ ├── gmc.py │ ├── kalman_filter.py │ └── matching.py ├── utils ├── __init__.py ├── _base_metric.py ├── _timing.py ├── autobatch.py ├── baselines │ ├── __init__.py │ ├── baseline_utils.py │ ├── non_overlap.py │ ├── pascal_colormap.py │ ├── stp.py │ ├── thresholder.py │ └── vizualize.py ├── benchmarks.py ├── callbacks │ ├── __init__.py │ ├── base.py │ ├── clearml.py │ ├── comet.py │ ├── dvc.py │ ├── hub.py │ ├── mlflow.py │ ├── neptune.py │ ├── raytune.py │ ├── tensorboard.py │ └── wb.py ├── checks.py ├── dist.py ├── downloads.py ├── errors.py ├── files.py ├── hota.py ├── instance.py ├── loss.py ├── metrics.py ├── misc.py ├── ops.py ├── patches.py ├── plotting.py ├── tal.py ├── torch_utils.py └── tuner.py └── yolo ├── __init__.py ├── cfg └── __init__.py ├── data └── __init__.py ├── engine └── __init__.py ├── utils └── __init__.py └── v8 └── __init__.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # Profiling 85 | *.pclprof 86 | 87 | # pyenv 88 | .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 98 | __pypackages__/ 99 | 100 | # Celery stuff 101 | celerybeat-schedule 102 | celerybeat.pid 103 | 104 | # SageMath parsed files 105 | *.sage.py 106 | 107 | # Environments 108 | .env 109 | .venv 110 | .idea 111 | env/ 112 | venv/ 113 | ENV/ 114 | env.bak/ 115 | venv.bak/ 116 | 117 | # Spyder project settings 118 | .spyderproject 119 | .spyproject 120 | 121 | # Rope project settings 122 | .ropeproject 123 | 124 | # mkdocs documentation 125 | /site 126 | 127 | # mypy 128 | .mypy_cache/ 129 | .dmypy.json 130 | dmypy.json 131 | 132 | # Pyre type checker 133 | .pyre/ 134 | 135 | # datasets and projects 136 | datasets/ 137 | runs/ 138 | wandb/ 139 | 140 | .DS_Store 141 | 142 | # Neural Network weights ----------------------------------------------------------------------------------------------- 143 | weights/ 144 | *.weights 145 | *.pt 146 | *.pb 147 | *.onnx 148 | *.engine 149 | *.mlmodel 150 | *.torchscript 151 | *.tflite 152 | *.h5 153 | *_saved_model/ 154 | *_web_model/ 155 | *_openvino_model/ 156 | *_paddle_model/ 157 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # Pre-commit hooks. For more information see https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md 3 | 4 | exclude: 'docs/' 5 | # Define bot property if installed via https://github.com/marketplace/pre-commit-ci 6 | ci: 7 | autofix_prs: true 8 | autoupdate_commit_msg: '[pre-commit.ci] pre-commit suggestions' 9 | autoupdate_schedule: monthly 10 | # submodules: true 11 | 12 | repos: 13 | - repo: https://github.com/pre-commit/pre-commit-hooks 14 | rev: v4.4.0 15 | hooks: 16 | - id: end-of-file-fixer 17 | - id: trailing-whitespace 18 | - id: check-case-conflict 19 | # - id: check-yaml 20 | - id: check-docstring-first 21 | - id: double-quote-string-fixer 22 | - id: detect-private-key 23 | 24 | - repo: https://github.com/asottile/pyupgrade 25 | rev: v3.8.0 26 | hooks: 27 | - id: pyupgrade 28 | name: Upgrade code 29 | 30 | - repo: https://github.com/PyCQA/isort 31 | rev: 5.12.0 32 | hooks: 33 | - id: isort 34 | name: Sort imports 35 | 36 | - repo: https://github.com/google/yapf 37 | rev: v0.40.0 38 | hooks: 39 | - id: yapf 40 | name: YAPF formatting 41 | 42 | - repo: https://github.com/executablebooks/mdformat 43 | rev: 0.7.16 44 | hooks: 45 | - id: mdformat 46 | name: MD formatting 47 | additional_dependencies: 48 | - mdformat-gfm 49 | - mdformat-black 50 | # exclude: "README.md|README.zh-CN.md|CONTRIBUTING.md" 51 | 52 | - repo: https://github.com/PyCQA/flake8 53 | rev: 6.0.0 54 | hooks: 55 | - id: flake8 56 | name: PEP8 57 | 58 | - repo: https://github.com/codespell-project/codespell 59 | rev: v2.2.5 60 | hooks: 61 | - id: codespell 62 | args: 63 | - --ignore-words-list=crate,nd,strack,dota 64 | 65 | # - repo: https://github.com/asottile/yesqa 66 | # rev: v1.4.0 67 | # hooks: 68 | # - id: yesqa 69 | 70 | # - repo: https://github.com/asottile/dead 71 | # rev: v1.5.0 72 | # hooks: 73 | # - id: dead 74 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | preferred-citation: 3 | type: software 4 | message: If you use this software, please cite it as below. 5 | authors: 6 | - family-names: Jocher 7 | given-names: Glenn 8 | orcid: "https://orcid.org/0000-0001-5950-6979" 9 | - family-names: Chaurasia 10 | given-names: Ayush 11 | orcid: "https://orcid.org/0000-0002-7603-6750" 12 | - family-names: Qiu 13 | given-names: Jing 14 | orcid: "https://orcid.org/0000-0003-3783-7069" 15 | title: "YOLO by Ultralytics" 16 | version: 8.0.0 17 | # doi: 10.5281/zenodo.3908559 # TODO 18 | date-released: 2023-1-10 19 | license: AGPL-3.0 20 | url: "https://github.com/ultralytics/ultralytics" 21 | -------------------------------------------------------------------------------- /KITTI.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # COCO128 dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics 3 | # Example usage: yolo train data=coco128.yaml 4 | # parent 5 | # ├── ultralytics 6 | # └── datasets 7 | # └── coco128 ← downloads here (7 MB) 8 | 9 | 10 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] 11 | train: E:\data\KITTI_TRACKING\training_yolotrack_format\data\train.txt # train images (relative to 'path') 128 images 12 | val: E:\data\KITTI_TRACKING\training_yolotrack_format\data\val.txt # val images (relative to 'path') 128 images 13 | test: # test images (optional) 14 | 15 | # Classes 16 | names: 17 | 0: Cyclist 18 | 1: Van 19 | 2: Car 20 | 3: Pedestrian 21 | 4: Truck 22 | 23 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include *.md 2 | include requirements.txt 3 | include LICENSE 4 | include setup.py 5 | include ultralytics/assets/bus.jpg 6 | include ultralytics/assets/zidane.jpg 7 | recursive-include ultralytics *.yaml 8 | recursive-exclude __pycache__ * 9 | -------------------------------------------------------------------------------- /MOT.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # COCO128 dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics 3 | # Example usage: yolo train data=coco128.yaml 4 | # parent 5 | # ├── ultralytics 6 | # └── datasets 7 | # └── coco128 ← downloads here (7 MB) 8 | 9 | 10 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] 11 | train: E:\data\MOT17\train_yolo_track\train.txt # train images (relative to 'path') 128 images 12 | val: E:\data\MOT17\train_yolo_track\val.txt # val images (relative to 'path') 128 images 13 | test: # test images (optional) 14 | 15 | # Classes 16 | names: 17 | 0: person 18 | -------------------------------------------------------------------------------- /MOTR/benchmark.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 3 | # ------------------------------------------------------------------------ 4 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 5 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 6 | # ------------------------------------------------------------------------ 7 | # Modified from DETR (https://github.com/facebookresearch/detr) 8 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 9 | # ------------------------------------------------------------------------ 10 | 11 | 12 | """ 13 | Benchmark inference speed of Deformable DETR. 14 | """ 15 | import os 16 | import time 17 | import argparse 18 | 19 | import torch 20 | 21 | from main import get_args_parser as get_main_args_parser 22 | from models import build_model 23 | from datasets import build_dataset 24 | from util.misc import nested_tensor_from_tensor_list 25 | 26 | 27 | def get_benckmark_arg_parser(): 28 | parser = argparse.ArgumentParser('Benchmark inference speed of Deformable DETR.') 29 | parser.add_argument('--num_iters', type=int, default=300, help='total iters to benchmark speed') 30 | parser.add_argument('--warm_iters', type=int, default=5, help='ignore first several iters that are very slow') 31 | parser.add_argument('--batch_size', type=int, default=1, help='batch size in inference') 32 | parser.add_argument('--resume', type=str, help='load the pre-trained checkpoint') 33 | return parser 34 | 35 | 36 | @torch.no_grad() 37 | def measure_average_inference_time(model, inputs, num_iters=100, warm_iters=5): 38 | ts = [] 39 | for iter_ in range(num_iters): 40 | torch.cuda.synchronize() 41 | t_ = time.perf_counter() 42 | model(inputs) 43 | torch.cuda.synchronize() 44 | t = time.perf_counter() - t_ 45 | if iter_ >= warm_iters: 46 | ts.append(t) 47 | print(ts) 48 | return sum(ts) / len(ts) 49 | 50 | 51 | def benchmark(): 52 | args, _ = get_benckmark_arg_parser().parse_known_args() 53 | main_args = get_main_args_parser().parse_args(_) 54 | assert args.warm_iters < args.num_iters and args.num_iters > 0 and args.warm_iters >= 0 55 | assert args.batch_size > 0 56 | assert args.resume is None or os.path.exists(args.resume) 57 | dataset = build_dataset('val', main_args) 58 | model, _, _ = build_model(main_args) 59 | model.cuda() 60 | model.eval() 61 | if args.resume is not None: 62 | ckpt = torch.load(args.resume, map_location=lambda storage, loc: storage) 63 | model.load_state_dict(ckpt['model']) 64 | inputs = nested_tensor_from_tensor_list([dataset.__getitem__(0)[0].cuda() for _ in range(args.batch_size)]) 65 | t = measure_average_inference_time(model, inputs, args.num_iters, args.warm_iters) 66 | return 1.0 / t * args.batch_size 67 | 68 | 69 | if __name__ == '__main__': 70 | fps = benchmark() 71 | print(f'Inference Speed: {fps:.1f} FPS') 72 | 73 | -------------------------------------------------------------------------------- /MOTR/configs/r50_deformable_detr.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ------------------------------------------------------------------------ 3 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 4 | # ------------------------------------------------------------------------ 5 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 6 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 7 | # ------------------------------------------------------------------------ 8 | 9 | set -x 10 | 11 | EXP_DIR=exps/r50_deformable_detr 12 | PY_ARGS=${@:1} 13 | 14 | python -u main.py \ 15 | --output_dir ${EXP_DIR} \ 16 | ${PY_ARGS} 17 | -------------------------------------------------------------------------------- /MOTR/configs/r50_deformable_detr_plus_iterative_bbox_refinement.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ------------------------------------------------------------------------ 3 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 4 | # ------------------------------------------------------------------------ 5 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 6 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 7 | # ------------------------------------------------------------------------ 8 | 9 | set -x 10 | 11 | EXP_DIR=exps/r50_deformable_detr_plus_iterative_bbox_refinement 12 | PY_ARGS=${@:1} 13 | 14 | python -u main.py \ 15 | --output_dir ${EXP_DIR} \ 16 | --with_box_refine \ 17 | ${PY_ARGS} 18 | -------------------------------------------------------------------------------- /MOTR/configs/r50_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ------------------------------------------------------------------------ 3 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 4 | # ------------------------------------------------------------------------ 5 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 6 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 7 | # ------------------------------------------------------------------------ 8 | 9 | set -x 10 | 11 | EXP_DIR=exps/r50_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage 12 | PY_ARGS=${@:1} 13 | 14 | python -u main.py \ 15 | --output_dir ${EXP_DIR} \ 16 | --with_box_refine \ 17 | --two_stage \ 18 | ${PY_ARGS} 19 | -------------------------------------------------------------------------------- /MOTR/configs/r50_deformable_detr_single_scale.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ------------------------------------------------------------------------ 3 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 4 | # ------------------------------------------------------------------------ 5 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 6 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 7 | # ------------------------------------------------------------------------ 8 | 9 | set -x 10 | 11 | EXP_DIR=exps/r50_deformable_detr_single_scale 12 | PY_ARGS=${@:1} 13 | 14 | python -u main.py \ 15 | --num_feature_levels 1 \ 16 | --output_dir ${EXP_DIR} \ 17 | ${PY_ARGS} 18 | -------------------------------------------------------------------------------- /MOTR/configs/r50_deformable_detr_single_scale_dc5.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ------------------------------------------------------------------------ 3 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 4 | # ------------------------------------------------------------------------ 5 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 6 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 7 | # ------------------------------------------------------------------------ 8 | 9 | set -x 10 | 11 | EXP_DIR=exps/r50_deformable_detr_single_scale_dc5 12 | PY_ARGS=${@:1} 13 | 14 | python -u main.py \ 15 | --num_feature_levels 1 \ 16 | --dilation \ 17 | --output_dir ${EXP_DIR} \ 18 | ${PY_ARGS} 19 | -------------------------------------------------------------------------------- /MOTR/configs/r50_motr_demo.sh: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 3 | # ------------------------------------------------------------------------ 4 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 5 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 6 | # ------------------------------------------------------------------------ 7 | 8 | EXP_DIR=exps/e2e_motr_r50_joint 9 | python3 demo.py \ 10 | --meta_arch motr \ 11 | --dataset_file e2e_joint \ 12 | --epoch 200 \ 13 | --with_box_refine \ 14 | --lr_drop 100 \ 15 | --lr 2e-4 \ 16 | --lr_backbone 2e-5 \ 17 | --pretrained ${EXP_DIR}/motr_final.pth \ 18 | --output_dir ${EXP_DIR} \ 19 | --batch_size 1 \ 20 | --sample_mode 'random_interval' \ 21 | --sample_interval 10 \ 22 | --sampler_steps 50 90 120 \ 23 | --sampler_lengths 2 3 4 5 \ 24 | --update_query_pos \ 25 | --merger_dropout 0 \ 26 | --dropout 0 \ 27 | --random_drop 0.1 \ 28 | --fp_ratio 0.3 \ 29 | --query_interaction_layer 'QIM' \ 30 | --extra_track_attn \ 31 | --resume ${EXP_DIR}/motr_final.pth \ 32 | --input_video figs/demo.avi -------------------------------------------------------------------------------- /MOTR/configs/r50_motr_eval.sh: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 3 | # ------------------------------------------------------------------------ 4 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 5 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 6 | # ------------------------------------------------------------------------ 7 | 8 | # for MOT17 9 | 10 | # EXP_DIR=exps/e2e_motr_r50_joint 11 | # python3 eval.py \ 12 | # --meta_arch motr \ 13 | # --dataset_file e2e_joint \ 14 | # --epoch 200 \ 15 | # --with_box_refine \ 16 | # --lr_drop 100 \ 17 | # --lr 2e-4 \ 18 | # --lr_backbone 2e-5 \ 19 | # --pretrained ${EXP_DIR}/motr_final.pth \ 20 | # --output_dir ${EXP_DIR} \ 21 | # --batch_size 1 \ 22 | # --sample_mode 'random_interval' \ 23 | # --sample_interval 10 \ 24 | # --sampler_steps 50 90 120 \ 25 | # --sampler_lengths 2 3 4 5 \ 26 | # --update_query_pos \ 27 | # --merger_dropout 0 \ 28 | # --dropout 0 \ 29 | # --random_drop 0.1 \ 30 | # --fp_ratio 0.3 \ 31 | # --query_interaction_layer 'QIM' \ 32 | # --extra_track_attn \ 33 | # --data_txt_path_train ./datasets/data_path/joint.train \ 34 | # --data_txt_path_val ./datasets/data_path/mot17.train \ 35 | # --resume ${EXP_DIR}/motr_final.pth \ -------------------------------------------------------------------------------- /MOTR/configs/r50_motr_submit.sh: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 3 | # ------------------------------------------------------------------------ 4 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 5 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 6 | # ------------------------------------------------------------------------ 7 | 8 | EXP_DIR=exps/e2e_motr_r50_joint 9 | python3 submit.py \ 10 | --meta_arch motr \ 11 | --dataset_file e2e_joint \ 12 | --epoch 200 \ 13 | --with_box_refine \ 14 | --lr_drop 100 \ 15 | --lr 2e-4 \ 16 | --lr_backbone 2e-5 \ 17 | --pretrained ${EXP_DIR}/motr_final.pth \ 18 | --output_dir ${EXP_DIR} \ 19 | --batch_size 1 \ 20 | --sample_mode 'random_interval' \ 21 | --sample_interval 10 \ 22 | --sampler_steps 50 90 150 \ 23 | --sampler_lengths 2 3 4 5 \ 24 | --update_query_pos \ 25 | --merger_dropout 0 \ 26 | --dropout 0 \ 27 | --random_drop 0.1 \ 28 | --fp_ratio 0.3 \ 29 | --query_interaction_layer 'QIM' \ 30 | --extra_track_attn \ 31 | --data_txt_path_train ./datasets/data_path/joint.train \ 32 | --data_txt_path_val ./datasets/data_path/mot17.train \ 33 | --resume ${EXP_DIR}/motr_final.pth \ 34 | --exp_name pub_submit_17 -------------------------------------------------------------------------------- /MOTR/configs/r50_motr_submit_dance.sh: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 3 | # ------------------------------------------------------------------------ 4 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 5 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 6 | # ------------------------------------------------------------------------ 7 | 8 | EXP_DIR=exps/e2e_motr_r50_dance 9 | python3 submit_dance.py \ 10 | --meta_arch motr \ 11 | --dataset_file e2e_joint \ 12 | --mot_path /data/datasets \ 13 | --epoch 200 \ 14 | --with_box_refine \ 15 | --lr_drop 100 \ 16 | --lr 2e-4 \ 17 | --lr_backbone 2e-5 \ 18 | --output_dir ${EXP_DIR} \ 19 | --batch_size 1 \ 20 | --sample_mode 'random_interval' \ 21 | --sample_interval 10 \ 22 | --sampler_steps 50 90 150 \ 23 | --sampler_lengths 2 3 4 5 \ 24 | --update_query_pos \ 25 | --merger_dropout 0 \ 26 | --dropout 0 \ 27 | --random_drop 0.1 \ 28 | --fp_ratio 0.3 \ 29 | --query_interaction_layer 'QIM' \ 30 | --extra_track_attn \ 31 | --data_txt_path_train ./datasets/data_path/joint.train \ 32 | --data_txt_path_val ./datasets/data_path/mot17.train \ 33 | --resume ${EXP_DIR}/checkpoint.pth \ 34 | --exp_name tracker 35 | -------------------------------------------------------------------------------- /MOTR/configs/r50_motr_train.sh: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 3 | # ------------------------------------------------------------------------ 4 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 5 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 6 | # ------------------------------------------------------------------------ 7 | 8 | 9 | # for MOT17 10 | 11 | # PRETRAIN=coco_model_final.pth 12 | # EXP_DIR=exps/e2e_motr_r50_joint 13 | # python3 -m torch.distributed.launch --nproc_per_node=8 \ 14 | # --use_env main.py \ 15 | # --meta_arch motr \ 16 | # --use_checkpoint \ 17 | # --dataset_file e2e_joint \ 18 | # --epoch 200 \ 19 | # --with_box_refine \ 20 | # --lr_drop 100 \ 21 | # --lr 2e-4 \ 22 | # --lr_backbone 2e-5 \ 23 | # --pretrained ${PRETRAIN} \ 24 | # --output_dir ${EXP_DIR} \ 25 | # --batch_size 1 \ 26 | # --sample_mode 'random_interval' \ 27 | # --sample_interval 10 \ 28 | # --sampler_steps 50 90 150 \ 29 | # --sampler_lengths 2 3 4 5 \ 30 | # --update_query_pos \ 31 | # --merger_dropout 0 \ 32 | # --dropout 0 \ 33 | # --random_drop 0.1 \ 34 | # --fp_ratio 0.3 \ 35 | # --query_interaction_layer 'QIM' \ 36 | # --extra_track_attn \ 37 | # --data_txt_path_train ./datasets/data_path/joint.train \ 38 | # --data_txt_path_val ./datasets/data_path/mot17.train \ -------------------------------------------------------------------------------- /MOTR/configs/r50_motr_train_dance.sh: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 3 | # ------------------------------------------------------------------------ 4 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 5 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 6 | # ------------------------------------------------------------------------ 7 | 8 | 9 | # for MOT17 10 | 11 | PRETRAIN=r50_deformable_detr_plus_iterative_bbox_refinement-checkpoint.pth 12 | EXP_DIR=exps/e2e_motr_r50_dance 13 | python3 -m torch.distributed.launch --nproc_per_node=8 \ 14 | --use_env main.py \ 15 | --meta_arch motr \ 16 | --use_checkpoint \ 17 | --dataset_file e2e_dance \ 18 | --epoch 20 \ 19 | --with_box_refine \ 20 | --lr_drop 10 \ 21 | --lr 2e-4 \ 22 | --lr_backbone 2e-5 \ 23 | --pretrained ${PRETRAIN} \ 24 | --output_dir ${EXP_DIR} \ 25 | --batch_size 1 \ 26 | --sample_mode 'random_interval' \ 27 | --sample_interval 10 \ 28 | --sampler_steps 5 9 15 \ 29 | --sampler_lengths 2 3 4 5 \ 30 | --update_query_pos \ 31 | --merger_dropout 0 \ 32 | --dropout 0 \ 33 | --random_drop 0.1 \ 34 | --fp_ratio 0.3 \ 35 | --query_interaction_layer 'QIM' \ 36 | --extra_track_attn \ 37 | --data_txt_path_train ./datasets/data_path/joint.train \ 38 | --data_txt_path_val ./datasets/data_path/mot17.train \ 39 | |& tee ${EXP_DIR}/output.log 40 | -------------------------------------------------------------------------------- /MOTR/models/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Deformable DETR 3 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 4 | # Licensed under the Apache License, Version 2.0 [see LICENSE for details] 5 | # ------------------------------------------------------------------------ 6 | # Modified from DETR (https://github.com/facebookresearch/detr) 7 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 8 | # ------------------------------------------------------------------------ 9 | 10 | from .deformable_detr import build as build_deformable_detr 11 | from .motr import build as build_motr 12 | 13 | 14 | def build_model(args): 15 | arch_catalog = { 16 | 'deformable_detr': build_deformable_detr, 17 | 'motr': build_motr, 18 | } 19 | assert args.meta_arch in arch_catalog, 'invalid arch: {}'.format(args.meta_arch) 20 | build_func = arch_catalog[args.meta_arch] 21 | return build_func(args) 22 | 23 | -------------------------------------------------------------------------------- /MOTR/models/ops/functions/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 3 | # ------------------------------------------------------------------------ 4 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 5 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 6 | # ------------------------------------------------------------------------ 7 | # Modified from DETR (https://github.com/facebookresearch/detr) 8 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 9 | # ------------------------------------------------------------------------ 10 | 11 | 12 | from .ms_deform_attn_func import MSDeformAttnFunction 13 | 14 | -------------------------------------------------------------------------------- /MOTR/models/ops/make.sh: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------------------------ 2 | # Deformable DETR 3 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 4 | # Licensed under the Apache License, Version 2.0 [see LICENSE for details] 5 | # ------------------------------------------------------------------------------------------------ 6 | # Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 7 | # ------------------------------------------------------------------------------------------------ 8 | 9 | python setup.py build install 10 | -------------------------------------------------------------------------------- /MOTR/models/ops/modules/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 3 | # ------------------------------------------------------------------------ 4 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 5 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 6 | # ------------------------------------------------------------------------ 7 | # Modified from DETR (https://github.com/facebookresearch/detr) 8 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 9 | # ------------------------------------------------------------------------ 10 | 11 | 12 | from .ms_deform_attn import MSDeformAttn 13 | -------------------------------------------------------------------------------- /MOTR/models/ops/setup.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------------------------ 2 | # Deformable DETR 3 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 4 | # Licensed under the Apache License, Version 2.0 [see LICENSE for details] 5 | # ------------------------------------------------------------------------------------------------ 6 | # Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 7 | # ------------------------------------------------------------------------------------------------ 8 | 9 | import os 10 | import glob 11 | 12 | import torch 13 | 14 | from torch.utils.cpp_extension import CUDA_HOME 15 | from torch.utils.cpp_extension import CppExtension 16 | from torch.utils.cpp_extension import CUDAExtension 17 | 18 | from setuptools import find_packages 19 | from setuptools import setup 20 | 21 | requirements = ["torch", "torchvision"] 22 | 23 | def get_extensions(): 24 | this_dir = os.path.dirname(os.path.abspath(__file__)) 25 | extensions_dir = os.path.join(this_dir, "src") 26 | 27 | main_file = glob.glob(os.path.join(extensions_dir, "*.cpp")) 28 | source_cpu = glob.glob(os.path.join(extensions_dir, "cpu", "*.cpp")) 29 | source_cuda = glob.glob(os.path.join(extensions_dir, "cuda", "*.cu")) 30 | 31 | sources = main_file + source_cpu 32 | extension = CppExtension 33 | extra_compile_args = {"cxx": []} 34 | define_macros = [] 35 | 36 | if torch.cuda.is_available() and CUDA_HOME is not None: 37 | extension = CUDAExtension 38 | sources += source_cuda 39 | define_macros += [("WITH_CUDA", None)] 40 | extra_compile_args["nvcc"] = [ 41 | "-DCUDA_HAS_FP16=1", 42 | "-D__CUDA_NO_HALF_OPERATORS__", 43 | "-D__CUDA_NO_HALF_CONVERSIONS__", 44 | "-D__CUDA_NO_HALF2_OPERATORS__", 45 | ] 46 | else: 47 | raise NotImplementedError('Cuda is not availabel') 48 | 49 | sources = [os.path.join(extensions_dir, s) for s in sources] 50 | include_dirs = [extensions_dir] 51 | ext_modules = [ 52 | extension( 53 | "MultiScaleDeformableAttention", 54 | sources, 55 | include_dirs=include_dirs, 56 | define_macros=define_macros, 57 | extra_compile_args=extra_compile_args, 58 | ) 59 | ] 60 | return ext_modules 61 | 62 | setup( 63 | name="MultiScaleDeformableAttention", 64 | version="1.0", 65 | author="Weijie Su", 66 | url="https://github.com/fundamentalvision/Deformable-DETR", 67 | description="PyTorch Wrapper for CUDA Functions of Multi-Scale Deformable Attention", 68 | packages=find_packages(exclude=("configs", "tests",)), 69 | ext_modules=get_extensions(), 70 | cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension}, 71 | ) 72 | -------------------------------------------------------------------------------- /MOTR/models/ops/src/cpu/ms_deform_attn_cpu.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | 17 | at::Tensor 18 | ms_deform_attn_cpu_forward( 19 | const at::Tensor &value, 20 | const at::Tensor &spatial_shapes, 21 | const at::Tensor &level_start_index, 22 | const at::Tensor &sampling_loc, 23 | const at::Tensor &attn_weight, 24 | const int im2col_step) 25 | { 26 | AT_ERROR("Not implement on cpu"); 27 | } 28 | 29 | std::vector 30 | ms_deform_attn_cpu_backward( 31 | const at::Tensor &value, 32 | const at::Tensor &spatial_shapes, 33 | const at::Tensor &level_start_index, 34 | const at::Tensor &sampling_loc, 35 | const at::Tensor &attn_weight, 36 | const at::Tensor &grad_output, 37 | const int im2col_step) 38 | { 39 | AT_ERROR("Not implement on cpu"); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /MOTR/models/ops/src/cpu/ms_deform_attn_cpu.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | #pragma once 12 | #include 13 | 14 | at::Tensor 15 | ms_deform_attn_cpu_forward( 16 | const at::Tensor &value, 17 | const at::Tensor &spatial_shapes, 18 | const at::Tensor &level_start_index, 19 | const at::Tensor &sampling_loc, 20 | const at::Tensor &attn_weight, 21 | const int im2col_step); 22 | 23 | std::vector 24 | ms_deform_attn_cpu_backward( 25 | const at::Tensor &value, 26 | const at::Tensor &spatial_shapes, 27 | const at::Tensor &level_start_index, 28 | const at::Tensor &sampling_loc, 29 | const at::Tensor &attn_weight, 30 | const at::Tensor &grad_output, 31 | const int im2col_step); 32 | 33 | 34 | -------------------------------------------------------------------------------- /MOTR/models/ops/src/cuda/ms_deform_attn_cuda.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | #pragma once 12 | #include 13 | 14 | at::Tensor ms_deform_attn_cuda_forward( 15 | const at::Tensor &value, 16 | const at::Tensor &spatial_shapes, 17 | const at::Tensor &level_start_index, 18 | const at::Tensor &sampling_loc, 19 | const at::Tensor &attn_weight, 20 | const int im2col_step); 21 | 22 | std::vector ms_deform_attn_cuda_backward( 23 | const at::Tensor &value, 24 | const at::Tensor &spatial_shapes, 25 | const at::Tensor &level_start_index, 26 | const at::Tensor &sampling_loc, 27 | const at::Tensor &attn_weight, 28 | const at::Tensor &grad_output, 29 | const int im2col_step); 30 | 31 | -------------------------------------------------------------------------------- /MOTR/models/ops/src/ms_deform_attn.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | #pragma once 12 | 13 | #include "cpu/ms_deform_attn_cpu.h" 14 | 15 | #ifdef WITH_CUDA 16 | #include "cuda/ms_deform_attn_cuda.h" 17 | #endif 18 | 19 | 20 | at::Tensor 21 | ms_deform_attn_forward( 22 | const at::Tensor &value, 23 | const at::Tensor &spatial_shapes, 24 | const at::Tensor &level_start_index, 25 | const at::Tensor &sampling_loc, 26 | const at::Tensor &attn_weight, 27 | const int im2col_step) 28 | { 29 | if (value.type().is_cuda()) 30 | { 31 | #ifdef WITH_CUDA 32 | return ms_deform_attn_cuda_forward( 33 | value, spatial_shapes, level_start_index, sampling_loc, attn_weight, im2col_step); 34 | #else 35 | AT_ERROR("Not compiled with GPU support"); 36 | #endif 37 | } 38 | AT_ERROR("Not implemented on the CPU"); 39 | } 40 | 41 | std::vector 42 | ms_deform_attn_backward( 43 | const at::Tensor &value, 44 | const at::Tensor &spatial_shapes, 45 | const at::Tensor &level_start_index, 46 | const at::Tensor &sampling_loc, 47 | const at::Tensor &attn_weight, 48 | const at::Tensor &grad_output, 49 | const int im2col_step) 50 | { 51 | if (value.type().is_cuda()) 52 | { 53 | #ifdef WITH_CUDA 54 | return ms_deform_attn_cuda_backward( 55 | value, spatial_shapes, level_start_index, sampling_loc, attn_weight, grad_output, im2col_step); 56 | #else 57 | AT_ERROR("Not compiled with GPU support"); 58 | #endif 59 | } 60 | AT_ERROR("Not implemented on the CPU"); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /MOTR/models/ops/src/vision.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | #include "ms_deform_attn.h" 12 | 13 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 14 | m.def("ms_deform_attn_forward", &ms_deform_attn_forward, "ms_deform_attn_forward"); 15 | m.def("ms_deform_attn_backward", &ms_deform_attn_backward, "ms_deform_attn_backward"); 16 | } 17 | -------------------------------------------------------------------------------- /MOTR/models/relu_dropout.py: -------------------------------------------------------------------------------- 1 | # https://gist.github.com/vadimkantorov/360ece06de4fd2641fa9ed1085f76d48 2 | import torch 3 | 4 | class ReLUDropout(torch.nn.Dropout): 5 | def forward(self, input): 6 | return relu_dropout(input, p=self.p, training=self.training, inplace=self.inplace) 7 | 8 | def relu_dropout(x, p=0, inplace=False, training=False): 9 | if not training or p == 0: 10 | return x.clamp_(min=0) if inplace else x.clamp(min=0) 11 | 12 | mask = (x < 0) | (torch.rand_like(x) > 1 - p) 13 | return x.masked_fill_(mask, 0).div_(1 - p) if inplace else x.masked_fill(mask, 0).div(1 - p) 14 | -------------------------------------------------------------------------------- /MOTR/models/structures/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Modified from Detectron2 (https://github.com/facebookresearch/detectron2) 3 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 4 | # ------------------------------------------------------------------------ 5 | from .boxes import Boxes, BoxMode, pairwise_iou, pairwise_ioa, matched_boxlist_iou 6 | from .instances import Instances 7 | 8 | __all__ = [k for k in globals().keys() if not k.startswith("_")] -------------------------------------------------------------------------------- /MOTR/requirements.txt: -------------------------------------------------------------------------------- 1 | pycocotools 2 | tqdm 3 | cython 4 | scipy 5 | motmetrics 6 | opencv-python 7 | seaborn 8 | lap 9 | -------------------------------------------------------------------------------- /MOTR/tools/run_dist_launch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ------------------------------------------------------------------------ 3 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 4 | # ------------------------------------------------------------------------ 5 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 6 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 7 | # ------------------------------------------------------------------------ 8 | # Modified from DETR (https://github.com/facebookresearch/detr) 9 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 10 | # ------------------------------------------------------------------------ 11 | 12 | 13 | set -x 14 | 15 | GPUS=$1 16 | RUN_COMMAND=${@:2} 17 | if [ $GPUS -lt 8 ]; then 18 | GPUS_PER_NODE=${GPUS_PER_NODE:-$GPUS} 19 | else 20 | GPUS_PER_NODE=${GPUS_PER_NODE:-8} 21 | fi 22 | MASTER_ADDR=${MASTER_ADDR:-"127.0.0.1"} 23 | MASTER_PORT=${MASTER_PORT:-"29500"} 24 | NODE_RANK=${NODE_RANK:-0} 25 | 26 | let "NNODES=GPUS/GPUS_PER_NODE" 27 | 28 | python3 ./tools/launch.py \ 29 | --nnodes ${NNODES} \ 30 | --node_rank ${NODE_RANK} \ 31 | --master_addr ${MASTER_ADDR} \ 32 | --master_port ${MASTER_PORT} \ 33 | --nproc_per_node ${GPUS_PER_NODE} \ 34 | ${RUN_COMMAND} -------------------------------------------------------------------------------- /MOTR/tools/run_dist_slurm.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ------------------------------------------------------------------------ 3 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 4 | # ------------------------------------------------------------------------ 5 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 6 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 7 | # ------------------------------------------------------------------------ 8 | # Modified from DETR (https://github.com/facebookresearch/detr) 9 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 10 | # ------------------------------------------------------------------------ 11 | 12 | 13 | set -x 14 | 15 | PARTITION=$1 16 | JOB_NAME=$2 17 | GPUS=$3 18 | RUN_COMMAND=${@:4} 19 | if [ $GPUS -lt 8 ]; then 20 | GPUS_PER_NODE=${GPUS_PER_NODE:-$GPUS} 21 | else 22 | GPUS_PER_NODE=${GPUS_PER_NODE:-8} 23 | fi 24 | CPUS_PER_TASK=${CPUS_PER_TASK:-4} 25 | SRUN_ARGS=${SRUN_ARGS:-""} 26 | 27 | srun -p ${PARTITION} \ 28 | --job-name=${JOB_NAME} \ 29 | --gres=gpu:${GPUS_PER_NODE} \ 30 | --ntasks=${GPUS} \ 31 | --ntasks-per-node=${GPUS_PER_NODE} \ 32 | --cpus-per-task=${CPUS_PER_TASK} \ 33 | --kill-on-bad-exit=1 \ 34 | ${SRUN_ARGS} \ 35 | ${RUN_COMMAND} 36 | 37 | -------------------------------------------------------------------------------- /MOTR/util/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 3 | # ------------------------------------------------------------------------ 4 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 5 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 6 | # ------------------------------------------------------------------------ 7 | # Modified from DETR (https://github.com/facebookresearch/detr) 8 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 9 | # ------------------------------------------------------------------------ 10 | 11 | -------------------------------------------------------------------------------- /MOTR/util/box_ops.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 3 | # ------------------------------------------------------------------------ 4 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 5 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 6 | # ------------------------------------------------------------------------ 7 | # Modified from DETR (https://github.com/facebookresearch/detr) 8 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 9 | # ------------------------------------------------------------------------ 10 | 11 | 12 | """ 13 | Utilities for bounding box manipulation and GIoU. 14 | """ 15 | import torch 16 | from torchvision.ops.boxes import box_area 17 | 18 | 19 | def box_cxcywh_to_xyxy(x): 20 | x_c, y_c, w, h = x.unbind(-1) 21 | b = [(x_c - 0.5 * w), (y_c - 0.5 * h), 22 | (x_c + 0.5 * w), (y_c + 0.5 * h)] 23 | return torch.stack(b, dim=-1) 24 | 25 | 26 | def box_xyxy_to_cxcywh(x): 27 | x0, y0, x1, y1 = x.unbind(-1) 28 | b = [(x0 + x1) / 2, (y0 + y1) / 2, 29 | (x1 - x0), (y1 - y0)] 30 | return torch.stack(b, dim=-1) 31 | 32 | 33 | # modified from torchvision to also return the union 34 | def box_iou(boxes1, boxes2): 35 | area1 = box_area(boxes1) 36 | area2 = box_area(boxes2) 37 | 38 | lt = torch.max(boxes1[:, None, :2], boxes2[:, :2]) # [N,M,2] 39 | rb = torch.min(boxes1[:, None, 2:], boxes2[:, 2:]) # [N,M,2] 40 | 41 | wh = (rb - lt).clamp(min=0) # [N,M,2] 42 | inter = wh[:, :, 0] * wh[:, :, 1] # [N,M] 43 | 44 | union = area1[:, None] + area2 - inter 45 | 46 | iou = inter / union 47 | return iou, union 48 | 49 | 50 | def generalized_box_iou(boxes1, boxes2): 51 | """ 52 | Generalized IoU from https://giou.stanford.edu/ 53 | 54 | The boxes should be in [x0, y0, x1, y1] format 55 | 56 | Returns a [N, M] pairwise matrix, where N = len(boxes1) 57 | and M = len(boxes2) 58 | """ 59 | # degenerate boxes gives inf / nan results 60 | # so do an early check 61 | assert (boxes1[:, 2:] >= boxes1[:, :2]).all() 62 | assert (boxes2[:, 2:] >= boxes2[:, :2]).all() 63 | iou, union = box_iou(boxes1, boxes2) 64 | 65 | lt = torch.min(boxes1[:, None, :2], boxes2[:, :2]) 66 | rb = torch.max(boxes1[:, None, 2:], boxes2[:, 2:]) 67 | 68 | wh = (rb - lt).clamp(min=0) # [N,M,2] 69 | area = wh[:, :, 0] * wh[:, :, 1] 70 | 71 | return iou - (area - union) / area 72 | 73 | 74 | def masks_to_boxes(masks): 75 | """Compute the bounding boxes around the provided masks 76 | 77 | The masks should be in format [N, H, W] where N is the number of masks, (H, W) are the spatial dimensions. 78 | 79 | Returns a [N, 4] tensors, with the boxes in xyxy format 80 | """ 81 | if masks.numel() == 0: 82 | return torch.zeros((0, 4), device=masks.device) 83 | 84 | h, w = masks.shape[-2:] 85 | 86 | y = torch.arange(0, h, dtype=torch.float) 87 | x = torch.arange(0, w, dtype=torch.float) 88 | y, x = torch.meshgrid(y, x) 89 | 90 | x_mask = (masks * x.unsqueeze(0)) 91 | x_max = x_mask.flatten(1).max(-1)[0] 92 | x_min = x_mask.masked_fill(~(masks.bool()), 1e8).flatten(1).min(-1)[0] 93 | 94 | y_mask = (masks * y.unsqueeze(0)) 95 | y_max = y_mask.flatten(1).max(-1)[0] 96 | y_min = y_mask.masked_fill(~(masks.bool()), 1e8).flatten(1).min(-1)[0] 97 | 98 | return torch.stack([x_min, y_min, x_max, y_max], 1) 99 | -------------------------------------------------------------------------------- /MOTR/util/checkpoint.py: -------------------------------------------------------------------------------- 1 | # from: https://github.com/csrhddlam/pytorch-checkpoint 2 | 3 | import torch 4 | import warnings 5 | 6 | 7 | def detach_variable(inputs): 8 | if isinstance(inputs, tuple): 9 | out = [] 10 | for inp in inputs: 11 | x = inp.detach() 12 | x.requires_grad = inp.requires_grad 13 | out.append(x) 14 | return tuple(out) 15 | else: 16 | raise RuntimeError( 17 | "Only tuple of tensors is supported. Got Unsupported input type: ", type(inputs).__name__) 18 | 19 | 20 | def check_backward_validity(inputs): 21 | if not any(inp.requires_grad for inp in inputs): 22 | warnings.warn("None of the inputs have requires_grad=True. Gradients will be None") 23 | 24 | 25 | class CheckpointFunction(torch.autograd.Function): 26 | @staticmethod 27 | def forward(ctx, run_function, length, *args): 28 | ctx.run_function = run_function 29 | ctx.input_tensors = list(args[:length]) 30 | ctx.input_params = list(args[length:]) 31 | with torch.no_grad(): 32 | output_tensors = ctx.run_function(*ctx.input_tensors) 33 | return output_tensors 34 | 35 | @staticmethod 36 | def backward(ctx, *output_grads): 37 | for i in range(len(ctx.input_tensors)): 38 | temp = ctx.input_tensors[i] 39 | ctx.input_tensors[i] = temp.detach() 40 | ctx.input_tensors[i].requires_grad = temp.requires_grad 41 | with torch.enable_grad(): 42 | output_tensors = ctx.run_function(*ctx.input_tensors) 43 | to_autograd = [] 44 | for i in range(len(ctx.input_tensors)): 45 | if ctx.input_tensors[i].requires_grad: 46 | to_autograd.append(ctx.input_tensors[i]) 47 | output_tensors, output_grads = zip(*filter(lambda t: t[0].requires_grad, zip(output_tensors, output_grads))) 48 | input_grads = torch.autograd.grad(output_tensors, to_autograd + ctx.input_params, output_grads, allow_unused=True) 49 | input_grads = list(input_grads) 50 | for i in range(len(ctx.input_tensors)): 51 | if not ctx.input_tensors[i].requires_grad: 52 | input_grads.insert(i, None) 53 | return (None, None) + tuple(input_grads) 54 | -------------------------------------------------------------------------------- /MOTR/util/tool.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Copyright (c) 2021 megvii-model. All Rights Reserved. 3 | # ------------------------------------------------------------------------ 4 | # Modified from Deformable DETR (https://github.com/fundamentalvision/Deformable-DETR) 5 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 6 | # ------------------------------------------------------------------------ 7 | # Modified from DETR (https://github.com/facebookresearch/detr) 8 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 9 | # ------------------------------------------------------------------------ 10 | 11 | import torch 12 | import numpy as np 13 | 14 | 15 | def load_model(model, model_path, optimizer=None, resume=False, 16 | lr=None, lr_step=None): 17 | start_epoch = 0 18 | checkpoint = torch.load(model_path, map_location=lambda storage, loc: storage) 19 | print(f'loaded {model_path}') 20 | state_dict = checkpoint['model'] 21 | model_state_dict = model.state_dict() 22 | 23 | # check loaded parameters and created model parameters 24 | msg = 'If you see this, your model does not fully load the ' + \ 25 | 'pre-trained weight. Please make sure ' + \ 26 | 'you set the correct --num_classes for your own dataset.' 27 | for k in state_dict: 28 | if k in model_state_dict: 29 | if state_dict[k].shape != model_state_dict[k].shape: 30 | print('Skip loading parameter {}, required shape{}, ' \ 31 | 'loaded shape{}. {}'.format( 32 | k, model_state_dict[k].shape, state_dict[k].shape, msg)) 33 | if 'class_embed' in k: 34 | print("load class_embed: {} shape={}".format(k, state_dict[k].shape)) 35 | if model_state_dict[k].shape[0] == 1: 36 | state_dict[k] = state_dict[k][1:2] 37 | elif model_state_dict[k].shape[0] == 2: 38 | state_dict[k] = state_dict[k][1:3] 39 | elif model_state_dict[k].shape[0] == 3: 40 | state_dict[k] = state_dict[k][1:4] 41 | else: 42 | raise NotImplementedError('invalid shape: {}'.format(model_state_dict[k].shape)) 43 | continue 44 | state_dict[k] = model_state_dict[k] 45 | else: 46 | print('Drop parameter {}.'.format(k) + msg) 47 | for k in model_state_dict: 48 | if not (k in state_dict): 49 | print('No param {}.'.format(k) + msg) 50 | state_dict[k] = model_state_dict[k] 51 | model.load_state_dict(state_dict, strict=False) 52 | 53 | # resume optimizer parameters 54 | if optimizer is not None and resume: 55 | if 'optimizer' in checkpoint: 56 | optimizer.load_state_dict(checkpoint['optimizer']) 57 | start_epoch = checkpoint['epoch'] 58 | start_lr = lr 59 | for step in lr_step: 60 | if start_epoch >= step: 61 | start_lr *= 0.1 62 | for param_group in optimizer.param_groups: 63 | param_group['lr'] = start_lr 64 | print('Resumed optimizer with start lr', start_lr) 65 | else: 66 | print('No optimizer parameters in checkpoint.') 67 | if optimizer is not None: 68 | return model, optimizer, start_epoch 69 | else: 70 | return model 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DecoderTracker: Decoder-Only Method for Multiple-Object Tracking 2 | Official implementation of ['DecoderTracker: Decoder-Only Method for Multiple-Object Tracking'](https://arxiv.org/abs/2310.17170) . 3 | 4 | 5 | # Notice to Users 6 | Thank you for your interest in the DecoderTracker implementation. We want to inform you that the current code release includes known issues that we are actively working to resolve. This notice outlines the identified problems and our plan to address them in the near future. 7 | 8 | 9 | 啊,之前实现的时候偷懒三个阶段训练阶段用了三份代码,现在这好麻烦啊。 10 | 11 | 这篇sb论文要是能中,一定开源完整的代码。PR是真的离谱,为什么会有三审再给个拒稿重投的啊!!!!!要是后面彻底拒了,我直接在改标题,标题上加上Rejected by Pattern Recognition after X review(X大于等于4) 12 | 13 | # Acknowlegment 14 | Thanks for [Ultralytics](https://github.com/ultralytics/ultralytics/) and [MOTR](https://github.com/megvii-research/MOTR). 15 | -------------------------------------------------------------------------------- /dancetracker.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # COCO128 dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics 3 | # Example usage: yolo train data=coco128.yaml 4 | # parent 5 | # ├── ultralytics 6 | # └── datasets 7 | # └── coco128 ← downloads here (7 MB) 8 | 9 | 10 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] 11 | train: E:\data\dancetrack\yolo_track\train.txt # train images (relative to 'path') 128 images 12 | val: E:\data\dancetrack\yolo_track\val_1.txt # val images (relative to 'path') 128 images 13 | test: # test images (optional) 14 | 15 | # Classes 16 | names: 17 | 0: person 18 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # Ultralytics requirements 2 | # Usage: pip install -r requirements.txt 3 | 4 | # Base ---------------------------------------- 5 | matplotlib>=3.2.2 6 | opencv-python>=4.6.0 7 | Pillow>=7.1.2 8 | PyYAML>=5.3.1 9 | requests>=2.23.0 10 | scipy>=1.4.1 11 | #torch>=1.7.0 12 | #torchvision>=0.8.1 13 | tqdm>=4.64.0 14 | 15 | # Logging ------------------------------------- 16 | # tensorboard>=2.13.0 17 | # dvclive>=2.12.0 18 | # clearml 19 | # comet 20 | 21 | # Plotting ------------------------------------ 22 | pandas>=1.1.4 23 | seaborn>=0.11.0 24 | 25 | # Export -------------------------------------- 26 | # coremltools>=6.0 # CoreML export 27 | # onnx>=1.12.0 # ONNX export 28 | # onnxsim>=0.4.1 # ONNX simplifier 29 | # nvidia-pyindex # TensorRT export 30 | # nvidia-tensorrt # TensorRT export 31 | # scikit-learn==0.19.2 # CoreML quantization 32 | # tensorflow>=2.4.1 # TF exports (-cpu, -aarch64, -macos) 33 | # tflite-support 34 | # tensorflowjs>=3.9.0 # TF.js export 35 | # openvino-dev>=2023.0 # OpenVINO export 36 | 37 | # Extras -------------------------------------- 38 | psutil # system utilization 39 | # thop>=0.1.1 # FLOPs computation 40 | # ipython # interactive notebook 41 | # albumentations>=1.0.3 42 | # pycocotools>=2.0.6 # COCO mAP 43 | # roboflow 44 | -------------------------------------------------------------------------------- /run_test.py: -------------------------------------------------------------------------------- 1 | from ultralytics import YOLO, MOTRTrack, RTDETR 2 | import os 3 | if __name__ == '__main__': 4 | # model = YOLO('yolov8n.pt') 5 | # model = YOLO('yolov8m.yaml') 6 | # model = YOLO(r"E:\cv\yolo_tracking\weights\yolov8_MOT17.pt") 7 | # model(source=r"E:\data\MOT17\test\MOT17-03-DPM\img1") 8 | # model(source=r"E:\data\MOT17\test\MOT17-03-DPM\img1") 9 | 10 | # model = MOTRTrack("yolo_track.yaml") # 7443199 7447807 7443199 11 | # model = MOTRTrack("yolov8m_track.yaml") 12 | # model = MOTRTrack(r"E:\cv\KITTI_detection\weights\best.pt") # 加载预训练模型(建议用于训练) 13 | # model = MOTRTrack(r"E:\cv\MOT17_detection\best.pt") # 加载预训练模型(建议用于训练) 14 | # folder_path = r'E:\data\dancetrack\test' 15 | # 16 | # # 使用os.listdir()获取目录下所有文件和子文件夹 17 | # subfolders = [f for f in os.listdir(folder_path) if os.path.isdir(os.path.join(folder_path, f))] 18 | # 19 | # 20 | # for subpath in subfolders: 21 | # model = MOTRTrack(r"F:\cv\tracking_pretrain\runs\track\dancetrack\weights\best.pt") # 加载预训练模型(建议用于训练) 22 | # 23 | # model(folder_path+'/'+subpath+r'/img1') 24 | 25 | # subfolders 列表中包含了指定目录下的所有子文件夹的名称 26 | 27 | # model = MOTRTrack(r"C:\Users\a\Desktop\train3\weights\best.pt") # 加载预训练模型(建议用于训练) 28 | # model = MOTRTrack(r"F:\cv\tracking_pretrain\runs\track\MOT17\weights\best.pt") # 加载预训练模型(建议用于训练) 29 | # model = MOTRTrack(r"F:\cv\tracking_pretrain\runs\track\train2\weights\best.pt") # 加载预训练模型(建议用于训练) 30 | # model = RTDETR("best.pt") # 加载预训练模型(建议用于训练) 31 | 32 | # 使用模型 33 | # model.train(data="KITTI.yaml", epochs=10, batch=1) # 训练模型 34 | # model.train(data="MOT.yaml", epochs=20, batch=1) # 训练模型 35 | 36 | # model(r"E:\data\KITTI_TRACKING\training\images\0000", show=False, save=True) # 查看结果14 37 | # model(r"E:\data\KITTI_TRACKING\training\images\0000", show=False, save=False) # 查看结果 38 | # model(r"E:\data\MOT17\images\test\MOT17-01-DPM\img1", show=False, save_txt=True) # 查看结果 39 | # model(r"E:\data\MOT17\images\train\MOT17-02-DPM\img1", show=False, save_txt=True) # 查看结果 40 | # MOT_test = ['03', '06', '07', '08', '12', '14'] 41 | # for i in MOT_test: 42 | # model = MOTRTrack(r"C:\Users\a\Desktop\train3\weights\best.pt") # 加载预训练模型(建议用于训练) 43 | # test_url = r"E:\data\MOT17\images\test\MOT17-" + i + r"-DPM\img1" 44 | # model(test_url, show=False, save_txt=True) # 查看结果 45 | 46 | # dancetrack_name = [3, 9, 11, 13, 17, 21, 22, 28, 31, 36, 38, 40, 42, 46, 48, 50, 54, 56, 59, 60, 64, 67, 70, 71, 76, 78, 84, 85, 88, 89, 91, 92, 93, 95, 100] 47 | # for i in dancetrack_name: 48 | # model = MOTRTrack(r'F:\cv\ultralytics_trackingv3\runs\track\train5\weights\best.pt') # 加载预训练模型(建议用于训练) 49 | # test_url = r"E:\data\dancetrack\test\dancetrack" + '{:04d}'.format(i) + r"\img1" 50 | # model(test_url, show=False, save_txt=True) # 查看结果 51 | 52 | # folder_path = r'E:\data\KITTI_TRACKING\testing\images' 53 | # KITTI_url = [f.path for f in os.scandir(folder_path) if f.is_dir()] 54 | KITTI_url = [1] 55 | for i in KITTI_url: 56 | model = MOTRTrack(r"F:\cv\ultralytics_trackingv3\runs\track\train6\weights\best.pt") # 加载预训练模型(建议用于训练) 57 | 58 | model(r'E:\data\MOT17\train_yolo_track\images\val', show=True,save=False) # 查看结果 59 | # model.train(data="MOT.yaml", epochs=30, batch=1) # 训练模型 60 | # metrics = model.val() # 在验证集上评估模型性能 61 | # results = model("https://ultralytics.com/images/bus.jpg") # 对图像进行预测 62 | # success = model.export(format="onnx") # 将模型导出为 ONNX 格式 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | # Project-wide configuration file, can be used for package metadata and other toll configurations 2 | # Example usage: global configuration for PEP8 (via flake8) setting or default pytest arguments 3 | # Local usage: pip install pre-commit, pre-commit run --all-files 4 | 5 | [metadata] 6 | license_files = LICENSE 7 | description_file = README.md 8 | 9 | [tool:pytest] 10 | norecursedirs = 11 | .git 12 | dist 13 | build 14 | addopts = 15 | --doctest-modules 16 | --durations=25 17 | --color=yes 18 | 19 | [flake8] 20 | max-line-length = 120 21 | exclude = .tox,*.egg,build,temp 22 | select = E,W,F 23 | doctests = True 24 | verbose = 2 25 | # https://pep8.readthedocs.io/en/latest/intro.html#error-codes 26 | format = pylint 27 | # see: https://www.flake8rules.com/ 28 | ignore = E731,F405,E402,W504,E501 29 | # E731: Do not assign a lambda expression, use a def 30 | # F405: name may be undefined, or defined from star imports: module 31 | # E402: module level import not at top of file 32 | # W504: line break after binary operator 33 | # E501: line too long 34 | # removed: 35 | # F401: module imported but unused 36 | # E231: missing whitespace after ‘,’, ‘;’, or ‘:’ 37 | # E127: continuation line over-indented for visual indent 38 | # F403: ‘from module import *’ used; unable to detect undefined names 39 | 40 | 41 | [isort] 42 | # https://pycqa.github.io/isort/docs/configuration/options.html 43 | line_length = 120 44 | # see: https://pycqa.github.io/isort/docs/configuration/multi_line_output_modes.html 45 | multi_line_output = 0 46 | 47 | [yapf] 48 | based_on_style = pep8 49 | spaces_before_comment = 2 50 | COLUMN_LIMIT = 120 51 | COALESCE_BRACKETS = True 52 | SPACES_AROUND_POWER_OPERATOR = True 53 | SPACE_BETWEEN_ENDING_COMMA_AND_CLOSING_BRACKET = True 54 | SPLIT_BEFORE_CLOSING_BRACKET = False 55 | SPLIT_BEFORE_FIRST_ARGUMENT = False 56 | # EACH_DICT_ENTRY_ON_SEPARATE_LINE = False 57 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | import re 4 | from pathlib import Path 5 | 6 | import pkg_resources as pkg 7 | from setuptools import find_packages, setup 8 | 9 | # Settings 10 | FILE = Path(__file__).resolve() 11 | PARENT = FILE.parent # root directory 12 | README = (PARENT / 'README.md').read_text(encoding='utf-8') 13 | REQUIREMENTS = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements((PARENT / 'requirements.txt').read_text())] 14 | 15 | 16 | def get_version(): 17 | file = PARENT / 'ultralytics/__init__.py' 18 | return re.search(r'^__version__ = [\'"]([^\'"]*)[\'"]', file.read_text(encoding='utf-8'), re.M)[1] 19 | 20 | 21 | setup( 22 | name='ultralytics', # name of pypi package 23 | version=get_version(), # version of pypi package 24 | python_requires='>=3.7', 25 | license='AGPL-3.0', 26 | description=('Ultralytics YOLOv8 for SOTA object detection, multi-object tracking, instance segmentation, ' 27 | 'pose estimation and image classification.'), 28 | long_description=README, 29 | long_description_content_type='text/markdown', 30 | url='https://github.com/ultralytics/ultralytics', 31 | project_urls={ 32 | 'Bug Reports': 'https://github.com/ultralytics/ultralytics/issues', 33 | 'Funding': 'https://ultralytics.com', 34 | 'Source': 'https://github.com/ultralytics/ultralytics'}, 35 | author='Ultralytics', 36 | author_email='hello@ultralytics.com', 37 | packages=find_packages(), # required 38 | include_package_data=True, 39 | install_requires=REQUIREMENTS, 40 | extras_require={ 41 | 'dev': [ 42 | 'check-manifest', 43 | 'pytest', 44 | 'pytest-cov', 45 | 'coverage', 46 | 'mkdocs-material', 47 | 'mkdocstrings[python]', 48 | 'mkdocs-redirects', # for 301 redirects 49 | 'mkdocs-ultralytics-plugin>=0.0.21', # for meta descriptions and images, dates and authors 50 | ], 51 | 'export': ['coremltools>=6.0,<=6.2', 'openvino-dev>=2023.0', 52 | 'tensorflowjs'], # automatically installs tensorflow 53 | }, 54 | classifiers=[ 55 | 'Development Status :: 4 - Beta', 56 | 'Intended Audience :: Developers', 57 | 'Intended Audience :: Education', 58 | 'Intended Audience :: Science/Research', 59 | 'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)', 60 | 'Programming Language :: Python :: 3', 61 | 'Programming Language :: Python :: 3.7', 62 | 'Programming Language :: Python :: 3.8', 63 | 'Programming Language :: Python :: 3.9', 64 | 'Programming Language :: Python :: 3.10', 65 | 'Programming Language :: Python :: 3.11', 66 | 'Topic :: Software Development', 67 | 'Topic :: Scientific/Engineering', 68 | 'Topic :: Scientific/Engineering :: Artificial Intelligence', 69 | 'Topic :: Scientific/Engineering :: Image Recognition', 70 | 'Operating System :: POSIX :: Linux', 71 | 'Operating System :: MacOS', 72 | 'Operating System :: Microsoft :: Windows', ], 73 | keywords='machine-learning, deep-learning, vision, ML, DL, AI, YOLO, YOLOv3, YOLOv5, YOLOv8, HUB, Ultralytics', 74 | entry_points={'console_scripts': ['yolo = ultralytics.cfg:entrypoint', 'ultralytics = ultralytics.cfg:entrypoint']}) 75 | -------------------------------------------------------------------------------- /start_train.py: -------------------------------------------------------------------------------- 1 | from ultralytics import YOLO, MOTRTrack, RTDETR 2 | import os 3 | import time 4 | 5 | 6 | 7 | 8 | if __name__ == '__main__': 9 | 10 | 11 | model = MOTRTrack("yolo_track.yaml") # 7443199 7447807 7443199 12 | 13 | # 使用模型 14 | model.train(data="dancetracker.yaml", epochs=1, batch=1) # 训练模型 15 | 16 | -------------------------------------------------------------------------------- /tests/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | 4 | def pytest_addoption(parser): 5 | parser.addoption('--runslow', action='store_true', default=False, help='run slow tests') 6 | 7 | 8 | def pytest_configure(config): 9 | config.addinivalue_line('markers', 'slow: mark test as slow to run') 10 | 11 | 12 | def pytest_collection_modifyitems(config, items): 13 | if config.getoption('--runslow'): 14 | # --runslow given in cli: do not skip slow tests 15 | return 16 | skip_slow = pytest.mark.skip(reason='need --runslow option to run') 17 | for item in items: 18 | if 'slow' in item.keywords: 19 | item.add_marker(skip_slow) 20 | -------------------------------------------------------------------------------- /tests/test_cli.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | import subprocess 4 | from pathlib import Path 5 | 6 | import pytest 7 | 8 | from ultralytics.utils import ONLINE, ROOT, SETTINGS 9 | 10 | WEIGHT_DIR = Path(SETTINGS['weights_dir']) 11 | TASK_ARGS = [ # (task, model, data) 12 | ('detect', 'yolov8n', 'coco8.yaml'), ('segment', 'yolov8n-seg', 'coco8-seg.yaml'), 13 | ('classify', 'yolov8n-cls', 'imagenet10'), ('pose', 'yolov8n-pose', 'coco8-pose.yaml')] 14 | EXPORT_ARGS = [ # (model, format) 15 | ('yolov8n', 'torchscript'), ('yolov8n-seg', 'torchscript'), ('yolov8n-cls', 'torchscript'), 16 | ('yolov8n-pose', 'torchscript')] 17 | 18 | 19 | def run(cmd): 20 | # Run a subprocess command with check=True 21 | subprocess.run(cmd.split(), check=True) 22 | 23 | 24 | def test_special_modes(): 25 | run('yolo checks') 26 | run('yolo settings') 27 | run('yolo help') 28 | 29 | 30 | @pytest.mark.parametrize('task,model,data', TASK_ARGS) 31 | def test_train(task, model, data): 32 | run(f'yolo train {task} model={model}.yaml data={data} imgsz=32 epochs=1 cache=disk') 33 | 34 | 35 | @pytest.mark.parametrize('task,model,data', TASK_ARGS) 36 | def test_val(task, model, data): 37 | run(f'yolo val {task} model={model}.pt data={data} imgsz=32') 38 | 39 | 40 | @pytest.mark.parametrize('task,model,data', TASK_ARGS) 41 | def test_predict(task, model, data): 42 | run(f"yolo predict model={model}.pt source={ROOT / 'assets'} imgsz=32 save save_crop save_txt") 43 | if ONLINE: 44 | run(f'yolo predict model={model}.pt source=https://ultralytics.com/images/bus.jpg imgsz=32') 45 | run(f'yolo predict model={model}.pt source=https://ultralytics.com/assets/decelera_landscape_min.mov imgsz=32') 46 | run(f'yolo predict model={model}.pt source=https://ultralytics.com/assets/decelera_portrait_min.mov imgsz=32') 47 | 48 | 49 | @pytest.mark.parametrize('model,format', EXPORT_ARGS) 50 | def test_export(model, format): 51 | run(f'yolo export model={model}.pt format={format}') 52 | 53 | 54 | # Slow Tests 55 | @pytest.mark.slow 56 | @pytest.mark.parametrize('task,model,data', TASK_ARGS) 57 | def test_train_gpu(task, model, data): 58 | run(f'yolo train {task} model={model}.yaml data={data} imgsz=32 epochs=1 device="0"') # single GPU 59 | run(f'yolo train {task} model={model}.pt data={data} imgsz=32 epochs=1 device="0,1"') # Multi GPU 60 | -------------------------------------------------------------------------------- /ultralytics/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | __version__ = '8.0.139' 4 | 5 | from ultralytics.engine.model import YOLO 6 | from ultralytics.hub import start 7 | from ultralytics.models import RTDETR, SAM, MOTRTrack 8 | from ultralytics.models.fastsam import FastSAM 9 | from ultralytics.models.nas import NAS 10 | from ultralytics.utils.checks import check_yolo as checks 11 | from ultralytics.utils.downloads import download 12 | 13 | __all__ = '__version__', 'YOLO', 'NAS', 'SAM', 'FastSAM', 'RTDETR', 'checks', 'download', 'start', 'MOTRTrack' # allow simpler import 14 | -------------------------------------------------------------------------------- /ultralytics/assets/bus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liaopan-lp/MO-YOLO/81d917e0cafb68fda27c757ad2c35d7f1eb5f254/ultralytics/assets/bus.jpg -------------------------------------------------------------------------------- /ultralytics/assets/zidane.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liaopan-lp/MO-YOLO/81d917e0cafb68fda27c757ad2c35d7f1eb5f254/ultralytics/assets/zidane.jpg -------------------------------------------------------------------------------- /ultralytics/cfg/models/README.md: -------------------------------------------------------------------------------- 1 | ## Models 2 | 3 | Welcome to the Ultralytics Models directory! Here you will find a wide variety of pre-configured model configuration 4 | files (`*.yaml`s) that can be used to create custom YOLO models. The models in this directory have been expertly crafted 5 | and fine-tuned by the Ultralytics team to provide the best performance for a wide range of object detection and image 6 | segmentation tasks. 7 | 8 | These model configurations cover a wide range of scenarios, from simple object detection to more complex tasks like 9 | instance segmentation and object tracking. They are also designed to run efficiently on a variety of hardware platforms, 10 | from CPUs to GPUs. Whether you are a seasoned machine learning practitioner or just getting started with YOLO, this 11 | directory provides a great starting point for your custom model development needs. 12 | 13 | To get started, simply browse through the models in this directory and find one that best suits your needs. Once you've 14 | selected a model, you can use the provided `*.yaml` file to train and deploy your custom YOLO model with ease. See full 15 | details at the Ultralytics [Docs](https://docs.ultralytics.com/models), and if you need help or have any questions, feel free 16 | to reach out to the Ultralytics team for support. So, don't wait, start creating your custom YOLO model now! 17 | 18 | ### Usage 19 | 20 | Model `*.yaml` files may be used directly in the Command Line Interface (CLI) with a `yolo` command: 21 | 22 | ```bash 23 | yolo task=detect mode=train model=yolov8n.yaml data=coco128.yaml epochs=100 24 | ``` 25 | 26 | They may also be used directly in a Python environment, and accepts the same 27 | [arguments](https://docs.ultralytics.com/usage/cfg/) as in the CLI example above: 28 | 29 | ```python 30 | from ultralytics import YOLO 31 | 32 | model = YOLO("model.yaml") # build a YOLOv8n model from scratch 33 | # YOLO("model.pt") use pre-trained model if available 34 | model.info() # display model information 35 | model.train(data="coco128.yaml", epochs=100) # train the model 36 | ``` 37 | 38 | ## Pre-trained Model Architectures 39 | 40 | Ultralytics supports many model architectures. Visit https://docs.ultralytics.com/models to view detailed information 41 | and usage. Any of these models can be used by loading their configs or pretrained checkpoints if available. 42 | 43 | ## Contributing New Models 44 | 45 | If you've developed a new model architecture or have improvements for existing models that you'd like to contribute to the Ultralytics community, please submit your contribution in a new Pull Request. For more details, visit our [Contributing Guide](https://docs.ultralytics.com/help/contributing). 46 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/rt-detr/rtdetr-l.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # RT-DETR-l object detection model with P3-P5 outputs. For details see https://docs.ultralytics.com/models/rtdetr 3 | 4 | # Parameters 5 | nc: 80 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov8n-cls.yaml' will call yolov8-cls.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | l: [1.00, 1.00, 1024] 9 | 10 | backbone: 11 | # [from, repeats, module, args] 12 | - [-1, 1, HGStem, [32, 48]] # 0-P2/4 13 | - [-1, 6, HGBlock, [48, 128, 3]] # stage 1 14 | 15 | - [-1, 1, DWConv, [128, 3, 2, 1, False]] # 2-P3/8 16 | - [-1, 6, HGBlock, [96, 512, 3]] # stage 2 17 | 18 | - [-1, 1, DWConv, [512, 3, 2, 1, False]] # 4-P3/16 19 | - [-1, 6, HGBlock, [192, 1024, 5, True, False]] # cm, c2, k, light, shortcut 20 | - [-1, 6, HGBlock, [192, 1024, 5, True, True]] 21 | - [-1, 6, HGBlock, [192, 1024, 5, True, True]] # stage 3 22 | 23 | - [-1, 1, DWConv, [1024, 3, 2, 1, False]] # 8-P4/32 24 | - [-1, 6, HGBlock, [384, 2048, 5, True, False]] # stage 4 25 | 26 | head: 27 | - [-1, 1, Conv, [256, 1, 1, None, 1, 1, False]] # 10 input_proj.2 28 | - [-1, 1, AIFI, [1024, 8]] 29 | - [-1, 1, Conv, [256, 1, 1]] # 12, Y5, lateral_convs.0 30 | 31 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 32 | - [7, 1, Conv, [256, 1, 1, None, 1, 1, False]] # 14 input_proj.1 33 | - [[-2, -1], 1, Concat, [1]] 34 | - [-1, 3, RepC3, [256]] # 16, fpn_blocks.0 35 | - [-1, 1, Conv, [256, 1, 1]] # 17, Y4, lateral_convs.1 36 | 37 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 38 | - [3, 1, Conv, [256, 1, 1, None, 1, 1, False]] # 19 input_proj.0 39 | - [[-2, -1], 1, Concat, [1]] # cat backbone P4 40 | - [-1, 3, RepC3, [256]] # X3 (21), fpn_blocks.1 41 | 42 | - [-1, 1, Conv, [256, 3, 2]] # 22, downsample_convs.0 43 | - [[-1, 17], 1, Concat, [1]] # cat Y4 44 | - [-1, 3, RepC3, [256]] # F4 (24), pan_blocks.0 45 | 46 | - [-1, 1, Conv, [256, 3, 2]] # 25, downsample_convs.1 47 | - [[-1, 12], 1, Concat, [1]] # cat Y5 48 | - [-1, 3, RepC3, [256]] # F5 (27), pan_blocks.1 49 | 50 | - [[21, 24, 27], 1, RTDETRDecoder, [nc]] # Detect(P3, P4, P5) 51 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/rt-detr/rtdetr-x.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # RT-DETR-x object detection model with P3-P5 outputs. For details see https://docs.ultralytics.com/models/rtdetr 3 | 4 | # Parameters 5 | nc: 80 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov8n-cls.yaml' will call yolov8-cls.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | x: [1.00, 1.00, 2048] 9 | 10 | backbone: 11 | # [from, repeats, module, args] 12 | - [-1, 1, HGStem, [32, 64]] # 0-P2/4 13 | - [-1, 6, HGBlock, [64, 128, 3]] # stage 1 14 | 15 | - [-1, 1, DWConv, [128, 3, 2, 1, False]] # 2-P3/8 16 | - [-1, 6, HGBlock, [128, 512, 3]] 17 | - [-1, 6, HGBlock, [128, 512, 3, False, True]] # 4-stage 2 18 | 19 | - [-1, 1, DWConv, [512, 3, 2, 1, False]] # 5-P3/16 20 | - [-1, 6, HGBlock, [256, 1024, 5, True, False]] # cm, c2, k, light, shortcut 21 | - [-1, 6, HGBlock, [256, 1024, 5, True, True]] 22 | - [-1, 6, HGBlock, [256, 1024, 5, True, True]] 23 | - [-1, 6, HGBlock, [256, 1024, 5, True, True]] 24 | - [-1, 6, HGBlock, [256, 1024, 5, True, True]] # 10-stage 3 25 | 26 | - [-1, 1, DWConv, [1024, 3, 2, 1, False]] # 11-P4/32 27 | - [-1, 6, HGBlock, [512, 2048, 5, True, False]] 28 | - [-1, 6, HGBlock, [512, 2048, 5, True, True]] # 13-stage 4 29 | 30 | head: 31 | - [-1, 1, Conv, [384, 1, 1, None, 1, 1, False]] # 14 input_proj.2 32 | - [-1, 1, AIFI, [2048, 8]] 33 | - [-1, 1, Conv, [384, 1, 1]] # 16, Y5, lateral_convs.0 34 | 35 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 36 | - [10, 1, Conv, [384, 1, 1, None, 1, 1, False]] # 18 input_proj.1 37 | - [[-2, -1], 1, Concat, [1]] 38 | - [-1, 3, RepC3, [384]] # 20, fpn_blocks.0 39 | - [-1, 1, Conv, [384, 1, 1]] # 21, Y4, lateral_convs.1 40 | 41 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 42 | - [4, 1, Conv, [384, 1, 1, None, 1, 1, False]] # 23 input_proj.0 43 | - [[-2, -1], 1, Concat, [1]] # cat backbone P4 44 | - [-1, 3, RepC3, [384]] # X3 (25), fpn_blocks.1 45 | 46 | - [-1, 1, Conv, [384, 3, 2]] # 26, downsample_convs.0 47 | - [[-1, 21], 1, Concat, [1]] # cat Y4 48 | - [-1, 3, RepC3, [384]] # F4 (28), pan_blocks.0 49 | 50 | - [-1, 1, Conv, [384, 3, 2]] # 29, downsample_convs.1 51 | - [[-1, 16], 1, Concat, [1]] # cat Y5 52 | - [-1, 3, RepC3, [384]] # F5 (31), pan_blocks.1 53 | 54 | - [[25, 28, 31], 1, RTDETRDecoder, [nc]] # Detect(P3, P4, P5) 55 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v3/yolov3-spp.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv3-SPP object detection model with P3-P5 outputs. For details see https://docs.ultralytics.com/models/yolov3 3 | 4 | # Parameters 5 | nc: 80 # number of classes 6 | depth_multiple: 1.0 # model depth multiple 7 | width_multiple: 1.0 # layer channel multiple 8 | 9 | # darknet53 backbone 10 | backbone: 11 | # [from, number, module, args] 12 | [[-1, 1, Conv, [32, 3, 1]], # 0 13 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 14 | [-1, 1, Bottleneck, [64]], 15 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 16 | [-1, 2, Bottleneck, [128]], 17 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8 18 | [-1, 8, Bottleneck, [256]], 19 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16 20 | [-1, 8, Bottleneck, [512]], 21 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32 22 | [-1, 4, Bottleneck, [1024]], # 10 23 | ] 24 | 25 | # YOLOv3-SPP head 26 | head: 27 | [[-1, 1, Bottleneck, [1024, False]], 28 | [-1, 1, SPP, [512, [5, 9, 13]]], 29 | [-1, 1, Conv, [1024, 3, 1]], 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large) 32 | 33 | [-2, 1, Conv, [256, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 35 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 36 | [-1, 1, Bottleneck, [512, False]], 37 | [-1, 1, Bottleneck, [512, False]], 38 | [-1, 1, Conv, [256, 1, 1]], 39 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium) 40 | 41 | [-2, 1, Conv, [128, 1, 1]], 42 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 43 | [[-1, 6], 1, Concat, [1]], # cat backbone P3 44 | [-1, 1, Bottleneck, [256, False]], 45 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small) 46 | 47 | [[27, 22, 15], 1, Detect, [nc]], # Detect(P3, P4, P5) 48 | ] 49 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v3/yolov3-tiny.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv3-tiny object detection model with P4-P5 outputs. For details see https://docs.ultralytics.com/models/yolov3 3 | 4 | # Parameters 5 | nc: 80 # number of classes 6 | depth_multiple: 1.0 # model depth multiple 7 | width_multiple: 1.0 # layer channel multiple 8 | 9 | # YOLOv3-tiny backbone 10 | backbone: 11 | # [from, number, module, args] 12 | [[-1, 1, Conv, [16, 3, 1]], # 0 13 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 1-P1/2 14 | [-1, 1, Conv, [32, 3, 1]], 15 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 3-P2/4 16 | [-1, 1, Conv, [64, 3, 1]], 17 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 5-P3/8 18 | [-1, 1, Conv, [128, 3, 1]], 19 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 7-P4/16 20 | [-1, 1, Conv, [256, 3, 1]], 21 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 9-P5/32 22 | [-1, 1, Conv, [512, 3, 1]], 23 | [-1, 1, nn.ZeroPad2d, [[0, 1, 0, 1]]], # 11 24 | [-1, 1, nn.MaxPool2d, [2, 1, 0]], # 12 25 | ] 26 | 27 | # YOLOv3-tiny head 28 | head: 29 | [[-1, 1, Conv, [1024, 3, 1]], 30 | [-1, 1, Conv, [256, 1, 1]], 31 | [-1, 1, Conv, [512, 3, 1]], # 15 (P5/32-large) 32 | 33 | [-2, 1, Conv, [128, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 35 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 36 | [-1, 1, Conv, [256, 3, 1]], # 19 (P4/16-medium) 37 | 38 | [[19, 15], 1, Detect, [nc]], # Detect(P4, P5) 39 | ] 40 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v3/yolov3.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv3 object detection model with P3-P5 outputs. For details see https://docs.ultralytics.com/models/yolov3 3 | 4 | # Parameters 5 | nc: 80 # number of classes 6 | depth_multiple: 1.0 # model depth multiple 7 | width_multiple: 1.0 # layer channel multiple 8 | 9 | # darknet53 backbone 10 | backbone: 11 | # [from, number, module, args] 12 | [[-1, 1, Conv, [32, 3, 1]], # 0 13 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 14 | [-1, 1, Bottleneck, [64]], 15 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 16 | [-1, 2, Bottleneck, [128]], 17 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8 18 | [-1, 8, Bottleneck, [256]], 19 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16 20 | [-1, 8, Bottleneck, [512]], 21 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32 22 | [-1, 4, Bottleneck, [1024]], # 10 23 | ] 24 | 25 | # YOLOv3 head 26 | head: 27 | [[-1, 1, Bottleneck, [1024, False]], 28 | [-1, 1, Conv, [512, 1, 1]], 29 | [-1, 1, Conv, [1024, 3, 1]], 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large) 32 | 33 | [-2, 1, Conv, [256, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 35 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 36 | [-1, 1, Bottleneck, [512, False]], 37 | [-1, 1, Bottleneck, [512, False]], 38 | [-1, 1, Conv, [256, 1, 1]], 39 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium) 40 | 41 | [-2, 1, Conv, [128, 1, 1]], 42 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 43 | [[-1, 6], 1, Concat, [1]], # cat backbone P3 44 | [-1, 1, Bottleneck, [256, False]], 45 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small) 46 | 47 | [[27, 22, 15], 1, Detect, [nc]], # Detect(P3, P4, P5) 48 | ] 49 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v5/yolov5-p6.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv5 object detection model with P3-P6 outputs. For details see https://docs.ultralytics.com/models/yolov5 3 | 4 | # Parameters 5 | nc: 80 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov5n-p6.yaml' will call yolov5-p6.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | n: [0.33, 0.25, 1024] 9 | s: [0.33, 0.50, 1024] 10 | m: [0.67, 0.75, 1024] 11 | l: [1.00, 1.00, 1024] 12 | x: [1.33, 1.25, 1024] 13 | 14 | # YOLOv5 v6.0 backbone 15 | backbone: 16 | # [from, number, module, args] 17 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 19 | [-1, 3, C3, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 21 | [-1, 6, C3, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 23 | [-1, 9, C3, [512]], 24 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 25 | [-1, 3, C3, [768]], 26 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 27 | [-1, 3, C3, [1024]], 28 | [-1, 1, SPPF, [1024, 5]], # 11 29 | ] 30 | 31 | # YOLOv5 v6.0 head 32 | head: 33 | [[-1, 1, Conv, [768, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 35 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 36 | [-1, 3, C3, [768, False]], # 15 37 | 38 | [-1, 1, Conv, [512, 1, 1]], 39 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 40 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 41 | [-1, 3, C3, [512, False]], # 19 42 | 43 | [-1, 1, Conv, [256, 1, 1]], 44 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 45 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 46 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 47 | 48 | [-1, 1, Conv, [256, 3, 2]], 49 | [[-1, 20], 1, Concat, [1]], # cat head P4 50 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 51 | 52 | [-1, 1, Conv, [512, 3, 2]], 53 | [[-1, 16], 1, Concat, [1]], # cat head P5 54 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 55 | 56 | [-1, 1, Conv, [768, 3, 2]], 57 | [[-1, 12], 1, Concat, [1]], # cat head P6 58 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) 59 | 60 | [[23, 26, 29, 32], 1, Detect, [nc]], # Detect(P3, P4, P5, P6) 61 | ] 62 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v5/yolov5.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv5 object detection model with P3-P5 outputs. For details see https://docs.ultralytics.com/models/yolov5 3 | 4 | # Parameters 5 | nc: 80 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov5n.yaml' will call yolov5.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | n: [0.33, 0.25, 1024] 9 | s: [0.33, 0.50, 1024] 10 | m: [0.67, 0.75, 1024] 11 | l: [1.00, 1.00, 1024] 12 | x: [1.33, 1.25, 1024] 13 | 14 | # YOLOv5 v6.0 backbone 15 | backbone: 16 | # [from, number, module, args] 17 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 19 | [-1, 3, C3, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 21 | [-1, 6, C3, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 23 | [-1, 9, C3, [512]], 24 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 25 | [-1, 3, C3, [1024]], 26 | [-1, 1, SPPF, [1024, 5]], # 9 27 | ] 28 | 29 | # YOLOv5 v6.0 head 30 | head: 31 | [[-1, 1, Conv, [512, 1, 1]], 32 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 33 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 34 | [-1, 3, C3, [512, False]], # 13 35 | 36 | [-1, 1, Conv, [256, 1, 1]], 37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 38 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 39 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 40 | 41 | [-1, 1, Conv, [256, 3, 2]], 42 | [[-1, 14], 1, Concat, [1]], # cat head P4 43 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 44 | 45 | [-1, 1, Conv, [512, 3, 2]], 46 | [[-1, 10], 1, Concat, [1]], # cat head P5 47 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 48 | 49 | [[17, 20, 23], 1, Detect, [nc]], # Detect(P3, P4, P5) 50 | ] 51 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v6/yolov6.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv6 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/models/yolov6 3 | 4 | # Parameters 5 | nc: 80 # number of classes 6 | activation: nn.ReLU() # (optional) model default activation function 7 | scales: # model compound scaling constants, i.e. 'model=yolov6n.yaml' will call yolov8.yaml with scale 'n' 8 | # [depth, width, max_channels] 9 | n: [0.33, 0.25, 1024] 10 | s: [0.33, 0.50, 1024] 11 | m: [0.67, 0.75, 768] 12 | l: [1.00, 1.00, 512] 13 | x: [1.00, 1.25, 512] 14 | 15 | # YOLOv6-3.0s backbone 16 | backbone: 17 | # [from, repeats, module, args] 18 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 19 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 20 | - [-1, 6, Conv, [128, 3, 1]] 21 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 22 | - [-1, 12, Conv, [256, 3, 1]] 23 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 24 | - [-1, 18, Conv, [512, 3, 1]] 25 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 26 | - [-1, 6, Conv, [1024, 3, 1]] 27 | - [-1, 1, SPPF, [1024, 5]] # 9 28 | 29 | # YOLOv6-3.0s head 30 | head: 31 | - [-1, 1, Conv, [256, 1, 1]] 32 | - [-1, 1, nn.ConvTranspose2d, [256, 2, 2, 0]] 33 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 34 | - [-1, 1, Conv, [256, 3, 1]] 35 | - [-1, 9, Conv, [256, 3, 1]] # 14 36 | 37 | - [-1, 1, Conv, [128, 1, 1]] 38 | - [-1, 1, nn.ConvTranspose2d, [128, 2, 2, 0]] 39 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 40 | - [-1, 1, Conv, [128, 3, 1]] 41 | - [-1, 9, Conv, [128, 3, 1]] # 19 42 | 43 | - [-1, 1, Conv, [128, 3, 2]] 44 | - [[-1, 15], 1, Concat, [1]] # cat head P4 45 | - [-1, 1, Conv, [256, 3, 1]] 46 | - [-1, 9, Conv, [256, 3, 1]] # 23 47 | 48 | - [-1, 1, Conv, [256, 3, 2]] 49 | - [[-1, 10], 1, Concat, [1]] # cat head P5 50 | - [-1, 1, Conv, [512, 3, 1]] 51 | - [-1, 9, Conv, [512, 3, 1]] # 27 52 | 53 | - [[19, 23, 27], 1, Detect, [nc]] # Detect(P3, P4, P5) 54 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/YOLO_MOT.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv8 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect 3 | 4 | # Parameters 5 | nc: 1 # number of classes 6 | depth_multiple: 1.00 # scales module repeats 7 | width_multiple: 1.00 # scales convolution channels 8 | 9 | # YOLOv8.0l backbone 10 | backbone: 11 | # [from, repeats, module, args] 12 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 13 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 14 | - [-1, 3, C2f, [128, True]] 15 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 16 | - [-1, 6, C2f, [256, True]] 17 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 18 | - [-1, 6, C2f, [512, True]] 19 | - [-1, 1, Conv, [512, 3, 2]] # 7-P5/32 20 | - [-1, 3, C2f, [512, True]] 21 | - [-1, 1, SPPF, [512, 5]] # 9 22 | 23 | # YOLOv8.0l head 24 | head: 25 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 26 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 27 | - [-1, 3, C2f, [512]] # 12 28 | 29 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 30 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 31 | - [-1, 3, C2f, [256]] # 15 (P3/8-small) 32 | 33 | - [-1, 1, Conv, [256, 3, 2]] 34 | - [[-1, 12], 1, Concat, [1]] # cat head P4 35 | - [-1, 3, C2f, [512]] # 18 (P4/16-medium) 36 | 37 | - [-1, 1, Conv, [512, 3, 2]] 38 | - [[-1, 9], 1, Concat, [1]] # cat head P5 39 | - [-1, 3, C2f, [512]] # 21 (P5/32-large) 40 | 41 | - [[15, 18, 21], 1, RTDETRDecoder, [nc]] # Detect(P3, P4, P5) 42 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/cls/yolov8l-cls.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 1000 # number of classes 5 | depth_multiple: 1.00 # scales module repeats 6 | width_multiple: 1.00 # scales convolution channels 7 | 8 | # YOLOv8.0n backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [1024, True]] 20 | 21 | # YOLOv8.0n head 22 | head: 23 | - [-1, 1, Classify, [nc]] 24 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/cls/yolov8m-cls.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 1000 # number of classes 5 | depth_multiple: 0.67 # scales module repeats 6 | width_multiple: 0.75 # scales convolution channels 7 | 8 | # YOLOv8.0n backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [1024, True]] 20 | 21 | # YOLOv8.0n head 22 | head: 23 | - [-1, 1, Classify, [nc]] 24 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/cls/yolov8n-cls.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 1000 # number of classes 5 | depth_multiple: 0.33 # scales module repeats 6 | width_multiple: 0.25 # scales convolution channels 7 | 8 | # YOLOv8.0n backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [1024, True]] 20 | 21 | # YOLOv8.0n head 22 | head: 23 | - [-1, 1, Classify, [nc]] 24 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/cls/yolov8s-cls.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 1000 # number of classes 5 | depth_multiple: 0.33 # scales module repeats 6 | width_multiple: 0.50 # scales convolution channels 7 | 8 | # YOLOv8.0n backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [1024, True]] 20 | 21 | # YOLOv8.0n head 22 | head: 23 | - [-1, 1, Classify, [nc]] 24 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/cls/yolov8x-cls.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 1000 # number of classes 5 | depth_multiple: 1.00 # scales module repeats 6 | width_multiple: 1.25 # scales convolution channels 7 | 8 | # YOLOv8.0n backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [1024, True]] 20 | 21 | # YOLOv8.0n head 22 | head: 23 | - [-1, 1, Classify, [nc]] 24 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/detr_track.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv8 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect 3 | 4 | # Parameters 5 | nc: 5 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | # n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPs 9 | # s: [0.33, 0.50, 1024] # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients, 28.8 GFLOPs 10 | # m: [0.67, 0.75, 768] # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients, 79.3 GFLOPs 11 | depth_multiple: 1.00 # scales module repeats 12 | width_multiple: 1.00 # scales convolution channels 13 | 14 | backbone: 15 | # [from, repeats, module, args] 16 | - [-1, 1, HGStem, [32, 48]] # 0-P2/4 17 | - [-1, 6, HGBlock, [48, 128, 3]] # stage 1 18 | 19 | - [-1, 1, DWConv, [128, 3, 2, 1, False]] # 2-P3/8 20 | - [-1, 6, HGBlock, [96, 512, 3]] # stage 2 21 | 22 | - [-1, 1, DWConv, [512, 3, 2, 1, False]] # 4-P3/16 23 | - [-1, 6, HGBlock, [192, 1024, 5, True, False]] # cm, c2, k, light, shortcut 24 | - [-1, 6, HGBlock, [192, 1024, 5, True, True]] 25 | - [-1, 6, HGBlock, [192, 1024, 5, True, True]] # stage 3 26 | 27 | - [-1, 1, DWConv, [1024, 3, 2, 1, False]] # 8-P4/32 28 | - [-1, 6, HGBlock, [384, 2048, 5, True, False]] # stage 4 29 | 30 | head: 31 | - [-1, 1, Conv, [256, 1, 1, None, 1, 1, False]] # 10 input_proj.2 32 | - [-1, 1, AIFI, [1024, 8]] 33 | - [-1, 1, Conv, [256, 1, 1]] # 12, Y5, lateral_convs.0 34 | 35 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 36 | - [7, 1, Conv, [256, 1, 1, None, 1, 1, False]] # 14 input_proj.1 37 | - [[-2, -1], 1, Concat, [1]] 38 | - [-1, 3, RepC3, [256]] # 16, fpn_blocks.0 39 | - [-1, 1, Conv, [256, 1, 1]] # 17, Y4, lateral_convs.1 40 | 41 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 42 | - [3, 1, Conv, [256, 1, 1, None, 1, 1, False]] # 19 input_proj.0 43 | - [[-2, -1], 1, Concat, [1]] # cat backbone P4 44 | - [-1, 3, RepC3, [256]] # X3 (21), fpn_blocks.1 45 | 46 | - [-1, 1, Conv, [256, 3, 2]] # 22, downsample_convs.0 47 | - [[-1, 17], 1, Concat, [1]] # cat Y4 48 | - [-1, 3, RepC3, [256]] # F4 (24), pan_blocks.0 49 | 50 | - [-1, 1, Conv, [256, 3, 2]] # 25, downsample_convs.1 51 | - [[-1, 12], 1, Concat, [1]] # cat Y5 52 | - [-1, 3, RepC3, [256]] # F5 (27), pan_blocks.1 53 | 54 | 55 | - [[21, 24, 27], 1, MOTRTrack, [nc]] # Detect(P3, P4, P5) 56 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/seg/yolov8l-seg.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.00 # scales module repeats 6 | width_multiple: 1.00 # scales convolution channels 7 | 8 | # YOLOv8.0l backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [512, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [512, True]] 20 | - [-1, 1, SPPF, [512, 5]] # 9 21 | 22 | # YOLOv8.0l head 23 | head: 24 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 25 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 26 | - [-1, 3, C2f, [512]] # 13 27 | 28 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 29 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 30 | - [-1, 3, C2f, [256]] # 17 (P3/8-small) 31 | 32 | - [-1, 1, Conv, [256, 3, 2]] 33 | - [[-1, 12], 1, Concat, [1]] # cat head P4 34 | - [-1, 3, C2f, [512]] # 20 (P4/16-medium) 35 | 36 | - [-1, 1, Conv, [512, 3, 2]] 37 | - [[-1, 9], 1, Concat, [1]] # cat head P5 38 | - [-1, 3, C2f, [512]] # 23 (P5/32-large) 39 | 40 | - [[15, 18, 21], 1, Segment, [nc, 32, 256]] # Detect(P3, P4, P5) 41 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/seg/yolov8m-seg.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # scales module repeats 6 | width_multiple: 0.75 # scales convolution channels 7 | 8 | # YOLOv8.0m backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [768, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [768, True]] 20 | - [-1, 1, SPPF, [768, 5]] # 9 21 | 22 | # YOLOv8.0m head 23 | head: 24 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 25 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 26 | - [-1, 3, C2f, [512]] # 13 27 | 28 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 29 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 30 | - [-1, 3, C2f, [256]] # 17 (P3/8-small) 31 | 32 | - [-1, 1, Conv, [256, 3, 2]] 33 | - [[-1, 12], 1, Concat, [1]] # cat head P4 34 | - [-1, 3, C2f, [512]] # 20 (P4/16-medium) 35 | 36 | - [-1, 1, Conv, [512, 3, 2]] 37 | - [[-1, 9], 1, Concat, [1]] # cat head P5 38 | - [-1, 3, C2f, [768]] # 23 (P5/32-large) 39 | 40 | - [[15, 18, 21], 1, Segment, [nc, 32, 256]] # Detect(P3, P4, P5) 41 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/seg/yolov8n-seg.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # scales module repeats 6 | width_multiple: 0.25 # scales convolution channels 7 | 8 | # YOLOv8.0n backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [1024, True]] 20 | - [-1, 1, SPPF, [1024, 5]] # 9 21 | 22 | # YOLOv8.0n head 23 | head: 24 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 25 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 26 | - [-1, 3, C2f, [512]] # 13 27 | 28 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 29 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 30 | - [-1, 3, C2f, [256]] # 17 (P3/8-small) 31 | 32 | - [-1, 1, Conv, [256, 3, 2]] 33 | - [[-1, 12], 1, Concat, [1]] # cat head P4 34 | - [-1, 3, C2f, [512]] # 20 (P4/16-medium) 35 | 36 | - [-1, 1, Conv, [512, 3, 2]] 37 | - [[-1, 9], 1, Concat, [1]] # cat head P5 38 | - [-1, 3, C2f, [1024]] # 23 (P5/32-large) 39 | 40 | - [[15, 18, 21], 1, Segment, [nc, 32, 256]] # Detect(P3, P4, P5) 41 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/seg/yolov8s-seg.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # scales module repeats 6 | width_multiple: 0.50 # scales convolution channels 7 | 8 | # YOLOv8.0s backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [1024, True]] 20 | - [-1, 1, SPPF, [1024, 5]] # 9 21 | 22 | # YOLOv8.0s head 23 | head: 24 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 25 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 26 | - [-1, 3, C2f, [512]] # 13 27 | 28 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 29 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 30 | - [-1, 3, C2f, [256]] # 17 (P3/8-small) 31 | 32 | - [-1, 1, Conv, [256, 3, 2]] 33 | - [[-1, 12], 1, Concat, [1]] # cat head P4 34 | - [-1, 3, C2f, [512]] # 20 (P4/16-medium) 35 | 36 | - [-1, 1, Conv, [512, 3, 2]] 37 | - [[-1, 9], 1, Concat, [1]] # cat head P5 38 | - [-1, 3, C2f, [1024]] # 23 (P5/32-large) 39 | 40 | - [[15, 18, 21], 1, Segment, [nc, 32, 256]] # Detect(P3, P4, P5) 41 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/seg/yolov8x-seg.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.00 # scales module repeats 6 | width_multiple: 1.25 # scales convolution channels 7 | 8 | # YOLOv8.0x backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [512, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [512, True]] 20 | - [-1, 1, SPPF, [512, 5]] # 9 21 | 22 | # YOLOv8.0x head 23 | head: 24 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 25 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 26 | - [-1, 3, C2f, [512]] # 13 27 | 28 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 29 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 30 | - [-1, 3, C2f, [256]] # 17 (P3/8-small) 31 | 32 | - [-1, 1, Conv, [256, 3, 2]] 33 | - [[-1, 12], 1, Concat, [1]] # cat head P4 34 | - [-1, 3, C2f, [512]] # 20 (P4/16-medium) 35 | 36 | - [-1, 1, Conv, [512, 3, 2]] 37 | - [[-1, 9], 1, Concat, [1]] # cat head P5 38 | - [-1, 3, C2f, [512]] # 23 (P5/32-large) 39 | 40 | - [[15, 18, 21], 1, Segment, [nc, 32, 256]] # Detect(P3, P4, P5) 41 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolo_track.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv8 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect 3 | 4 | # Parameters 5 | nc: 5 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | # n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPs 9 | # s: [0.33, 0.50, 1024] # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients, 28.8 GFLOPs 10 | # m: [0.67, 0.75, 768] # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients, 79.3 GFLOPs 11 | depth_multiple: 1.00 # scales module repeats 12 | width_multiple: 1.00 # scales convolution channels 13 | 14 | # YOLOv8.0l backbone 15 | backbone: 16 | # [from, repeats, module, args] 17 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 18 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 19 | - [-1, 3, C2f, [128, True]] 20 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 21 | - [-1, 6, C2f, [256, True]] 22 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 23 | - [-1, 6, C2f, [512, True]] 24 | - [-1, 1, Conv, [512, 3, 2]] # 7-P5/32 25 | - [-1, 3, C2f, [512, True]] 26 | - [-1, 1, SPPF, [512, 5]] # 9 27 | 28 | # YOLOv8.0l head 29 | head: 30 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 31 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 32 | - [-1, 3, C2f, [512]] # 13 33 | 34 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 35 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 36 | - [-1, 3, C2f, [256]] # 17 (P3/8-small) 37 | 38 | - [-1, 1, Conv, [256, 3, 2]] 39 | - [[-1, 12], 1, Concat, [1]] # cat head P4 40 | - [-1, 3, C2f, [512]] # 20 (P4/16-medium) 41 | 42 | - [-1, 1, Conv, [512, 3, 2]] 43 | - [[-1, 9], 1, Concat, [1]] # cat head P5 44 | - [-1, 3, C2f, [512]] # 23 (P5/32-large) 45 | 46 | - [[15, 18, 21], 1, MOTRTrack, [nc]] # Detect(P3, P4, P5) 47 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolo_track_rare.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv8 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect 3 | 4 | # Parameters 5 | nc: 5 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | # n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPs 9 | # s: [0.33, 0.50, 1024] # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients, 28.8 GFLOPs 10 | # m: [0.67, 0.75, 768] # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients, 79.3 GFLOPs 11 | l: [1.00, 1.00, 512] # YOLOv8l summary: 365 layers, 43691520 parameters, 43691504 gradients, 165.7 GFLOPs 12 | # x: [1.00, 1.25, 512] # YOLOv8x summary: 365 layers, 68229648 parameters, 68229632 gradients, 258.5 GFLOPs 13 | 14 | # YOLOv8.0n backbone 15 | backbone: 16 | # [from, repeats, module, args] 17 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 18 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 19 | - [-1, 3, C2f, [128, True]] 20 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 21 | - [-1, 6, C2f, [256, True]] 22 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 23 | - [-1, 6, C2f, [512, True]] 24 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 25 | - [-1, 3, C2f, [1024, True]] 26 | - [-1, 1, SPPF, [1024, 5]] # 9 27 | 28 | # YOLOv8.0n head 29 | head: 30 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 31 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 32 | - [-1, 3, C2f, [512]] # 12 33 | 34 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 35 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 36 | - [-1, 3, C2f, [256]] # 15 (P3/8-small) 37 | 38 | - [-1, 1, Conv, [256, 3, 2]] 39 | - [[-1, 12], 1, Concat, [1]] # cat head P4 40 | - [-1, 3, C2f, [512]] # 18 (P4/16-medium) 41 | 42 | - [-1, 1, Conv, [512, 3, 2]] 43 | - [[-1, 9], 1, Concat, [1]] # cat head P5 44 | - [-1, 3, C2f, [1024]] # 21 (P5/32-large) 45 | 46 | - [[15, 18, 21], 1, MOTRTrack, [nc]] # Detect(P3, P4, P5) 47 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8-cls.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv8-cls image classification model. For Usage examples see https://docs.ultralytics.com/tasks/classify 3 | 4 | # Parameters 5 | nc: 1000 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov8n-cls.yaml' will call yolov8-cls.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | n: [0.33, 0.25, 1024] 9 | s: [0.33, 0.50, 1024] 10 | m: [0.67, 0.75, 1024] 11 | l: [1.00, 1.00, 1024] 12 | x: [1.00, 1.25, 1024] 13 | 14 | # YOLOv8.0n backbone 15 | backbone: 16 | # [from, repeats, module, args] 17 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 18 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 19 | - [-1, 3, C2f, [128, True]] 20 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 21 | - [-1, 6, C2f, [256, True]] 22 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 23 | - [-1, 6, C2f, [512, True]] 24 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 25 | - [-1, 3, C2f, [1024, True]] 26 | 27 | # YOLOv8.0n head 28 | head: 29 | - [-1, 1, Classify, [nc]] # Classify 30 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8-p2.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv8 object detection model with P2-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect 3 | 4 | # Parameters 5 | nc: 80 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | n: [0.33, 0.25, 1024] 9 | s: [0.33, 0.50, 1024] 10 | m: [0.67, 0.75, 768] 11 | l: [1.00, 1.00, 512] 12 | x: [1.00, 1.25, 512] 13 | 14 | # YOLOv8.0 backbone 15 | backbone: 16 | # [from, repeats, module, args] 17 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 18 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 19 | - [-1, 3, C2f, [128, True]] 20 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 21 | - [-1, 6, C2f, [256, True]] 22 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 23 | - [-1, 6, C2f, [512, True]] 24 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 25 | - [-1, 3, C2f, [1024, True]] 26 | - [-1, 1, SPPF, [1024, 5]] # 9 27 | 28 | # YOLOv8.0-p2 head 29 | head: 30 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 31 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 32 | - [-1, 3, C2f, [512]] # 12 33 | 34 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 35 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 36 | - [-1, 3, C2f, [256]] # 15 (P3/8-small) 37 | 38 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 39 | - [[-1, 2], 1, Concat, [1]] # cat backbone P2 40 | - [-1, 3, C2f, [128]] # 18 (P2/4-xsmall) 41 | 42 | - [-1, 1, Conv, [128, 3, 2]] 43 | - [[-1, 15], 1, Concat, [1]] # cat head P3 44 | - [-1, 3, C2f, [256]] # 21 (P3/8-small) 45 | 46 | - [-1, 1, Conv, [256, 3, 2]] 47 | - [[-1, 12], 1, Concat, [1]] # cat head P4 48 | - [-1, 3, C2f, [512]] # 24 (P4/16-medium) 49 | 50 | - [-1, 1, Conv, [512, 3, 2]] 51 | - [[-1, 9], 1, Concat, [1]] # cat head P5 52 | - [-1, 3, C2f, [1024]] # 27 (P5/32-large) 53 | 54 | - [[18, 21, 24, 27], 1, Detect, [nc]] # Detect(P2, P3, P4, P5) 55 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8-p6.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv8 object detection model with P3-P6 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect 3 | 4 | # Parameters 5 | nc: 80 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov8n-p6.yaml' will call yolov8-p6.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | n: [0.33, 0.25, 1024] 9 | s: [0.33, 0.50, 1024] 10 | m: [0.67, 0.75, 768] 11 | l: [1.00, 1.00, 512] 12 | x: [1.00, 1.25, 512] 13 | 14 | # YOLOv8.0x6 backbone 15 | backbone: 16 | # [from, repeats, module, args] 17 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 18 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 19 | - [-1, 3, C2f, [128, True]] 20 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 21 | - [-1, 6, C2f, [256, True]] 22 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 23 | - [-1, 6, C2f, [512, True]] 24 | - [-1, 1, Conv, [768, 3, 2]] # 7-P5/32 25 | - [-1, 3, C2f, [768, True]] 26 | - [-1, 1, Conv, [1024, 3, 2]] # 9-P6/64 27 | - [-1, 3, C2f, [1024, True]] 28 | - [-1, 1, SPPF, [1024, 5]] # 11 29 | 30 | # YOLOv8.0x6 head 31 | head: 32 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 33 | - [[-1, 8], 1, Concat, [1]] # cat backbone P5 34 | - [-1, 3, C2, [768, False]] # 14 35 | 36 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 37 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 38 | - [-1, 3, C2, [512, False]] # 17 39 | 40 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 41 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 42 | - [-1, 3, C2, [256, False]] # 20 (P3/8-small) 43 | 44 | - [-1, 1, Conv, [256, 3, 2]] 45 | - [[-1, 17], 1, Concat, [1]] # cat head P4 46 | - [-1, 3, C2, [512, False]] # 23 (P4/16-medium) 47 | 48 | - [-1, 1, Conv, [512, 3, 2]] 49 | - [[-1, 14], 1, Concat, [1]] # cat head P5 50 | - [-1, 3, C2, [768, False]] # 26 (P5/32-large) 51 | 52 | - [-1, 1, Conv, [768, 3, 2]] 53 | - [[-1, 11], 1, Concat, [1]] # cat head P6 54 | - [-1, 3, C2, [1024, False]] # 29 (P6/64-xlarge) 55 | 56 | - [[20, 23, 26, 29], 1, Detect, [nc]] # Detect(P3, P4, P5, P6) 57 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8-pose-p6.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv8-pose keypoints/pose estimation model. For Usage examples see https://docs.ultralytics.com/tasks/pose 3 | 4 | # Parameters 5 | nc: 1 # number of classes 6 | kpt_shape: [17, 3] # number of keypoints, number of dims (2 for x,y or 3 for x,y,visible) 7 | scales: # model compound scaling constants, i.e. 'model=yolov8n-p6.yaml' will call yolov8-p6.yaml with scale 'n' 8 | # [depth, width, max_channels] 9 | n: [0.33, 0.25, 1024] 10 | s: [0.33, 0.50, 1024] 11 | m: [0.67, 0.75, 768] 12 | l: [1.00, 1.00, 512] 13 | x: [1.00, 1.25, 512] 14 | 15 | # YOLOv8.0x6 backbone 16 | backbone: 17 | # [from, repeats, module, args] 18 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 19 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 20 | - [-1, 3, C2f, [128, True]] 21 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 22 | - [-1, 6, C2f, [256, True]] 23 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 24 | - [-1, 6, C2f, [512, True]] 25 | - [-1, 1, Conv, [768, 3, 2]] # 7-P5/32 26 | - [-1, 3, C2f, [768, True]] 27 | - [-1, 1, Conv, [1024, 3, 2]] # 9-P6/64 28 | - [-1, 3, C2f, [1024, True]] 29 | - [-1, 1, SPPF, [1024, 5]] # 11 30 | 31 | # YOLOv8.0x6 head 32 | head: 33 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 34 | - [[-1, 8], 1, Concat, [1]] # cat backbone P5 35 | - [-1, 3, C2, [768, False]] # 14 36 | 37 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 38 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 39 | - [-1, 3, C2, [512, False]] # 17 40 | 41 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 42 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 43 | - [-1, 3, C2, [256, False]] # 20 (P3/8-small) 44 | 45 | - [-1, 1, Conv, [256, 3, 2]] 46 | - [[-1, 17], 1, Concat, [1]] # cat head P4 47 | - [-1, 3, C2, [512, False]] # 23 (P4/16-medium) 48 | 49 | - [-1, 1, Conv, [512, 3, 2]] 50 | - [[-1, 14], 1, Concat, [1]] # cat head P5 51 | - [-1, 3, C2, [768, False]] # 26 (P5/32-large) 52 | 53 | - [-1, 1, Conv, [768, 3, 2]] 54 | - [[-1, 11], 1, Concat, [1]] # cat head P6 55 | - [-1, 3, C2, [1024, False]] # 29 (P6/64-xlarge) 56 | 57 | - [[20, 23, 26, 29], 1, Pose, [nc, kpt_shape]] # Pose(P3, P4, P5, P6) 58 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8-pose.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv8-pose keypoints/pose estimation model. For Usage examples see https://docs.ultralytics.com/tasks/pose 3 | 4 | # Parameters 5 | nc: 1 # number of classes 6 | kpt_shape: [17, 3] # number of keypoints, number of dims (2 for x,y or 3 for x,y,visible) 7 | scales: # model compound scaling constants, i.e. 'model=yolov8n-pose.yaml' will call yolov8-pose.yaml with scale 'n' 8 | # [depth, width, max_channels] 9 | n: [0.33, 0.25, 1024] 10 | s: [0.33, 0.50, 1024] 11 | m: [0.67, 0.75, 768] 12 | l: [1.00, 1.00, 512] 13 | x: [1.00, 1.25, 512] 14 | 15 | # YOLOv8.0n backbone 16 | backbone: 17 | # [from, repeats, module, args] 18 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 19 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 20 | - [-1, 3, C2f, [128, True]] 21 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 22 | - [-1, 6, C2f, [256, True]] 23 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 24 | - [-1, 6, C2f, [512, True]] 25 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 26 | - [-1, 3, C2f, [1024, True]] 27 | - [-1, 1, SPPF, [1024, 5]] # 9 28 | 29 | # YOLOv8.0n head 30 | head: 31 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 32 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 33 | - [-1, 3, C2f, [512]] # 12 34 | 35 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 36 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 37 | - [-1, 3, C2f, [256]] # 15 (P3/8-small) 38 | 39 | - [-1, 1, Conv, [256, 3, 2]] 40 | - [[-1, 12], 1, Concat, [1]] # cat head P4 41 | - [-1, 3, C2f, [512]] # 18 (P4/16-medium) 42 | 43 | - [-1, 1, Conv, [512, 3, 2]] 44 | - [[-1, 9], 1, Concat, [1]] # cat head P5 45 | - [-1, 3, C2f, [1024]] # 21 (P5/32-large) 46 | 47 | - [[15, 18, 21], 1, Pose, [nc, kpt_shape]] # Pose(P3, P4, P5) 48 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8-rtdetr.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv8 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect 3 | 4 | # Parameters 5 | nc: 80 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPs 9 | s: [0.33, 0.50, 1024] # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients, 28.8 GFLOPs 10 | m: [0.67, 0.75, 768] # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients, 79.3 GFLOPs 11 | l: [1.00, 1.00, 512] # YOLOv8l summary: 365 layers, 43691520 parameters, 43691504 gradients, 165.7 GFLOPs 12 | x: [1.00, 1.25, 512] # YOLOv8x summary: 365 layers, 68229648 parameters, 68229632 gradients, 258.5 GFLOPs 13 | 14 | # YOLOv8.0n backbone 15 | backbone: 16 | # [from, repeats, module, args] 17 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 18 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 19 | - [-1, 3, C2f, [128, True]] 20 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 21 | - [-1, 6, C2f, [256, True]] 22 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 23 | - [-1, 6, C2f, [512, True]] 24 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 25 | - [-1, 3, C2f, [1024, True]] 26 | - [-1, 1, SPPF, [1024, 5]] # 9 27 | 28 | # YOLOv8.0n head 29 | head: 30 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 31 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 32 | - [-1, 3, C2f, [512]] # 12 33 | 34 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 35 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 36 | - [-1, 3, C2f, [256]] # 15 (P3/8-small) 37 | 38 | - [-1, 1, Conv, [256, 3, 2]] 39 | - [[-1, 12], 1, Concat, [1]] # cat head P4 40 | - [-1, 3, C2f, [512]] # 18 (P4/16-medium) 41 | 42 | - [-1, 1, Conv, [512, 3, 2]] 43 | - [[-1, 9], 1, Concat, [1]] # cat head P5 44 | - [-1, 3, C2f, [1024]] # 21 (P5/32-large) 45 | 46 | - [[15, 18, 21], 1, RTDETRDecoder, [nc]] # Detect(P3, P4, P5) 47 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8-seg.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv8-seg instance segmentation model. For Usage examples see https://docs.ultralytics.com/tasks/segment 3 | 4 | # Parameters 5 | nc: 80 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov8n-seg.yaml' will call yolov8-seg.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | n: [0.33, 0.25, 1024] 9 | s: [0.33, 0.50, 1024] 10 | m: [0.67, 0.75, 768] 11 | l: [1.00, 1.00, 512] 12 | x: [1.00, 1.25, 512] 13 | 14 | # YOLOv8.0n backbone 15 | backbone: 16 | # [from, repeats, module, args] 17 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 18 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 19 | - [-1, 3, C2f, [128, True]] 20 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 21 | - [-1, 6, C2f, [256, True]] 22 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 23 | - [-1, 6, C2f, [512, True]] 24 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 25 | - [-1, 3, C2f, [1024, True]] 26 | - [-1, 1, SPPF, [1024, 5]] # 9 27 | 28 | # YOLOv8.0n head 29 | head: 30 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 31 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 32 | - [-1, 3, C2f, [512]] # 12 33 | 34 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 35 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 36 | - [-1, 3, C2f, [256]] # 15 (P3/8-small) 37 | 38 | - [-1, 1, Conv, [256, 3, 2]] 39 | - [[-1, 12], 1, Concat, [1]] # cat head P4 40 | - [-1, 3, C2f, [512]] # 18 (P4/16-medium) 41 | 42 | - [-1, 1, Conv, [512, 3, 2]] 43 | - [[-1, 9], 1, Concat, [1]] # cat head P5 44 | - [-1, 3, C2f, [1024]] # 21 (P5/32-large) 45 | 46 | - [[15, 18, 21], 1, Segment, [nc, 32, 256]] # Segment(P3, P4, P5) 47 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv8 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect 3 | 4 | # Parameters 5 | nc: 80 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPs 9 | s: [0.33, 0.50, 1024] # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients, 28.8 GFLOPs 10 | m: [0.67, 0.75, 768] # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients, 79.3 GFLOPs 11 | l: [1.00, 1.00, 512] # YOLOv8l summary: 365 layers, 43691520 parameters, 43691504 gradients, 165.7 GFLOPs 12 | x: [1.00, 1.25, 512] # YOLOv8x summary: 365 layers, 68229648 parameters, 68229632 gradients, 258.5 GFLOPs 13 | 14 | # YOLOv8.0n backbone 15 | backbone: 16 | # [from, repeats, module, args] 17 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 18 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 19 | - [-1, 3, C2f, [128, True]] 20 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 21 | - [-1, 6, C2f, [256, True]] 22 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 23 | - [-1, 6, C2f, [512, True]] 24 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 25 | - [-1, 3, C2f, [1024, True]] 26 | - [-1, 1, SPPF, [1024, 5]] # 9 27 | 28 | # YOLOv8.0n head 29 | head: 30 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 31 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 32 | - [-1, 3, C2f, [512]] # 12 33 | 34 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 35 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 36 | - [-1, 3, C2f, [256]] # 15 (P3/8-small) 37 | 38 | - [-1, 1, Conv, [256, 3, 2]] 39 | - [[-1, 12], 1, Concat, [1]] # cat head P4 40 | - [-1, 3, C2f, [512]] # 18 (P4/16-medium) 41 | 42 | - [-1, 1, Conv, [512, 3, 2]] 43 | - [[-1, 9], 1, Concat, [1]] # cat head P5 44 | - [-1, 3, C2f, [1024]] # 21 (P5/32-large) 45 | 46 | - [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5) 47 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8l.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.00 # scales module repeats 6 | width_multiple: 1.00 # scales convolution channels 7 | 8 | # YOLOv8.0l backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [512, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [512, True]] 20 | - [-1, 1, SPPF, [512, 5]] # 9 21 | 22 | # YOLOv8.0l head 23 | head: 24 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 25 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 26 | - [-1, 3, C2f, [512]] # 13 27 | 28 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 29 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 30 | - [-1, 3, C2f, [256]] # 17 (P3/8-small) 31 | 32 | - [-1, 1, Conv, [256, 3, 2]] 33 | - [[-1, 12], 1, Concat, [1]] # cat head P4 34 | - [-1, 3, C2f, [512]] # 20 (P4/16-medium) 35 | 36 | - [-1, 1, Conv, [512, 3, 2]] 37 | - [[-1, 9], 1, Concat, [1]] # cat head P5 38 | - [-1, 3, C2f, [512]] # 23 (P5/32-large) 39 | 40 | - [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5) 41 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8m.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # scales module repeats 6 | width_multiple: 0.75 # scales convolution channels 7 | 8 | # YOLOv8.0m backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [768, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [768, True]] 20 | - [-1, 1, SPPF, [768, 5]] # 9 21 | 22 | # YOLOv8.0m head 23 | head: 24 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 25 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 26 | - [-1, 3, C2f, [512]] # 13 27 | 28 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 29 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 30 | - [-1, 3, C2f, [256]] # 17 (P3/8-small) 31 | 32 | - [-1, 1, Conv, [256, 3, 2]] 33 | - [[-1, 12], 1, Concat, [1]] # cat head P4 34 | - [-1, 3, C2f, [512]] # 20 (P4/16-medium) 35 | 36 | - [-1, 1, Conv, [512, 3, 2]] 37 | - [[-1, 9], 1, Concat, [1]] # cat head P5 38 | - [-1, 3, C2f, [768]] # 23 (P5/32-large) 39 | 40 | - [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5) 41 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8m_track.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # YOLOv8 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect 3 | 4 | # Parameters 5 | nc: 5 # number of classes 6 | scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n' 7 | # [depth, width, max_channels] 8 | # n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPs 9 | # s: [0.33, 0.50, 1024] # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients, 28.8 GFLOPs 10 | # m: [0.67, 0.75, 768] # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients, 79.3 GFLOPs 11 | depth_multiple: 1.00 # scales module repeats 12 | width_multiple: 1.00 # scales convolution channels 13 | 14 | backbone: 15 | # [from, repeats, module, args] 16 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 17 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 18 | - [-1, 3, C2f, [128, True]] 19 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 20 | - [-1, 6, C2f, [256, True]] 21 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 22 | - [-1, 6, C2f, [512, True]] 23 | - [-1, 1, Conv, [768, 3, 2]] # 7-P5/32 24 | - [-1, 3, C2f, [768, True]] 25 | - [-1, 1, SPPF, [768, 5]] # 9 26 | 27 | # YOLOv8.0m head 28 | head: 29 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 30 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 31 | - [-1, 3, C2f, [512]] # 13 32 | 33 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 34 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 35 | - [-1, 3, C2f, [256]] # 17 (P3/8-small) 36 | 37 | - [-1, 1, Conv, [256, 3, 2]] 38 | - [[-1, 12], 1, Concat, [1]] # cat head P4 39 | - [-1, 3, C2f, [512]] # 20 (P4/16-medium) 40 | 41 | - [-1, 1, Conv, [512, 3, 2]] 42 | - [[-1, 9], 1, Concat, [1]] # cat head P5 43 | - [-1, 3, C2f, [768]] # 23 (P5/32-large) 44 | 45 | - [[15, 18, 21], 1, MOTRTrack, [nc]] # Detect(P3, P4, P5) 46 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8n.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # scales module repeats 6 | width_multiple: 0.25 # scales convolution channels 7 | 8 | # YOLOv8.0n backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [1024, True]] 20 | - [-1, 1, SPPF, [1024, 5]] # 9 21 | 22 | # YOLOv8.0n head 23 | head: 24 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 25 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 26 | - [-1, 3, C2f, [512]] # 13 27 | 28 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 29 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 30 | - [-1, 3, C2f, [256]] # 17 (P3/8-small) 31 | 32 | - [-1, 1, Conv, [256, 3, 2]] 33 | - [[-1, 12], 1, Concat, [1]] # cat head P4 34 | - [-1, 3, C2f, [512]] # 20 (P4/16-medium) 35 | 36 | - [-1, 1, Conv, [512, 3, 2]] 37 | - [[-1, 9], 1, Concat, [1]] # cat head P5 38 | - [-1, 3, C2f, [1024]] # 23 (P5/32-large) 39 | 40 | - [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5) 41 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8s.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # scales module repeats 6 | width_multiple: 0.50 # scales convolution channels 7 | 8 | # YOLOv8.0s backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [1024, True]] 20 | - [-1, 1, SPPF, [1024, 5]] # 9 21 | 22 | # YOLOv8.0s head 23 | head: 24 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 25 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 26 | - [-1, 3, C2f, [512]] # 13 27 | 28 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 29 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 30 | - [-1, 3, C2f, [256]] # 17 (P3/8-small) 31 | 32 | - [-1, 1, Conv, [256, 3, 2]] 33 | - [[-1, 12], 1, Concat, [1]] # cat head P4 34 | - [-1, 3, C2f, [512]] # 20 (P4/16-medium) 35 | 36 | - [-1, 1, Conv, [512, 3, 2]] 37 | - [[-1, 9], 1, Concat, [1]] # cat head P5 38 | - [-1, 3, C2f, [1024]] # 23 (P5/32-large) 39 | 40 | - [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5) 41 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8x.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.00 # scales module repeats 6 | width_multiple: 1.25 # scales convolution channels 7 | 8 | # YOLOv8.0x backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [512, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [512, True]] 20 | - [-1, 1, SPPF, [512, 5]] # 9 21 | 22 | # YOLOv8.0x head 23 | head: 24 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 25 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 26 | - [-1, 3, C2f, [512]] # 13 27 | 28 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 29 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 30 | - [-1, 3, C2f, [256]] # 17 (P3/8-small) 31 | 32 | - [-1, 1, Conv, [256, 3, 2]] 33 | - [[-1, 12], 1, Concat, [1]] # cat head P4 34 | - [-1, 3, C2f, [512]] # 20 (P4/16-medium) 35 | 36 | - [-1, 1, Conv, [512, 3, 2]] 37 | - [[-1, 9], 1, Concat, [1]] # cat head P5 38 | - [-1, 3, C2f, [512]] # 23 (P5/32-large) 39 | 40 | - [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5) 41 | -------------------------------------------------------------------------------- /ultralytics/cfg/models/v8/yolov8x6.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, GPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.00 # scales module repeats 6 | width_multiple: 1.25 # scales convolution channels 7 | 8 | # YOLOv8.0x6 backbone 9 | backbone: 10 | # [from, repeats, module, args] 11 | - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 12 | - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 13 | - [-1, 3, C2f, [128, True]] 14 | - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 15 | - [-1, 6, C2f, [256, True]] 16 | - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 17 | - [-1, 6, C2f, [512, True]] 18 | - [-1, 1, Conv, [512, 3, 2]] # 7-P5/32 19 | - [-1, 3, C2f, [512, True]] 20 | - [-1, 1, Conv, [512, 3, 2]] # 9-P6/64 21 | - [-1, 3, C2f, [512, True]] 22 | - [-1, 1, SPPF, [512, 5]] # 11 23 | 24 | # YOLOv8.0x6 head 25 | head: 26 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 27 | - [[-1, 8], 1, Concat, [1]] # cat backbone P5 28 | - [-1, 3, C2, [512, False]] # 14 29 | 30 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 31 | - [[-1, 6], 1, Concat, [1]] # cat backbone P4 32 | - [-1, 3, C2, [512, False]] # 17 33 | 34 | - [-1, 1, nn.Upsample, [None, 2, 'nearest']] 35 | - [[-1, 4], 1, Concat, [1]] # cat backbone P3 36 | - [-1, 3, C2, [256, False]] # 20 (P3/8-small) 37 | 38 | - [-1, 1, Conv, [256, 3, 2]] 39 | - [[-1, 17], 1, Concat, [1]] # cat head P4 40 | - [-1, 3, C2, [512, False]] # 23 (P4/16-medium) 41 | 42 | - [-1, 1, Conv, [512, 3, 2]] 43 | - [[-1, 14], 1, Concat, [1]] # cat head P5 44 | - [-1, 3, C2, [512, False]] # 26 (P5/32-large) 45 | 46 | - [-1, 1, Conv, [512, 3, 2]] 47 | - [[-1, 11], 1, Concat, [1]] # cat head P6 48 | - [-1, 3, C2, [512, False]] # 29 (P6/64-xlarge) 49 | 50 | - [[20, 23, 26, 29], 1, Detect, [nc]] # Detect(P3, P4, P5, P6) 51 | -------------------------------------------------------------------------------- /ultralytics/cfg/trackers/botsort.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # Default YOLO tracker settings for BoT-SORT tracker https://github.com/NirAharon/BoT-SORT 3 | 4 | tracker_type: botsort # tracker type, ['botsort', 'bytetrack'] 5 | track_high_thresh: 0.5 # threshold for the first association 6 | track_low_thresh: 0.1 # threshold for the second association 7 | new_track_thresh: 0.6 # threshold for init new track if the detection does not match any tracks 8 | track_buffer: 30 # buffer to calculate the time when to remove tracks 9 | match_thresh: 0.8 # threshold for matching tracks 10 | # min_box_area: 10 # threshold for min box areas(for tracker evaluation, not used for now) 11 | # mot20: False # for tracker evaluation(not used for now) 12 | 13 | # BoT-SORT settings 14 | cmc_method: sparseOptFlow # method of global motion compensation 15 | # ReID model related thresh (not supported yet) 16 | proximity_thresh: 0.5 17 | appearance_thresh: 0.25 18 | with_reid: False 19 | -------------------------------------------------------------------------------- /ultralytics/cfg/trackers/bytetrack.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | # Default YOLO tracker settings for ByteTrack tracker https://github.com/ifzhang/ByteTrack 3 | 4 | tracker_type: bytetrack # tracker type, ['botsort', 'bytetrack'] 5 | track_high_thresh: 0.5 # threshold for the first association 6 | track_low_thresh: 0.1 # threshold for the second association 7 | new_track_thresh: 0.6 # threshold for init new track if the detection does not match any tracks 8 | track_buffer: 30 # buffer to calculate the time when to remove tracks 9 | match_thresh: 0.8 # threshold for matching tracks 10 | # min_box_area: 10 # threshold for min box areas(for tracker evaluation, not used for now) 11 | # mot20: False # for tracker evaluation(not used for now) 12 | -------------------------------------------------------------------------------- /ultralytics/data/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from .base import BaseDataset 4 | from .build import build_dataloader, build_yolo_dataset, load_inference_source, build_track_dataloader 5 | from .dataset import ClassificationDataset, SemanticDataset, YOLODataset,YOLOTrackDataset 6 | 7 | __all__ = ('BaseDataset', 'ClassificationDataset', 'SemanticDataset', 'YOLODataset', 'YOLOTrackDataset','build_yolo_dataset', 8 | 'build_dataloader', 'load_inference_source','build_track_dataloader') 9 | -------------------------------------------------------------------------------- /ultralytics/data/annotator.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | from ultralytics import SAM, YOLO 4 | 5 | 6 | def auto_annotate(data, det_model='yolov8x.pt', sam_model='sam_b.pt', device='', output_dir=None): 7 | """ 8 | Automatically annotates images using a YOLO object detection model and a SAM segmentation model. 9 | Args: 10 | data (str): Path to a folder containing images to be annotated. 11 | det_model (str, optional): Pre-trained YOLO detection model. Defaults to 'yolov8x.pt'. 12 | sam_model (str, optional): Pre-trained SAM segmentation model. Defaults to 'sam_b.pt'. 13 | device (str, optional): Device to run the models on. Defaults to an empty string (CPU or GPU, if available). 14 | output_dir (str | None | optional): Directory to save the annotated results. 15 | Defaults to a 'labels' folder in the same directory as 'data'. 16 | """ 17 | det_model = YOLO(det_model) 18 | sam_model = SAM(sam_model) 19 | 20 | if not output_dir: 21 | output_dir = Path(str(data)).parent / 'labels' 22 | Path(output_dir).mkdir(exist_ok=True, parents=True) 23 | 24 | det_results = det_model(data, stream=True, device=device) 25 | 26 | for result in det_results: 27 | boxes = result.boxes.xyxy # Boxes object for bbox outputs 28 | class_ids = result.boxes.cls.int().tolist() # noqa 29 | if len(class_ids): 30 | sam_results = sam_model(result.orig_img, bboxes=boxes, verbose=False, save=False, device=device) 31 | segments = sam_results[0].masks.xyn # noqa 32 | 33 | with open(str(Path(output_dir) / Path(result.path).stem) + '.txt', 'w') as f: 34 | for i in range(len(segments)): 35 | s = segments[i] 36 | if len(s) == 0: 37 | continue 38 | segment = map(str, segments[i].reshape(-1).tolist()) 39 | f.write(f'{class_ids[i]} ' + ' '.join(segment) + '\n') 40 | -------------------------------------------------------------------------------- /ultralytics/data/dataloaders/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liaopan-lp/MO-YOLO/81d917e0cafb68fda27c757ad2c35d7f1eb5f254/ultralytics/data/dataloaders/__init__.py -------------------------------------------------------------------------------- /ultralytics/data/scripts/download_weights.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Ultralytics YOLO 🚀, AGPL-3.0 license 3 | # Download latest models from https://github.com/ultralytics/assets/releases 4 | # Example usage: bash ultralytics/data/scripts/download_weights.sh 5 | # parent 6 | # └── weights 7 | # ├── yolov8n.pt ← downloads here 8 | # ├── yolov8s.pt 9 | # └── ... 10 | 11 | python - < w - threshold, 2] = w # x2 26 | boxes[boxes[:, 3] > h - threshold, 3] = h # y2 27 | return boxes 28 | 29 | 30 | def bbox_iou(box1, boxes, iou_thres=0.9, image_shape=(640, 640), raw_output=False): 31 | """ 32 | Compute the Intersection-Over-Union of a bounding box with respect to an array of other bounding boxes. 33 | 34 | Args: 35 | box1 (torch.Tensor): (4, ) 36 | boxes (torch.Tensor): (n, 4) 37 | 38 | Returns: 39 | high_iou_indices (torch.Tensor): Indices of boxes with IoU > thres 40 | """ 41 | boxes = adjust_bboxes_to_image_border(boxes, image_shape) 42 | # obtain coordinates for intersections 43 | x1 = torch.max(box1[0], boxes[:, 0]) 44 | y1 = torch.max(box1[1], boxes[:, 1]) 45 | x2 = torch.min(box1[2], boxes[:, 2]) 46 | y2 = torch.min(box1[3], boxes[:, 3]) 47 | 48 | # compute the area of intersection 49 | intersection = (x2 - x1).clamp(0) * (y2 - y1).clamp(0) 50 | 51 | # compute the area of both individual boxes 52 | box1_area = (box1[2] - box1[0]) * (box1[3] - box1[1]) 53 | box2_area = (boxes[:, 2] - boxes[:, 0]) * (boxes[:, 3] - boxes[:, 1]) 54 | 55 | # compute the area of union 56 | union = box1_area + box2_area - intersection 57 | 58 | # compute the IoU 59 | iou = intersection / union # Should be shape (n, ) 60 | if raw_output: 61 | return 0 if iou.numel() == 0 else iou 62 | 63 | # return indices of boxes with IoU > thres 64 | return torch.nonzero(iou > iou_thres).flatten() 65 | -------------------------------------------------------------------------------- /ultralytics/models/nas/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from .model import NAS 4 | from .predict import NASPredictor 5 | from .val import NASValidator 6 | 7 | __all__ = 'NASPredictor', 'NASValidator', 'NAS' 8 | -------------------------------------------------------------------------------- /ultralytics/models/nas/predict.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | import torch 4 | 5 | from ultralytics.engine.predictor import BasePredictor 6 | from ultralytics.engine.results import Results 7 | from ultralytics.utils import ops 8 | from ultralytics.utils.ops import xyxy2xywh 9 | 10 | 11 | class NASPredictor(BasePredictor): 12 | 13 | def postprocess(self, preds_in, img, orig_imgs): 14 | """Postprocesses predictions and returns a list of Results objects.""" 15 | 16 | # Cat boxes and class scores 17 | boxes = xyxy2xywh(preds_in[0][0]) 18 | preds = torch.cat((boxes, preds_in[0][1]), -1).permute(0, 2, 1) 19 | 20 | preds = ops.non_max_suppression(preds, 21 | self.args.conf, 22 | self.args.iou, 23 | agnostic=self.args.agnostic_nms, 24 | max_det=self.args.max_det, 25 | classes=self.args.classes) 26 | 27 | results = [] 28 | for i, pred in enumerate(preds): 29 | orig_img = orig_imgs[i] if isinstance(orig_imgs, list) else orig_imgs 30 | if not isinstance(orig_imgs, torch.Tensor): 31 | pred[:, :4] = ops.scale_boxes(img.shape[2:], pred[:, :4], orig_img.shape) 32 | path = self.batch[0] 33 | img_path = path[i] if isinstance(path, list) else path 34 | results.append(Results(orig_img=orig_img, path=img_path, names=self.model.names, boxes=pred)) 35 | return results 36 | -------------------------------------------------------------------------------- /ultralytics/models/nas/val.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | import torch 4 | 5 | from ultralytics.models.yolo.detect import DetectionValidator 6 | from ultralytics.utils import ops 7 | from ultralytics.utils.ops import xyxy2xywh 8 | 9 | __all__ = ['NASValidator'] 10 | 11 | 12 | class NASValidator(DetectionValidator): 13 | 14 | def postprocess(self, preds_in): 15 | """Apply Non-maximum suppression to prediction outputs.""" 16 | boxes = xyxy2xywh(preds_in[0][0]) 17 | preds = torch.cat((boxes, preds_in[0][1]), -1).permute(0, 2, 1) 18 | return ops.non_max_suppression(preds, 19 | self.args.conf, 20 | self.args.iou, 21 | labels=self.lb, 22 | multi_label=False, 23 | agnostic=self.args.single_cls, 24 | max_det=self.args.max_det, 25 | max_time_img=0.5) 26 | -------------------------------------------------------------------------------- /ultralytics/models/rtdetr/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from .model import RTDETR 4 | from .predict import RTDETRPredictor 5 | from .val import RTDETRValidator 6 | 7 | __all__ = 'RTDETRPredictor', 'RTDETRValidator', 'RTDETR' 8 | -------------------------------------------------------------------------------- /ultralytics/models/rtdetr/predict.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | import torch 4 | 5 | from ultralytics.data.augment import LetterBox 6 | from ultralytics.engine.predictor import BasePredictor 7 | from ultralytics.engine.results import Results 8 | from ultralytics.utils import ops 9 | 10 | 11 | class RTDETRPredictor(BasePredictor): 12 | 13 | def postprocess(self, preds, img, orig_imgs): 14 | """Postprocess predictions and returns a list of Results objects.""" 15 | nd = preds[0].shape[-1] 16 | bboxes, scores = preds[0].split((4, nd - 4), dim=-1) 17 | results = [] 18 | for i, bbox in enumerate(bboxes): # (300, 4) 19 | bbox = ops.xywh2xyxy(bbox) 20 | score, cls = scores[i].max(-1, keepdim=True) # (300, 1) 21 | idx = score.squeeze(-1) > self.args.conf # (300, ) 22 | if self.args.classes is not None: 23 | idx = (cls == torch.tensor(self.args.classes, device=cls.device)).any(1) & idx 24 | pred = torch.cat([bbox, score, cls], dim=-1)[idx] # filter 25 | orig_img = orig_imgs[i] if isinstance(orig_imgs, list) else orig_imgs 26 | oh, ow = orig_img.shape[:2] 27 | if not isinstance(orig_imgs, torch.Tensor): 28 | pred[..., [0, 2]] *= ow 29 | pred[..., [1, 3]] *= oh 30 | path = self.batch[0] 31 | img_path = path[i] if isinstance(path, list) else path 32 | results.append(Results(orig_img=orig_img, path=img_path, names=self.model.names, boxes=pred)) 33 | return results 34 | 35 | def pre_transform(self, im): 36 | """Pre-transform input image before inference. 37 | 38 | Args: 39 | im (List(np.ndarray)): (N, 3, h, w) for tensor, [(h, w, 3) x N] for list. 40 | 41 | Return: A list of transformed imgs. 42 | """ 43 | # The size must be square(640) and scaleFilled. 44 | return [LetterBox(self.imgsz, auto=False, scaleFill=True)(image=x) for x in im] 45 | -------------------------------------------------------------------------------- /ultralytics/models/rtdetr/train.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from copy import copy 4 | 5 | import torch 6 | 7 | from ultralytics.models.yolo.detect import DetectionTrainer 8 | from ultralytics.nn.tasks import RTDETRDetectionModel 9 | from ultralytics.utils import DEFAULT_CFG, RANK, colorstr 10 | 11 | from .val import RTDETRDataset, RTDETRValidator 12 | 13 | 14 | class RTDETRTrainer(DetectionTrainer): 15 | 16 | def get_model(self, cfg=None, weights=None, verbose=True): 17 | """Return a YOLO detection model.""" 18 | model = RTDETRDetectionModel(cfg, nc=self.data['nc'], verbose=verbose and RANK == -1) 19 | if weights: 20 | model.load(weights) 21 | return model 22 | 23 | def build_dataset(self, img_path, mode='val', batch=None): 24 | """Build RTDETR Dataset 25 | 26 | Args: 27 | img_path (str): Path to the folder containing images. 28 | mode (str): `train` mode or `val` mode, users are able to customize different augmentations for each mode. 29 | batch (int, optional): Size of batches, this is for `rect`. Defaults to None. 30 | """ 31 | return RTDETRDataset( 32 | img_path=img_path, 33 | imgsz=self.args.imgsz, 34 | batch_size=batch, 35 | augment=mode == 'train', # no augmentation 36 | hyp=self.args, 37 | rect=False, # no rect 38 | cache=self.args.cache or None, 39 | prefix=colorstr(f'{mode}: '), 40 | data=self.data) 41 | 42 | def get_validator(self): 43 | """Returns a DetectionValidator for RTDETR model validation.""" 44 | self.loss_names = 'giou_loss', 'cls_loss', 'l1_loss' 45 | return RTDETRValidator(self.test_loader, save_dir=self.save_dir, args=copy(self.args)) 46 | 47 | def preprocess_batch(self, batch): 48 | """Preprocesses a batch of images by scaling and converting to float.""" 49 | batch = super().preprocess_batch(batch) 50 | bs = len(batch['img']) 51 | batch_idx = batch['batch_idx'] 52 | gt_bbox, gt_class = [], [] 53 | for i in range(bs): 54 | gt_bbox.append(batch['bboxes'][batch_idx == i].to(batch_idx.device)) 55 | gt_class.append(batch['cls'][batch_idx == i].to(device=batch_idx.device, dtype=torch.long)) 56 | return batch 57 | 58 | 59 | def train(cfg=DEFAULT_CFG, use_python=False): 60 | """Train and optimize RTDETR model given training data and device.""" 61 | model = 'rtdetr-l.yaml' 62 | data = cfg.data or 'coco128.yaml' # or yolo.ClassificationDataset("mnist") 63 | device = cfg.device if cfg.device is not None else '' 64 | 65 | # NOTE: F.grid_sample which is in rt-detr does not support deterministic=True 66 | # NOTE: amp training causes nan outputs and end with error while doing bipartite graph matching 67 | args = dict(model=model, 68 | data=data, 69 | device=device, 70 | imgsz=640, 71 | exist_ok=True, 72 | batch=4, 73 | deterministic=False, 74 | amp=False) 75 | trainer = RTDETRTrainer(overrides=args) 76 | trainer.train() 77 | 78 | 79 | if __name__ == '__main__': 80 | train() 81 | -------------------------------------------------------------------------------- /ultralytics/models/sam/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from .model import SAM 4 | from .predict import Predictor 5 | 6 | # from .build import build_sam 7 | 8 | __all__ = 'SAM', 'Predictor' # tuple or list 9 | -------------------------------------------------------------------------------- /ultralytics/models/sam/model.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | """ 3 | SAM model interface 4 | """ 5 | 6 | from ultralytics.cfg import get_cfg 7 | from ultralytics.utils.torch_utils import model_info 8 | 9 | from .build import build_sam 10 | from .predict import Predictor 11 | 12 | 13 | class SAM: 14 | 15 | def __init__(self, model='sam_b.pt') -> None: 16 | if model and not model.endswith('.pt') and not model.endswith('.pth'): 17 | # Should raise AssertionError instead? 18 | raise NotImplementedError('Segment anything prediction requires pre-trained checkpoint') 19 | self.model = build_sam(model) 20 | self.task = 'segment' # required 21 | self.predictor = None # reuse predictor 22 | 23 | def predict(self, source, stream=False, bboxes=None, points=None, labels=None, **kwargs): 24 | """Predicts and returns segmentation masks for given image or video source.""" 25 | overrides = dict(conf=0.25, task='segment', mode='predict', imgsz=1024) 26 | overrides.update(kwargs) # prefer kwargs 27 | if not self.predictor: 28 | self.predictor = Predictor(overrides=overrides) 29 | self.predictor.setup_model(model=self.model) 30 | else: # only update args if predictor is already setup 31 | self.predictor.args = get_cfg(self.predictor.args, overrides) 32 | return self.predictor(source, stream=stream, bboxes=bboxes, points=points, labels=labels) 33 | 34 | def train(self, **kwargs): 35 | """Function trains models but raises an error as SAM models do not support training.""" 36 | raise NotImplementedError("SAM models don't support training") 37 | 38 | def val(self, **kwargs): 39 | """Run validation given dataset.""" 40 | raise NotImplementedError("SAM models don't support validation") 41 | 42 | def __call__(self, source=None, stream=False, bboxes=None, points=None, labels=None, **kwargs): 43 | """Calls the 'predict' function with given arguments to perform object detection.""" 44 | return self.predict(source, stream, bboxes, points, labels, **kwargs) 45 | 46 | def __getattr__(self, attr): 47 | """Raises error if object has no requested attribute.""" 48 | name = self.__class__.__name__ 49 | raise AttributeError(f"'{name}' object has no attribute '{attr}'. See valid attributes below.\n{self.__doc__}") 50 | 51 | def info(self, detailed=False, verbose=True): 52 | """ 53 | Logs model info. 54 | 55 | Args: 56 | detailed (bool): Show detailed information about model. 57 | verbose (bool): Controls verbosity. 58 | """ 59 | return model_info(self.model, detailed=detailed, verbose=verbose) 60 | -------------------------------------------------------------------------------- /ultralytics/models/sam/modules/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | -------------------------------------------------------------------------------- /ultralytics/models/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | from .ops import HungarianMatcher 3 | 4 | __all__ = "HungarianMatcher" -------------------------------------------------------------------------------- /ultralytics/models/yolo/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from ultralytics.models.yolo import classify, detect, pose, segment, track 4 | 5 | __all__ = 'classify', 'segment', 'detect', 'pose', 'track' 6 | -------------------------------------------------------------------------------- /ultralytics/models/yolo/classify/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from ultralytics.models.yolo.classify.predict import ClassificationPredictor, predict 4 | from ultralytics.models.yolo.classify.train import ClassificationTrainer, train 5 | from ultralytics.models.yolo.classify.val import ClassificationValidator, val 6 | 7 | __all__ = 'ClassificationPredictor', 'predict', 'ClassificationTrainer', 'train', 'ClassificationValidator', 'val' 8 | -------------------------------------------------------------------------------- /ultralytics/models/yolo/classify/predict.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | import torch 4 | 5 | from ultralytics.engine.predictor import BasePredictor 6 | from ultralytics.engine.results import Results 7 | from ultralytics.utils import DEFAULT_CFG, ROOT 8 | 9 | 10 | class ClassificationPredictor(BasePredictor): 11 | 12 | def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None): 13 | super().__init__(cfg, overrides, _callbacks) 14 | self.args.task = 'classify' 15 | 16 | def preprocess(self, img): 17 | """Converts input image to model-compatible data type.""" 18 | if not isinstance(img, torch.Tensor): 19 | img = torch.stack([self.transforms(im) for im in img], dim=0) 20 | img = (img if isinstance(img, torch.Tensor) else torch.from_numpy(img)).to(self.model.device) 21 | return img.half() if self.model.fp16 else img.float() # uint8 to fp16/32 22 | 23 | def postprocess(self, preds, img, orig_imgs): 24 | """Postprocesses predictions to return Results objects.""" 25 | results = [] 26 | for i, pred in enumerate(preds): 27 | orig_img = orig_imgs[i] if isinstance(orig_imgs, list) else orig_imgs 28 | path = self.batch[0] 29 | img_path = path[i] if isinstance(path, list) else path 30 | results.append(Results(orig_img=orig_img, path=img_path, names=self.model.names, probs=pred)) 31 | 32 | return results 33 | 34 | 35 | def predict(cfg=DEFAULT_CFG, use_python=False): 36 | """Run YOLO model predictions on input images/videos.""" 37 | model = cfg.model or 'yolov8n-cls.pt' # or "resnet18" 38 | source = cfg.source if cfg.source is not None else ROOT / 'assets' if (ROOT / 'assets').exists() \ 39 | else 'https://ultralytics.com/images/bus.jpg' 40 | 41 | args = dict(model=model, source=source) 42 | if use_python: 43 | from ultralytics import YOLO 44 | YOLO(model)(**args) 45 | else: 46 | predictor = ClassificationPredictor(overrides=args) 47 | predictor.predict_cli() 48 | 49 | 50 | if __name__ == '__main__': 51 | predict() 52 | -------------------------------------------------------------------------------- /ultralytics/models/yolo/detect/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from .predict import DetectionPredictor, predict 4 | from .train import DetectionTrainer, train 5 | from .val import DetectionValidator, val 6 | 7 | __all__ = 'DetectionPredictor', 'predict', 'DetectionTrainer', 'train', 'DetectionValidator', 'val' 8 | -------------------------------------------------------------------------------- /ultralytics/models/yolo/detect/predict.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | import torch 4 | 5 | from ultralytics.engine.predictor import BasePredictor 6 | from ultralytics.engine.results import Results 7 | from ultralytics.utils import DEFAULT_CFG, ROOT, ops 8 | 9 | 10 | class DetectionPredictor(BasePredictor): 11 | 12 | def postprocess(self, preds, img, orig_imgs): 13 | """Postprocesses predictions and returns a list of Results objects.""" 14 | preds = ops.non_max_suppression(preds, 15 | self.args.conf, 16 | self.args.iou, 17 | agnostic=self.args.agnostic_nms, 18 | max_det=self.args.max_det, 19 | classes=self.args.classes) 20 | 21 | results = [] 22 | for i, pred in enumerate(preds): 23 | orig_img = orig_imgs[i] if isinstance(orig_imgs, list) else orig_imgs 24 | if not isinstance(orig_imgs, torch.Tensor): 25 | pred[:, :4] = ops.scale_boxes(img.shape[2:], pred[:, :4], orig_img.shape) 26 | path = self.batch[0] 27 | img_path = path[i] if isinstance(path, list) else path 28 | results.append(Results(orig_img=orig_img, path=img_path, names=self.model.names, boxes=pred)) 29 | return results 30 | 31 | 32 | def predict(cfg=DEFAULT_CFG, use_python=False): 33 | """Runs YOLO model inference on input image(s).""" 34 | model = cfg.model or 'yolov8n.pt' 35 | source = cfg.source if cfg.source is not None else ROOT / 'assets' if (ROOT / 'assets').exists() \ 36 | else 'https://ultralytics.com/images/bus.jpg' 37 | 38 | args = dict(model=model, source=source) 39 | if use_python: 40 | from ultralytics import YOLO 41 | YOLO(model)(**args) 42 | else: 43 | predictor = DetectionPredictor(overrides=args) 44 | predictor.predict_cli() 45 | 46 | 47 | if __name__ == '__main__': 48 | predict() 49 | -------------------------------------------------------------------------------- /ultralytics/models/yolo/pose/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from .predict import PosePredictor, predict 4 | from .train import PoseTrainer, train 5 | from .val import PoseValidator, val 6 | 7 | __all__ = 'PoseTrainer', 'train', 'PoseValidator', 'val', 'PosePredictor', 'predict' 8 | -------------------------------------------------------------------------------- /ultralytics/models/yolo/pose/predict.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from ultralytics.engine.results import Results 4 | from ultralytics.models.yolo.detect.predict import DetectionPredictor 5 | from ultralytics.utils import DEFAULT_CFG, ROOT, ops 6 | 7 | 8 | class PosePredictor(DetectionPredictor): 9 | 10 | def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None): 11 | super().__init__(cfg, overrides, _callbacks) 12 | self.args.task = 'pose' 13 | 14 | def postprocess(self, preds, img, orig_imgs): 15 | """Return detection results for a given input image or list of images.""" 16 | preds = ops.non_max_suppression(preds, 17 | self.args.conf, 18 | self.args.iou, 19 | agnostic=self.args.agnostic_nms, 20 | max_det=self.args.max_det, 21 | classes=self.args.classes, 22 | nc=len(self.model.names)) 23 | 24 | results = [] 25 | for i, pred in enumerate(preds): 26 | orig_img = orig_imgs[i] if isinstance(orig_imgs, list) else orig_imgs 27 | shape = orig_img.shape 28 | pred[:, :4] = ops.scale_boxes(img.shape[2:], pred[:, :4], shape).round() 29 | pred_kpts = pred[:, 6:].view(len(pred), *self.model.kpt_shape) if len(pred) else pred[:, 6:] 30 | pred_kpts = ops.scale_coords(img.shape[2:], pred_kpts, shape) 31 | path = self.batch[0] 32 | img_path = path[i] if isinstance(path, list) else path 33 | results.append( 34 | Results(orig_img=orig_img, 35 | path=img_path, 36 | names=self.model.names, 37 | boxes=pred[:, :6], 38 | keypoints=pred_kpts)) 39 | return results 40 | 41 | 42 | def predict(cfg=DEFAULT_CFG, use_python=False): 43 | """Runs YOLO to predict objects in an image or video.""" 44 | model = cfg.model or 'yolov8n-pose.pt' 45 | source = cfg.source if cfg.source is not None else ROOT / 'assets' if (ROOT / 'assets').exists() \ 46 | else 'https://ultralytics.com/images/bus.jpg' 47 | 48 | args = dict(model=model, source=source) 49 | if use_python: 50 | from ultralytics import YOLO 51 | YOLO(model)(**args) 52 | else: 53 | predictor = PosePredictor(overrides=args) 54 | predictor.predict_cli() 55 | 56 | 57 | if __name__ == '__main__': 58 | predict() 59 | -------------------------------------------------------------------------------- /ultralytics/models/yolo/pose/train.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from copy import copy 4 | 5 | from ultralytics.models import yolo 6 | from ultralytics.nn.tasks import PoseModel 7 | from ultralytics.utils import DEFAULT_CFG 8 | from ultralytics.utils.plotting import plot_images, plot_results 9 | 10 | 11 | # BaseTrainer python usage 12 | class PoseTrainer(yolo.detect.DetectionTrainer): 13 | 14 | def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None): 15 | """Initialize a PoseTrainer object with specified configurations and overrides.""" 16 | if overrides is None: 17 | overrides = {} 18 | overrides['task'] = 'pose' 19 | super().__init__(cfg, overrides, _callbacks) 20 | 21 | def get_model(self, cfg=None, weights=None, verbose=True): 22 | """Get pose estimation model with specified configuration and weights.""" 23 | model = PoseModel(cfg, ch=3, nc=self.data['nc'], data_kpt_shape=self.data['kpt_shape'], verbose=verbose) 24 | if weights: 25 | model.load(weights) 26 | 27 | return model 28 | 29 | def set_model_attributes(self): 30 | """Sets keypoints shape attribute of PoseModel.""" 31 | super().set_model_attributes() 32 | self.model.kpt_shape = self.data['kpt_shape'] 33 | 34 | def get_validator(self): 35 | """Returns an instance of the PoseValidator class for validation.""" 36 | self.loss_names = 'box_loss', 'pose_loss', 'kobj_loss', 'cls_loss', 'dfl_loss' 37 | return yolo.pose.PoseValidator(self.test_loader, save_dir=self.save_dir, args=copy(self.args)) 38 | 39 | def plot_training_samples(self, batch, ni): 40 | """Plot a batch of training samples with annotated class labels, bounding boxes, and keypoints.""" 41 | images = batch['img'] 42 | kpts = batch['keypoints'] 43 | cls = batch['cls'].squeeze(-1) 44 | bboxes = batch['bboxes'] 45 | paths = batch['im_file'] 46 | batch_idx = batch['batch_idx'] 47 | plot_images(images, 48 | batch_idx, 49 | cls, 50 | bboxes, 51 | kpts=kpts, 52 | paths=paths, 53 | fname=self.save_dir / f'train_batch{ni}.jpg', 54 | on_plot=self.on_plot) 55 | 56 | def plot_metrics(self): 57 | """Plots training/val metrics.""" 58 | plot_results(file=self.csv, pose=True, on_plot=self.on_plot) # save results.png 59 | 60 | 61 | def train(cfg=DEFAULT_CFG, use_python=False): 62 | """Train the YOLO model on the given data and device.""" 63 | model = cfg.model or 'yolov8n-pose.yaml' 64 | data = cfg.data or 'coco8-pose.yaml' 65 | device = cfg.device if cfg.device is not None else '' 66 | 67 | args = dict(model=model, data=data, device=device) 68 | if use_python: 69 | from ultralytics import YOLO 70 | YOLO(model).train(**args) 71 | else: 72 | trainer = PoseTrainer(overrides=args) 73 | trainer.train() 74 | 75 | 76 | if __name__ == '__main__': 77 | train() 78 | -------------------------------------------------------------------------------- /ultralytics/models/yolo/segment/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from .predict import SegmentationPredictor, predict 4 | from .train import SegmentationTrainer, train 5 | from .val import SegmentationValidator, val 6 | 7 | __all__ = 'SegmentationPredictor', 'predict', 'SegmentationTrainer', 'train', 'SegmentationValidator', 'val' 8 | -------------------------------------------------------------------------------- /ultralytics/models/yolo/segment/predict.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | import torch 4 | 5 | from ultralytics.engine.results import Results 6 | from ultralytics.models.yolo.detect.predict import DetectionPredictor 7 | from ultralytics.utils import DEFAULT_CFG, ROOT, ops 8 | 9 | 10 | class SegmentationPredictor(DetectionPredictor): 11 | 12 | def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None): 13 | super().__init__(cfg, overrides, _callbacks) 14 | self.args.task = 'segment' 15 | 16 | def postprocess(self, preds, img, orig_imgs): 17 | """TODO: filter by classes.""" 18 | p = ops.non_max_suppression(preds[0], 19 | self.args.conf, 20 | self.args.iou, 21 | agnostic=self.args.agnostic_nms, 22 | max_det=self.args.max_det, 23 | nc=len(self.model.names), 24 | classes=self.args.classes) 25 | results = [] 26 | proto = preds[1][-1] if len(preds[1]) == 3 else preds[1] # second output is len 3 if pt, but only 1 if exported 27 | for i, pred in enumerate(p): 28 | orig_img = orig_imgs[i] if isinstance(orig_imgs, list) else orig_imgs 29 | path = self.batch[0] 30 | img_path = path[i] if isinstance(path, list) else path 31 | if not len(pred): # save empty boxes 32 | results.append(Results(orig_img=orig_img, path=img_path, names=self.model.names, boxes=pred[:, :6])) 33 | continue 34 | if self.args.retina_masks: 35 | if not isinstance(orig_imgs, torch.Tensor): 36 | pred[:, :4] = ops.scale_boxes(img.shape[2:], pred[:, :4], orig_img.shape) 37 | masks = ops.process_mask_native(proto[i], pred[:, 6:], pred[:, :4], orig_img.shape[:2]) # HWC 38 | else: 39 | masks = ops.process_mask(proto[i], pred[:, 6:], pred[:, :4], img.shape[2:], upsample=True) # HWC 40 | if not isinstance(orig_imgs, torch.Tensor): 41 | pred[:, :4] = ops.scale_boxes(img.shape[2:], pred[:, :4], orig_img.shape) 42 | results.append( 43 | Results(orig_img=orig_img, path=img_path, names=self.model.names, boxes=pred[:, :6], masks=masks)) 44 | return results 45 | 46 | 47 | def predict(cfg=DEFAULT_CFG, use_python=False): 48 | """Runs YOLO object detection on an image or video source.""" 49 | model = cfg.model or 'yolov8n-seg.pt' 50 | source = cfg.source if cfg.source is not None else ROOT / 'assets' if (ROOT / 'assets').exists() \ 51 | else 'https://ultralytics.com/images/bus.jpg' 52 | 53 | args = dict(model=model, source=source) 54 | if use_python: 55 | from ultralytics import YOLO 56 | YOLO(model)(**args) 57 | else: 58 | predictor = SegmentationPredictor(overrides=args) 59 | predictor.predict_cli() 60 | 61 | 62 | if __name__ == '__main__': 63 | predict() 64 | -------------------------------------------------------------------------------- /ultralytics/models/yolo/segment/train.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | from copy import copy 3 | 4 | from ultralytics.models import yolo 5 | from ultralytics.nn.tasks import SegmentationModel 6 | from ultralytics.utils import DEFAULT_CFG, RANK 7 | from ultralytics.utils.plotting import plot_images, plot_results 8 | 9 | 10 | # BaseTrainer python usage 11 | class SegmentationTrainer(yolo.detect.DetectionTrainer): 12 | 13 | def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None): 14 | """Initialize a SegmentationTrainer object with given arguments.""" 15 | if overrides is None: 16 | overrides = {} 17 | overrides['task'] = 'segment' 18 | super().__init__(cfg, overrides, _callbacks) 19 | 20 | def get_model(self, cfg=None, weights=None, verbose=True): 21 | """Return SegmentationModel initialized with specified config and weights.""" 22 | model = SegmentationModel(cfg, ch=3, nc=self.data['nc'], verbose=verbose and RANK == -1) 23 | if weights: 24 | model.load(weights) 25 | 26 | return model 27 | 28 | def get_validator(self): 29 | """Return an instance of SegmentationValidator for validation of YOLO model.""" 30 | self.loss_names = 'box_loss', 'seg_loss', 'cls_loss', 'dfl_loss' 31 | return yolo.segment.SegmentationValidator(self.test_loader, save_dir=self.save_dir, args=copy(self.args)) 32 | 33 | def plot_training_samples(self, batch, ni): 34 | """Creates a plot of training sample images with labels and box coordinates.""" 35 | plot_images(batch['img'], 36 | batch['batch_idx'], 37 | batch['cls'].squeeze(-1), 38 | batch['bboxes'], 39 | batch['masks'], 40 | paths=batch['im_file'], 41 | fname=self.save_dir / f'train_batch{ni}.jpg', 42 | on_plot=self.on_plot) 43 | 44 | def plot_metrics(self): 45 | """Plots training/val metrics.""" 46 | plot_results(file=self.csv, segment=True, on_plot=self.on_plot) # save results.png 47 | 48 | 49 | def train(cfg=DEFAULT_CFG, use_python=False): 50 | """Train a YOLO segmentation model based on passed arguments.""" 51 | model = cfg.model or 'yolov8n-seg.pt' 52 | data = cfg.data or 'coco128-seg.yaml' # or yolo.ClassificationDataset("mnist") 53 | device = cfg.device if cfg.device is not None else '' 54 | 55 | args = dict(model=model, data=data, device=device) 56 | if use_python: 57 | from ultralytics import YOLO 58 | YOLO(model).train(**args) 59 | else: 60 | trainer = SegmentationTrainer(overrides=args) 61 | trainer.train() 62 | 63 | 64 | if __name__ == '__main__': 65 | train() 66 | -------------------------------------------------------------------------------- /ultralytics/models/yolo/track/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from .model import MOTRTrack 4 | from .predict import TrackPredictor 5 | from .val import TrackValidator 6 | from .train import TrackTrainer 7 | 8 | __all__ = 'TrackPredictor', 'TrackValidator', 'MOTRTrack', 'TrackTrainer' 9 | -------------------------------------------------------------------------------- /ultralytics/models/yolo/track/predict.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | import torch 4 | 5 | from ultralytics.data.augment import LetterBox 6 | from ultralytics.engine.predictor import BasePredictor 7 | from ultralytics.engine.results import Results 8 | from ultralytics.utils import ops 9 | 10 | 11 | class TrackPredictor(BasePredictor): 12 | 13 | def postprocess(self, preds, img, orig_imgs): 14 | """Postprocess predictions and returns a list of Results objects.""" 15 | nd = preds[0].shape[-1] 16 | bboxes, scores = preds[0].split((4, nd - 4), dim=-1) 17 | results = [] 18 | for i, bbox in enumerate(bboxes): # (300, 4) 19 | bbox = ops.xywh2xyxy(bbox) 20 | score, cls = scores[i].max(-1, keepdim=True) # (300, 1) 21 | idx = score.squeeze(-1) > self.args.conf # (300, ) 22 | if self.args.classes is not None: 23 | idx = (cls == torch.tensor(self.args.classes, device=cls.device)).any(1) & idx 24 | pred = torch.cat([bbox, score, cls], dim=-1)[idx] # filter 25 | orig_img = orig_imgs[i] if isinstance(orig_imgs, list) else orig_imgs 26 | oh, ow = orig_img.shape[:2] 27 | if not isinstance(orig_imgs, torch.Tensor): 28 | pred[..., [0, 2]] *= ow 29 | pred[..., [1, 3]] *= oh 30 | path = self.batch[0] 31 | img_path = path[i] if isinstance(path, list) else path 32 | results.append(Results(orig_img=orig_img, path=img_path, names=self.model.names, boxes=pred)) 33 | return results 34 | 35 | def pre_transform(self, im): 36 | """Pre-transform input image before inference. 37 | 38 | Args: 39 | im (List(np.ndarray)): (N, 3, h, w) for tensor, [(h, w, 3) x N] for list. 40 | 41 | Return: A list of transformed imgs. 42 | """ 43 | # The size must be square(640) and scaleFilled. 44 | return [LetterBox(self.imgsz, auto=False, scaleFill=True)(image=x) for x in im] 45 | -------------------------------------------------------------------------------- /ultralytics/models/yolo/track/train.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from copy import copy 4 | 5 | import torch 6 | from yaml import warnings 7 | 8 | from ultralytics.models.yolo.detect import DetectionTrainer 9 | from ultralytics.nn.tasks import TrackingModel 10 | from ultralytics.utils import DEFAULT_CFG, RANK, colorstr 11 | 12 | from .val import TrackDataset, TrackValidator 13 | 14 | 15 | class TrackTrainer(DetectionTrainer): 16 | 17 | def get_model(self, cfg=None, weights=None, verbose=True): 18 | """Return a YOLO detection model.""" 19 | model = TrackingModel(cfg, nc=self.data['nc'], verbose=verbose and RANK == -1) 20 | if weights: 21 | model.load(weights) 22 | return model 23 | 24 | def build_dataset(self, img_path, mode='val', batch=1): 25 | """Build RTDETR Dataset 26 | 27 | Args: 28 | img_path (str): Path to the folder containing images. 29 | mode (str): `train` mode or `val` mode, users are able to customize different augmentations for each mode. 30 | batch (int, optional): Size of batches, this is for `rect`. Defaults to None.跟踪的只能是1,因为最好是用整个视频来训练 31 | """ 32 | if batch != 1: 33 | warnings("batch_size should be 1,when you train traking mode") 34 | batch = 1 35 | return TrackDataset( 36 | img_path=img_path, 37 | imgsz=self.args.imgsz, 38 | batch_size=batch, 39 | augment=mode == 'train', # no augmentation 40 | hyp=self.args, 41 | rect=False, # no rect 42 | cache=self.args.cache or None, 43 | prefix=colorstr(f'{mode}: '), 44 | data=self.data) 45 | 46 | def get_validator(self): 47 | """Returns a DetectionValidator for RTDETR model validation.""" 48 | self.loss_names = 'giou_loss', 'cls_loss', 'l1_loss' 49 | return TrackValidator(self.test_loader, save_dir=self.save_dir, args=copy(self.args)) 50 | 51 | def preprocess_batch(self, batch): 52 | """Preprocesses a batch of images by scaling and converting to float.""" 53 | batch = super().preprocess_batch(batch) 54 | bs = len(batch['img']) 55 | batch_idx = batch['batch_idx'] 56 | gt_bbox, gt_class = [], [] 57 | for i in range(bs): 58 | gt_bbox.append(batch['bboxes'][batch_idx == i].to(batch_idx.device)) 59 | gt_class.append(batch['cls'][batch_idx == i].to(device=batch_idx.device, dtype=torch.long)) 60 | return batch 61 | 62 | 63 | def train(cfg=DEFAULT_CFG, use_python=False): 64 | """Train and optimize RTDETR model given training data and device.""" 65 | model = 'rtdetr-l.yaml' 66 | data = cfg.data or 'coco128.yaml' # or yolo.ClassificationDataset("mnist") 67 | device = cfg.device if cfg.device is not None else '' 68 | 69 | # NOTE: F.grid_sample which is in rt-detr does not support deterministic=True 70 | # NOTE: amp training causes nan outputs and end with error while doing bipartite graph matching 71 | args = dict(model=model, 72 | data=data, 73 | device=device, 74 | imgsz=640, 75 | exist_ok=True, 76 | batch=4, 77 | deterministic=False, 78 | amp=False) 79 | trainer = TrackTrainer(overrides=args) 80 | trainer.train() 81 | 82 | 83 | if __name__ == '__main__': 84 | train() 85 | -------------------------------------------------------------------------------- /ultralytics/nn/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from .tasks import (BaseModel, ClassificationModel, DetectionModel, SegmentationModel, attempt_load_one_weight, 4 | attempt_load_weights, guess_model_scale, guess_model_task, parse_model, torch_safe_load, 5 | yaml_model_load) 6 | 7 | __all__ = ('attempt_load_one_weight', 'attempt_load_weights', 'parse_model', 'yaml_model_load', 'guess_model_task', 8 | 'guess_model_scale', 'torch_safe_load', 'DetectionModel', 'SegmentationModel', 'ClassificationModel', 9 | 'BaseModel') 10 | -------------------------------------------------------------------------------- /ultralytics/nn/modules/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | """ 3 | Ultralytics modules. Visualize with: 4 | 5 | from ultralytics.nn.modules import * 6 | import torch 7 | import os 8 | 9 | x = torch.ones(1, 128, 40, 40) 10 | m = Conv(128, 128) 11 | f = f'{m._get_name()}.onnx' 12 | torch.onnx.export(m, x, f) 13 | os.system(f'onnxsim {f} {f} && open {f}') 14 | """ 15 | 16 | from .block import (C1, C2, C3, C3TR, DFL, SPP, SPPF, Bottleneck, BottleneckCSP, C2f, C3Ghost, C3x, GhostBottleneck, 17 | HGBlock, HGStem, Proto, RepC3) 18 | from .conv import (CBAM, ChannelAttention, Concat, Conv, Conv2, ConvTranspose, DWConv, DWConvTranspose2d, Focus, 19 | GhostConv, LightConv, RepConv, SpatialAttention) 20 | from .head import Classify, Detect, Pose, RTDETRDecoder, Segment, MOTRTrack 21 | from .transformer import (AIFI, MLP, DeformableTransformerDecoder, DeformableTransformerDecoderLayer, LayerNorm2d, 22 | MLPBlock, MSDeformAttn, TransformerBlock, TransformerEncoderLayer, TransformerLayer) 23 | 24 | __all__ = ('Conv', 'Conv2', 'LightConv', 'RepConv', 'DWConv', 'DWConvTranspose2d', 'ConvTranspose', 'Focus', 25 | 'GhostConv', 'ChannelAttention', 'SpatialAttention', 'CBAM', 'Concat', 'TransformerLayer', 26 | 'TransformerBlock', 'MLPBlock', 'LayerNorm2d', 'DFL', 'HGBlock', 'HGStem', 'SPP', 'SPPF', 'C1', 'C2', 'C3', 27 | 'C2f', 'C3x', 'C3TR', 'C3Ghost', 'GhostBottleneck', 'Bottleneck', 'BottleneckCSP', 'Proto', 'Detect', 28 | 'Segment', 'Pose', "MOTRTrack", 'Classify', 'TransformerEncoderLayer', 'RepC3', 'RTDETRDecoder', 'AIFI', 29 | 'DeformableTransformerDecoder', 'DeformableTransformerDecoderLayer', 'MSDeformAttn', 'MLP') 30 | -------------------------------------------------------------------------------- /ultralytics/nn/modules/structures/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------ 2 | # Modified from Detectron2 (https://github.com/facebookresearch/detectron2) 3 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 4 | # ------------------------------------------------------------------------ 5 | from .boxes import Boxes, BoxMode, pairwise_iou, pairwise_ioa, matched_boxlist_iou 6 | from .instances import Instances 7 | 8 | __all__ = [k for k in globals().keys() if not k.startswith("_")] -------------------------------------------------------------------------------- /ultralytics/nn/modules/utils.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | """ 3 | Module utils 4 | """ 5 | 6 | import copy 7 | import math 8 | 9 | import numpy as np 10 | import torch 11 | import torch.nn as nn 12 | import torch.nn.functional as F 13 | from torch.nn.init import uniform_ 14 | 15 | __all__ = 'multi_scale_deformable_attn_pytorch', 'inverse_sigmoid' 16 | 17 | 18 | def _get_clones(module, n): 19 | return nn.ModuleList([copy.deepcopy(module) for _ in range(n)]) 20 | 21 | 22 | def bias_init_with_prob(prior_prob=0.01): 23 | """initialize conv/fc bias value according to a given probability value.""" 24 | return float(-np.log((1 - prior_prob) / prior_prob)) # return bias_init 25 | 26 | 27 | def linear_init_(module): 28 | bound = 1 / math.sqrt(module.weight.shape[0]) 29 | uniform_(module.weight, -bound, bound) 30 | if hasattr(module, 'bias') and module.bias is not None: 31 | uniform_(module.bias, -bound, bound) 32 | 33 | 34 | def inverse_sigmoid(x, eps=1e-5): 35 | x = x.clamp(min=0, max=1) 36 | x1 = x.clamp(min=eps) 37 | x2 = (1 - x).clamp(min=eps) 38 | return torch.log(x1 / x2) 39 | 40 | 41 | def multi_scale_deformable_attn_pytorch(value: torch.Tensor, value_spatial_shapes: torch.Tensor, 42 | sampling_locations: torch.Tensor, 43 | attention_weights: torch.Tensor) -> torch.Tensor: 44 | """ 45 | Multi-scale deformable attention. 46 | https://github.com/IDEA-Research/detrex/blob/main/detrex/layers/multi_scale_deform_attn.py 47 | """ 48 | 49 | bs, _, num_heads, embed_dims = value.shape 50 | _, num_queries, num_heads, num_levels, num_points, _ = sampling_locations.shape 51 | value_list = value.split([H_ * W_ for H_, W_ in value_spatial_shapes], dim=1) 52 | sampling_grids = 2 * sampling_locations - 1 53 | sampling_value_list = [] 54 | for level, (H_, W_) in enumerate(value_spatial_shapes): 55 | # bs, H_*W_, num_heads, embed_dims -> 56 | # bs, H_*W_, num_heads*embed_dims -> 57 | # bs, num_heads*embed_dims, H_*W_ -> 58 | # bs*num_heads, embed_dims, H_, W_ 59 | value_l_ = (value_list[level].flatten(2).transpose(1, 2).reshape(bs * num_heads, embed_dims, H_, W_)) 60 | # bs, num_queries, num_heads, num_points, 2 -> 61 | # bs, num_heads, num_queries, num_points, 2 -> 62 | # bs*num_heads, num_queries, num_points, 2 63 | sampling_grid_l_ = sampling_grids[:, :, :, level].transpose(1, 2).flatten(0, 1) 64 | # bs*num_heads, embed_dims, num_queries, num_points 65 | sampling_value_l_ = F.grid_sample(value_l_, 66 | sampling_grid_l_, 67 | mode='bilinear', 68 | padding_mode='zeros', 69 | align_corners=False) 70 | sampling_value_list.append(sampling_value_l_) 71 | # (bs, num_queries, num_heads, num_levels, num_points) -> 72 | # (bs, num_heads, num_queries, num_levels, num_points) -> 73 | # (bs, num_heads, 1, num_queries, num_levels*num_points) 74 | attention_weights = attention_weights.transpose(1, 2).reshape(bs * num_heads, 1, num_queries, 75 | num_levels * num_points) 76 | output = ((torch.stack(sampling_value_list, dim=-2).flatten(-2) * attention_weights).sum(-1).view( 77 | bs, num_heads * embed_dims, num_queries)) 78 | return output.transpose(1, 2).contiguous() 79 | -------------------------------------------------------------------------------- /ultralytics/trackers/README.md: -------------------------------------------------------------------------------- 1 | # Tracker 2 | 3 | ## Supported Trackers 4 | 5 | - [x] ByteTracker 6 | - [x] BoT-SORT 7 | 8 | ## Usage 9 | 10 | ### python interface: 11 | 12 | You can use the Python interface to track objects using the YOLO model. 13 | 14 | ```python 15 | from ultralytics import YOLO 16 | 17 | model = YOLO("yolov8n.pt") # or a segmentation model .i.e yolov8n-seg.pt 18 | model.track( 19 | source="video/streams", 20 | stream=True, 21 | tracker="botsort.yaml", # or 'bytetrack.yaml' 22 | show=True, 23 | ) 24 | ``` 25 | 26 | You can get the IDs of the tracked objects using the following code: 27 | 28 | ```python 29 | from ultralytics import YOLO 30 | 31 | model = YOLO("yolov8n.pt") 32 | 33 | for result in model.track(source="video.mp4"): 34 | print( 35 | result.boxes.id.cpu().numpy().astype(int) 36 | ) # this will print the IDs of the tracked objects in the frame 37 | ``` 38 | 39 | If you want to use the tracker with a folder of images or when you loop on the video frames, you should use the `persist` parameter to tell the model that these frames are related to each other so the IDs will be fixed for the same objects. Otherwise, the IDs will be different in each frame because in each loop, the model creates a new object for tracking, but the `persist` parameter makes it use the same object for tracking. 40 | 41 | ```python 42 | import cv2 43 | from ultralytics import YOLO 44 | 45 | cap = cv2.VideoCapture("video.mp4") 46 | model = YOLO("yolov8n.pt") 47 | while True: 48 | ret, frame = cap.read() 49 | if not ret: 50 | break 51 | results = model.track(frame, persist=True) 52 | boxes = results[0].boxes.xyxy.cpu().numpy().astype(int) 53 | ids = results[0].boxes.id.cpu().numpy().astype(int) 54 | for box, id in zip(boxes, ids): 55 | cv2.rectangle(frame, (box[0], box[1]), (box[2], box[3]), (0, 255, 0), 2) 56 | cv2.putText( 57 | frame, 58 | f"Id {id}", 59 | (box[0], box[1]), 60 | cv2.FONT_HERSHEY_SIMPLEX, 61 | 1, 62 | (0, 0, 255), 63 | 2, 64 | ) 65 | cv2.imshow("frame", frame) 66 | if cv2.waitKey(1) & 0xFF == ord("q"): 67 | break 68 | ``` 69 | 70 | ## Change tracker parameters 71 | 72 | You can change the tracker parameters by eding the `tracker.yaml` file which is located in the ultralytics/cfg/trackers folder. 73 | 74 | ## Command Line Interface (CLI) 75 | 76 | You can also use the command line interface to track objects using the YOLO model. 77 | 78 | ```bash 79 | yolo detect track source=... tracker=... 80 | yolo segment track source=... tracker=... 81 | yolo pose track source=... tracker=... 82 | ``` 83 | 84 | By default, trackers will use the configuration in `ultralytics/cfg/trackers`. 85 | We also support using a modified tracker config file. Please refer to the tracker config files 86 | in `ultralytics/cfg/trackers`.
87 | -------------------------------------------------------------------------------- /ultralytics/trackers/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from .bot_sort import BOTSORT 4 | from .byte_tracker import BYTETracker 5 | from .track import register_tracker 6 | 7 | __all__ = 'register_tracker', 'BOTSORT', 'BYTETracker' # allow simpler import 8 | -------------------------------------------------------------------------------- /ultralytics/trackers/basetrack.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from collections import OrderedDict 4 | 5 | import numpy as np 6 | 7 | 8 | class TrackState: 9 | """Enumeration of possible object tracking states.""" 10 | 11 | New = 0 12 | Tracked = 1 13 | Lost = 2 14 | Removed = 3 15 | 16 | 17 | class BaseTrack: 18 | """Base class for object tracking, handling basic track attributes and operations.""" 19 | 20 | _count = 0 21 | 22 | track_id = 0 23 | is_activated = False 24 | state = TrackState.New 25 | 26 | history = OrderedDict() 27 | features = [] 28 | curr_feature = None 29 | score = 0 30 | start_frame = 0 31 | frame_id = 0 32 | time_since_update = 0 33 | 34 | # Multi-camera 35 | location = (np.inf, np.inf) 36 | 37 | @property 38 | def end_frame(self): 39 | """Return the last frame ID of the track.""" 40 | return self.frame_id 41 | 42 | @staticmethod 43 | def next_id(): 44 | """Increment and return the global track ID counter.""" 45 | BaseTrack._count += 1 46 | return BaseTrack._count 47 | 48 | def activate(self, *args): 49 | """Activate the track with the provided arguments.""" 50 | raise NotImplementedError 51 | 52 | def predict(self): 53 | """Predict the next state of the track.""" 54 | raise NotImplementedError 55 | 56 | def update(self, *args, **kwargs): 57 | """Update the track with new observations.""" 58 | raise NotImplementedError 59 | 60 | def mark_lost(self): 61 | """Mark the track as lost.""" 62 | self.state = TrackState.Lost 63 | 64 | def mark_removed(self): 65 | """Mark the track as removed.""" 66 | self.state = TrackState.Removed 67 | 68 | @staticmethod 69 | def reset_id(): 70 | """Reset the global track ID counter.""" 71 | BaseTrack._count = 0 72 | -------------------------------------------------------------------------------- /ultralytics/trackers/track.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from functools import partial 4 | 5 | import torch 6 | 7 | from ultralytics.utils import IterableSimpleNamespace, yaml_load 8 | from ultralytics.utils.checks import check_yaml 9 | 10 | from .bot_sort import BOTSORT 11 | from .byte_tracker import BYTETracker 12 | 13 | TRACKER_MAP = {'bytetrack': BYTETracker, 'botsort': BOTSORT} 14 | 15 | 16 | def on_predict_start(predictor, persist=False): 17 | """ 18 | Initialize trackers for object tracking during prediction. 19 | 20 | Args: 21 | predictor (object): The predictor object to initialize trackers for. 22 | persist (bool, optional): Whether to persist the trackers if they already exist. Defaults to False. 23 | 24 | Raises: 25 | AssertionError: If the tracker_type is not 'bytetrack' or 'botsort'. 26 | """ 27 | if hasattr(predictor, 'trackers') and persist: 28 | return 29 | tracker = check_yaml(predictor.args.tracker) 30 | cfg = IterableSimpleNamespace(**yaml_load(tracker)) 31 | assert cfg.tracker_type in ['bytetrack', 'botsort'], \ 32 | f"Only support 'bytetrack' and 'botsort' for now, but got '{cfg.tracker_type}'" 33 | trackers = [] 34 | for _ in range(predictor.dataset.bs): 35 | tracker = TRACKER_MAP[cfg.tracker_type](args=cfg, frame_rate=30) 36 | trackers.append(tracker) 37 | predictor.trackers = trackers 38 | 39 | 40 | def on_predict_postprocess_end(predictor): 41 | """Postprocess detected boxes and update with object tracking.""" 42 | bs = predictor.dataset.bs 43 | im0s = predictor.batch[1] 44 | for i in range(bs): 45 | det = predictor.results[i].boxes.cpu().numpy() 46 | if len(det) == 0: 47 | continue 48 | tracks = predictor.trackers[i].update(det, im0s[i]) 49 | if len(tracks) == 0: 50 | continue 51 | idx = tracks[:, -1].astype(int) 52 | predictor.results[i] = predictor.results[i][idx] 53 | predictor.results[i].update(boxes=torch.as_tensor(tracks[:, :-1])) 54 | 55 | 56 | def register_tracker(model, persist): 57 | """ 58 | Register tracking callbacks to the model for object tracking during prediction. 59 | 60 | Args: 61 | model (object): The model object to register tracking callbacks for. 62 | persist (bool): Whether to persist the trackers if they already exist. 63 | 64 | """ 65 | model.add_callback('on_predict_start', partial(on_predict_start, persist=persist)) 66 | model.add_callback('on_predict_postprocess_end', on_predict_postprocess_end) 67 | -------------------------------------------------------------------------------- /ultralytics/trackers/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liaopan-lp/MO-YOLO/81d917e0cafb68fda27c757ad2c35d7f1eb5f254/ultralytics/trackers/utils/__init__.py -------------------------------------------------------------------------------- /ultralytics/utils/_timing.py: -------------------------------------------------------------------------------- 1 | from functools import wraps 2 | from time import perf_counter 3 | import inspect 4 | 5 | DO_TIMING = False 6 | DISPLAY_LESS_PROGRESS = False 7 | timer_dict = {} 8 | counter = 0 9 | 10 | 11 | def time(f): 12 | @wraps(f) 13 | def wrap(*args, **kw): 14 | if DO_TIMING: 15 | # Run function with timing 16 | ts = perf_counter() 17 | result = f(*args, **kw) 18 | te = perf_counter() 19 | tt = te-ts 20 | 21 | # Get function name 22 | arg_names = inspect.getfullargspec(f)[0] 23 | if arg_names[0] == 'self' and DISPLAY_LESS_PROGRESS: 24 | return result 25 | elif arg_names[0] == 'self': 26 | method_name = type(args[0]).__name__ + '.' + f.__name__ 27 | else: 28 | method_name = f.__name__ 29 | 30 | # Record accumulative time in each function for analysis 31 | if method_name in timer_dict.keys(): 32 | timer_dict[method_name] += tt 33 | else: 34 | timer_dict[method_name] = tt 35 | 36 | # If code is finished, display timing summary 37 | if method_name == "Evaluator.evaluate": 38 | print("") 39 | print("Timing analysis:") 40 | for key, value in timer_dict.items(): 41 | print('%-70s %2.4f sec' % (key, value)) 42 | else: 43 | # Get function argument values for printing special arguments of interest 44 | arg_titles = ['tracker', 'seq', 'cls'] 45 | arg_vals = [] 46 | for i, a in enumerate(arg_names): 47 | if a in arg_titles: 48 | arg_vals.append(args[i]) 49 | arg_text = '(' + ', '.join(arg_vals) + ')' 50 | 51 | # Display methods and functions with different indentation. 52 | if arg_names[0] == 'self': 53 | print('%-74s %2.4f sec' % (' '*4 + method_name + arg_text, tt)) 54 | elif arg_names[0] == 'test': 55 | pass 56 | else: 57 | global counter 58 | counter += 1 59 | print('%i %-70s %2.4f sec' % (counter, method_name + arg_text, tt)) 60 | 61 | return result 62 | else: 63 | # If config["TIME_PROGRESS"] is false, or config["USE_PARALLEL"] is true, run functions normally without timing. 64 | return f(*args, **kw) 65 | return wrap 66 | -------------------------------------------------------------------------------- /ultralytics/utils/baselines/__init__.py: -------------------------------------------------------------------------------- 1 | import baseline_utils 2 | import stp 3 | import non_overlap 4 | import pascal_colormap 5 | import thresholder 6 | import vizualize -------------------------------------------------------------------------------- /ultralytics/utils/baselines/thresholder.py: -------------------------------------------------------------------------------- 1 | """ 2 | Thresholder 3 | 4 | Author: Jonathon Luiten 5 | 6 | Simply reads in a set of detection, thresholds them at a certain score threshold, and writes them out again. 7 | """ 8 | 9 | import os 10 | import sys 11 | from multiprocessing.pool import Pool 12 | from multiprocessing import freeze_support 13 | 14 | sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) 15 | from trackeval.baselines import baseline_utils as butils 16 | from trackeval.utils import get_code_path 17 | 18 | THRESHOLD = 0.2 19 | 20 | code_path = get_code_path() 21 | config = { 22 | 'INPUT_FOL': os.path.join(code_path, 'data/detections/rob_mots/{split}/non_overlap_supplied/data/'), 23 | 'OUTPUT_FOL': os.path.join(code_path, 'data/detections/rob_mots/{split}/threshold_' + str(100*THRESHOLD) + '/data/'), 24 | 'SPLIT': 'train', # valid: 'train', 'val', 'test'. 25 | 'Benchmarks': None, # If None, all benchmarks in SPLIT. 26 | 27 | 'Num_Parallel_Cores': None, # If None, run without parallel. 28 | 29 | 'DETECTION_THRESHOLD': THRESHOLD, 30 | } 31 | 32 | 33 | def do_sequence(seq_file): 34 | 35 | # Load input data from file (e.g. provided detections) 36 | # data format: data['cls'][t] = {'ids', 'scores', 'im_hs', 'im_ws', 'mask_rles'} 37 | data = butils.load_seq(seq_file) 38 | 39 | # Where to accumulate output data for writing out 40 | output_data = [] 41 | 42 | # Run for each class. 43 | for cls, cls_data in data.items(): 44 | 45 | # Run for each timestep. 46 | for timestep, t_data in enumerate(cls_data): 47 | 48 | # Threshold detections. 49 | t_data = butils.threshold(t_data, config['DETECTION_THRESHOLD']) 50 | 51 | # Save result in output format to write to file later. 52 | # Output Format = [timestep ID class score im_h im_w mask_RLE] 53 | for i in range(len(t_data['ids'])): 54 | row = [timestep, int(t_data['ids'][i]), cls, t_data['scores'][i], t_data['im_hs'][i], 55 | t_data['im_ws'][i], t_data['mask_rles'][i]] 56 | output_data.append(row) 57 | 58 | # Write results to file 59 | out_file = seq_file.replace(config['INPUT_FOL'].format(split=config['SPLIT']), 60 | config['OUTPUT_FOL'].format(split=config['SPLIT'])) 61 | butils.write_seq(output_data, out_file) 62 | 63 | print('DONE:', seq_todo) 64 | 65 | 66 | if __name__ == '__main__': 67 | 68 | # Required to fix bug in multiprocessing on windows. 69 | freeze_support() 70 | 71 | # Obtain list of sequences to run tracker for. 72 | if config['Benchmarks']: 73 | benchmarks = config['Benchmarks'] 74 | else: 75 | benchmarks = ['davis_unsupervised', 'kitti_mots', 'youtube_vis', 'ovis', 'bdd_mots', 'tao'] 76 | if config['SPLIT'] != 'train': 77 | benchmarks += ['waymo', 'mots_challenge'] 78 | seqs_todo = [] 79 | for bench in benchmarks: 80 | bench_fol = os.path.join(config['INPUT_FOL'].format(split=config['SPLIT']), bench) 81 | seqs_todo += [os.path.join(bench_fol, seq) for seq in os.listdir(bench_fol)] 82 | 83 | # Run in parallel 84 | if config['Num_Parallel_Cores']: 85 | with Pool(config['Num_Parallel_Cores']) as pool: 86 | results = pool.map(do_sequence, seqs_todo) 87 | 88 | # Run in series 89 | else: 90 | for seq_todo in seqs_todo: 91 | do_sequence(seq_todo) 92 | 93 | -------------------------------------------------------------------------------- /ultralytics/utils/callbacks/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from .base import add_integration_callbacks, default_callbacks, get_default_callbacks 4 | 5 | __all__ = 'add_integration_callbacks', 'default_callbacks', 'get_default_callbacks' 6 | -------------------------------------------------------------------------------- /ultralytics/utils/callbacks/mlflow.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | import os 4 | import re 5 | from pathlib import Path 6 | 7 | from ultralytics.utils import LOGGER, TESTS_RUNNING, colorstr 8 | 9 | try: 10 | import mlflow 11 | 12 | assert not TESTS_RUNNING # do not log pytest 13 | assert hasattr(mlflow, '__version__') # verify package is not directory 14 | except (ImportError, AssertionError): 15 | mlflow = None 16 | 17 | 18 | def on_pretrain_routine_end(trainer): 19 | """Logs training parameters to MLflow.""" 20 | global mlflow, run, run_id, experiment_name 21 | 22 | if os.environ.get('MLFLOW_TRACKING_URI') is None: 23 | mlflow = None 24 | 25 | if mlflow: 26 | mlflow_location = os.environ['MLFLOW_TRACKING_URI'] # "http://192.168.xxx.xxx:5000" 27 | mlflow.set_tracking_uri(mlflow_location) 28 | 29 | experiment_name = os.environ.get('MLFLOW_EXPERIMENT_NAME') or trainer.args.project or '/Shared/YOLOv8' 30 | run_name = os.environ.get('MLFLOW_RUN') or trainer.args.name 31 | experiment = mlflow.get_experiment_by_name(experiment_name) 32 | if experiment is None: 33 | mlflow.create_experiment(experiment_name) 34 | mlflow.set_experiment(experiment_name) 35 | 36 | prefix = colorstr('MLFlow: ') 37 | try: 38 | run, active_run = mlflow, mlflow.active_run() 39 | if not active_run: 40 | active_run = mlflow.start_run(experiment_id=experiment.experiment_id, run_name=run_name) 41 | run_id = active_run.info.run_id 42 | LOGGER.info(f'{prefix}Using run_id({run_id}) at {mlflow_location}') 43 | run.log_params(vars(trainer.model.args)) 44 | except Exception as err: 45 | LOGGER.error(f'{prefix}Failing init - {repr(err)}') 46 | LOGGER.warning(f'{prefix}Continuing without Mlflow') 47 | 48 | 49 | def on_fit_epoch_end(trainer): 50 | """Logs training metrics to Mlflow.""" 51 | if mlflow: 52 | metrics_dict = {f"{re.sub('[()]', '', k)}": float(v) for k, v in trainer.metrics.items()} 53 | run.log_metrics(metrics=metrics_dict, step=trainer.epoch) 54 | 55 | 56 | def on_train_end(trainer): 57 | """Called at end of train loop to log model artifact info.""" 58 | if mlflow: 59 | root_dir = Path(__file__).resolve().parents[3] 60 | run.log_artifact(trainer.last) 61 | run.log_artifact(trainer.best) 62 | run.pyfunc.log_model(artifact_path=experiment_name, 63 | code_path=[str(root_dir)], 64 | artifacts={'model_path': str(trainer.save_dir)}, 65 | python_model=run.pyfunc.PythonModel()) 66 | 67 | 68 | callbacks = { 69 | 'on_pretrain_routine_end': on_pretrain_routine_end, 70 | 'on_fit_epoch_end': on_fit_epoch_end, 71 | 'on_train_end': on_train_end} if mlflow else {} 72 | -------------------------------------------------------------------------------- /ultralytics/utils/callbacks/raytune.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | try: 4 | import ray 5 | from ray import tune 6 | from ray.air import session 7 | except (ImportError, AssertionError): 8 | tune = None 9 | 10 | 11 | def on_fit_epoch_end(trainer): 12 | """Sends training metrics to Ray Tune at end of each epoch.""" 13 | if ray.tune.is_session_enabled(): 14 | metrics = trainer.metrics 15 | metrics['epoch'] = trainer.epoch 16 | session.report(metrics) 17 | 18 | 19 | callbacks = { 20 | 'on_fit_epoch_end': on_fit_epoch_end, } if tune else {} 21 | -------------------------------------------------------------------------------- /ultralytics/utils/callbacks/tensorboard.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from ultralytics.utils import LOGGER, TESTS_RUNNING, colorstr 4 | 5 | try: 6 | from torch.utils.tensorboard import SummaryWriter 7 | 8 | assert not TESTS_RUNNING # do not log pytest 9 | except (ImportError, AssertionError): 10 | SummaryWriter = None 11 | 12 | writer = None # TensorBoard SummaryWriter instance 13 | 14 | 15 | def _log_scalars(scalars, step=0): 16 | """Logs scalar values to TensorBoard.""" 17 | if writer: 18 | for k, v in scalars.items(): 19 | writer.add_scalar(k, v, step) 20 | 21 | 22 | def on_pretrain_routine_start(trainer): 23 | """Initialize TensorBoard logging with SummaryWriter.""" 24 | if SummaryWriter: 25 | try: 26 | global writer 27 | writer = SummaryWriter(str(trainer.save_dir)) 28 | prefix = colorstr('TensorBoard: ') 29 | LOGGER.info(f"{prefix}Start with 'tensorboard --logdir {trainer.save_dir}', view at http://localhost:6006/") 30 | except Exception as e: 31 | LOGGER.warning(f'WARNING ⚠️ TensorBoard not initialized correctly, not logging this run. {e}') 32 | 33 | 34 | def on_batch_end(trainer): 35 | """Logs scalar statistics at the end of a training batch.""" 36 | _log_scalars(trainer.label_loss_items(trainer.tloss, prefix='train'), trainer.epoch + 1) 37 | 38 | 39 | def on_fit_epoch_end(trainer): 40 | """Logs epoch metrics at end of training epoch.""" 41 | _log_scalars(trainer.metrics, trainer.epoch + 1) 42 | 43 | 44 | callbacks = { 45 | 'on_pretrain_routine_start': on_pretrain_routine_start, 46 | 'on_fit_epoch_end': on_fit_epoch_end, 47 | 'on_batch_end': on_batch_end} 48 | -------------------------------------------------------------------------------- /ultralytics/utils/callbacks/wb.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | from ultralytics.utils import TESTS_RUNNING 3 | from ultralytics.utils.torch_utils import model_info_for_loggers 4 | 5 | try: 6 | import wandb as wb 7 | 8 | assert hasattr(wb, '__version__') 9 | assert not TESTS_RUNNING # do not log pytest 10 | except (ImportError, AssertionError): 11 | wb = None 12 | 13 | _processed_plots = {} 14 | 15 | 16 | def _log_plots(plots, step): 17 | for name, params in plots.items(): 18 | timestamp = params['timestamp'] 19 | if _processed_plots.get(name, None) != timestamp: 20 | wb.run.log({name.stem: wb.Image(str(name))}, step=step) 21 | _processed_plots[name] = timestamp 22 | 23 | 24 | def on_pretrain_routine_start(trainer): 25 | """Initiate and start project if module is present.""" 26 | wb.run or wb.init(project=trainer.args.project or 'YOLOv8', name=trainer.args.name, config=vars(trainer.args)) 27 | 28 | 29 | def on_fit_epoch_end(trainer): 30 | """Logs training metrics and model information at the end of an epoch.""" 31 | wb.run.log(trainer.metrics, step=trainer.epoch + 1) 32 | _log_plots(trainer.plots, step=trainer.epoch + 1) 33 | _log_plots(trainer.validator.plots, step=trainer.epoch + 1) 34 | if trainer.epoch == 0: 35 | wb.run.log(model_info_for_loggers(trainer), step=trainer.epoch + 1) 36 | 37 | 38 | def on_train_epoch_end(trainer): 39 | """Log metrics and save images at the end of each training epoch.""" 40 | wb.run.log(trainer.label_loss_items(trainer.tloss, prefix='train'), step=trainer.epoch + 1) 41 | wb.run.log(trainer.lr, step=trainer.epoch + 1) 42 | if trainer.epoch == 1: 43 | _log_plots(trainer.plots, step=trainer.epoch + 1) 44 | 45 | 46 | def on_train_end(trainer): 47 | """Save the best model as an artifact at end of training.""" 48 | _log_plots(trainer.validator.plots, step=trainer.epoch + 1) 49 | _log_plots(trainer.plots, step=trainer.epoch + 1) 50 | art = wb.Artifact(type='model', name=f'run_{wb.run.id}_model') 51 | if trainer.best.exists(): 52 | art.add_file(trainer.best) 53 | wb.run.log_artifact(art, aliases=['best']) 54 | 55 | 56 | callbacks = { 57 | 'on_pretrain_routine_start': on_pretrain_routine_start, 58 | 'on_train_epoch_end': on_train_epoch_end, 59 | 'on_fit_epoch_end': on_fit_epoch_end, 60 | 'on_train_end': on_train_end} if wb else {} 61 | -------------------------------------------------------------------------------- /ultralytics/utils/dist.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | import os 4 | import re 5 | import shutil 6 | import socket 7 | import sys 8 | import tempfile 9 | from pathlib import Path 10 | 11 | from . import USER_CONFIG_DIR 12 | from .torch_utils import TORCH_1_9 13 | 14 | 15 | def find_free_network_port() -> int: 16 | """Finds a free port on localhost. 17 | 18 | It is useful in single-node training when we don't want to connect to a real main node but have to set the 19 | `MASTER_PORT` environment variable. 20 | """ 21 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: 22 | s.bind(('127.0.0.1', 0)) 23 | return s.getsockname()[1] # port 24 | 25 | 26 | def generate_ddp_file(trainer): 27 | """Generates a DDP file and returns its file name.""" 28 | module, name = f'{trainer.__class__.__module__}.{trainer.__class__.__name__}'.rsplit('.', 1) 29 | 30 | content = f'''overrides = {vars(trainer.args)} \nif __name__ == "__main__": 31 | from {module} import {name} 32 | from ultralytics.utils import DEFAULT_CFG_DICT 33 | 34 | cfg = DEFAULT_CFG_DICT.copy() 35 | cfg.update(save_dir='') # handle the extra key 'save_dir' 36 | trainer = {name}(cfg=cfg, overrides=overrides) 37 | trainer.train()''' 38 | (USER_CONFIG_DIR / 'DDP').mkdir(exist_ok=True) 39 | with tempfile.NamedTemporaryFile(prefix='_temp_', 40 | suffix=f'{id(trainer)}.py', 41 | mode='w+', 42 | encoding='utf-8', 43 | dir=USER_CONFIG_DIR / 'DDP', 44 | delete=False) as file: 45 | file.write(content) 46 | return file.name 47 | 48 | 49 | def generate_ddp_command(world_size, trainer): 50 | """Generates and returns command for distributed training.""" 51 | import __main__ # noqa local import to avoid https://github.com/Lightning-AI/lightning/issues/15218 52 | if not trainer.resume: 53 | shutil.rmtree(trainer.save_dir) # remove the save_dir 54 | file = str(Path(sys.argv[0]).resolve()) 55 | safe_pattern = re.compile(r'^[a-zA-Z0-9_. /\\-]{1,128}$') # allowed characters and maximum of 100 characters 56 | if not (safe_pattern.match(file) and Path(file).exists() and file.endswith('.py')): # using CLI 57 | file = generate_ddp_file(trainer) 58 | dist_cmd = 'torch.distributed.run' if TORCH_1_9 else 'torch.distributed.launch' 59 | port = find_free_network_port() 60 | cmd = [sys.executable, '-m', dist_cmd, '--nproc_per_node', f'{world_size}', '--master_port', f'{port}', file] 61 | return cmd, file 62 | 63 | 64 | def ddp_cleanup(trainer, file): 65 | """Delete temp file if created.""" 66 | if f'{id(trainer)}.py' in file: # if temp_file suffix in file 67 | os.remove(file) 68 | -------------------------------------------------------------------------------- /ultralytics/utils/errors.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from ultralytics.utils import emojis 4 | 5 | 6 | class HUBModelError(Exception): 7 | 8 | def __init__(self, message='Model not found. Please check model URL and try again.'): 9 | """Create an exception for when a model is not found.""" 10 | super().__init__(emojis(message)) 11 | -------------------------------------------------------------------------------- /ultralytics/utils/patches.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | """ 3 | Monkey patches to update/extend functionality of existing functions 4 | """ 5 | 6 | from pathlib import Path 7 | 8 | import cv2 9 | import numpy as np 10 | import torch 11 | 12 | # OpenCV Multilanguage-friendly functions ------------------------------------------------------------------------------ 13 | _imshow = cv2.imshow # copy to avoid recursion errors 14 | 15 | 16 | def imread(filename, flags=cv2.IMREAD_COLOR): 17 | return cv2.imdecode(np.fromfile(filename, np.uint8), flags) 18 | 19 | 20 | def imwrite(filename, img): 21 | try: 22 | cv2.imencode(Path(filename).suffix, img)[1].tofile(filename) 23 | return True 24 | except Exception: 25 | return False 26 | 27 | 28 | def imshow(path, im): 29 | _imshow(path.encode('unicode_escape').decode(), im) 30 | 31 | 32 | # PyTorch functions ---------------------------------------------------------------------------------------------------- 33 | _torch_save = torch.save # copy to avoid recursion errors 34 | 35 | 36 | def torch_save(*args, **kwargs): 37 | """Use dill (if exists) to serialize the lambda functions where pickle does not do this.""" 38 | try: 39 | import dill as pickle 40 | except ImportError: 41 | import pickle 42 | 43 | if 'pickle_module' not in kwargs: 44 | kwargs['pickle_module'] = pickle 45 | return _torch_save(*args, **kwargs) 46 | -------------------------------------------------------------------------------- /ultralytics/yolo/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics YOLO 🚀, AGPL-3.0 license 2 | 3 | from . import v8 4 | 5 | __all__ = 'v8', # tuple or list 6 | -------------------------------------------------------------------------------- /ultralytics/yolo/cfg/__init__.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | import sys 3 | 4 | from ultralytics.utils import LOGGER 5 | 6 | # Set modules in sys.modules under their old name 7 | sys.modules['ultralytics.yolo.cfg'] = importlib.import_module('ultralytics.cfg') 8 | 9 | LOGGER.warning("WARNING ⚠️ 'ultralytics.yolo.cfg' is deprecated since '8.0.136' and will be removed in '8.1.0'. " 10 | "Please use 'ultralytics.cfg' instead.") 11 | -------------------------------------------------------------------------------- /ultralytics/yolo/data/__init__.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | import sys 3 | 4 | from ultralytics.utils import LOGGER 5 | 6 | # Set modules in sys.modules under their old name 7 | sys.modules['ultralytics.yolo.data'] = importlib.import_module('ultralytics.data') 8 | # This is for updating old cls models, or the way in following warning won't work. 9 | sys.modules['ultralytics.yolo.data.augment'] = importlib.import_module('ultralytics.data.augment') 10 | 11 | DATA_WARNING = """WARNING ⚠️ 'ultralytics.yolo.data' is deprecated since '8.0.136' and will be removed in '8.1.0'. Please use 'ultralytics.data' instead. 12 | Note this warning may be related to loading older models. You can update your model to current structure with: 13 | import torch 14 | ckpt = torch.load("model.pt") # applies to both official and custom models 15 | torch.save(ckpt, "updated-model.pt") 16 | """ 17 | LOGGER.warning(DATA_WARNING) 18 | -------------------------------------------------------------------------------- /ultralytics/yolo/engine/__init__.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | import sys 3 | 4 | from ultralytics.utils import LOGGER 5 | 6 | # Set modules in sys.modules under their old name 7 | sys.modules['ultralytics.yolo.engine'] = importlib.import_module('ultralytics.engine') 8 | 9 | LOGGER.warning("WARNING ⚠️ 'ultralytics.yolo.engine' is deprecated since '8.0.136' and will be removed in '8.1.0'. " 10 | "Please use 'ultralytics.engine' instead.") 11 | -------------------------------------------------------------------------------- /ultralytics/yolo/utils/__init__.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | import sys 3 | 4 | from ultralytics.utils import LOGGER 5 | 6 | # Set modules in sys.modules under their old name 7 | sys.modules['ultralytics.yolo.utils'] = importlib.import_module('ultralytics.utils') 8 | 9 | UTILS_WARNING = """WARNING ⚠️ 'ultralytics.yolo.utils' is deprecated since '8.0.136' and will be removed in '8.1.0'. Please use 'ultralytics.utils' instead. 10 | Note this warning may be related to loading older models. You can update your model to current structure with: 11 | import torch 12 | ckpt = torch.load("model.pt") # applies to both official and custom models 13 | torch.save(ckpt, "updated-model.pt") 14 | """ 15 | LOGGER.warning(UTILS_WARNING) 16 | -------------------------------------------------------------------------------- /ultralytics/yolo/v8/__init__.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | import sys 3 | 4 | from ultralytics.utils import LOGGER 5 | 6 | # Set modules in sys.modules under their old name 7 | sys.modules['ultralytics.yolo.v8'] = importlib.import_module('ultralytics.models.yolo') 8 | 9 | LOGGER.warning("WARNING ⚠️ 'ultralytics.yolo.v8' is deprecated since '8.0.136' and will be removed in '8.1.0'. " 10 | "Please use 'ultralytics.models.yolo' instead.") 11 | --------------------------------------------------------------------------------