├── vit ├── quant │ ├── __init__.py │ └── quant_mode.py ├── tools │ ├── __init__.py │ ├── dist_train.sh │ ├── dist_test.sh │ ├── config │ │ ├── generation.json │ │ ├── qat_full_deit.json │ │ ├── qat_syn.json │ │ ├── 128_qat.json │ │ ├── 2048_qat.json │ │ ├── 2048_qatkd.json │ │ └── qat_full.json │ ├── kd │ │ └── mse.py │ ├── visualize.py │ ├── generate_gauss.py │ └── rescale_images.py ├── .python-version ├── baseline │ ├── __init__.py │ └── psaq │ │ ├── __init__.py │ │ ├── models │ │ ├── __init__.py │ │ └── quantization_utils │ │ │ └── __init__.py │ │ ├── overview.png │ │ └── utils │ │ └── __init__.py ├── mmcv_custom │ └── __init__.py ├── configs │ ├── mask_rcnn │ │ ├── mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco.py │ │ ├── mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco.py │ │ ├── retinanet_swin-t-p4-w7_fpn_1x_coco.py │ │ └── mask_rcnn_swin-t-p4-w7_fpn_1x_coco.py │ ├── _base_ │ │ ├── schedules │ │ │ ├── schedule_1x.py │ │ │ ├── schedule_20e.py │ │ │ ├── schedule_2x.py │ │ │ ├── schedule_3x.py │ │ │ └── schedule_6x.py │ │ ├── default_runtime.py │ │ ├── datasets │ │ │ ├── coco_detection.py │ │ │ └── coco_instance.py │ │ └── models │ │ │ ├── ssd300.py │ │ │ ├── retinanet_r50_fpn.py │ │ │ ├── rpn_r50_fpn.py │ │ │ └── rpn_r50_caffe_c4.py │ └── datasets │ │ ├── generation.py │ │ ├── syn.py │ │ ├── coco_128.py │ │ └── coco_2048.py ├── LICENSE ├── mmdet_custom │ ├── __init__.py │ └── datasets │ │ └── coco_fraction.py ├── scripts │ ├── stage_two │ │ ├── exact_2k │ │ │ ├── exact2k_t_8.sh │ │ │ └── exact2k_s_8.sh │ │ ├── exact_full │ │ │ ├── exactfull_t_8.sh │ │ │ └── exactfull_s_8.sh │ │ └── ours │ │ │ ├── ours_t_8.sh │ │ │ └── ours_s_8.sh │ ├── stage_one │ │ ├── gen_s.sh │ │ ├── gen_t.sh │ │ ├── gen_s_8.sh │ │ └── gen_t_8.sh │ └── README.md ├── .gitignore └── pyproject.toml ├── yolo11 ├── external │ ├── __init__.py │ ├── config │ │ ├── qat.json │ │ ├── qat_full.json │ │ ├── gimg.json │ │ ├── ptq.json │ │ └── kd.json │ └── gimg_loader.py ├── label │ └── __init__.py ├── quant │ ├── __init__.py │ ├── mse.py │ ├── kd_mode.py │ ├── quant_mode.py │ └── dist_kd.py ├── .python-version ├── generation │ ├── __init__.py │ ├── config │ │ ├── true_label.json │ │ ├── genlabel.json │ │ └── relabel-syn.json │ └── main.py ├── data │ ├── .gitignore │ └── cocoonebox.yaml ├── scripts │ ├── stage_one │ │ ├── adaptive_label_sampling │ │ │ ├── synthesize_image.sh │ │ │ ├── create_label.sh │ │ │ └── sample_label.sh │ │ └── true_label │ │ │ ├── yolo11l.sh │ │ │ ├── yolo11m.sh │ │ │ └── yolo11s.sh │ ├── stage_two │ │ ├── exact_2k │ │ │ ├── l.sh │ │ │ ├── m.sh │ │ │ └── s.sh │ │ ├── exact_full │ │ │ ├── l.sh │ │ │ ├── m.sh │ │ │ └── s.sh │ │ └── ours │ │ │ ├── l.sh │ │ │ ├── m.sh │ │ │ └── s.sh │ └── README.md ├── pyproject.toml └── tools │ └── visualize.py ├── yolov5 ├── models │ ├── __init__.py │ ├── hub │ │ ├── yolov5-fpn.yaml │ │ ├── yolov5-p34.yaml │ │ ├── yolov3-tiny.yaml │ │ ├── yolov5-panet.yaml │ │ ├── yolov5-bifpn.yaml │ │ ├── yolov5s-transformer.yaml │ │ ├── yolov5s-ghost.yaml │ │ ├── yolov5s-LeakyReLU.yaml │ │ ├── yolov3.yaml │ │ ├── yolov3-spp.yaml │ │ ├── yolov5-p2.yaml │ │ ├── yolov5-p6.yaml │ │ ├── yolov5l6.yaml │ │ ├── yolov5m6.yaml │ │ ├── yolov5n6.yaml │ │ ├── yolov5s6.yaml │ │ └── yolov5x6.yaml │ ├── yolov5l.yaml │ ├── yolov5m.yaml │ ├── yolov5n.yaml │ ├── yolov5s.yaml │ ├── yolov5x.yaml │ ├── segment │ │ ├── yolov5l-seg.yaml │ │ ├── yolov5m-seg.yaml │ │ ├── yolov5n-seg.yaml │ │ ├── yolov5s-seg.yaml │ │ └── yolov5x-seg.yaml │ ├── 4bitLSQ_yolov5s.yaml │ ├── 4bitlsq_yolov5l.yaml │ ├── 4bitlsq_yolov5m.yaml │ ├── 4bitlsq_yolov5n.yaml │ ├── 4bitlsq_yolov5s.yaml │ ├── 5bitlsq_yolov5l.yaml │ ├── 5bitlsq_yolov5m.yaml │ ├── 5bitlsq_yolov5n.yaml │ ├── 5bitlsq_yolov5s.yaml │ ├── 6bitlsq_yolov5l.yaml │ ├── 6bitlsq_yolov5m.yaml │ ├── 6bitlsq_yolov5n.yaml │ ├── 6bitlsq_yolov5s.yaml │ ├── 7bitlsq_yolov5l.yaml │ ├── 7bitlsq_yolov5m.yaml │ ├── 7bitlsq_yolov5n.yaml │ ├── 7bitlsq_yolov5s.yaml │ ├── 8bitlsq_yolov5l.yaml │ ├── 8bitlsq_yolov5m.yaml │ ├── 8bitlsq_yolov5n.yaml │ └── 8bitlsq_yolov5s.yaml ├── utils │ ├── aws │ │ ├── __init__.py │ │ └── resume.py │ ├── segment │ │ └── __init__.py │ ├── loggers │ │ ├── wandb │ │ │ └── __init__.py │ │ └── clearml │ │ │ └── __init__.py │ ├── google_app_engine │ │ ├── additional_requirements.txt │ │ ├── app.yaml │ │ └── Dockerfile │ ├── flask_rest_api │ │ ├── example_request.py │ │ ├── restapi.py │ │ └── README.md │ ├── mse.py │ ├── docker │ │ ├── Dockerfile-arm64 │ │ └── Dockerfile-cpu │ └── dist_kd.py ├── .gitattributes ├── data │ ├── images │ │ ├── bus.jpg │ │ └── zidane.jpg │ ├── hyps │ │ ├── hyp.Objects365.yaml │ │ ├── hyp.VOC.yaml │ │ ├── hyp.scratch-high.yaml │ │ ├── hyp.distill.yaml │ │ ├── hyp.scratch-med.yaml │ │ ├── hyp.no-augmentation.yaml │ │ ├── hyp.scratch-low.yaml │ │ └── hyps.qat.yaml │ ├── ImageNet10.yaml │ ├── GlobalWheat2020.yaml │ └── coco128.yaml └── CITATION.cff ├── resnet ├── .python-version ├── backbone │ └── __init__.py ├── main.py ├── requirements.txt ├── network_files │ ├── __init__.py │ └── image_list.py ├── train_utils │ ├── __init__.py │ ├── mse.py │ └── loggers.py ├── create_dir.py ├── clear.py ├── pascal_voc_indices.json ├── pyproject.toml ├── .gitignore ├── transforms.py ├── plot_curve.py └── coco91_indices.json ├── structure.png ├── .editorconfig ├── tools └── coco.sh └── .gitignore /vit/quant/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vit/tools/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vit/.python-version: -------------------------------------------------------------------------------- 1 | 3.9 2 | -------------------------------------------------------------------------------- /vit/baseline/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /yolo11/external/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /yolo11/label/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /yolo11/quant/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /yolov5/models/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /yolov5/utils/aws/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /resnet/.python-version: -------------------------------------------------------------------------------- 1 | 3.9 2 | -------------------------------------------------------------------------------- /vit/baseline/psaq/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /yolo11/.python-version: -------------------------------------------------------------------------------- 1 | 3.12 2 | -------------------------------------------------------------------------------- /yolo11/generation/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /yolov5/utils/segment/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /yolov5/utils/loggers/wandb/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /yolov5/utils/loggers/clearml/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /yolo11/data/.gitignore: -------------------------------------------------------------------------------- 1 | coco 2 | COCO2017 3 | -------------------------------------------------------------------------------- /structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DFQ-Dojo/dfq-toolkit/HEAD/structure.png -------------------------------------------------------------------------------- /resnet/backbone/__init__.py: -------------------------------------------------------------------------------- 1 | from .resnet50_fpn_model import resnet50_fpn_backbone 2 | -------------------------------------------------------------------------------- /vit/baseline/psaq/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .vit_quant import * 2 | from .swin_quant import * 3 | -------------------------------------------------------------------------------- /yolov5/.gitattributes: -------------------------------------------------------------------------------- 1 | # this drop notebooks from GitHub language stats 2 | *.ipynb linguist-vendored 3 | -------------------------------------------------------------------------------- /yolov5/data/images/bus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DFQ-Dojo/dfq-toolkit/HEAD/yolov5/data/images/bus.jpg -------------------------------------------------------------------------------- /vit/baseline/psaq/overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DFQ-Dojo/dfq-toolkit/HEAD/vit/baseline/psaq/overview.png -------------------------------------------------------------------------------- /yolov5/data/images/zidane.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DFQ-Dojo/dfq-toolkit/HEAD/yolov5/data/images/zidane.jpg -------------------------------------------------------------------------------- /resnet/main.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | print("Hello from resnet!") 3 | 4 | 5 | if __name__ == "__main__": 6 | main() 7 | -------------------------------------------------------------------------------- /vit/baseline/psaq/models/quantization_utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .quant_modules import QuantLinear, QuantAct, QuantConv2d 2 | -------------------------------------------------------------------------------- /resnet/requirements.txt: -------------------------------------------------------------------------------- 1 | lxml 2 | matplotlib 3 | numpy 4 | tqdm 5 | pycocotools 6 | Pillow 7 | torch==1.10.0 8 | torchvision==0.11.1 9 | -------------------------------------------------------------------------------- /vit/baseline/psaq/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .build_model import * 2 | from .kde import KernelDensityEstimator 3 | from .data_utils import build_dataset 4 | -------------------------------------------------------------------------------- /resnet/network_files/__init__.py: -------------------------------------------------------------------------------- 1 | from .faster_rcnn_framework import FasterRCNN, FastRCNNPredictor 2 | from .rpn_function import AnchorsGenerator 3 | from .mask_rcnn import MaskRCNN 4 | -------------------------------------------------------------------------------- /yolo11/scripts/stage_one/adaptive_label_sampling/synthesize_image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | GENERATION_CONFIG=./generation/config/relabel-syn.json \ 4 | python -m generation.main 5 | -------------------------------------------------------------------------------- /vit/mmcv_custom/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Shanghai AI Lab. All rights reserved. 2 | from .checkpoint import load_checkpoint 3 | from .my_checkpoint import my_load_checkpoint 4 | 5 | __all__ = ["load_checkpoint", "my_load_checkpoint"] 6 | -------------------------------------------------------------------------------- /vit/configs/mask_rcnn/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco.py: -------------------------------------------------------------------------------- 1 | _base_ = "./mask_rcnn_swin-t-p4-w7_fpn_ms-crop-3x_coco.py" 2 | # you need to set mode='dynamic' if you are using pytorch<=1.5.0 3 | fp16 = dict(loss_scale=dict(init_scale=512)) 4 | -------------------------------------------------------------------------------- /vit/LICENSE: -------------------------------------------------------------------------------- 1 | # LICENSE 2 | 3 | We reused some code from Vit-Adapter. 4 | 5 | Their license: https://github.com/czczup/ViT-Adapter/blob/main/LICENSE.md 6 | 7 | Our changes: 8 | 9 | - remove vit-adapter's models 10 | - added our method to this codebase. 11 | -------------------------------------------------------------------------------- /yolo11/scripts/stage_one/true_label/yolo11l.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | GENERATION_CONFIG=./generation/config/true_label.json \ 4 | python -m generation.main \ 5 | --device cuda:0 \ 6 | --teacher_weights yolo11l.pt \ 7 | --relabel_weights yolo11l.pt 8 | -------------------------------------------------------------------------------- /yolo11/scripts/stage_one/true_label/yolo11m.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | GENERATION_CONFIG=./generation/config/true_label.json \ 4 | python -m generation.main \ 5 | --device cuda:0 \ 6 | --teacher_weights yolo11m.pt \ 7 | --relabel_weights yolo11m.pt 8 | -------------------------------------------------------------------------------- /yolo11/scripts/stage_one/true_label/yolo11s.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | GENERATION_CONFIG=./generation/config/true_label.json \ 4 | python -m generation.main \ 5 | --device cuda:0 \ 6 | --teacher_weights yolo11s.pt \ 7 | --relabel_weights yolo11s.pt 8 | -------------------------------------------------------------------------------- /yolov5/utils/google_app_engine/additional_requirements.txt: -------------------------------------------------------------------------------- 1 | # add these requirements in your app on top of the existing ones 2 | pip==23.3 3 | Flask==2.3.2 4 | gunicorn==19.10.0 5 | werkzeug>=3.0.1 # not directly required, pinned by Snyk to avoid a vulnerability 6 | -------------------------------------------------------------------------------- /yolo11/scripts/stage_one/adaptive_label_sampling/create_label.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | outdir=$(pwd)/data/COCO2017/cocoonebox 4 | 5 | echo "generating image to $outdir" 6 | 7 | python -m label.generate_one_label \ 8 | --numImages 5120 \ 9 | --outdir $outdir 10 | -------------------------------------------------------------------------------- /yolov5/utils/google_app_engine/app.yaml: -------------------------------------------------------------------------------- 1 | runtime: custom 2 | env: flex 3 | 4 | service: yolov5app 5 | 6 | liveness_check: 7 | initial_delay_sec: 600 8 | 9 | manual_scaling: 10 | instances: 1 11 | resources: 12 | cpu: 1 13 | memory_gb: 4 14 | disk_size_gb: 20 15 | -------------------------------------------------------------------------------- /vit/mmdet_custom/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Shanghai AI Lab. All rights reserved. 2 | from .models.vit_baseline import ViTBaseline # noqa: F401,F403 3 | from .datasets.coco_fraction import CocoFraction 4 | from .datasets.syn_data import SynDataset 5 | 6 | __all__ = ["ViTBaseline", "CocoFraction", "SynDataset"] 7 | -------------------------------------------------------------------------------- /vit/tools/dist_train.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CONFIG=$1 4 | GPUS=$2 5 | PORT=${PORT:-29500} 6 | 7 | PYTHONPATH="$(dirname $0)/..":$PYTHONPATH \ 8 | python -m torch.distributed.launch --nproc_per_node=$GPUS --master_port=63667 \ 9 | $(dirname "$0")/train.py $CONFIG --launcher pytorch ${@:3} 10 | -------------------------------------------------------------------------------- /vit/tools/dist_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CONFIG=$1 4 | CHECKPOINT=$2 5 | GPUS=$3 6 | PORT=${PORT:-29600} 7 | 8 | PYTHONPATH="$(dirname $0)/..":$PYTHONPATH \ 9 | python -m torch.distributed.launch --nproc_per_node=$GPUS --master_port=$PORT \ 10 | $(dirname "$0")/test.py $CONFIG $CHECKPOINT --launcher pytorch ${@:4} 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | insert_final_newline = true 7 | trim_trailing_whitespace = true 8 | end_of_line = lf 9 | charset = utf-8 10 | 11 | [*.py] 12 | max_line_length = 80 13 | ensure_newline_before_comments = true 14 | include_trailing_comma = true 15 | use_parentheses = true 16 | -------------------------------------------------------------------------------- /tools/coco.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script downloads COCO2017 dataset automatically. 4 | 5 | wget https://www.modelscope.cn/datasets/PAI/COCO2017/resolve/master/train2017.zip 6 | wget https://www.modelscope.cn/datasets/PAI/COCO2017/resolve/master/val2017.zip 7 | wget https://www.modelscope.cn/datasets/PAI/COCO2017/resolve/master/annotations_trainval2017.zip 8 | -------------------------------------------------------------------------------- /vit/configs/_base_/schedules/schedule_1x.py: -------------------------------------------------------------------------------- 1 | # optimizer 2 | optimizer = dict(type="SGD", lr=0.02, momentum=0.9, weight_decay=0.0001) 3 | optimizer_config = dict(grad_clip=None) 4 | # learning policy 5 | lr_config = dict( 6 | policy="step", warmup="linear", warmup_iters=500, warmup_ratio=0.001, step=[8, 11] 7 | ) 8 | runner = dict(type="EpochBasedRunner", max_epochs=12) 9 | -------------------------------------------------------------------------------- /vit/configs/_base_/schedules/schedule_20e.py: -------------------------------------------------------------------------------- 1 | # optimizer 2 | optimizer = dict(type="SGD", lr=0.02, momentum=0.9, weight_decay=0.0001) 3 | optimizer_config = dict(grad_clip=None) 4 | # learning policy 5 | lr_config = dict( 6 | policy="step", warmup="linear", warmup_iters=500, warmup_ratio=0.001, step=[16, 19] 7 | ) 8 | runner = dict(type="EpochBasedRunner", max_epochs=20) 9 | -------------------------------------------------------------------------------- /vit/configs/_base_/schedules/schedule_2x.py: -------------------------------------------------------------------------------- 1 | # optimizer 2 | optimizer = dict(type="SGD", lr=0.02, momentum=0.9, weight_decay=0.0001) 3 | optimizer_config = dict(grad_clip=None) 4 | # learning policy 5 | lr_config = dict( 6 | policy="step", warmup="linear", warmup_iters=500, warmup_ratio=0.001, step=[16, 22] 7 | ) 8 | runner = dict(type="EpochBasedRunner", max_epochs=24) 9 | -------------------------------------------------------------------------------- /vit/configs/_base_/schedules/schedule_3x.py: -------------------------------------------------------------------------------- 1 | # optimizer 2 | optimizer = dict(type="SGD", lr=0.02, momentum=0.9, weight_decay=0.0001) 3 | optimizer_config = dict(grad_clip=None) 4 | # learning policy 5 | lr_config = dict( 6 | policy="step", warmup="linear", warmup_iters=500, warmup_ratio=0.001, step=[27, 33] 7 | ) 8 | runner = dict(type="EpochBasedRunner", max_epochs=36) 9 | -------------------------------------------------------------------------------- /vit/configs/_base_/schedules/schedule_6x.py: -------------------------------------------------------------------------------- 1 | # optimizer 2 | optimizer = dict(type="SGD", lr=0.02, momentum=0.9, weight_decay=0.0001) 3 | optimizer_config = dict(grad_clip=None) 4 | # learning policy 5 | lr_config = dict( 6 | policy="step", warmup="linear", warmup_iters=2000, warmup_ratio=0.001, step=[62, 68] 7 | ) 8 | runner = dict(type="EpochBasedRunner", max_epochs=72) 9 | -------------------------------------------------------------------------------- /resnet/train_utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .group_by_aspect_ratio import GroupedBatchSampler, create_aspect_ratio_groups 2 | from .distributed_utils import init_distributed_mode, save_on_master, mkdir 3 | from .coco_eval import EvalCOCOMetric 4 | from .coco_utils import ( 5 | coco_remove_images_without_annotations, 6 | convert_coco_poly_mask, 7 | convert_to_coco_api, 8 | ) 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # python files 2 | .mypy_cache 3 | __pycache__ 4 | 5 | # exploratory programming 6 | explore.ipynb 7 | 8 | # pytorch files 9 | *.pt 10 | 11 | # local 12 | local 13 | 14 | # experiment logs and datasets 15 | *.log 16 | exp 17 | runs 18 | 19 | ckpt 20 | ckpt2 21 | ckpt3 22 | ckpt4 23 | Distill 24 | .vscode 25 | 26 | # download weights/datasets 27 | download 28 | *.ipynb 29 | TODO.md 30 | -------------------------------------------------------------------------------- /resnet/create_dir.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | if __name__ == "__main__": 4 | import argparse 5 | 6 | parser = argparse.ArgumentParser(description=__doc__) 7 | 8 | parser.add_argument( 9 | "--output-dir", default="./multi_train", help="path where to save" 10 | ) 11 | args = parser.parse_args() 12 | if args.output_dir: 13 | os.makedirs(args.output_dir, exist_ok=True) 14 | -------------------------------------------------------------------------------- /vit/configs/mask_rcnn/mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco.py: -------------------------------------------------------------------------------- 1 | _base_ = "./mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco.py" 2 | pretrained = "https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_small_patch4_window7_224.pth" # noqa 3 | model = dict( 4 | backbone=dict( 5 | depths=[2, 2, 18, 2], init_cfg=dict(type="Pretrained", checkpoint=pretrained) 6 | ) 7 | ) 8 | -------------------------------------------------------------------------------- /yolov5/CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | preferred-citation: 3 | type: software 4 | message: If you use YOLOv5, 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 | title: "YOLOv5 by Ultralytics" 10 | version: 7.0 11 | doi: 10.5281/zenodo.3908559 12 | date-released: 2020-5-29 13 | license: AGPL-3.0 14 | url: "https://github.com/ultralytics/yolov5" 15 | -------------------------------------------------------------------------------- /vit/scripts/stage_two/exact_2k/exact2k_t_8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | me=$(basename "$0") 3 | 4 | mkdir -p ./runs/${me} 5 | 6 | work_dir=./runs/${me}/2kreal 7 | 8 | mkdir -p $work_dir 9 | 10 | PYTHONPATH="$(dirname $0)/..":$PYTHONPATH TRAIN_CONFIG=$(dirname $0)/../tools/config/2048_qat.json python -m torch.distributed.launch \ 11 | --nproc_per_node=8 --master_port=63667 \ 12 | $(dirname "$0")/../tools/train_qat.py \ 13 | --work_dir $work_dir \ 14 | --launcher pytorch 15 | -------------------------------------------------------------------------------- /yolov5/utils/flask_rest_api/example_request.py: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | """Perform test request.""" 3 | 4 | import pprint 5 | 6 | import requests 7 | 8 | DETECTION_URL = "http://localhost:5000/v1/object-detection/yolov5s" 9 | IMAGE = "zidane.jpg" 10 | 11 | # Read image 12 | with open(IMAGE, "rb") as f: 13 | image_data = f.read() 14 | 15 | response = requests.post(DETECTION_URL, files={"image": image_data}).json() 16 | 17 | pprint.pprint(response) 18 | -------------------------------------------------------------------------------- /resnet/clear.py: -------------------------------------------------------------------------------- 1 | import os 2 | import glob 3 | 4 | 5 | def delete_seg_txt_files_in_current_directory(): 6 | # 获取当前目录 7 | current_dir = os.getcwd() 8 | 9 | # 查找当前目录中的所有 seg*.txt 文件 10 | seg_txt_files = glob.glob(os.path.join(current_dir, "*.jpg")) 11 | 12 | # 删除找到的 seg*.txt 文件 13 | for file_path in seg_txt_files: 14 | os.remove(file_path) 15 | print(f"Deleted: {file_path}") 16 | 17 | 18 | # 调用函数删除当前目录下的 seg*.txt 文件 19 | delete_seg_txt_files_in_current_directory() 20 | -------------------------------------------------------------------------------- /resnet/pascal_voc_indices.json: -------------------------------------------------------------------------------- 1 | { 2 | "1": "aeroplane", 3 | "2": "bicycle", 4 | "3": "bird", 5 | "4": "boat", 6 | "5": "bottle", 7 | "6": "bus", 8 | "7": "car", 9 | "8": "cat", 10 | "9": "chair", 11 | "10": "cow", 12 | "11": "diningtable", 13 | "12": "dog", 14 | "13": "horse", 15 | "14": "motorbike", 16 | "15": "person", 17 | "16": "pottedplant", 18 | "17": "sheep", 19 | "18": "sofa", 20 | "19": "train", 21 | "20": "tvmonitor" 22 | } -------------------------------------------------------------------------------- /vit/.gitignore: -------------------------------------------------------------------------------- 1 | # Python-generated files 2 | __pycache__/ 3 | *.py[oc] 4 | build/ 5 | dist/ 6 | wheels/ 7 | *.egg-info 8 | 9 | # Virtual environments 10 | .venv 11 | 12 | # exploratory programming 13 | explore.ipynb 14 | *.ipynb 15 | 16 | # pytorch files 17 | *.pt 18 | 19 | # local 20 | local 21 | 22 | # experiment logs and datasets 23 | *.log 24 | exp 25 | runs 26 | ckpt2 27 | Distill 28 | ckpt 29 | .vscode 30 | 31 | # download weights/datasets 32 | download 33 | data 34 | 35 | pretrained 36 | results 37 | -------------------------------------------------------------------------------- /vit/scripts/stage_two/exact_full/exactfull_t_8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | me=$(basename "$0") 3 | mkdir -p ./runs/${me} 4 | 5 | work_dir=./runs/${me}/fullreal 6 | mkdir -p $work_dir 7 | 8 | PYTHONPATH="$(dirname $0)/..":$PYTHONPATH TRAIN_CONFIG=$(dirname $0)/../tools/config/qat_full.json python -m torch.distributed.launch \ 9 | --nproc_per_node=8 --master_port=63667 \ 10 | $(dirname "$0")/../tools/train_qat.py \ 11 | --work_dir $work_dir \ 12 | --launcher pytorch \ 13 | | tee ${work_dir}/train.log -------------------------------------------------------------------------------- /yolo11/scripts/stage_two/exact_2k/l.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | WBITS=(8 4 4) 4 | ABITS=(8 4 8) 5 | 6 | for ((i = 0; i < ${#WBITS[@]}; i++)); do 7 | model="yolo11l.pt" 8 | wbit="${WBITS[$i]}" 9 | abit="${ABITS[$i]}" 10 | echo "running $model exact in W$wbit A$abit" 11 | TRAIN_CONFIG="./external/config/qat.json" python -m external.yolo_main \ 12 | --model "$model" \ 13 | --model_quantize_mode.weight_bits "$wbit" \ 14 | --model_quantize_mode.activation_bits "$abit" 15 | done 16 | -------------------------------------------------------------------------------- /yolo11/scripts/stage_two/exact_2k/m.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | WBITS=(8 4 4) 4 | ABITS=(8 4 8) 5 | 6 | for ((i = 0; i < ${#WBITS[@]}; i++)); do 7 | model="yolo11m.pt" 8 | wbit="${WBITS[$i]}" 9 | abit="${ABITS[$i]}" 10 | echo "running $model exact in W$wbit A$abit" 11 | TRAIN_CONFIG="./external/config/qat.json" python -m external.yolo_main \ 12 | --model "$model" \ 13 | --model_quantize_mode.weight_bits "$wbit" \ 14 | --model_quantize_mode.activation_bits "$abit" 15 | done 16 | -------------------------------------------------------------------------------- /yolo11/scripts/stage_two/exact_2k/s.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | WBITS=(8 4 4) 4 | ABITS=(8 4 8) 5 | 6 | for ((i = 0; i < ${#WBITS[@]}; i++)); do 7 | model="yolo11s.pt" 8 | wbit="${WBITS[$i]}" 9 | abit="${ABITS[$i]}" 10 | echo "running $model exact in W$wbit A$abit" 11 | TRAIN_CONFIG="./external/config/qat.json" python -m external.yolo_main \ 12 | --model "$model" \ 13 | --model_quantize_mode.weight_bits "$wbit" \ 14 | --model_quantize_mode.activation_bits "$abit" 15 | done 16 | -------------------------------------------------------------------------------- /yolo11/scripts/stage_two/exact_full/l.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | WBITS=(8 4 4) 4 | ABITS=(8 4 8) 5 | 6 | for ((i = 0; i < ${#WBITS[@]}; i++)); do 7 | model="yolo11l.pt" 8 | wbit="${WBITS[$i]}" 9 | abit="${ABITS[$i]}" 10 | echo "running $model exact in W$wbit A$abit" 11 | TRAIN_CONFIG="./external/config/qat_full.json" python -m external.yolo_main \ 12 | --model "$model" \ 13 | --model_quantize_mode.weight_bits "$wbit" \ 14 | --model_quantize_mode.activation_bits "$abit" 15 | done 16 | -------------------------------------------------------------------------------- /yolo11/scripts/stage_two/exact_full/m.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | WBITS=(8 4 4) 4 | ABITS=(8 4 8) 5 | 6 | for ((i = 0; i < ${#WBITS[@]}; i++)); do 7 | model="yolo11m.pt" 8 | wbit="${WBITS[$i]}" 9 | abit="${ABITS[$i]}" 10 | echo "running $model exact in W$wbit A$abit" 11 | TRAIN_CONFIG="./external/config/qat_full.json" python -m external.yolo_main \ 12 | --model "$model" \ 13 | --model_quantize_mode.weight_bits "$wbit" \ 14 | --model_quantize_mode.activation_bits "$abit" 15 | done 16 | -------------------------------------------------------------------------------- /yolo11/scripts/stage_two/exact_full/s.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | WBITS=(8 4 4) 4 | ABITS=(8 4 8) 5 | 6 | for ((i = 0; i < ${#WBITS[@]}; i++)); do 7 | model="yolo11s.pt" 8 | wbit="${WBITS[$i]}" 9 | abit="${ABITS[$i]}" 10 | echo "running $model exact in W$wbit A$abit" 11 | TRAIN_CONFIG="./external/config/qat_full.json" python -m external.yolo_main \ 12 | --model "$model" \ 13 | --model_quantize_mode.weight_bits "$wbit" \ 14 | --model_quantize_mode.activation_bits "$abit" 15 | done 16 | -------------------------------------------------------------------------------- /vit/tools/config/generation.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": "./configs/mask_rcnn/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco.py", 3 | "pretrained_weights": "./pretrained/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco_20210908_165006-90a4008c.pth", 4 | "work_dir": "./runs/distill", 5 | "dataset_config": "./configs/mask_rcnn/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco.py", 6 | "workers_per_gpu": 2, 7 | "batch_size": 12, 8 | "calibration_size": 60, 9 | "available_gpus": 1, 10 | "lr": 0.2, 11 | "iterations": 2000 12 | } -------------------------------------------------------------------------------- /vit/configs/_base_/default_runtime.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | checkpoint_config = dict(interval=1) 3 | # yapf:disable 4 | log_config = dict( 5 | interval=50, 6 | hooks=[ 7 | dict(type="TextLoggerHook"), 8 | # dict(type='TensorboardLoggerHook') 9 | ], 10 | ) 11 | # yapf:enable 12 | custom_hooks = [dict(type="NumClassCheckHook")] 13 | # evaluation = dict(save_best='auto') 14 | dist_params = dict(backend="nccl") 15 | log_level = "INFO" 16 | load_from = None 17 | resume_from = None 18 | workflow = [("train", 1)] 19 | -------------------------------------------------------------------------------- /vit/tools/config/qat_full_deit.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": "./configs/mask_rcnn/mask_rcnn_deit_tiny_fpn_3x_coco.py", 3 | "work_dir": "./runs/qat_swin_full", 4 | "pretrained_path": "./pretrained/mask_rcnn_deit_tiny_fpn_3x_coco.pth.tar", 5 | "dataset_path": "./configs/mask_rcnn/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco.py", 6 | "quant_mode": { 7 | "kind": "quantize_sym", 8 | "weight_bits": 8, 9 | "activation_bits": 8 10 | }, 11 | "no_validate": false, 12 | "gpus": 1, 13 | "seed": 0, 14 | "deterministic": true, 15 | "launcher": "none" 16 | } -------------------------------------------------------------------------------- /yolo11/scripts/README.md: -------------------------------------------------------------------------------- 1 | # Scripts 2 | 3 | This folder provides scripts for reproducing our experiment results. 4 | 5 | Stage 1: Calibration set generation 6 | 7 | For adaptive label sampling, please use scripts in `./stage_one/adaptive_label_sampling`. 8 | 9 | For real label, please use scripts in `./stage_one/true_label`. 10 | 11 | Stage 2: Task specific distillation 12 | 13 | For exact 2k images, please use scripts in `./stage_two/exact_2k`. 14 | 15 | For exact full images, please use scripts in `./stage_two/exact_full`. 16 | 17 | For our method, please use scripts in `./stage_two/ours`. 18 | -------------------------------------------------------------------------------- /vit/tools/config/qat_syn.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": "./configs/mask_rcnn/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco.py", 3 | "pretrained_path": "./pretrained/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco_20210908_165006-90a4008c.pth", 4 | "dataset_path": "./configs/datasets/syn.py", 5 | "quant_mode": { 6 | "kind": "quantize_sym", 7 | "weight_bits": 8, 8 | "activation_bits": 8 9 | }, 10 | "no_validate": false, 11 | "gpus": 1, 12 | "seed": 0, 13 | "deterministic": true, 14 | "launcher": "none", 15 | "lr": 1e-6, 16 | "enable_kd": false 17 | } -------------------------------------------------------------------------------- /yolo11/scripts/stage_one/adaptive_label_sampling/sample_label.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | outdir=$(pwd)/data/COCO2017/cocoonebox 4 | 5 | echo "using image in $outdir" 6 | 7 | config_file="$(pwd)/data/cocoonebox.yaml" 8 | escaped_outdir=$(printf '%s\n' "$outdir" | sed 's/[\/&]/\\&/g') 9 | 10 | sed -i "s/PLACEHOLDER/$escaped_outdir/" "$config_file" 11 | 12 | GENERATION_CONFIG=./generation/config/genlabel.json python -m generation.main \ 13 | --teacher_weights yolo11s.pt \ 14 | --relabel_weights yolo11s.pt 15 | 16 | # rollback to the original state. 17 | sed -i "s/$escaped_outdir/PLACEHOLDER" "$config_file" 18 | -------------------------------------------------------------------------------- /yolo11/scripts/stage_two/ours/l.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Please add your generated_weights_path" 4 | 5 | WBITS=(8 4 4) 6 | ABITS=(8 4 8) 7 | 8 | for ((i = 0; i < ${#WBITS[@]}; i++)); do 9 | model="yolo11l.pt" 10 | wbit="${WBITS[$i]}" 11 | abit="${ABITS[$i]}" 12 | echo "running $model ours in W$wbit A$abit" 13 | TRAIN_CONFIG="./external/config/kd.json" python -m external.main \ 14 | --device cuda \ 15 | --model $model \ 16 | --model_quantize_mode.weight_bits "$wbit" \ 17 | --model_quantize_mode.activation_bits "$abit" \ 18 | --generated_weights_path 19 | done 20 | -------------------------------------------------------------------------------- /vit/tools/config/128_qat.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": "./configs/mask_rcnn/swin-t_coco128.py", 3 | "work_dir": "./runs/qat_swin_128", 4 | "pretrained_path": "./pretrained/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco_20210908_165006-90a4008c.pth", 5 | "dataset_path": "./configs/mask_rcnn/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco.py", 6 | "quant_mode": { 7 | "kind": "quantize_sym", 8 | "weight_bits": 8, 9 | "activation_bits": 8 10 | }, 11 | "no_validate": false, 12 | "gpus": 1, 13 | "seed": 0, 14 | "deterministic": true, 15 | "launcher": "none", 16 | "lr": 1e-4 17 | } -------------------------------------------------------------------------------- /yolo11/scripts/stage_two/ours/m.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Please add your generated_weights_path" 4 | 5 | WBITS=(8 4 4) 6 | ABITS=(8 4 8) 7 | 8 | for ((i = 0; i < ${#WBITS[@]}; i++)); do 9 | model="yolo11m.pt" 10 | wbit="${WBITS[$i]}" 11 | abit="${ABITS[$i]}" 12 | echo "running $model ours in W$wbit A$abit" 13 | TRAIN_CONFIG="./external/config/kd.json" python -m external.main \ 14 | --device cuda \ 15 | --model $model \ 16 | --model_quantize_mode.weight_bits "$wbit" \ 17 | --model_quantize_mode.activation_bits "$abit" \ 18 | --generated_weights_path 19 | done 20 | 21 | -------------------------------------------------------------------------------- /yolo11/scripts/stage_two/ours/s.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Please add your generated_weights_path" 4 | 5 | WBITS=(8 4 4) 6 | ABITS=(8 4 8) 7 | 8 | for ((i = 0; i < ${#WBITS[@]}; i++)); do 9 | model="yolo11s.pt" 10 | wbit="${WBITS[$i]}" 11 | abit="${ABITS[$i]}" 12 | echo "running $model ours in W$wbit A$abit" 13 | TRAIN_CONFIG="./external/config/kd.json" python -m external.main \ 14 | --device cuda \ 15 | --model $model \ 16 | --model_quantize_mode.weight_bits "$wbit" \ 17 | --model_quantize_mode.activation_bits "$abit" \ 18 | --generated_weights_path 19 | done 20 | 21 | -------------------------------------------------------------------------------- /vit/quant/quant_mode.py: -------------------------------------------------------------------------------- 1 | from pydantic import BaseModel, Field 2 | 3 | from typing import Annotated, Literal, Union 4 | 5 | 6 | class ExactModel(BaseModel): 7 | kind: Literal["exact"] 8 | 9 | 10 | class SymQuantizeOption(BaseModel): 11 | kind: Literal["quantize_sym"] 12 | weight_bits: int 13 | activation_bits: int 14 | 15 | 16 | class AsymQuantizeOption(BaseModel): 17 | kind: Literal["quantize_asym"] 18 | weight_bits: int 19 | activation_bits: int 20 | 21 | 22 | QuantizeMode = Annotated[ 23 | Union[ExactModel, SymQuantizeOption, AsymQuantizeOption], 24 | Field(discriminator="kind"), 25 | ] 26 | -------------------------------------------------------------------------------- /resnet/pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "resnet" 3 | version = "0.1.0" 4 | description = "Add your description here" 5 | readme = "README.md" 6 | requires-python = "==3.9.23" 7 | dependencies = [ 8 | "lxml>=6.0.0", 9 | "matplotlib>=3.9.4", 10 | "numpy>=2.0.2", 11 | "pillow>=11.3.0", 12 | "pycocotools>=2.0.10", 13 | "torch==1.10.0", 14 | "torchvision==0.11.1", 15 | "tqdm>=4.67.1", 16 | ] 17 | 18 | [[tool.uv.index]] 19 | name = "TUNA" 20 | url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple" 21 | 22 | [[tool.uv.index]] 23 | name = "Tencent" 24 | url = "https://mirrors.cloud.tencent.com/pypi/simple" 25 | -------------------------------------------------------------------------------- /vit/scripts/stage_one/gen_s.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | me=$(basename "$0") 4 | 5 | work_dir="./runs/${me}/swinS" 6 | mkdir -p $work_dir 7 | 8 | GENERATION_CONFIG=./tools/config/generation.json \ 9 | python -m tools.generation \ 10 | --config ./configs/mask_rcnn/mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco.py \ 11 | --dataset_config ./configs/datasets/generation.py \ 12 | --pretrained_weights ./pretrained/mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco_20210903_104808-b92c91f1.pth \ 13 | --work_dir $work_dir \ 14 | --calibration_size 2048 \ 15 | --batch_size 12 \ 16 | | tee ${work_dir}/g_${i}.log 17 | -------------------------------------------------------------------------------- /vit/scripts/stage_one/gen_t.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | me=$(basename "$0") 4 | 5 | work_dir="./runs/${me}/swinT" 6 | mkdir -p $work_dir 7 | 8 | GENERATION_CONFIG=./tools/config/generation.json \ 9 | python -m tools.generation \ 10 | --config ./configs/mask_rcnn/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco.py \ 11 | --dataset_config ./configs/datasets/generation.py \ 12 | --pretrained_weights ./pretrained/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco_20210908_165006-90a4008c.pth \ 13 | --work_dir $work_dir \ 14 | --calibration_size 2048 \ 15 | --batch_size 12 \ 16 | | tee ${work_dir}/g_${i}.log 17 | -------------------------------------------------------------------------------- /vit/scripts/stage_two/ours/ours_t_8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | me=$(basename "$0") 3 | mkdir -p ./runs/${me} 4 | 5 | work_dir=./runs/${me}/2kpseudo_kd 6 | mkdir -p $work_dir 7 | 8 | PYTHONPATH="$(dirname $0)/..":$PYTHONPATH TRAIN_CONFIG=$(dirname $0)/../tools/config/qat_syn.json python -m torch.distributed.launch \ 9 | --nproc_per_node=8 --master_port=63667 \ 10 | $(dirname "$0")/../tools/train_qat.py \ 11 | --work_dir $work_dir \ 12 | --pseudo_data INSERT_DATA_PATH_HERE \ 13 | --enable_kd true \ 14 | --kd_modules block \ 15 | --original_loss_weight 1.0 \ 16 | --kd_loss_weight 1.0 \ 17 | --mse_loss_weight 1.0 \ 18 | --launcher pytorch 19 | -------------------------------------------------------------------------------- /vit/scripts/stage_two/exact_2k/exact2k_s_8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | me=$(basename "$0") 3 | 4 | mkdir -p ./runs/${me} 5 | 6 | work_dir=./runs/${me}/2kreal 7 | 8 | mkdir -p $work_dir 9 | 10 | PYTHONPATH="$(dirname $0)/..":$PYTHONPATH TRAIN_CONFIG=$(dirname $0)/../tools/config/2048_qat.json python -m torch.distributed.launch \ 11 | --nproc_per_node=8 --master_port=63667 \ 12 | $(dirname "$0")/../tools/train_qat.py \ 13 | --work_dir $work_dir \ 14 | --config ./configs/mask_rcnn/mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco.py \ 15 | --pretrained_path ./pretrained/mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco_20210903_104808-b92c91f1.pth \ 16 | --launcher pytorch 17 | -------------------------------------------------------------------------------- /vit/scripts/stage_two/exact_full/exactfull_s_8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | me=$(basename "$0") 3 | mkdir -p ./runs/${me} 4 | 5 | work_dir=./runs/${me}/fullreal 6 | mkdir -p $work_dir 7 | 8 | PYTHONPATH="$(dirname $0)/..":$PYTHONPATH TRAIN_CONFIG=$(dirname $0)/../tools/config/qat_full.json python -m torch.distributed.launch \ 9 | --nproc_per_node=8 --master_port=63667 \ 10 | $(dirname "$0")/../tools/train_qat.py \ 11 | --config ./configs/mask_rcnn/mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco.py \ 12 | --pretrained_path ./pretrained/mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco_20210903_104808-b92c91f1.pth \ 13 | --work_dir $work_dir \ 14 | --launcher pytorch \ 15 | | tee ${work_dir}/train.log 16 | -------------------------------------------------------------------------------- /vit/configs/datasets/generation.py: -------------------------------------------------------------------------------- 1 | _base_ = [ 2 | '../_base_/datasets/coco_instance.py', 3 | ] 4 | 5 | 6 | img_norm_cfg = dict( 7 | mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) 8 | 9 | # augmentation strategy originates from DETR / Sparse RCNN 10 | train_pipeline = [ 11 | dict(type='LoadImageFromFile'), 12 | dict(type='LoadAnnotations', with_bbox=True, with_mask=True), 13 | dict(type="RandomFlip", flip_ratio=0.0), 14 | dict(type='Normalize', **img_norm_cfg), 15 | dict(type='Pad', size_divisor=32), 16 | dict(type='DefaultFormatBundle'), 17 | dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels', 'gt_masks']), 18 | ] 19 | data = dict(train=dict(pipeline=train_pipeline)) 20 | -------------------------------------------------------------------------------- /vit/scripts/stage_one/gen_s_8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | me=$(basename "$0") 3 | 4 | work_dir="./runs/${me}/swinS" 5 | mkdir -p $work_dir 6 | 7 | for ((i = 0; i < 8; i++)); do 8 | GENERATION_CONFIG=./tools/config/generation.json \ 9 | python -m tools.generation \ 10 | --config ./configs/mask_rcnn/mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco.py \ 11 | --dataset_config ./configs/datasets/generation.py \ 12 | --pretrained_weights ./pretrained/mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco_20210903_104808-b92c91f1.pth \ 13 | --work_dir $work_dir \ 14 | --calibration_size 256 \ 15 | --batch_size 12 \ 16 | --devices $i \ 17 | | tee ${work_dir}/g_${i}.log & 18 | done 19 | 20 | wait 21 | -------------------------------------------------------------------------------- /vit/scripts/stage_one/gen_t_8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | me=$(basename "$0") 3 | 4 | work_dir="./runs/${me}/swinT" 5 | mkdir -p $work_dir 6 | 7 | for ((i = 0; i < 8; i++)); do 8 | GENERATION_CONFIG=./tools/config/generation.json \ 9 | python -m tools.generation \ 10 | --config ./configs/mask_rcnn/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco.py \ 11 | --dataset_config ./configs/datasets/generation.py \ 12 | --pretrained_weights ./pretrained/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco_20210908_165006-90a4008c.pth \ 13 | --work_dir $work_dir \ 14 | --calibration_size 256 \ 15 | --batch_size 12 \ 16 | --devices $i \ 17 | | tee ${work_dir}/g_${i}.log & 18 | done 19 | 20 | wait 21 | -------------------------------------------------------------------------------- /yolo11/external/config/qat.json: -------------------------------------------------------------------------------- 1 | { 2 | "device": "cuda", 3 | "dataset_manifest": "coco.yaml", 4 | "batch_size": 16, 5 | "fraction": 0.02, 6 | "generated_weights_path": null, 7 | "calibration_size": 10000, 8 | "model": "yolo11s.pt", 9 | "model_quantize_mode": { 10 | "kind": "quantize_sym", 11 | "weight_bits": 8, 12 | "activation_bits": 8 13 | }, 14 | "kd_method": null, 15 | "hyps": { 16 | "optimizer_name": "Adam", 17 | "lr0": 1e-5, 18 | "lrf": 0.01, 19 | "momentum": 0.937, 20 | "weight_decay": 0.0005, 21 | "box": 7.5, 22 | "cls": 0.5, 23 | "dfl": 1.5 24 | }, 25 | "end_epochs": 100, 26 | "patience": 10 27 | } 28 | -------------------------------------------------------------------------------- /yolo11/external/config/qat_full.json: -------------------------------------------------------------------------------- 1 | { 2 | "device": "cuda", 3 | "dataset_manifest": "coco.yaml", 4 | "batch_size": 16, 5 | "fraction": 1.0, 6 | "generated_weights_path": null, 7 | "calibration_size": 10000, 8 | "model": "yolo11s.pt", 9 | "model_quantize_mode": { 10 | "kind": "quantize_sym", 11 | "weight_bits": 8, 12 | "activation_bits": 8 13 | }, 14 | "kd_method": null, 15 | "hyps": { 16 | "optimizer_name": "Adam", 17 | "lr0": 1e-5, 18 | "lrf": 0.01, 19 | "momentum": 0.937, 20 | "weight_decay": 0.0005, 21 | "box": 7.5, 22 | "cls": 0.5, 23 | "dfl": 1.5 24 | }, 25 | "end_epochs": 100, 26 | "patience": 5 27 | } 28 | -------------------------------------------------------------------------------- /vit/tools/config/2048_qat.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": "./configs/mask_rcnn/swin-t_coco2048.py", 3 | "work_dir": "./runs/qat_swin_2048", 4 | "pretrained_path": "./pretrained/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco_20210908_165006-90a4008c.pth", 5 | "dataset_path": "./configs/datasets/coco_2048.py", 6 | "quant_mode": { 7 | "kind": "quantize_sym", 8 | "weight_bits": 8, 9 | "activation_bits": 8 10 | }, 11 | "no_validate": false, 12 | "gpus": 2, 13 | "seed": 0, 14 | "deterministic": true, 15 | "launcher": "none", 16 | "lr": 1e-6, 17 | "enable_kd": false, 18 | "kd_modules": "block", 19 | "original_loss_weight": 1.0, 20 | "kd_loss_weight": 1.0, 21 | "mse_loss_weight": 1.0 22 | } -------------------------------------------------------------------------------- /vit/tools/config/2048_qatkd.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": "./configs/mask_rcnn/swin-t_coco2048.py", 3 | "work_dir": "./runs/qat_swin_2048", 4 | "pretrained_path": "./pretrained/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco_20210908_165006-90a4008c.pth", 5 | "dataset_path": "./configs/datasets/coco_2048.py", 6 | "quant_mode": { 7 | "kind": "quantize_sym", 8 | "weight_bits": 8, 9 | "activation_bits": 8 10 | }, 11 | "no_validate": false, 12 | "gpus": 2, 13 | "seed": 0, 14 | "deterministic": true, 15 | "launcher": "none", 16 | "lr": 1e-5, 17 | "enable_kd": true, 18 | "kd_modules": "block", 19 | "original_loss_weight": 1.0, 20 | "kd_loss_weight": 1.0, 21 | "mse_loss_weight": 1.0 22 | } -------------------------------------------------------------------------------- /yolo11/external/config/gimg.json: -------------------------------------------------------------------------------- 1 | { 2 | "device": "cuda", 3 | "dataset_manifest": "coco.yaml", 4 | "batch_size": 16, 5 | "fraction": 0.1, 6 | "generated_weights_path": "./runs/exp/weights", 7 | "calibration_size": 10000, 8 | "model": "yolo11s.pt", 9 | "model_quantize_mode": { 10 | "kind": "quantize_sym", 11 | "weight_bits": 8, 12 | "activation_bits": 8 13 | }, 14 | "kd_method": null, 15 | "hyps": { 16 | "optimizer_name": "Adam", 17 | "lr0": 1e-5, 18 | "lrf": 0.01, 19 | "momentum": 0.937, 20 | "weight_decay": 0.0005, 21 | "box": 7.5, 22 | "cls": 0.5, 23 | "dfl": 1.5 24 | }, 25 | "end_epochs": 100, 26 | "patience": 50 27 | } 28 | -------------------------------------------------------------------------------- /vit/tools/kd/mse.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | import torch 3 | 4 | 5 | class MSE(nn.Module): 6 | def __init__(self): 7 | super(MSE, self).__init__() 8 | 9 | def forward(self, preds_S, preds_T): 10 | """ 11 | mse between predT & predS 12 | only works when Stu & Tea are same architecture 13 | """ 14 | assert len(preds_S) == len(preds_T) 15 | dLoss = [] 16 | for branchS, branchT in zip(preds_S, preds_T): 17 | branchT = branchT.detach() 18 | dLoss.append(torch.mean((branchS - branchT) ** 2)) 19 | 20 | dLoss = sum(dLoss) / len(dLoss) 21 | dLoss_items = torch.tensor((0.0, 0.0, 0.0, dLoss.item())).to(dLoss.device) 22 | return dLoss, dLoss_items.detach() 23 | -------------------------------------------------------------------------------- /yolo11/external/config/ptq.json: -------------------------------------------------------------------------------- 1 | { 2 | "device": "cuda", 3 | "dataset_manifest": "coco.yaml", 4 | "batch_size": 32, 5 | "fraction": 1.0, 6 | "generated_weights_path": null, 7 | "calibration_size": 10000, 8 | "model": "yolo11s.pt", 9 | "model_quantize_mode": { 10 | "kind": "quantize_sym", 11 | "weight_bits": 6, 12 | "activation_bits": 6 13 | }, 14 | "ptq": true, 15 | "kd_method": null, 16 | "hyps": { 17 | "optimizer_name": "SGD", 18 | "lr0": 0.01, 19 | "lrf": 0.01, 20 | "momentum": 0.937, 21 | "weight_decay": 0.0005, 22 | "box": 7.5, 23 | "cls": 0.5, 24 | "dfl": 1.5 25 | }, 26 | "end_epochs": 100, 27 | "patience": 5 28 | } 29 | -------------------------------------------------------------------------------- /yolo11/quant/mse.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | import torch 3 | 4 | 5 | class MSE(nn.Module): 6 | """ 7 | MSE between student and teacher networks. 8 | 9 | Precondition: student and teacher networks are required to be the SAME ARCHITECTURE!! 10 | """ 11 | 12 | def __init__(self): 13 | super(MSE, self).__init__() 14 | 15 | def forward(self, preds_S, preds_T): 16 | assert len(preds_S) == len(preds_T) 17 | dLoss = [] 18 | for branchS, branchT in zip(preds_S, preds_T): 19 | dLoss.append(torch.mean((branchS - branchT) ** 2)) 20 | 21 | dLoss = sum(dLoss) / len(dLoss) 22 | dLoss_items = torch.tensor((0.0, 0.0, 0.0, dLoss.item())).to(dLoss.device) 23 | return dLoss, dLoss_items.detach() 24 | -------------------------------------------------------------------------------- /yolov5/utils/mse.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | import torch.nn.functional as F 3 | import torch 4 | 5 | 6 | class MSE(nn.Module): 7 | def __init__( 8 | self, 9 | ): 10 | super(MSE, self).__init__() 11 | 12 | def forward(self, preds_S, preds_T): 13 | """ 14 | mse between predT & predS 15 | only works when Stu & Tea are same architecture 16 | """ 17 | assert len(preds_S) == len(preds_T) 18 | dLoss = [] 19 | for branchS, branchT in zip(preds_S, preds_T): 20 | dLoss.append(torch.mean((branchS - branchT) ** 2)) 21 | dLoss = sum(dLoss) / len(dLoss) 22 | dLoss_items = torch.tensor((0.0, 0.0, 0.0, dLoss.item())).to(dLoss.device) 23 | return dLoss, dLoss_items.detach() 24 | -------------------------------------------------------------------------------- /vit/tools/config/qat_full.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": "./configs/mask_rcnn/swin-t_coco2048.py", 3 | "work_dir": "./runs/qat_swint_full", 4 | "pretrained_path": "./pretrained/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco_20210908_165006-90a4008c.pth", 5 | "dataset_path": "./configs/mask_rcnn/mask_rcnn_swin-t-p4-w7_fpn_ms-crop-3x_coco.py", 6 | "quant_mode": { 7 | "kind": "quantize_sym", 8 | "weight_bits": 8, 9 | "activation_bits": 8 10 | }, 11 | "no_validate": false, 12 | "gpus": 2, 13 | "seed": 0, 14 | "deterministic": true, 15 | "launcher": "none", 16 | "lr": 1e-6, 17 | "enable_kd": false, 18 | "kd_modules": "block", 19 | "original_loss_weight": 1.0, 20 | "kd_loss_weight": 1.0, 21 | "mse_loss_weight": 1.0 22 | } 23 | -------------------------------------------------------------------------------- /yolov5/data/hyps/hyp.Objects365.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | # Hyperparameters for Objects365 training 3 | # python train.py --weights yolov5m.pt --data Objects365.yaml --evolve 4 | # See Hyperparameter Evolution tutorial for details https://github.com/ultralytics/yolov5#tutorials 5 | 6 | lr0: 0.00258 7 | lrf: 0.17 8 | momentum: 0.779 9 | weight_decay: 0.00058 10 | warmup_epochs: 1.33 11 | warmup_momentum: 0.86 12 | warmup_bias_lr: 0.0711 13 | box: 0.0539 14 | cls: 0.299 15 | cls_pw: 0.825 16 | obj: 0.632 17 | obj_pw: 1.0 18 | iou_t: 0.2 19 | anchor_t: 3.44 20 | anchors: 3.2 21 | fl_gamma: 0.0 22 | hsv_h: 0.0188 23 | hsv_s: 0.704 24 | hsv_v: 0.36 25 | degrees: 0.0 26 | translate: 0.0902 27 | scale: 0.491 28 | shear: 0.0 29 | perspective: 0.0 30 | flipud: 0.0 31 | fliplr: 0.5 32 | mosaic: 1.0 33 | mixup: 0.0 34 | copy_paste: 0.0 35 | -------------------------------------------------------------------------------- /vit/tools/visualize.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torchvision 3 | 4 | 5 | def denormalize(img): 6 | invTrans = torchvision.transforms.Compose( 7 | [ 8 | torchvision.transforms.Normalize( 9 | mean=[0.0, 0.0, 0.0], std=[1 / 0.229, 1 / 0.224, 1 / 0.225] 10 | ), 11 | torchvision.transforms.Normalize( 12 | mean=[-0.485, -0.456, -0.406], std=[1.0, 1.0, 1.0] 13 | ), 14 | ] 15 | ) 16 | 17 | inv_tensor = invTrans(img) 18 | return torchvision.transforms.ToPILImage()(inv_tensor) 19 | 20 | 21 | def showone(ckpt_path, normalize): 22 | ckpt = torch.load(ckpt_path) 23 | img = ckpt["img"].data[0] 24 | print(ckpt["img_metas"].data[0][0]) 25 | if normalize: 26 | return denormalize(img) 27 | return torchvision.transforms.ToPILImage()(img) 28 | -------------------------------------------------------------------------------- /vit/scripts/stage_two/ours/ours_s_8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | me=$(basename "$0") 3 | mkdir -p ./runs/${me} 4 | 5 | work_dir=./runs/${me}/2kpseudo_kd 6 | mkdir -p $work_dir 7 | 8 | PYTHONPATH="$(dirname $0)/..":$PYTHONPATH TRAIN_CONFIG=$(dirname $0)/../tools/config/qat_syn.json python -m torch.distributed.launch \ 9 | --nproc_per_node=8 --master_port=63667 \ 10 | $(dirname "$0")/../tools/train_qat.py \ 11 | --work_dir $work_dir \ 12 | --pseudo_data INSERT_DATA_PATH_HERE \ 13 | --enable_kd true \ 14 | --kd_modules block \ 15 | --config ./configs/mask_rcnn/mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco.py \ 16 | --pretrained_path ./pretrained/mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco_20210903_104808-b92c91f1.pth \ 17 | --original_loss_weight 1.0 \ 18 | --kd_loss_weight 1.0 \ 19 | --mse_loss_weight 1.0 \ 20 | --launcher pytorch 21 | -------------------------------------------------------------------------------- /resnet/.gitignore: -------------------------------------------------------------------------------- 1 | ##ignore this file## 2 | *.idea 3 | __pycache__ 4 | *.zip 5 | flower_data 6 | *.h5 7 | *.pth 8 | *.pt 9 | *.jpg 10 | *.ckpt.* 11 | *.ckpt 12 | *.config 13 | *.gz 14 | *.onnx 15 | *.xml 16 | *.bin 17 | *.mapping 18 | *.csv 19 | checkpoint 20 | data 21 | VOCdevkit 22 | ssd_resnet50_v1_fpn_shared_box_predictor 23 | 24 | seg_results.json 25 | det_results.json 26 | det_record_mAP.txt 27 | seg_record_mAP.txt 28 | det_results*.txt 29 | seg_results*.txt 30 | 31 | *.sh 32 | !/pytorch_object_detection/mask_rcnn/scripts/*.sh 33 | *.png 34 | pytorch_object_detection/mask_rcnn/multi_train/ 35 | pytorch_object_detection/mask_rcnn/Distill/ 36 | pytorch_object_detection/mask_rcnn/test* 37 | pytorch_object_detection/mask_rcnn/Debug/ 38 | pytorch_object_detection/mask_rcnn/DebugNew/ 39 | pytorch_object_detection/mask_rcnn/PseudoQAT/ 40 | pytorch_object_detection/mask_rcnn/RealQAT/ 41 | debug* 42 | tmp* -------------------------------------------------------------------------------- /yolo11/pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "zescond" 3 | version = "0.1.0" 4 | description = "Zescond is the project of ZEro-shot Quantization Object Detection" 5 | readme = "README.md" 6 | requires-python = ">=3.12" 7 | dependencies = [ 8 | "pydantic-settings>=2.7.0", 9 | "pydantic>=2.10.4", 10 | "torch>=2.5.1", 11 | "torchvision>=0.20.1", 12 | "ultralytics==8.3.53", 13 | "tensorboard>=2.18.0", 14 | "types-pyyaml>=6.0.12.20241230", 15 | "pyyaml>=6.0.2", 16 | "pycocotools>=2.0.8", 17 | ] 18 | 19 | [[tool.uv.index]] 20 | name = "Tencent" 21 | url = "https://mirrors.cloud.tencent.com/pypi/simple" 22 | 23 | [[tool.uv.index]] 24 | name = "TUNA" 25 | url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple" 26 | 27 | [tool.mypy] 28 | plugins = ['pydantic.mypy'] 29 | ignore_missing_imports = true 30 | 31 | [dependency-groups] 32 | dev = [ 33 | "ipykernel>=6.29.5", 34 | ] 35 | -------------------------------------------------------------------------------- /resnet/network_files/image_list.py: -------------------------------------------------------------------------------- 1 | from typing import List, Tuple 2 | from torch import Tensor 3 | 4 | 5 | class ImageList(object): 6 | """ 7 | Structure that holds a list of images (of possibly 8 | varying sizes) as a single tensor. 9 | This works by padding the images to the same size, 10 | and storing in a field the original sizes of each image 11 | """ 12 | 13 | def __init__(self, tensors, image_sizes): 14 | # type: (Tensor, List[Tuple[int, int]]) -> None 15 | """ 16 | Arguments: 17 | tensors (tensor) padding后的图像数据 18 | image_sizes (list[tuple[int, int]]) padding前的图像尺寸 19 | """ 20 | self.tensors = tensors 21 | self.image_sizes = image_sizes 22 | 23 | def to(self, device): 24 | # type: (Device) -> ImageList # noqa 25 | cast_tensor = self.tensors.to(device) 26 | return ImageList(cast_tensor, self.image_sizes) 27 | -------------------------------------------------------------------------------- /yolov5/utils/google_app_engine/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gcr.io/google-appengine/python 2 | 3 | # Create a virtualenv for dependencies. This isolates these packages from 4 | # system-level packages. 5 | # Use -p python3 or -p python3.7 to select python version. Default is version 2. 6 | RUN virtualenv /env -p python3 7 | 8 | # Setting these environment variables are the same as running 9 | # source /env/bin/activate. 10 | ENV VIRTUAL_ENV /env 11 | ENV PATH /env/bin:$PATH 12 | 13 | RUN apt-get update && apt-get install -y python-opencv 14 | 15 | # Copy the application's requirements.txt and run pip to install all 16 | # dependencies into the virtualenv. 17 | ADD requirements.txt /app/requirements.txt 18 | RUN pip install -r /app/requirements.txt 19 | 20 | # Add the application source code. 21 | ADD . /app 22 | 23 | # Run a WSGI server to serve the application. gunicorn must be declared as 24 | # a dependency in requirements.txt. 25 | CMD gunicorn -b :$PORT main:app 26 | -------------------------------------------------------------------------------- /yolo11/generation/config/true_label.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": "runs/Distill", 3 | "name": "exp", 4 | "device": "cuda", 5 | "teacher_weights": "yolo11s.pt", 6 | "relabel_weights": "yolo11s.pt", 7 | "dataset_configs": { 8 | "kind": "real", 9 | "data": "coco.yaml", 10 | "batch_size": 32, 11 | "workers": 8 12 | }, 13 | "img_size": 640, 14 | "calibration_size": 2048, 15 | "iterations": 3000, 16 | "hyp": { 17 | "lr": 0.2, 18 | "r_feature": 0.001, 19 | "tv_l1": 0, 20 | "tv_l2": 0.00005, 21 | "main_loss_multiplier": 0.001, 22 | "first_bn_coef": 1.0 23 | }, 24 | "box_sampler_config": { 25 | "box_sampler": false, 26 | "box_sampler_warmup": 0, 27 | "box_sampler_conf": 0.5, 28 | "box_sampler_overlap_iou": 0.2, 29 | "box_sampler_minarea": 0.0, 30 | "box_sampler_maxarea": 1.0, 31 | "box_sampler_earlyexit": 1000000 32 | }, 33 | "save_every": 100, 34 | "save_images": false, 35 | "skip_generated": false 36 | } 37 | -------------------------------------------------------------------------------- /vit/scripts/README.md: -------------------------------------------------------------------------------- 1 | # Scripts 2 | 3 | This folder contains scripts to reproduce our experimental results. 4 | 5 | --- 6 | 7 | ## Stage 1: Calibration Set Generation 8 | 9 | Run the calibration generation scripts from the `./stage_one` directory: 10 | 11 | - Use `s.sh`, `m.sh`, and `l.sh` for different model sizes. 12 | - For faster ViT processing (which can be time-consuming), use the 8-GPU versions: `s_8.sh`, `m_8.sh`, and `l_8.sh`. 13 | 14 | After generation, you may need to use `rescale_image.py` to convert the images. 15 | 16 | --- 17 | 18 | ## Stage 2: Task-Specific Distillation 19 | 20 | Choose the appropriate folder under `./stage_two` based on your dataset: 21 | 22 | - `exact_2k`: Scripts for distillation using exactly 2,000 images. 23 | - `exact_full`: Scripts for distillation using the full dataset. 24 | - `ours`: Scripts for our proposed method. 25 | 26 | Remember to fill in your generated image path. 27 | 28 | > **Note**: All scripts in Stage 2 are configured for 8-GPU training. 29 | -------------------------------------------------------------------------------- /yolo11/generation/main.py: -------------------------------------------------------------------------------- 1 | # This file is the entrance of calibration set generation step. 2 | # 3 | # It parses commandline arguments, then starts generation. 4 | # 5 | 6 | from generation.config import get_config, GenerationConfig 7 | from generation.distill_trainer import build_distill_trainer # type: ignore 8 | from pathlib import Path 9 | 10 | from ultralytics.utils.files import increment_path # type: ignore 11 | 12 | 13 | def save_config(work_dir: Path, config: GenerationConfig): 14 | config_path = work_dir / "config.json" 15 | with config_path.open("w") as f: 16 | f.write(config.model_dump_json(indent=2)) 17 | 18 | 19 | if __name__ == "__main__": 20 | config = get_config() 21 | save_dir = increment_path( 22 | Path(config.project) / config.name, exist_ok=False, mkdir=True 23 | ) 24 | save_config(save_dir, config) # for reproduction of experiment results. 25 | distill_trainer = build_distill_trainer(save_dir, config) 26 | distill_trainer.train_all() 27 | -------------------------------------------------------------------------------- /vit/pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "zescond-vit" 3 | version = "0.1.0" 4 | description = "Add your description here" 5 | readme = "README.md" 6 | requires-python = ">=3.9" 7 | dependencies = [ 8 | "mmcv-full==1.4.2", 9 | "mmdet==2.22.0", 10 | "pydantic-settings>=2.7.1", 11 | "pydantic>=2.10.6", 12 | "requests>=2.28.1", 13 | "scipy>=1.13.1", 14 | "setuptools==69.5.1", 15 | "timm==0.4.12", 16 | "torch==1.9.0+cu111", 17 | "torchaudio==0.9.0", 18 | "torchvision==0.10.0+cu111", 19 | "tqdm>=4.67.1", 20 | ] 21 | 22 | [[tool.uv.index]] 23 | name = "pytorch-cu111" 24 | url = "https://download.pytorch.org/whl/cu111" 25 | 26 | [[tool.uv.index]] 27 | name = "Tencent" 28 | url = "https://mirrors.cloud.tencent.com/pypi/simple" 29 | 30 | [[tool.uv.index]] 31 | name = "TUNA" 32 | url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple" 33 | 34 | [tool.mypy] 35 | plugins = ['pydantic.mypy'] 36 | ignore_missing_imports = true 37 | 38 | [dependency-groups] 39 | dev = [ 40 | "ipykernel>=6.29.5", 41 | ] 42 | -------------------------------------------------------------------------------- /resnet/train_utils/mse.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | import torch.nn.functional as F 3 | import torch 4 | 5 | 6 | class MSE(nn.Module): 7 | def __init__( 8 | self, 9 | ): 10 | super(MSE, self).__init__() 11 | 12 | def forward(self, preds_S, preds_T, debug_S=None, debug_T=None): 13 | """ 14 | mse between predT & predS 15 | only works when Stu & Tea are same architecture 16 | """ 17 | assert len(preds_S) == len(preds_T) 18 | dLoss = [] 19 | for idx, (branchS, branchT) in enumerate(zip(preds_S, preds_T)): 20 | if branchS.shape != branchT.shape: 21 | # print('student:', debug_S[idx]) 22 | # print('teacher:', debug_T[idx]) 23 | # print() 24 | continue 25 | dLoss.append(torch.mean((branchS - branchT) ** 2)) 26 | dLoss = sum(dLoss) / len(dLoss) 27 | dLoss_items = torch.tensor((0.0, 0.0, 0.0, dLoss.item())).to(dLoss.device) 28 | return dLoss, dLoss_items.detach() 29 | -------------------------------------------------------------------------------- /vit/tools/generate_gauss.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from pydantic_settings import ( 3 | BaseSettings, 4 | CliApp, 5 | ) 6 | from pydantic import Field, ValidationError 7 | 8 | from pathlib import Path 9 | import logging 10 | 11 | 12 | class GenOptions(BaseSettings, cli_parse_args=True, cli_prog_name="Generation"): 13 | 14 | work_dir: str = Field(description="places of synthesized data") 15 | 16 | img_size: int = Field(description="generate how many images") 17 | 18 | 19 | def get_config() -> GenOptions: 20 | try: 21 | config = CliApp.run(GenOptions) 22 | except ValidationError as e: 23 | logging.fatal(e) 24 | exit(-1) 25 | return config 26 | 27 | 28 | def main(opt: GenOptions): 29 | work_dir = Path(opt.work_dir) 30 | work_dir.mkdir(parents=True, exist_ok=True) 31 | for i in range(0, opt.img_size, 16): 32 | t = torch.rand(16, 3, 640, 640) 33 | torch.save(t, work_dir / f"batch_{i}.pt") 34 | 35 | 36 | if __name__ == "__main__": 37 | opt = get_config() 38 | main(opt) 39 | -------------------------------------------------------------------------------- /yolov5/data/ImageNet10.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | # ImageNet-1k dataset https://www.image-net.org/index.php by Stanford University 3 | # Simplified class names from https://github.com/anishathalye/imagenet-simple-labels 4 | # Example usage: python classify/train.py --data imagenet 5 | # parent 6 | # ├── yolov5 7 | # └── datasets 8 | # └── imagenet10 ← downloads here 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 | path: ../datasets/imagenet10 # dataset root dir 12 | train: train # train images (relative to 'path') 1281167 images 13 | val: val # val images (relative to 'path') 50000 images 14 | test: # test images (optional) 15 | 16 | # Classes 17 | names: 18 | 0: tench 19 | 1: goldfish 20 | 2: great white shark 21 | 3: tiger shark 22 | 4: hammerhead shark 23 | 5: electric ray 24 | 6: stingray 25 | 7: cock 26 | 8: hen 27 | 9: ostrich 28 | 29 | # Download script/URL (optional) 30 | download: data/scripts/get_imagenet10.sh 31 | -------------------------------------------------------------------------------- /yolo11/external/config/kd.json: -------------------------------------------------------------------------------- 1 | { 2 | "device": "cuda", 3 | "dataset_manifest": "coco.yaml", 4 | "batch_size": 16, 5 | "fraction": 0.1, 6 | "generated_weights_path": "./runs/even_setting/weights", 7 | "calibration_size": 10000, 8 | "model": "yolo11s.pt", 9 | "model_quantize_mode": { 10 | "kind": "quantize_sym", 11 | "weight_bits": 8, 12 | "activation_bits": 8 13 | }, 14 | "kd_method": { 15 | "teacher_weight": "yolo11s.pt", 16 | "kd_module": "cnnbn", 17 | "original_loss_weight": 0.01, 18 | "kd_loss": { 19 | "kind": "kl", 20 | "tau": 4.0 21 | }, 22 | "kd_loss_weight": 0.1, 23 | "mse_loss_weight": 1.0 24 | }, 25 | "hyps": { 26 | "optimizer_name": "Adam", 27 | "lr0": 1e-5, 28 | "lrf": 0.01, 29 | "momentum": 0.937, 30 | "weight_decay": 0.0005, 31 | "box": 7.5, 32 | "cls": 0.5, 33 | "dfl": 1.5 34 | }, 35 | "end_epochs": 100, 36 | "patience": 10 37 | } 38 | -------------------------------------------------------------------------------- /yolo11/generation/config/genlabel.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": "runs/DistillOneBox", 3 | "name": "exp", 4 | "device": "cuda", 5 | "teacher_weights": "yolo11s.pt", 6 | "relabel_weights": "yolo11s.pt", 7 | "dataset_configs": { 8 | "kind": "real", 9 | "data": "data/cocoonebox.yaml", 10 | "batch_size": 512, 11 | "workers": 8 12 | }, 13 | "img_size": 160, 14 | "calibration_size": 2048, 15 | "da_configs": { 16 | "do_jitter": false, 17 | "do_flip": false, 18 | "rand_brightness": false, 19 | "rand_contrast": false, 20 | "random_erase": false 21 | }, 22 | "iterations": 3000, 23 | "hyp": { 24 | "lr": 0.2, 25 | "r_feature": 0.05, 26 | "tv_l1": 0, 27 | "tv_l2": 0.002, 28 | "main_loss_multiplier": 0.5, 29 | "first_bn_coef": 5.0 30 | }, 31 | "box_sampler_config": { 32 | "box_sampler": true, 33 | "box_sampler_warmup": 800, 34 | "box_sampler_conf": 0.2, 35 | "box_sampler_overlap_iou": 0.35, 36 | "box_sampler_minarea": 0.01, 37 | "box_sampler_maxarea": 0.85, 38 | "box_sampler_earlyexit": 2800 39 | }, 40 | "save_every": 100, 41 | "save_images": false, 42 | "skip_generated": false 43 | } 44 | -------------------------------------------------------------------------------- /yolo11/generation/config/relabel-syn.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": "runs/DistillSyn", 3 | "name": "exp", 4 | "device": "cuda", 5 | "teacher_weights": "yolo11s.pt", 6 | "relabel_weights": "yolo11s.pt", 7 | "dataset_configs": { 8 | "kind": "sampled", 9 | "sampling_weight_path": "./runs/DistillOneBox/exp/weights", 10 | "batch_size": 32 11 | }, 12 | "img_size": 640, 13 | "calibration_size": 2048, 14 | "da_configs": { 15 | "do_jitter": false, 16 | "do_flip": false, 17 | "rand_brightness": false, 18 | "rand_contrast": false, 19 | "random_erase": false 20 | }, 21 | "iterations": 3000, 22 | "hyp": { 23 | "lr": 0.2, 24 | "r_feature": 0.05, 25 | "tv_l1": 0.0, 26 | "tv_l2": 0.002, 27 | "main_loss_multiplier": 0.5, 28 | "first_bn_coef": 5.0 29 | }, 30 | "box_sampler_config": { 31 | "box_sampler": false, 32 | "box_sampler_warmup": 0, 33 | "box_sampler_conf": 0.5, 34 | "box_sampler_overlap_iou": 0.2, 35 | "box_sampler_minarea": 0.0, 36 | "box_sampler_maxarea": 1.0, 37 | "box_sampler_earlyexit": 1000000 38 | }, 39 | "save_every": 100, 40 | "save_images": false, 41 | "skip_generated": false 42 | } 43 | -------------------------------------------------------------------------------- /vit/mmdet_custom/datasets/coco_fraction.py: -------------------------------------------------------------------------------- 1 | from mmdet.datasets.builder import DATASETS 2 | from mmdet.datasets.coco import CocoDataset 3 | 4 | 5 | @DATASETS.register_module() 6 | class CocoFraction(CocoDataset): 7 | def __init__( 8 | self, 9 | ann_file, 10 | pipeline, 11 | dataset_size=None, 12 | classes=None, 13 | data_root=None, 14 | img_prefix="", 15 | seg_prefix=None, 16 | proposal_file=None, 17 | test_mode=False, 18 | filter_empty_gt=True, 19 | file_client_args=dict(backend="disk"), 20 | ): 21 | super().__init__( 22 | ann_file, 23 | pipeline, 24 | classes, 25 | data_root, 26 | img_prefix, 27 | seg_prefix, 28 | proposal_file, 29 | test_mode, 30 | filter_empty_gt, 31 | file_client_args, 32 | ) 33 | if dataset_size: 34 | self.dataset_size = dataset_size 35 | print(f"truncating dataset from {len(self.data_infos)} to {dataset_size}") 36 | self.data_infos = self.data_infos[: self.dataset_size] 37 | self.flag = self.flag[: self.dataset_size] 38 | -------------------------------------------------------------------------------- /vit/configs/mask_rcnn/retinanet_swin-t-p4-w7_fpn_1x_coco.py: -------------------------------------------------------------------------------- 1 | _base_ = [ 2 | "../_base_/models/retinanet_r50_fpn.py", 3 | "../_base_/datasets/coco_detection.py", 4 | "../_base_/schedules/schedule_1x.py", 5 | "../_base_/default_runtime.py", 6 | ] 7 | pretrained = "https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_tiny_patch4_window7_224.pth" # noqa 8 | model = dict( 9 | backbone=dict( 10 | _delete_=True, 11 | type="SwinTransformer", 12 | embed_dims=96, 13 | depths=[2, 2, 6, 2], 14 | num_heads=[3, 6, 12, 24], 15 | window_size=7, 16 | mlp_ratio=4, 17 | qkv_bias=True, 18 | qk_scale=None, 19 | drop_rate=0.0, 20 | attn_drop_rate=0.0, 21 | drop_path_rate=0.2, 22 | patch_norm=True, 23 | out_indices=(1, 2, 3), 24 | # Please only add indices that would be used 25 | # in FPN, otherwise some parameter will not be used 26 | with_cp=False, 27 | convert_weights=True, 28 | init_cfg=dict(type="Pretrained", checkpoint=pretrained), 29 | ), 30 | neck=dict(in_channels=[192, 384, 768], start_level=0, num_outs=5), 31 | ) 32 | 33 | optimizer = dict(type="SGD", lr=0.01, momentum=0.9, weight_decay=0.0001) 34 | -------------------------------------------------------------------------------- /resnet/transforms.py: -------------------------------------------------------------------------------- 1 | import random 2 | from torchvision.transforms import functional as F 3 | 4 | 5 | class Compose(object): 6 | """组合多个transform函数""" 7 | 8 | def __init__(self, transforms): 9 | self.transforms = transforms 10 | 11 | def __call__(self, image, target): 12 | for t in self.transforms: 13 | image, target = t(image, target) 14 | return image, target 15 | 16 | 17 | class ToTensor(object): 18 | """将PIL图像转为Tensor""" 19 | 20 | def __call__(self, image, target): 21 | image = F.to_tensor(image) 22 | return image, target 23 | 24 | 25 | class RandomHorizontalFlip(object): 26 | """随机水平翻转图像以及bboxes""" 27 | 28 | def __init__(self, prob=0.5): 29 | self.prob = prob 30 | 31 | def __call__(self, image, target): 32 | if random.random() < self.prob: 33 | height, width = image.shape[-2:] 34 | image = image.flip(-1) # 水平翻转图片 35 | bbox = target["boxes"] 36 | # bbox: xmin, ymin, xmax, ymax 37 | bbox[:, [0, 2]] = width - bbox[:, [2, 0]] # 翻转对应bbox坐标信息 38 | target["boxes"] = bbox 39 | if "masks" in target: 40 | target["masks"] = target["masks"].flip(-1) 41 | return image, target 42 | -------------------------------------------------------------------------------- /yolov5/data/hyps/hyp.VOC.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | # Hyperparameters for VOC training 3 | # python train.py --batch 128 --weights yolov5m6.pt --data VOC.yaml --epochs 50 --img 512 --hyp hyp.scratch-med.yaml --evolve 4 | # See Hyperparameter Evolution tutorial for details https://github.com/ultralytics/yolov5#tutorials 5 | 6 | # YOLOv5 Hyperparameter Evolution Results 7 | # Best generation: 467 8 | # Last generation: 996 9 | # metrics/precision, metrics/recall, metrics/mAP_0.5, metrics/mAP_0.5:0.95, val/box_loss, val/obj_loss, val/cls_loss 10 | # 0.87729, 0.85125, 0.91286, 0.72664, 0.0076739, 0.0042529, 0.0013865 11 | 12 | lr0: 0.00334 13 | lrf: 0.15135 14 | momentum: 0.74832 15 | weight_decay: 0.00025 16 | warmup_epochs: 3.3835 17 | warmup_momentum: 0.59462 18 | warmup_bias_lr: 0.18657 19 | box: 0.02 20 | cls: 0.21638 21 | cls_pw: 0.5 22 | obj: 0.51728 23 | obj_pw: 0.67198 24 | iou_t: 0.2 25 | anchor_t: 3.3744 26 | fl_gamma: 0.0 27 | hsv_h: 0.01041 28 | hsv_s: 0.54703 29 | hsv_v: 0.27739 30 | degrees: 0.0 31 | translate: 0.04591 32 | scale: 0.75544 33 | shear: 0.0 34 | perspective: 0.0 35 | flipud: 0.0 36 | fliplr: 0.5 37 | mosaic: 0.85834 38 | mixup: 0.04266 39 | copy_paste: 0.0 40 | anchors: 3.412 41 | -------------------------------------------------------------------------------- /yolov5/utils/aws/resume.py: -------------------------------------------------------------------------------- 1 | # Resume all interrupted trainings in yolov5/ dir including DDP trainings 2 | # Usage: $ python utils/aws/resume.py 3 | 4 | import os 5 | import sys 6 | from pathlib import Path 7 | 8 | import torch 9 | import yaml 10 | 11 | FILE = Path(__file__).resolve() 12 | ROOT = FILE.parents[2] # YOLOv5 root directory 13 | if str(ROOT) not in sys.path: 14 | sys.path.append(str(ROOT)) # add ROOT to PATH 15 | 16 | port = 0 # --master_port 17 | path = Path("").resolve() 18 | for last in path.rglob("*/**/last.pt"): 19 | ckpt = torch.load(last) 20 | if ckpt["optimizer"] is None: 21 | continue 22 | 23 | # Load opt.yaml 24 | with open(last.parent.parent / "opt.yaml", errors="ignore") as f: 25 | opt = yaml.safe_load(f) 26 | 27 | # Get device count 28 | d = opt["device"].split(",") # devices 29 | nd = len(d) # number of devices 30 | ddp = nd > 1 or ( 31 | nd == 0 and torch.cuda.device_count() > 1 32 | ) # distributed data parallel 33 | 34 | if ddp: # multi-GPU 35 | port += 1 36 | cmd = f"python -m torch.distributed.run --nproc_per_node {nd} --master_port {port} train.py --resume {last}" 37 | else: # single-GPU 38 | cmd = f"python train.py --resume {last}" 39 | 40 | cmd += " > /dev/null 2>&1 &" # redirect output to dev/null and run in daemon thread 41 | print(cmd) 42 | os.system(cmd) 43 | -------------------------------------------------------------------------------- /vit/configs/datasets/syn.py: -------------------------------------------------------------------------------- 1 | dataset_type = "CocoDataset" 2 | data_root = "data/coco/" 3 | img_norm_cfg = dict( 4 | mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True 5 | ) 6 | train_pipeline = [] # type: ignore 7 | test_pipeline = [ 8 | dict(type="LoadImageFromFile"), 9 | dict( 10 | type="MultiScaleFlipAug", 11 | img_scale=(1333, 800), 12 | flip=False, 13 | transforms=[ 14 | dict(type="Resize", keep_ratio=True), 15 | dict(type="RandomFlip"), 16 | dict(type="Normalize", **img_norm_cfg), 17 | dict(type="Pad", size_divisor=32), 18 | dict(type="ImageToTensor", keys=["img"]), 19 | dict(type="Collect", keys=["img"]), 20 | ], 21 | ), 22 | ] 23 | data = dict( 24 | samples_per_gpu=2, 25 | workers_per_gpu=0, 26 | train=dict( 27 | type="SynDataset", 28 | syn_dir="", 29 | ), 30 | val=dict( 31 | type=dataset_type, 32 | ann_file=data_root + "annotations/instances_val2017.json", 33 | img_prefix=data_root + "val2017/", 34 | pipeline=test_pipeline, 35 | ), 36 | test=dict( 37 | type=dataset_type, 38 | ann_file=data_root + "annotations/instances_val2017.json", 39 | img_prefix=data_root + "val2017/", 40 | pipeline=test_pipeline, 41 | ), 42 | ) 43 | evaluation = dict(metric=["bbox"]) 44 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5-fpn.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 FPN head 29 | head: [ 30 | [-1, 3, C3, [1024, False]], # 10 (P5/32-large) 31 | 32 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 33 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 34 | [-1, 1, Conv, [512, 1, 1]], 35 | [-1, 3, C3, [512, False]], # 14 (P4/16-medium) 36 | 37 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 38 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 39 | [-1, 1, Conv, [256, 1, 1]], 40 | [-1, 3, C3, [256, False]], # 18 (P3/8-small) 41 | 42 | [[18, 14, 10], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 43 | ] 44 | -------------------------------------------------------------------------------- /yolo11/external/gimg_loader.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch.utils.data import distributed 3 | 4 | from ultralytics.utils import RANK 5 | from ultralytics.data.build import InfiniteDataLoader, seed_worker 6 | from ultralytics.data.dataset import YOLODataset 7 | 8 | from pathlib import Path 9 | from external.data import get_generated_dataset 10 | 11 | 12 | def build_dataloader(dataset, batch_size, shuffle=True, rank=-1): 13 | """Return an InfiniteDataLoader or DataLoader for training or validation set.""" 14 | sampler = ( 15 | None if rank == -1 else distributed.DistributedSampler(dataset, shuffle=shuffle) 16 | ) 17 | generator = torch.Generator() 18 | generator.manual_seed(6148914691236517205 + RANK) 19 | return InfiniteDataLoader( 20 | dataset=dataset, 21 | batch_size=batch_size, 22 | shuffle=shuffle and sampler is None, 23 | num_workers=0, # TODO: check this 24 | sampler=sampler, 25 | pin_memory=True, 26 | collate_fn=YOLODataset.collate_fn, 27 | worker_init_fn=seed_worker, 28 | generator=generator, 29 | ) 30 | 31 | 32 | def build_dataloader_from_gimg( 33 | pseudo_data_path: Path, 34 | calibration_size: int, 35 | batch_size: int, 36 | shuffle: bool, 37 | rank: int, 38 | ): 39 | dataset = get_generated_dataset(pseudo_data_path, calibration_size) 40 | return build_dataloader(dataset, batch_size, shuffle, rank) 41 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5-p34.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 3 # AutoAnchor evolves 3 anchors per P output layer 8 | 9 | # YOLOv5 v6.0 backbone 10 | backbone: 11 | # [from, number, module, args] 12 | [ 13 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 14 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 15 | [-1, 3, C3, [128]], 16 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 17 | [-1, 6, C3, [256]], 18 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 19 | [-1, 9, C3, [512]], 20 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 21 | [-1, 3, C3, [1024]], 22 | [-1, 1, SPPF, [1024, 5]], # 9 23 | ] 24 | 25 | # YOLOv5 v6.0 head with (P3, P4) outputs 26 | head: [ 27 | [-1, 1, Conv, [512, 1, 1]], 28 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 29 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 30 | [-1, 3, C3, [512, False]], # 13 31 | 32 | [-1, 1, Conv, [256, 1, 1]], 33 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 34 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 35 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 36 | 37 | [-1, 1, Conv, [256, 3, 2]], 38 | [[-1, 14], 1, Concat, [1]], # cat head P4 39 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 40 | 41 | [[17, 20], 1, Detect, [nc, anchors]], # Detect(P3, P4) 42 | ] 43 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov3-tiny.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 14, 23, 27, 37, 58] # P4/16 9 | - [81, 82, 135, 169, 344, 319] # P5/32 10 | 11 | # YOLOv3-tiny backbone 12 | backbone: 13 | # [from, number, module, args] 14 | [ 15 | [-1, 1, Conv, [16, 3, 1]], # 0 16 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 1-P1/2 17 | [-1, 1, Conv, [32, 3, 1]], 18 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 3-P2/4 19 | [-1, 1, Conv, [64, 3, 1]], 20 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 5-P3/8 21 | [-1, 1, Conv, [128, 3, 1]], 22 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 7-P4/16 23 | [-1, 1, Conv, [256, 3, 1]], 24 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 9-P5/32 25 | [-1, 1, Conv, [512, 3, 1]], 26 | [-1, 1, nn.ZeroPad2d, [[0, 1, 0, 1]]], # 11 27 | [-1, 1, nn.MaxPool2d, [2, 1, 0]], # 12 28 | ] 29 | 30 | # YOLOv3-tiny head 31 | head: [ 32 | [-1, 1, Conv, [1024, 3, 1]], 33 | [-1, 1, Conv, [256, 1, 1]], 34 | [-1, 1, Conv, [512, 3, 1]], # 15 (P5/32-large) 35 | 36 | [-2, 1, Conv, [128, 1, 1]], 37 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 38 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 39 | [-1, 1, Conv, [256, 3, 1]], # 19 (P4/16-medium) 40 | 41 | [[19, 15], 1, Detect, [nc, anchors]], # Detect(P4, P5) 42 | ] 43 | -------------------------------------------------------------------------------- /yolo11/tools/visualize.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module provides utilities for display images in Jupyter notebooks. 3 | """ 4 | 5 | import torch 6 | import torchvision 7 | 8 | 9 | def denormalize(img): 10 | """Convert ImageNet scale to regular scale 11 | 12 | Parameters 13 | ---------- 14 | img : Tensor 15 | 16 | Returns 17 | ------- 18 | Tensor 19 | """ 20 | invTrans = torchvision.transforms.Compose( 21 | [ 22 | torchvision.transforms.Normalize( 23 | mean=[0.0, 0.0, 0.0], std=[1 / 0.229, 1 / 0.224, 1 / 0.225] 24 | ), 25 | torchvision.transforms.Normalize( 26 | mean=[-0.485, -0.456, -0.406], std=[1.0, 1.0, 1.0] 27 | ), 28 | ] 29 | ) 30 | 31 | inv_tensor = invTrans(img) 32 | return torchvision.transforms.ToPILImage()(inv_tensor) 33 | 34 | 35 | def showone(ckpt_path, normalize): 36 | """Display the second picture in the batch of `ckpt_path`. 37 | 38 | Parameters 39 | ---------- 40 | ckpt_path : str 41 | normalize : bool 42 | True -> the original ckpt is ImageNet scaled. 43 | False -> the original ckpt is [0, 1] scaled. 44 | 45 | NOTE: For YOLO models, normalize should always be False because it is [0, 1] scaled. 46 | 47 | Returns 48 | ------- 49 | A PILImage 50 | """ 51 | 52 | ckpt = torch.load(ckpt_path, map_location="cpu") 53 | img = ckpt[1] 54 | if normalize: 55 | return denormalize(img) 56 | return torchvision.transforms.ToPILImage()(img) 57 | -------------------------------------------------------------------------------- /vit/configs/mask_rcnn/mask_rcnn_swin-t-p4-w7_fpn_1x_coco.py: -------------------------------------------------------------------------------- 1 | _base_ = [ 2 | "../_base_/models/mask_rcnn_r50_fpn.py", 3 | "../_base_/datasets/coco_instance.py", 4 | "../_base_/schedules/schedule_1x.py", 5 | "../_base_/default_runtime.py", 6 | ] 7 | pretrained = "https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_tiny_patch4_window7_224.pth" # noqa 8 | model = dict( 9 | type="MaskRCNN", 10 | backbone=dict( 11 | _delete_=True, 12 | type="SwinTransformer", 13 | embed_dims=96, 14 | depths=[2, 2, 6, 2], 15 | num_heads=[3, 6, 12, 24], 16 | window_size=7, 17 | mlp_ratio=4, 18 | qkv_bias=True, 19 | qk_scale=None, 20 | drop_rate=0.0, 21 | attn_drop_rate=0.0, 22 | drop_path_rate=0.2, 23 | patch_norm=True, 24 | out_indices=(0, 1, 2, 3), 25 | with_cp=False, 26 | convert_weights=True, 27 | init_cfg=dict(type="Pretrained", checkpoint=pretrained), 28 | ), 29 | neck=dict(in_channels=[96, 192, 384, 768]), 30 | ) 31 | 32 | optimizer = dict( 33 | _delete_=True, 34 | type="AdamW", 35 | lr=0.0001, 36 | betas=(0.9, 0.999), 37 | weight_decay=0.05, 38 | paramwise_cfg=dict( 39 | custom_keys={ 40 | "absolute_pos_embed": dict(decay_mult=0.0), 41 | "relative_position_bias_table": dict(decay_mult=0.0), 42 | "norm": dict(decay_mult=0.0), 43 | } 44 | ), 45 | ) 46 | lr_config = dict(warmup_iters=1000, step=[8, 11]) 47 | runner = dict(max_epochs=12) 48 | -------------------------------------------------------------------------------- /yolov5/models/yolov5l.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/yolov5m.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # model depth multiple 6 | width_multiple: 0.75 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/yolov5n.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.25 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/yolov5s.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/yolov5x.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.33 # model depth multiple 6 | width_multiple: 1.25 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5-panet.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 PANet head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/segment/yolov5l-seg.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/segment/yolov5m-seg.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # model depth multiple 6 | width_multiple: 0.75 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/segment/yolov5n-seg.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.25 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/segment/yolov5s-seg.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.5 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/segment/yolov5x-seg.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.33 # model depth multiple 6 | width_multiple: 1.25 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5-bifpn.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 BiFPN head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14, 6], 1, Concat, [1]], # cat P4 <--- BiFPN change 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5s-transformer.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3TR, [1024]], # 9 <--- C3TR() Transformer module 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5s-ghost.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, GhostConv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3Ghost, [128]], 19 | [-1, 1, GhostConv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3Ghost, [256]], 21 | [-1, 1, GhostConv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3Ghost, [512]], 23 | [-1, 1, GhostConv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3Ghost, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, GhostConv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3Ghost, [512, False]], # 13 34 | 35 | [-1, 1, GhostConv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3Ghost, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, GhostConv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3Ghost, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, GhostConv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3Ghost, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/4bitLSQ_yolov5s.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 8, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 4, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 4, C3, [128]], 19 | [-1, 1, 4, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 4, C3, [256]], 21 | [-1, 1, 4, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 4, C3, [512]], 23 | [-1, 1, 4, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 4, C3, [1024]], 25 | [-1, 1, 4, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 4, Conv, [512, 1, 1]], 31 | [-1, 1, 4, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 4, Concat, [1]], # cat backbone P4 33 | [-1, 3, 4, C3, [512, False]], # 13 34 | 35 | [-1, 1, 4, Conv, [256, 1, 1]], 36 | [-1, 1, 4, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 4, Concat, [1]], # cat backbone P3 38 | [-1, 3, 4, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 4, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 4, Concat, [1]], # cat head P4 42 | [-1, 3, 4, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 4, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 4, Concat, [1]], # cat head P5 46 | [-1, 3, 4, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 8, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/4bitlsq_yolov5l.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 4, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 4, C3, [128]], 19 | [-1, 1, 4, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 4, C3, [256]], 21 | [-1, 1, 4, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 4, C3, [512]], 23 | [-1, 1, 4, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 4, C3, [1024]], 25 | [-1, 1, 4, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 4, Conv, [512, 1, 1]], 31 | [-1, 1, 4, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 4, Concat, [1]], # cat backbone P4 33 | [-1, 3, 4, C3, [512, False]], # 13 34 | 35 | [-1, 1, 4, Conv, [256, 1, 1]], 36 | [-1, 1, 4, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 4, Concat, [1]], # cat backbone P3 38 | [-1, 3, 4, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 4, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 4, Concat, [1]], # cat head P4 42 | [-1, 3, 4, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 4, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 4, Concat, [1]], # cat head P5 46 | [-1, 3, 4, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/4bitlsq_yolov5m.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # model depth multiple 6 | width_multiple: 0.75 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 4, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 4, C3, [128]], 19 | [-1, 1, 4, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 4, C3, [256]], 21 | [-1, 1, 4, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 4, C3, [512]], 23 | [-1, 1, 4, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 4, C3, [1024]], 25 | [-1, 1, 4, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 4, Conv, [512, 1, 1]], 31 | [-1, 1, 4, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 4, Concat, [1]], # cat backbone P4 33 | [-1, 3, 4, C3, [512, False]], # 13 34 | 35 | [-1, 1, 4, Conv, [256, 1, 1]], 36 | [-1, 1, 4, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 4, Concat, [1]], # cat backbone P3 38 | [-1, 3, 4, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 4, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 4, Concat, [1]], # cat head P4 42 | [-1, 3, 4, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 4, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 4, Concat, [1]], # cat head P5 46 | [-1, 3, 4, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/4bitlsq_yolov5n.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.25 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 4, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 4, C3, [128]], 19 | [-1, 1, 4, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 4, C3, [256]], 21 | [-1, 1, 4, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 4, C3, [512]], 23 | [-1, 1, 4, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 4, C3, [1024]], 25 | [-1, 1, 4, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 4, Conv, [512, 1, 1]], 31 | [-1, 1, 4, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 4, Concat, [1]], # cat backbone P4 33 | [-1, 3, 4, C3, [512, False]], # 13 34 | 35 | [-1, 1, 4, Conv, [256, 1, 1]], 36 | [-1, 1, 4, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 4, Concat, [1]], # cat backbone P3 38 | [-1, 3, 4, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 4, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 4, Concat, [1]], # cat head P4 42 | [-1, 3, 4, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 4, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 4, Concat, [1]], # cat head P5 46 | [-1, 3, 4, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/4bitlsq_yolov5s.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 4, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 4, C3, [128]], 19 | [-1, 1, 4, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 4, C3, [256]], 21 | [-1, 1, 4, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 4, C3, [512]], 23 | [-1, 1, 4, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 4, C3, [1024]], 25 | [-1, 1, 4, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 4, Conv, [512, 1, 1]], 31 | [-1, 1, 4, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 4, Concat, [1]], # cat backbone P4 33 | [-1, 3, 4, C3, [512, False]], # 13 34 | 35 | [-1, 1, 4, Conv, [256, 1, 1]], 36 | [-1, 1, 4, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 4, Concat, [1]], # cat backbone P3 38 | [-1, 3, 4, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 4, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 4, Concat, [1]], # cat head P4 42 | [-1, 3, 4, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 4, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 4, Concat, [1]], # cat head P5 46 | [-1, 3, 4, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/5bitlsq_yolov5l.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 5, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 5, C3, [128]], 19 | [-1, 1, 5, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 5, C3, [256]], 21 | [-1, 1, 5, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 5, C3, [512]], 23 | [-1, 1, 5, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 5, C3, [1024]], 25 | [-1, 1, 5, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 5, Conv, [512, 1, 1]], 31 | [-1, 1, 5, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 5, Concat, [1]], # cat backbone P4 33 | [-1, 3, 5, C3, [512, False]], # 13 34 | 35 | [-1, 1, 5, Conv, [256, 1, 1]], 36 | [-1, 1, 5, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 5, Concat, [1]], # cat backbone P3 38 | [-1, 3, 5, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 5, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 5, Concat, [1]], # cat head P4 42 | [-1, 3, 5, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 5, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 5, Concat, [1]], # cat head P5 46 | [-1, 3, 5, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/5bitlsq_yolov5m.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # model depth multiple 6 | width_multiple: 0.75 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 5, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 5, C3, [128]], 19 | [-1, 1, 5, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 5, C3, [256]], 21 | [-1, 1, 5, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 5, C3, [512]], 23 | [-1, 1, 5, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 5, C3, [1024]], 25 | [-1, 1, 5, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 5, Conv, [512, 1, 1]], 31 | [-1, 1, 5, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 5, Concat, [1]], # cat backbone P4 33 | [-1, 3, 5, C3, [512, False]], # 13 34 | 35 | [-1, 1, 5, Conv, [256, 1, 1]], 36 | [-1, 1, 5, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 5, Concat, [1]], # cat backbone P3 38 | [-1, 3, 5, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 5, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 5, Concat, [1]], # cat head P4 42 | [-1, 3, 5, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 5, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 5, Concat, [1]], # cat head P5 46 | [-1, 3, 5, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/5bitlsq_yolov5n.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.25 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 5, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 5, C3, [128]], 19 | [-1, 1, 5, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 5, C3, [256]], 21 | [-1, 1, 5, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 5, C3, [512]], 23 | [-1, 1, 5, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 5, C3, [1024]], 25 | [-1, 1, 5, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 5, Conv, [512, 1, 1]], 31 | [-1, 1, 5, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 5, Concat, [1]], # cat backbone P4 33 | [-1, 3, 5, C3, [512, False]], # 13 34 | 35 | [-1, 1, 5, Conv, [256, 1, 1]], 36 | [-1, 1, 5, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 5, Concat, [1]], # cat backbone P3 38 | [-1, 3, 5, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 5, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 5, Concat, [1]], # cat head P4 42 | [-1, 3, 5, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 5, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 5, Concat, [1]], # cat head P5 46 | [-1, 3, 5, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/5bitlsq_yolov5s.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 5, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 5, C3, [128]], 19 | [-1, 1, 5, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 5, C3, [256]], 21 | [-1, 1, 5, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 5, C3, [512]], 23 | [-1, 1, 5, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 5, C3, [1024]], 25 | [-1, 1, 5, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 5, Conv, [512, 1, 1]], 31 | [-1, 1, 5, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 5, Concat, [1]], # cat backbone P4 33 | [-1, 3, 5, C3, [512, False]], # 13 34 | 35 | [-1, 1, 5, Conv, [256, 1, 1]], 36 | [-1, 1, 5, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 5, Concat, [1]], # cat backbone P3 38 | [-1, 3, 5, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 5, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 5, Concat, [1]], # cat head P4 42 | [-1, 3, 5, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 5, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 5, Concat, [1]], # cat head P5 46 | [-1, 3, 5, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/6bitlsq_yolov5l.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 6, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 6, C3, [128]], 19 | [-1, 1, 6, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 6, C3, [256]], 21 | [-1, 1, 6, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 6, C3, [512]], 23 | [-1, 1, 6, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 6, C3, [1024]], 25 | [-1, 1, 6, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 6, Conv, [512, 1, 1]], 31 | [-1, 1, 6, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 6, Concat, [1]], # cat backbone P4 33 | [-1, 3, 6, C3, [512, False]], # 13 34 | 35 | [-1, 1, 6, Conv, [256, 1, 1]], 36 | [-1, 1, 6, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 6, Concat, [1]], # cat backbone P3 38 | [-1, 3, 6, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 6, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 6, Concat, [1]], # cat head P4 42 | [-1, 3, 6, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 6, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 6, Concat, [1]], # cat head P5 46 | [-1, 3, 6, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/6bitlsq_yolov5m.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # model depth multiple 6 | width_multiple: 0.75 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 6, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 6, C3, [128]], 19 | [-1, 1, 6, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 6, C3, [256]], 21 | [-1, 1, 6, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 6, C3, [512]], 23 | [-1, 1, 6, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 6, C3, [1024]], 25 | [-1, 1, 6, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 6, Conv, [512, 1, 1]], 31 | [-1, 1, 6, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 6, Concat, [1]], # cat backbone P4 33 | [-1, 3, 6, C3, [512, False]], # 13 34 | 35 | [-1, 1, 6, Conv, [256, 1, 1]], 36 | [-1, 1, 6, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 6, Concat, [1]], # cat backbone P3 38 | [-1, 3, 6, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 6, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 6, Concat, [1]], # cat head P4 42 | [-1, 3, 6, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 6, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 6, Concat, [1]], # cat head P5 46 | [-1, 3, 6, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/6bitlsq_yolov5n.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.25 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 6, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 6, C3, [128]], 19 | [-1, 1, 6, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 6, C3, [256]], 21 | [-1, 1, 6, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 6, C3, [512]], 23 | [-1, 1, 6, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 6, C3, [1024]], 25 | [-1, 1, 6, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 6, Conv, [512, 1, 1]], 31 | [-1, 1, 6, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 6, Concat, [1]], # cat backbone P4 33 | [-1, 3, 6, C3, [512, False]], # 13 34 | 35 | [-1, 1, 6, Conv, [256, 1, 1]], 36 | [-1, 1, 6, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 6, Concat, [1]], # cat backbone P3 38 | [-1, 3, 6, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 6, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 6, Concat, [1]], # cat head P4 42 | [-1, 3, 6, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 6, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 6, Concat, [1]], # cat head P5 46 | [-1, 3, 6, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/6bitlsq_yolov5s.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 6, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 6, C3, [128]], 19 | [-1, 1, 6, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 6, C3, [256]], 21 | [-1, 1, 6, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 6, C3, [512]], 23 | [-1, 1, 6, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 6, C3, [1024]], 25 | [-1, 1, 6, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 6, Conv, [512, 1, 1]], 31 | [-1, 1, 6, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 6, Concat, [1]], # cat backbone P4 33 | [-1, 3, 6, C3, [512, False]], # 13 34 | 35 | [-1, 1, 6, Conv, [256, 1, 1]], 36 | [-1, 1, 6, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 6, Concat, [1]], # cat backbone P3 38 | [-1, 3, 6, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 6, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 6, Concat, [1]], # cat head P4 42 | [-1, 3, 6, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 6, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 6, Concat, [1]], # cat head P5 46 | [-1, 3, 6, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/7bitlsq_yolov5l.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 7, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 7, C3, [128]], 19 | [-1, 1, 7, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 7, C3, [256]], 21 | [-1, 1, 7, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 7, C3, [512]], 23 | [-1, 1, 7, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 7, C3, [1024]], 25 | [-1, 1, 7, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 7, Conv, [512, 1, 1]], 31 | [-1, 1, 7, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 7, Concat, [1]], # cat backbone P4 33 | [-1, 3, 7, C3, [512, False]], # 13 34 | 35 | [-1, 1, 7, Conv, [256, 1, 1]], 36 | [-1, 1, 7, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 7, Concat, [1]], # cat backbone P3 38 | [-1, 3, 7, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 7, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 7, Concat, [1]], # cat head P4 42 | [-1, 3, 7, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 7, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 7, Concat, [1]], # cat head P5 46 | [-1, 3, 7, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/7bitlsq_yolov5m.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # model depth multiple 6 | width_multiple: 0.75 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 7, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 7, C3, [128]], 19 | [-1, 1, 7, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 7, C3, [256]], 21 | [-1, 1, 7, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 7, C3, [512]], 23 | [-1, 1, 7, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 7, C3, [1024]], 25 | [-1, 1, 7, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 7, Conv, [512, 1, 1]], 31 | [-1, 1, 7, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 7, Concat, [1]], # cat backbone P4 33 | [-1, 3, 7, C3, [512, False]], # 13 34 | 35 | [-1, 1, 7, Conv, [256, 1, 1]], 36 | [-1, 1, 7, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 7, Concat, [1]], # cat backbone P3 38 | [-1, 3, 7, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 7, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 7, Concat, [1]], # cat head P4 42 | [-1, 3, 7, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 7, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 7, Concat, [1]], # cat head P5 46 | [-1, 3, 7, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/7bitlsq_yolov5n.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.25 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 7, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 7, C3, [128]], 19 | [-1, 1, 7, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 7, C3, [256]], 21 | [-1, 1, 7, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 7, C3, [512]], 23 | [-1, 1, 7, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 7, C3, [1024]], 25 | [-1, 1, 7, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 7, Conv, [512, 1, 1]], 31 | [-1, 1, 7, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 7, Concat, [1]], # cat backbone P4 33 | [-1, 3, 7, C3, [512, False]], # 13 34 | 35 | [-1, 1, 7, Conv, [256, 1, 1]], 36 | [-1, 1, 7, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 7, Concat, [1]], # cat backbone P3 38 | [-1, 3, 7, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 7, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 7, Concat, [1]], # cat head P4 42 | [-1, 3, 7, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 7, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 7, Concat, [1]], # cat head P5 46 | [-1, 3, 7, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/7bitlsq_yolov5s.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 7, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 7, C3, [128]], 19 | [-1, 1, 7, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 7, C3, [256]], 21 | [-1, 1, 7, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 7, C3, [512]], 23 | [-1, 1, 7, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 7, C3, [1024]], 25 | [-1, 1, 7, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 7, Conv, [512, 1, 1]], 31 | [-1, 1, 7, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 7, Concat, [1]], # cat backbone P4 33 | [-1, 3, 7, C3, [512, False]], # 13 34 | 35 | [-1, 1, 7, Conv, [256, 1, 1]], 36 | [-1, 1, 7, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 7, Concat, [1]], # cat backbone P3 38 | [-1, 3, 7, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 7, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 7, Concat, [1]], # cat head P4 42 | [-1, 3, 7, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 7, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 7, Concat, [1]], # cat head P5 46 | [-1, 3, 7, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/8bitlsq_yolov5l.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 8, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 8, C3, [128]], 19 | [-1, 1, 8, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 8, C3, [256]], 21 | [-1, 1, 8, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 8, C3, [512]], 23 | [-1, 1, 8, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 8, C3, [1024]], 25 | [-1, 1, 8, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 8, Conv, [512, 1, 1]], 31 | [-1, 1, 8, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 8, Concat, [1]], # cat backbone P4 33 | [-1, 3, 8, C3, [512, False]], # 13 34 | 35 | [-1, 1, 8, Conv, [256, 1, 1]], 36 | [-1, 1, 8, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 8, Concat, [1]], # cat backbone P3 38 | [-1, 3, 8, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 8, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 8, Concat, [1]], # cat head P4 42 | [-1, 3, 8, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 8, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 8, Concat, [1]], # cat head P5 46 | [-1, 3, 8, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/8bitlsq_yolov5m.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # model depth multiple 6 | width_multiple: 0.75 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 8, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 8, C3, [128]], 19 | [-1, 1, 8, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 8, C3, [256]], 21 | [-1, 1, 8, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 8, C3, [512]], 23 | [-1, 1, 8, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 8, C3, [1024]], 25 | [-1, 1, 8, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 8, Conv, [512, 1, 1]], 31 | [-1, 1, 8, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 8, Concat, [1]], # cat backbone P4 33 | [-1, 3, 8, C3, [512, False]], # 13 34 | 35 | [-1, 1, 8, Conv, [256, 1, 1]], 36 | [-1, 1, 8, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 8, Concat, [1]], # cat backbone P3 38 | [-1, 3, 8, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 8, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 8, Concat, [1]], # cat head P4 42 | [-1, 3, 8, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 8, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 8, Concat, [1]], # cat head P5 46 | [-1, 3, 8, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/8bitlsq_yolov5n.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.25 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 8, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 8, C3, [128]], 19 | [-1, 1, 8, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 8, C3, [256]], 21 | [-1, 1, 8, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 8, C3, [512]], 23 | [-1, 1, 8, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 8, C3, [1024]], 25 | [-1, 1, 8, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 8, Conv, [512, 1, 1]], 31 | [-1, 1, 8, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 8, Concat, [1]], # cat backbone P4 33 | [-1, 3, 8, C3, [512, False]], # 13 34 | 35 | [-1, 1, 8, Conv, [256, 1, 1]], 36 | [-1, 1, 8, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 8, Concat, [1]], # cat backbone P3 38 | [-1, 3, 8, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 8, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 8, Concat, [1]], # cat head P4 42 | [-1, 3, 8, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 8, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 8, Concat, [1]], # cat head P5 46 | [-1, 3, 8, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/8bitlsq_yolov5s.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, num_bits, module, args] 15 | [ 16 | [-1, 1, 32, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, 8, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, 8, C3, [128]], 19 | [-1, 1, 8, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, 8, C3, [256]], 21 | [-1, 1, 8, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, 8, C3, [512]], 23 | [-1, 1, 8, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, 8, C3, [1024]], 25 | [-1, 1, 8, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, 8, Conv, [512, 1, 1]], 31 | [-1, 1, 8, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, 8, Concat, [1]], # cat backbone P4 33 | [-1, 3, 8, C3, [512, False]], # 13 34 | 35 | [-1, 1, 8, Conv, [256, 1, 1]], 36 | [-1, 1, 8, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, 8, Concat, [1]], # cat backbone P3 38 | [-1, 3, 8, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, 8, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, 8, Concat, [1]], # cat head P4 42 | [-1, 3, 8, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, 8, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, 8, Concat, [1]], # cat head P5 46 | [-1, 3, 8, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, 32, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5s-LeakyReLU.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | activation: nn.LeakyReLU(0.1) # <----- Conv() activation used throughout entire YOLOv5 model 6 | depth_multiple: 0.33 # model depth multiple 7 | width_multiple: 0.50 # layer channel multiple 8 | anchors: 9 | - [10, 13, 16, 30, 33, 23] # P3/8 10 | - [30, 61, 62, 45, 59, 119] # P4/16 11 | - [116, 90, 156, 198, 373, 326] # P5/32 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [ 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, anchors]], # Detect(P3, P4, P5) 50 | ] 51 | -------------------------------------------------------------------------------- /yolov5/utils/docker/Dockerfile-arm64: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | # Builds ultralytics/yolov5:latest-arm64 image on DockerHub https://hub.docker.com/r/ultralytics/yolov5 3 | # Image is aarch64-compatible for Apple M1 and other ARM architectures i.e. Jetson Nano and Raspberry Pi 4 | 5 | # Start FROM Ubuntu image https://hub.docker.com/_/ubuntu 6 | FROM arm64v8/ubuntu:22.10 7 | 8 | # Downloads to user config dir 9 | ADD https://ultralytics.com/assets/Arial.ttf https://ultralytics.com/assets/Arial.Unicode.ttf /root/.config/Ultralytics/ 10 | 11 | # Install linux packages 12 | ENV DEBIAN_FRONTEND noninteractive 13 | RUN apt update 14 | RUN TZ=Etc/UTC apt install -y tzdata 15 | RUN apt install --no-install-recommends -y python3-pip git zip curl htop gcc libgl1 libglib2.0-0 libpython3-dev 16 | # RUN alias python=python3 17 | 18 | # Install pip packages 19 | COPY requirements.txt . 20 | RUN python3 -m pip install --upgrade pip wheel 21 | RUN pip install --no-cache -r requirements.txt albumentations gsutil notebook \ 22 | coremltools onnx onnxruntime 23 | # tensorflow-aarch64 tensorflowjs \ 24 | 25 | # Create working directory 26 | RUN mkdir -p /usr/src/app 27 | WORKDIR /usr/src/app 28 | 29 | # Copy contents 30 | COPY . /usr/src/app 31 | ENV DEBIAN_FRONTEND teletype 32 | 33 | 34 | # Usage Examples ------------------------------------------------------------------------------------------------------- 35 | 36 | # Build and Push 37 | # t=ultralytics/yolov5:latest-arm64 && sudo docker build --platform linux/arm64 -f utils/docker/Dockerfile-arm64 -t $t . && sudo docker push $t 38 | 39 | # Pull and Run 40 | # t=ultralytics/yolov5:latest-arm64 && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/datasets:/usr/src/datasets $t 41 | -------------------------------------------------------------------------------- /yolov5/utils/dist_kd.py: -------------------------------------------------------------------------------- 1 | """copy from https://github.com/hunto/image_classification_sota/blob/d9662f7df68fe46b973c4580b7c9b896cedcd301/lib/models/losses/dist_kd.py""" 2 | 3 | import torch.nn as nn 4 | import torch 5 | 6 | 7 | def cosine_similarity(a, b, eps=1e-8): 8 | return (a * b).sum(1) / (a.norm(dim=1) * b.norm(dim=1) + eps) 9 | 10 | 11 | def pearson_correlation(a, b, eps=1e-8): 12 | return cosine_similarity( 13 | a - a.mean(1).unsqueeze(1), b - b.mean(1).unsqueeze(1), eps 14 | ) 15 | 16 | 17 | def inter_class_relation(y_s, y_t): 18 | return 1 - pearson_correlation(y_s, y_t).mean() 19 | 20 | 21 | def intra_class_relation(y_s, y_t): 22 | return inter_class_relation(y_s.transpose(0, 1), y_t.transpose(0, 1)) 23 | 24 | 25 | class DIST(nn.Module): 26 | def __init__(self, beta=1.0, gamma=1.0, tau=1.0): 27 | super(DIST, self).__init__() 28 | self.beta = beta 29 | self.gamma = gamma 30 | self.tau = tau 31 | 32 | def forward(self, preds_S, preds_T): 33 | assert len(preds_S) == len(preds_T) 34 | dLoss = [] 35 | dLoss_items = [] 36 | for branchS, branchT in zip(preds_S, preds_T): 37 | y_s = (branchS / self.tau).softmax(dim=1) 38 | y_t = (branchT / self.tau).softmax(dim=1) 39 | inter_loss = self.tau**2 * inter_class_relation(y_s, y_t) 40 | intra_loss = self.tau**2 * intra_class_relation(y_s, y_t) 41 | kd_loss = self.beta * inter_loss + self.gamma * intra_loss 42 | dLoss.append(kd_loss) 43 | dLoss_items.append(kd_loss) 44 | dLoss = sum(dLoss) / len(dLoss) 45 | dLoss_items.append(dLoss) 46 | dLoss_items = torch.tensor(dLoss_items).to(dLoss.device) 47 | return dLoss, dLoss_items.detach() 48 | -------------------------------------------------------------------------------- /yolov5/data/hyps/hyp.scratch-high.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | # Hyperparameters for high-augmentation COCO training from scratch 3 | # python train.py --batch 32 --cfg yolov5m6.yaml --weights '' --data coco.yaml --img 1280 --epochs 300 4 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials 5 | 6 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 7 | lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) 8 | momentum: 0.937 # SGD momentum/Adam beta1 9 | weight_decay: 0.0005 # optimizer weight decay 5e-4 10 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 11 | warmup_momentum: 0.8 # warmup initial momentum 12 | warmup_bias_lr: 0.1 # warmup initial bias lr 13 | box: 0.05 # box loss gain 14 | cls: 0.3 # cls loss gain 15 | cls_pw: 1.0 # cls BCELoss positive_weight 16 | obj: 0.7 # obj loss gain (scale with pixels) 17 | obj_pw: 1.0 # obj BCELoss positive_weight 18 | iou_t: 0.20 # IoU training threshold 19 | anchor_t: 4.0 # anchor-multiple threshold 20 | # anchors: 3 # anchors per output layer (0 to ignore) 21 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 22 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 23 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 24 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 25 | degrees: 0.0 # image rotation (+/- deg) 26 | translate: 0.1 # image translation (+/- fraction) 27 | scale: 0.9 # image scale (+/- gain) 28 | shear: 0.0 # image shear (+/- deg) 29 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 30 | flipud: 0.0 # image flip up-down (probability) 31 | fliplr: 0.5 # image flip left-right (probability) 32 | mosaic: 1.0 # image mosaic (probability) 33 | mixup: 0.1 # image mixup (probability) 34 | copy_paste: 0.1 # segment copy-paste (probability) 35 | -------------------------------------------------------------------------------- /yolov5/data/hyps/hyp.distill.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | # Hyperparameters for low-augmentation COCO training from scratch 3 | # python train.py --batch 64 --cfg yolov5n6.yaml --weights '' --data coco.yaml --img 640 --epochs 300 --linear 4 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials 5 | 6 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 7 | lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf) 8 | momentum: 0.937 # SGD momentum/Adam beta1 9 | weight_decay: 0.0005 # optimizer weight decay 5e-4 10 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 11 | warmup_momentum: 0.8 # warmup initial momentum 12 | warmup_bias_lr: 0.1 # warmup initial bias lr 13 | box: 0.05 # box loss gain 14 | cls: 0.5 # cls loss gain 15 | cls_pw: 1.0 # cls BCELoss positive_weight 16 | obj: 1.0 # obj loss gain (scale with pixels) 17 | obj_pw: 1.0 # obj BCELoss positive_weight 18 | iou_t: 0.20 # IoU training threshold 19 | anchor_t: 4.0 # anchor-multiple threshold 20 | # anchors: 3 # anchors per output layer (0 to ignore) 21 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 22 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 23 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 24 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 25 | degrees: 0.0 # image rotation (+/- deg) 26 | translate: 0.1 # image translation (+/- fraction) 27 | scale: 0.5 # image scale (+/- gain) 28 | shear: 0.0 # image shear (+/- deg) 29 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 30 | flipud: 0.0 # image flip up-down (probability) 31 | fliplr: 0.5 # image flip left-right (probability) 32 | mosaic: 0.0 # image mosaic (probability) 33 | mixup: 0.0 # image mixup (probability) 34 | copy_paste: 0.0 # segment copy-paste (probability) 35 | -------------------------------------------------------------------------------- /yolov5/data/hyps/hyp.scratch-med.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | # Hyperparameters for medium-augmentation COCO training from scratch 3 | # python train.py --batch 32 --cfg yolov5m6.yaml --weights '' --data coco.yaml --img 1280 --epochs 300 4 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials 5 | 6 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 7 | lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) 8 | momentum: 0.937 # SGD momentum/Adam beta1 9 | weight_decay: 0.0005 # optimizer weight decay 5e-4 10 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 11 | warmup_momentum: 0.8 # warmup initial momentum 12 | warmup_bias_lr: 0.1 # warmup initial bias lr 13 | box: 0.05 # box loss gain 14 | cls: 0.3 # cls loss gain 15 | cls_pw: 1.0 # cls BCELoss positive_weight 16 | obj: 0.7 # obj loss gain (scale with pixels) 17 | obj_pw: 1.0 # obj BCELoss positive_weight 18 | iou_t: 0.20 # IoU training threshold 19 | anchor_t: 4.0 # anchor-multiple threshold 20 | # anchors: 3 # anchors per output layer (0 to ignore) 21 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 22 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 23 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 24 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 25 | degrees: 0.0 # image rotation (+/- deg) 26 | translate: 0.1 # image translation (+/- fraction) 27 | scale: 0.9 # image scale (+/- gain) 28 | shear: 0.0 # image shear (+/- deg) 29 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 30 | flipud: 0.0 # image flip up-down (probability) 31 | fliplr: 0.5 # image flip left-right (probability) 32 | mosaic: 1.0 # image mosaic (probability) 33 | mixup: 0.1 # image mixup (probability) 34 | copy_paste: 0.0 # segment copy-paste (probability) 35 | -------------------------------------------------------------------------------- /yolov5/data/hyps/hyp.no-augmentation.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | # Hyperparameters when using Albumentations frameworks 3 | # python train.py --hyp hyp.no-augmentation.yaml 4 | # See https://github.com/ultralytics/yolov5/pull/3882 for YOLOv5 + Albumentations Usage examples 5 | 6 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 7 | lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) 8 | momentum: 0.937 # SGD momentum/Adam beta1 9 | weight_decay: 0.0005 # optimizer weight decay 5e-4 10 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 11 | warmup_momentum: 0.8 # warmup initial momentum 12 | warmup_bias_lr: 0.1 # warmup initial bias lr 13 | box: 0.05 # box loss gain 14 | cls: 0.3 # cls loss gain 15 | cls_pw: 1.0 # cls BCELoss positive_weight 16 | obj: 0.7 # obj loss gain (scale with pixels) 17 | obj_pw: 1.0 # obj BCELoss positive_weight 18 | iou_t: 0.20 # IoU training threshold 19 | anchor_t: 4.0 # anchor-multiple threshold 20 | # anchors: 3 # anchors per output layer (0 to ignore) 21 | # this parameters are all zero since we want to use albumentation framework 22 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 23 | hsv_h: 0 # image HSV-Hue augmentation (fraction) 24 | hsv_s: 0 # image HSV-Saturation augmentation (fraction) 25 | hsv_v: 0 # image HSV-Value augmentation (fraction) 26 | degrees: 0.0 # image rotation (+/- deg) 27 | translate: 0 # image translation (+/- fraction) 28 | scale: 0 # image scale (+/- gain) 29 | shear: 0 # image shear (+/- deg) 30 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 31 | flipud: 0.0 # image flip up-down (probability) 32 | fliplr: 0.0 # image flip left-right (probability) 33 | mosaic: 0.0 # image mosaic (probability) 34 | mixup: 0.0 # image mixup (probability) 35 | copy_paste: 0.0 # segment copy-paste (probability) 36 | -------------------------------------------------------------------------------- /yolov5/data/hyps/hyp.scratch-low.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | # Hyperparameters for low-augmentation COCO training from scratch 3 | # python train.py --batch 64 --cfg yolov5n6.yaml --weights '' --data coco.yaml --img 640 --epochs 300 --linear 4 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials 5 | 6 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 7 | lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf) 8 | momentum: 0.937 # SGD momentum/Adam beta1 9 | weight_decay: 0.0005 # optimizer weight decay 5e-4 10 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 11 | warmup_momentum: 0.8 # warmup initial momentum 12 | warmup_bias_lr: 0.1 # warmup initial bias lr 13 | box: 0.05 # box loss gain 14 | cls: 0.5 # cls loss gain 15 | cls_pw: 1.0 # cls BCELoss positive_weight 16 | obj: 1.0 # obj loss gain (scale with pixels) 17 | obj_pw: 1.0 # obj BCELoss positive_weight 18 | iou_t: 0.20 # IoU training threshold 19 | anchor_t: 4.0 # anchor-multiple threshold 20 | # anchors: 3 # anchors per output layer (0 to ignore) 21 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 22 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 23 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 24 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 25 | degrees: 0.0 # image rotation (+/- deg) 26 | translate: 0.1 # image translation (+/- fraction) 27 | scale: 0.5 # image scale (+/- gain) 28 | shear: 0.0 # image shear (+/- deg) 29 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 30 | flipud: 0.0 # image flip up-down (probability) 31 | fliplr: 0.5 # image flip left-right (probability) 32 | mosaic: 1.0 # image mosaic (probability) 33 | mixup: 0.0 # image mixup (probability) 34 | copy_paste: 0.0 # segment copy-paste (probability) 35 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov3.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # darknet53 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [32, 3, 1]], # 0 17 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 18 | [-1, 1, Bottleneck, [64]], 19 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 20 | [-1, 2, Bottleneck, [128]], 21 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8 22 | [-1, 8, Bottleneck, [256]], 23 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16 24 | [-1, 8, Bottleneck, [512]], 25 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32 26 | [-1, 4, Bottleneck, [1024]], # 10 27 | ] 28 | 29 | # YOLOv3 head 30 | head: [ 31 | [-1, 1, Bottleneck, [1024, False]], 32 | [-1, 1, Conv, [512, 1, 1]], 33 | [-1, 1, Conv, [1024, 3, 1]], 34 | [-1, 1, Conv, [512, 1, 1]], 35 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large) 36 | 37 | [-2, 1, Conv, [256, 1, 1]], 38 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 39 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 40 | [-1, 1, Bottleneck, [512, False]], 41 | [-1, 1, Bottleneck, [512, False]], 42 | [-1, 1, Conv, [256, 1, 1]], 43 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium) 44 | 45 | [-2, 1, Conv, [128, 1, 1]], 46 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 47 | [[-1, 6], 1, Concat, [1]], # cat backbone P3 48 | [-1, 1, Bottleneck, [256, False]], 49 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small) 50 | 51 | [[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 52 | ] 53 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov3-spp.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # darknet53 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [32, 3, 1]], # 0 17 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 18 | [-1, 1, Bottleneck, [64]], 19 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 20 | [-1, 2, Bottleneck, [128]], 21 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8 22 | [-1, 8, Bottleneck, [256]], 23 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16 24 | [-1, 8, Bottleneck, [512]], 25 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32 26 | [-1, 4, Bottleneck, [1024]], # 10 27 | ] 28 | 29 | # YOLOv3-SPP head 30 | head: [ 31 | [-1, 1, Bottleneck, [1024, False]], 32 | [-1, 1, SPP, [512, [5, 9, 13]]], 33 | [-1, 1, Conv, [1024, 3, 1]], 34 | [-1, 1, Conv, [512, 1, 1]], 35 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large) 36 | 37 | [-2, 1, Conv, [256, 1, 1]], 38 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 39 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 40 | [-1, 1, Bottleneck, [512, False]], 41 | [-1, 1, Bottleneck, [512, False]], 42 | [-1, 1, Conv, [256, 1, 1]], 43 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium) 44 | 45 | [-2, 1, Conv, [128, 1, 1]], 46 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 47 | [[-1, 6], 1, Concat, [1]], # cat backbone P3 48 | [-1, 1, Bottleneck, [256, False]], 49 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small) 50 | 51 | [[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 52 | ] 53 | -------------------------------------------------------------------------------- /yolov5/data/hyps/hyps.qat.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | # Hyperparameters for low-augmentation COCO training from scratch 3 | # python train.py --batch 64 --cfg yolov5n6.yaml --weights '' --data coco.yaml --img 640 --epochs 300 --linear 4 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials 5 | 6 | lr0: 0.0001 # initial learning rate (Adam=1E-4, see https://arxiv.org/pdf/2311.05109.pdf) 7 | lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf) 8 | momentum: 0.9 # SGD momentum/Adam beta1 9 | weight_decay: 0.0005 # optimizer weight decay 5e-4 10 | warmup_epochs: 3 # warmup epochs (fractions ok) 11 | warmup_momentum: 0.8 # warmup initial momentum 12 | warmup_bias_lr: 0.1 # warmup initial bias lr 13 | box: 0.05 # box loss gain 14 | cls: 0.5 # cls loss gain 15 | cls_pw: 1.0 # cls BCELoss positive_weight 16 | obj: 1.0 # obj loss gain (scale with pixels) 17 | obj_pw: 1.0 # obj BCELoss positive_weight 18 | iou_t: 0.20 # IoU training threshold 19 | anchor_t: 4.0 # anchor-multiple threshold 20 | # anchors: 3 # anchors per output layer (0 to ignore) 21 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 22 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 23 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 24 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 25 | degrees: 0.0 # image rotation (+/- deg) 26 | translate: 0.1 # image translation (+/- fraction) 27 | scale: 0.5 # image scale (+/- gain) 28 | shear: 0.0 # image shear (+/- deg) 29 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 30 | flipud: 0.0 # image flip up-down (probability) 31 | fliplr: 0.5 # image flip left-right (probability) 32 | mosaic: 1.0 # image mosaic (probability) 33 | mixup: 0.0 # image mixup (probability) 34 | copy_paste: 0.0 # segment copy-paste (probability) 35 | -------------------------------------------------------------------------------- /yolo11/quant/kd_mode.py: -------------------------------------------------------------------------------- 1 | from enum import StrEnum 2 | 3 | from pathlib import Path 4 | from pydantic import BaseModel, Field 5 | from typing import Annotated, Literal 6 | 7 | 8 | class KDMethodsKind(StrEnum): 9 | KL = "kl" 10 | DIST = "dist" 11 | 12 | 13 | class KLMethod(BaseModel): 14 | kind: Literal[KDMethodsKind.KL] 15 | # tau (float): Temperature coefficient. Defaults to 1.0. 16 | tau: float = Field(4.0) 17 | 18 | 19 | class DISTMethod(BaseModel): 20 | kind: Literal[KDMethodsKind.DIST] 21 | beta: float = Field(1.0) 22 | gamma: float = Field(1.0) 23 | tau: float = Field(1.0) 24 | 25 | 26 | class KDModules(StrEnum): 27 | NONE = "none" 28 | CNN = "cnn" 29 | BN = "bn" 30 | CNNBN = "cnnbn" 31 | ALL = "all" 32 | 33 | 34 | class KDMethods(BaseModel): 35 | """KDMethods describes the knowledge distillation method you are going to use.""" 36 | 37 | # The teacher model. 38 | teacher_weight: Path = Field( 39 | Path("yolo11n.pt"), description="the model weight for teacher" 40 | ) 41 | 42 | # This option controls which model KD aligns the student with the teacher. 43 | kd_module: KDModules = Field(KDModules.CNNBN, description="The kd modules") 44 | 45 | # This option controls the proportion of original loss function in KD. 46 | original_loss_weight: float = Field( 47 | 0.04, description="loss of the original weight." 48 | ) 49 | 50 | # This option controls the kind of KD loss function 51 | kd_loss: Annotated[KLMethod | DISTMethod, Field(discriminator="kind")] 52 | 53 | # This option controls the proportion of KD loss function 54 | kd_loss_weight: float = Field(0.1, description="loss of kd") 55 | 56 | # This option controls the proportion of MSE loss function 57 | mse_loss_weight: float = Field(1.0, description="loss of MSE") 58 | -------------------------------------------------------------------------------- /yolo11/quant/quant_mode.py: -------------------------------------------------------------------------------- 1 | from enum import StrEnum 2 | 3 | from pydantic import BaseModel, Field 4 | 5 | from typing import Annotated, Literal 6 | 7 | 8 | class QuantizeKind(StrEnum): 9 | EXACT = "exact" 10 | SYMMETRIC_QUANTIZE = "quantize_sym" 11 | ASYMMETRIC_QUANTIZE = "quantize_asym" 12 | 13 | 14 | class ExactModel(BaseModel): 15 | """Do not quantize the model.""" 16 | 17 | kind: Literal[QuantizeKind.EXACT] 18 | 19 | 20 | class SymQuantizeOption(BaseModel): 21 | """ 22 | Use LSQ(Learned Step-size Quantization, https://arxiv.org/abs/1902.08153) to quantize the model. 23 | 24 | weight_bits is the bit-width of network weights. 25 | activation_bits is the bit-width of intermediate value. 26 | """ 27 | 28 | kind: Literal[QuantizeKind.SYMMETRIC_QUANTIZE] 29 | weight_bits: int 30 | activation_bits: int 31 | 32 | 33 | class AsymQuantizeOption(BaseModel): 34 | """ 35 | Use LSQ+(https://arxiv.org/abs/2004.09576) to quantize the model. 36 | 37 | weight_bits is the bit-width of network weights. 38 | activation_bits is the bit-width of intermediate value. 39 | """ 40 | 41 | kind: Literal[QuantizeKind.ASYMMETRIC_QUANTIZE] 42 | weight_bits: int 43 | activation_bits: int 44 | 45 | 46 | # Our code supports three modes of model quantization. They are: 47 | # - ExactModel: Do not quantize the model. 48 | # - SymQuantizeModel: Use LSQ to quantize the model. This is controlled by `SymQuantizeOption` class. 49 | # See its definition for more instructions. 50 | # - AsymQuantizeOption: Use LSQ+ to quantize the model. This is controlled by `AsymQuantizeOption` class. 51 | # See its definition for more instructions. 52 | QuantizeMode = Annotated[ 53 | ExactModel | SymQuantizeOption | AsymQuantizeOption, Field(discriminator="kind") 54 | ] 55 | -------------------------------------------------------------------------------- /yolov5/utils/flask_rest_api/restapi.py: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | """Run a Flask REST API exposing one or more YOLOv5s models.""" 3 | 4 | import argparse 5 | import io 6 | 7 | import torch 8 | from flask import Flask, request 9 | from PIL import Image 10 | 11 | app = Flask(__name__) 12 | models = {} 13 | 14 | DETECTION_URL = "/v1/object-detection/" 15 | 16 | 17 | @app.route(DETECTION_URL, methods=["POST"]) 18 | def predict(model): 19 | """Predict and return object detections in JSON format given an image and model name via a Flask REST API POST 20 | request. 21 | """ 22 | if request.method != "POST": 23 | return 24 | 25 | if request.files.get("image"): 26 | # Method 1 27 | # with request.files["image"] as f: 28 | # im = Image.open(io.BytesIO(f.read())) 29 | 30 | # Method 2 31 | im_file = request.files["image"] 32 | im_bytes = im_file.read() 33 | im = Image.open(io.BytesIO(im_bytes)) 34 | 35 | if model in models: 36 | results = models[model]( 37 | im, size=640 38 | ) # reduce size=320 for faster inference 39 | return results.pandas().xyxy[0].to_json(orient="records") 40 | 41 | 42 | if __name__ == "__main__": 43 | parser = argparse.ArgumentParser(description="Flask API exposing YOLOv5 model") 44 | parser.add_argument("--port", default=5000, type=int, help="port number") 45 | parser.add_argument( 46 | "--model", 47 | nargs="+", 48 | default=["yolov5s"], 49 | help="model(s) to run, i.e. --model yolov5n yolov5s", 50 | ) 51 | opt = parser.parse_args() 52 | 53 | for m in opt.model: 54 | models[m] = torch.hub.load( 55 | "ultralytics/yolov5", m, force_reload=True, skip_validation=True 56 | ) 57 | 58 | app.run(host="0.0.0.0", port=opt.port) # debug=True causes Restarting with stat 59 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5-p2.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 3 # AutoAnchor evolves 3 anchors per P output layer 8 | 9 | # YOLOv5 v6.0 backbone 10 | backbone: 11 | # [from, number, module, args] 12 | [ 13 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 14 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 15 | [-1, 3, C3, [128]], 16 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 17 | [-1, 6, C3, [256]], 18 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 19 | [-1, 9, C3, [512]], 20 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 21 | [-1, 3, C3, [1024]], 22 | [-1, 1, SPPF, [1024, 5]], # 9 23 | ] 24 | 25 | # YOLOv5 v6.0 head with (P2, P3, P4, P5) outputs 26 | head: [ 27 | [-1, 1, Conv, [512, 1, 1]], 28 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 29 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 30 | [-1, 3, C3, [512, False]], # 13 31 | 32 | [-1, 1, Conv, [256, 1, 1]], 33 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 34 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 35 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 36 | 37 | [-1, 1, Conv, [128, 1, 1]], 38 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 39 | [[-1, 2], 1, Concat, [1]], # cat backbone P2 40 | [-1, 1, C3, [128, False]], # 21 (P2/4-xsmall) 41 | 42 | [-1, 1, Conv, [128, 3, 2]], 43 | [[-1, 18], 1, Concat, [1]], # cat head P3 44 | [-1, 3, C3, [256, False]], # 24 (P3/8-small) 45 | 46 | [-1, 1, Conv, [256, 3, 2]], 47 | [[-1, 14], 1, Concat, [1]], # cat head P4 48 | [-1, 3, C3, [512, False]], # 27 (P4/16-medium) 49 | 50 | [-1, 1, Conv, [512, 3, 2]], 51 | [[-1, 10], 1, Concat, [1]], # cat head P5 52 | [-1, 3, C3, [1024, False]], # 30 (P5/32-large) 53 | 54 | [[21, 24, 27, 30], 1, Detect, [nc, anchors]], # Detect(P2, P3, P4, P5) 55 | ] 56 | -------------------------------------------------------------------------------- /vit/configs/_base_/datasets/coco_detection.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | # dataset settings 3 | dataset_type = 'CocoDataset' 4 | data_root = 'data/coco/' 5 | img_norm_cfg = dict( 6 | mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) 7 | train_pipeline = [ 8 | dict(type='LoadImageFromFile'), 9 | dict(type='LoadAnnotations', with_bbox=True), 10 | dict(type='Resize', img_scale=(1333, 800), keep_ratio=True), 11 | dict(type='RandomFlip', flip_ratio=0.5), 12 | dict(type='Normalize', **img_norm_cfg), 13 | dict(type='Pad', size_divisor=32), 14 | dict(type='DefaultFormatBundle'), 15 | dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']), 16 | ] 17 | test_pipeline = [ 18 | dict(type='LoadImageFromFile'), 19 | dict(type='MultiScaleFlipAug', 20 | img_scale=(1333, 800), 21 | flip=False, 22 | transforms=[ 23 | dict(type='Resize', keep_ratio=True), 24 | dict(type='RandomFlip'), 25 | dict(type='Normalize', **img_norm_cfg), 26 | dict(type='Pad', size_divisor=32), 27 | dict(type='ImageToTensor', keys=['img']), 28 | dict(type='Collect', keys=['img']), 29 | ]) 30 | ] 31 | data = dict( 32 | samples_per_gpu=2, 33 | workers_per_gpu=2, 34 | train=dict(type=dataset_type, 35 | ann_file=data_root + 'annotations/instances_train2017.json', 36 | img_prefix=data_root + 'train2017/', 37 | pipeline=train_pipeline), 38 | val=dict(type=dataset_type, 39 | ann_file=data_root + 'annotations/instances_val2017.json', 40 | img_prefix=data_root + 'val2017/', 41 | pipeline=test_pipeline), 42 | test=dict(type=dataset_type, 43 | ann_file=data_root + 'annotations/instances_val2017.json', 44 | img_prefix=data_root + 'val2017/', 45 | pipeline=test_pipeline)) 46 | evaluation = dict(interval=1, metric='bbox') 47 | -------------------------------------------------------------------------------- /yolov5/utils/docker/Dockerfile-cpu: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | # Builds ultralytics/yolov5:latest-cpu image on DockerHub https://hub.docker.com/r/ultralytics/yolov5 3 | # Image is CPU-optimized for ONNX, OpenVINO and PyTorch YOLOv5 deployments 4 | 5 | # Start FROM Ubuntu image https://hub.docker.com/_/ubuntu 6 | FROM ubuntu:23.10 7 | 8 | # Downloads to user config dir 9 | ADD https://ultralytics.com/assets/Arial.ttf https://ultralytics.com/assets/Arial.Unicode.ttf /root/.config/Ultralytics/ 10 | 11 | # Install linux packages 12 | # g++ required to build 'tflite_support' and 'lap' packages, libusb-1.0-0 required for 'tflite_support' package 13 | RUN apt update \ 14 | && apt install --no-install-recommends -y python3-pip git zip curl htop libgl1 libglib2.0-0 libpython3-dev gnupg g++ libusb-1.0-0 15 | # RUN alias python=python3 16 | 17 | # Remove python3.11/EXTERNALLY-MANAGED or use 'pip install --break-system-packages' avoid 'externally-managed-environment' Ubuntu nightly error 18 | RUN rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED 19 | 20 | # Install pip packages 21 | COPY requirements.txt . 22 | RUN python3 -m pip install --upgrade pip wheel 23 | RUN pip install --no-cache -r requirements.txt albumentations gsutil notebook \ 24 | coremltools onnx onnx-simplifier onnxruntime 'openvino-dev>=2023.0' \ 25 | # tensorflow tensorflowjs \ 26 | --extra-index-url https://download.pytorch.org/whl/cpu 27 | 28 | # Create working directory 29 | RUN mkdir -p /usr/src/app 30 | WORKDIR /usr/src/app 31 | 32 | # Copy contents 33 | COPY . /usr/src/app 34 | 35 | 36 | # Usage Examples ------------------------------------------------------------------------------------------------------- 37 | 38 | # Build and Push 39 | # t=ultralytics/yolov5:latest-cpu && sudo docker build -f utils/docker/Dockerfile-cpu -t $t . && sudo docker push $t 40 | 41 | # Pull and Run 42 | # t=ultralytics/yolov5:latest-cpu && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/datasets:/usr/src/datasets $t 43 | -------------------------------------------------------------------------------- /vit/configs/datasets/coco_128.py: -------------------------------------------------------------------------------- 1 | dataset_type = "CocoFraction" 2 | data_root = "data/coco/" 3 | img_norm_cfg = dict( 4 | mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True 5 | ) 6 | train_pipeline = [ 7 | dict(type="LoadImageFromFile"), 8 | dict(type="LoadAnnotations", with_bbox=True, with_mask=True), 9 | dict(type="Resize", img_scale=(1333, 800), keep_ratio=True), 10 | dict(type="RandomFlip", flip_ratio=0.5), 11 | dict(type="Normalize", **img_norm_cfg), 12 | dict(type="Pad", size_divisor=32), 13 | dict(type="DefaultFormatBundle"), 14 | dict(type="Collect", keys=["img", "gt_bboxes", "gt_labels", "gt_masks"]), 15 | ] 16 | test_pipeline = [ 17 | dict(type="LoadImageFromFile"), 18 | dict( 19 | type="MultiScaleFlipAug", 20 | img_scale=(1333, 800), 21 | flip=False, 22 | transforms=[ 23 | dict(type="Resize", keep_ratio=True), 24 | dict(type="RandomFlip"), 25 | dict(type="Normalize", **img_norm_cfg), 26 | dict(type="Pad", size_divisor=32), 27 | dict(type="ImageToTensor", keys=["img"]), 28 | dict(type="Collect", keys=["img"]), 29 | ], 30 | ), 31 | ] 32 | data = dict( 33 | samples_per_gpu=2, 34 | workers_per_gpu=2, 35 | train=dict( 36 | type=dataset_type, 37 | dataset_size=128, 38 | ann_file=data_root + "annotations/instances_train2017.json", 39 | img_prefix=data_root + "train2017/", 40 | pipeline=train_pipeline, 41 | ), 42 | val=dict( 43 | type=dataset_type, 44 | ann_file=data_root + "annotations/instances_val2017.json", 45 | img_prefix=data_root + "val2017/", 46 | pipeline=test_pipeline, 47 | ), 48 | test=dict( 49 | type=dataset_type, 50 | ann_file=data_root + "annotations/instances_val2017.json", 51 | img_prefix=data_root + "val2017/", 52 | pipeline=test_pipeline, 53 | ), 54 | ) 55 | evaluation = dict(metric=["bbox"]) 56 | -------------------------------------------------------------------------------- /vit/configs/datasets/coco_2048.py: -------------------------------------------------------------------------------- 1 | dataset_type = "CocoFraction" 2 | data_root = "data/coco/" 3 | img_norm_cfg = dict( 4 | mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True 5 | ) 6 | train_pipeline = [ 7 | dict(type="LoadImageFromFile"), 8 | dict(type="LoadAnnotations", with_bbox=True, with_mask=True), 9 | dict(type="Resize", img_scale=(1333, 800), keep_ratio=True), 10 | dict(type="RandomFlip", flip_ratio=0.5), 11 | dict(type="Normalize", **img_norm_cfg), 12 | dict(type="Pad", size_divisor=32), 13 | dict(type="DefaultFormatBundle"), 14 | dict(type="Collect", keys=["img", "gt_bboxes", "gt_labels", "gt_masks"]), 15 | ] 16 | test_pipeline = [ 17 | dict(type="LoadImageFromFile"), 18 | dict( 19 | type="MultiScaleFlipAug", 20 | img_scale=(1333, 800), 21 | flip=False, 22 | transforms=[ 23 | dict(type="Resize", keep_ratio=True), 24 | dict(type="RandomFlip"), 25 | dict(type="Normalize", **img_norm_cfg), 26 | dict(type="Pad", size_divisor=32), 27 | dict(type="ImageToTensor", keys=["img"]), 28 | dict(type="Collect", keys=["img"]), 29 | ], 30 | ), 31 | ] 32 | data = dict( 33 | samples_per_gpu=2, 34 | workers_per_gpu=0, 35 | train=dict( 36 | type=dataset_type, 37 | dataset_size=2048, 38 | ann_file=data_root + "annotations/instances_train2017.json", 39 | img_prefix=data_root + "train2017/", 40 | pipeline=train_pipeline, 41 | ), 42 | val=dict( 43 | type=dataset_type, 44 | ann_file=data_root + "annotations/instances_val2017.json", 45 | img_prefix=data_root + "val2017/", 46 | pipeline=test_pipeline, 47 | ), 48 | test=dict( 49 | type=dataset_type, 50 | ann_file=data_root + "annotations/instances_val2017.json", 51 | img_prefix=data_root + "val2017/", 52 | pipeline=test_pipeline, 53 | ), 54 | ) 55 | evaluation = dict(metric=["bbox"]) 56 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5-p6.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 3 # AutoAnchor evolves 3 anchors per P output layer 8 | 9 | # YOLOv5 v6.0 backbone 10 | backbone: 11 | # [from, number, module, args] 12 | [ 13 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 14 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 15 | [-1, 3, C3, [128]], 16 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 17 | [-1, 6, C3, [256]], 18 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 19 | [-1, 9, C3, [512]], 20 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 21 | [-1, 3, C3, [768]], 22 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 23 | [-1, 3, C3, [1024]], 24 | [-1, 1, SPPF, [1024, 5]], # 11 25 | ] 26 | 27 | # YOLOv5 v6.0 head with (P3, P4, P5, P6) outputs 28 | head: [ 29 | [-1, 1, Conv, [768, 1, 1]], 30 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 31 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 32 | [-1, 3, C3, [768, False]], # 15 33 | 34 | [-1, 1, Conv, [512, 1, 1]], 35 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 36 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 37 | [-1, 3, C3, [512, False]], # 19 38 | 39 | [-1, 1, Conv, [256, 1, 1]], 40 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 41 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 42 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 43 | 44 | [-1, 1, Conv, [256, 3, 2]], 45 | [[-1, 20], 1, Concat, [1]], # cat head P4 46 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 47 | 48 | [-1, 1, Conv, [512, 3, 2]], 49 | [[-1, 16], 1, Concat, [1]], # cat head P5 50 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 51 | 52 | [-1, 1, Conv, [768, 3, 2]], 53 | [[-1, 12], 1, Concat, [1]], # cat head P6 54 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) 55 | 56 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 57 | ] 58 | -------------------------------------------------------------------------------- /vit/configs/_base_/datasets/coco_instance.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | # dataset settings 3 | dataset_type = 'CocoDataset' 4 | data_root = 'data/coco/' 5 | img_norm_cfg = dict( 6 | mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) 7 | train_pipeline = [ 8 | dict(type='LoadImageFromFile'), 9 | dict(type='LoadAnnotations', with_bbox=True, with_mask=True), 10 | dict(type='Resize', img_scale=(1333, 800), keep_ratio=True), 11 | dict(type='RandomFlip', flip_ratio=0.5), 12 | dict(type='Normalize', **img_norm_cfg), 13 | dict(type='Pad', size_divisor=32), 14 | dict(type='DefaultFormatBundle'), 15 | dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels', 'gt_masks']), 16 | ] 17 | test_pipeline = [ 18 | dict(type='LoadImageFromFile'), 19 | dict(type='MultiScaleFlipAug', 20 | img_scale=(1333, 800), 21 | flip=False, 22 | transforms=[ 23 | dict(type='Resize', keep_ratio=True), 24 | dict(type='RandomFlip'), 25 | dict(type='Normalize', **img_norm_cfg), 26 | dict(type='Pad', size_divisor=32), 27 | dict(type='ImageToTensor', keys=['img']), 28 | dict(type='Collect', keys=['img']), 29 | ]) 30 | ] 31 | data = dict( 32 | samples_per_gpu=2, 33 | workers_per_gpu=2, 34 | train=dict(type=dataset_type, 35 | ann_file=data_root + 'annotations/instances_train2017.json', 36 | img_prefix=data_root + 'train2017/', 37 | pipeline=train_pipeline), 38 | val=dict(type=dataset_type, 39 | ann_file=data_root + 'annotations/instances_val2017.json', 40 | img_prefix=data_root + 'val2017/', 41 | pipeline=test_pipeline), 42 | test=dict(type=dataset_type, 43 | ann_file=data_root + 'annotations/instances_val2017.json', 44 | img_prefix=data_root + 'val2017/', 45 | pipeline=test_pipeline)) 46 | evaluation = dict(metric=['bbox', 'segm']) 47 | -------------------------------------------------------------------------------- /yolov5/utils/flask_rest_api/README.md: -------------------------------------------------------------------------------- 1 | # Flask REST API 2 | 3 | [REST](https://en.wikipedia.org/wiki/Representational_state_transfer) [API](https://en.wikipedia.org/wiki/API)s are commonly used to expose Machine Learning (ML) models to other services. This folder contains an example REST API created using Flask to expose the YOLOv5s model from [PyTorch Hub](https://pytorch.org/hub/ultralytics_yolov5/). 4 | 5 | ## Requirements 6 | 7 | [Flask](https://palletsprojects.com/p/flask/) is required. Install with: 8 | 9 | ```shell 10 | $ pip install Flask 11 | ``` 12 | 13 | ## Run 14 | 15 | After Flask installation run: 16 | 17 | ```shell 18 | $ python3 restapi.py --port 5000 19 | ``` 20 | 21 | Then use [curl](https://curl.se/) to perform a request: 22 | 23 | ```shell 24 | $ curl -X POST -F image=@zidane.jpg 'http://localhost:5000/v1/object-detection/yolov5s' 25 | ``` 26 | 27 | The model inference results are returned as a JSON response: 28 | 29 | ```json 30 | [ 31 | { 32 | "class": 0, 33 | "confidence": 0.8900438547, 34 | "height": 0.9318675399, 35 | "name": "person", 36 | "width": 0.3264600933, 37 | "xcenter": 0.7438579798, 38 | "ycenter": 0.5207948685 39 | }, 40 | { 41 | "class": 0, 42 | "confidence": 0.8440024257, 43 | "height": 0.7155083418, 44 | "name": "person", 45 | "width": 0.6546785235, 46 | "xcenter": 0.427829951, 47 | "ycenter": 0.6334488392 48 | }, 49 | { 50 | "class": 27, 51 | "confidence": 0.3771208823, 52 | "height": 0.3902671337, 53 | "name": "tie", 54 | "width": 0.0696444362, 55 | "xcenter": 0.3675483763, 56 | "ycenter": 0.7991207838 57 | }, 58 | { 59 | "class": 27, 60 | "confidence": 0.3527112305, 61 | "height": 0.1540903747, 62 | "name": "tie", 63 | "width": 0.0336618312, 64 | "xcenter": 0.7814827561, 65 | "ycenter": 0.5065554976 66 | } 67 | ] 68 | ``` 69 | 70 | An example python script to perform inference using [requests](https://docs.python-requests.org/en/master/) is given in `example_request.py` 71 | -------------------------------------------------------------------------------- /yolo11/data/cocoonebox.yaml: -------------------------------------------------------------------------------- 1 | # 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, ..] 2 | path: PLACEHOLDER # dataset root dir 3 | train: train2017.txt # train images (relative to 'path') 118287 images 4 | val: train2017.txt # val images (relative to 'path') 5000 images 5 | test: train2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794 6 | 7 | # Classes 8 | names: 9 | 0: person 10 | 1: bicycle 11 | 2: car 12 | 3: motorcycle 13 | 4: airplane 14 | 5: bus 15 | 6: train 16 | 7: truck 17 | 8: boat 18 | 9: traffic light 19 | 10: fire hydrant 20 | 11: stop sign 21 | 12: parking meter 22 | 13: bench 23 | 14: bird 24 | 15: cat 25 | 16: dog 26 | 17: horse 27 | 18: sheep 28 | 19: cow 29 | 20: elephant 30 | 21: bear 31 | 22: zebra 32 | 23: giraffe 33 | 24: backpack 34 | 25: umbrella 35 | 26: handbag 36 | 27: tie 37 | 28: suitcase 38 | 29: frisbee 39 | 30: skis 40 | 31: snowboard 41 | 32: sports ball 42 | 33: kite 43 | 34: baseball bat 44 | 35: baseball glove 45 | 36: skateboard 46 | 37: surfboard 47 | 38: tennis racket 48 | 39: bottle 49 | 40: wine glass 50 | 41: cup 51 | 42: fork 52 | 43: knife 53 | 44: spoon 54 | 45: bowl 55 | 46: banana 56 | 47: apple 57 | 48: sandwich 58 | 49: orange 59 | 50: broccoli 60 | 51: carrot 61 | 52: hot dog 62 | 53: pizza 63 | 54: donut 64 | 55: cake 65 | 56: chair 66 | 57: couch 67 | 58: potted plant 68 | 59: bed 69 | 60: dining table 70 | 61: toilet 71 | 62: tv 72 | 63: laptop 73 | 64: mouse 74 | 65: remote 75 | 66: keyboard 76 | 67: cell phone 77 | 68: microwave 78 | 69: oven 79 | 70: toaster 80 | 71: sink 81 | 72: refrigerator 82 | 73: book 83 | 74: clock 84 | 75: vase 85 | 76: scissors 86 | 77: teddy bear 87 | 78: hair drier 88 | 79: toothbrush 89 | 90 | # Download script/URL (optional) 91 | download: | 92 | raise NotImplementedError("Please use generate_one_label") 93 | -------------------------------------------------------------------------------- /vit/tools/rescale_images.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from typing import List 3 | import torch 4 | 5 | from pydantic_settings import ( 6 | BaseSettings, 7 | CliApp, 8 | ) 9 | from pydantic import Field, ValidationError 10 | 11 | from pathlib import Path 12 | 13 | 14 | class GenOptions(BaseSettings, cli_parse_args=True, cli_prog_name="Generation"): 15 | 16 | syn_dir: str = Field(description="places of synthesized data") 17 | 18 | scale: str = Field(description="scale. std: [0, 1] image_net: [-m/s, (1-m) /s]") 19 | 20 | 21 | def get_all_pts(syn_dir: str) -> List[Path]: 22 | return [x for x in Path(syn_dir).iterdir() if x.name.endswith(".pt")] 23 | 24 | 25 | def std_scale(img: torch.Tensor): 26 | min_val = img.amin(dim=(2, 3), keepdim=True) 27 | max_val = img.amax(dim=(2, 3), keepdim=True) 28 | 29 | scaled_img = (img - min_val) / (max_val - min_val).clamp(min=1e-5) 30 | 31 | return scaled_img 32 | 33 | 34 | def image_net_scale(img: torch.Tensor): 35 | mean = torch.tensor([0.485, 0.456, 0.406]).view(1, -1, 1, 1) 36 | std = torch.tensor([0.229, 0.224, 0.225]).view(1, -1, 1, 1) 37 | scaled_img = std_scale(img) 38 | return (scaled_img - mean) / std 39 | 40 | 41 | scale_modes = {"std": std_scale, "image_net": image_net_scale} 42 | 43 | 44 | def scale_all_pts(syn_dir: str, scale: str): 45 | all_pts_path = get_all_pts(syn_dir) 46 | scaled_pts_path = Path(syn_dir) / scale 47 | scaled_pts_path.mkdir(exist_ok=True, parents=True) 48 | for pt_path in all_pts_path: 49 | sample = torch.load(pt_path, map_location="cpu") 50 | sample["img"] = scale_modes[scale](sample["img"]) 51 | torch.save(sample, scaled_pts_path / pt_path.name) 52 | 53 | 54 | def get_config() -> GenOptions: 55 | try: 56 | config = CliApp.run(GenOptions) 57 | except ValidationError as e: 58 | logging.fatal(e) 59 | exit(-1) 60 | return config 61 | 62 | 63 | if __name__ == "__main__": 64 | opt = get_config() 65 | scale_all_pts(syn_dir=opt.syn_dir, scale=opt.scale) 66 | -------------------------------------------------------------------------------- /resnet/train_utils/loggers.py: -------------------------------------------------------------------------------- 1 | import os 2 | import logging 3 | from logging import FileHandler, Formatter 4 | from datetime import datetime 5 | 6 | # Initial log directory 7 | # BASE_DIR = f"logs/{datetime.now().strftime('%Y%m%d-%H%M')}" 8 | # DIR = BASE_DIR 9 | # os.makedirs(DIR, exist_ok=True) 10 | 11 | 12 | def initial_log_dir(path): 13 | global DIR 14 | now_time = datetime.now().strftime("%Y%m%d-%H%M") 15 | DIR = f"{path}/{now_time}" 16 | os.makedirs(DIR, exist_ok=True) 17 | 18 | for logger_name, logger in loggers.items(): 19 | file_name = logger_file_map[logger.name] 20 | file_handler = FileHandler(f"{DIR}/{file_name}") 21 | file_handler.setFormatter(Formatter("%(message)s")) 22 | logger.addHandler(file_handler) 23 | 24 | 25 | def get_log_dir(): 26 | return DIR 27 | 28 | 29 | def update_log_folder(new_dir, process_index): 30 | global DIR 31 | DIR = f"{DIR}/{new_dir}/gpu_{process_index}" 32 | os.makedirs(DIR, exist_ok=True) 33 | 34 | # Update file handlers for each logger 35 | for logger_name, logger in loggers.items(): 36 | # Remove old file handlers 37 | for handler in logger.handlers[:]: 38 | if isinstance(handler, FileHandler): 39 | logger.removeHandler(handler) 40 | 41 | # For other loggers, create a separate directory for each GPU process 42 | logger_dir = DIR 43 | 44 | # Create a new file handler with the updated directory 45 | file_name = logger_file_map[logger.name] 46 | new_file_handler = FileHandler(f"{logger_dir}/{file_name}") 47 | new_file_handler.setFormatter(Formatter("%(message)s")) 48 | logger.addHandler(new_file_handler) 49 | 50 | 51 | # Store loggers and their corresponding file names 52 | logger_file_map = { 53 | "student": "student_info.log", 54 | "teacher": "teacher_info.log", 55 | } 56 | 57 | # Initialize loggers 58 | loggers = {name: logging.getLogger(name) for name in logger_file_map} 59 | for logger in loggers.values(): 60 | logger.setLevel(logging.DEBUG) 61 | -------------------------------------------------------------------------------- /vit/configs/_base_/models/ssd300.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | input_size = 300 3 | model = dict( 4 | type="SingleStageDetector", 5 | backbone=dict( 6 | type="SSDVGG", 7 | depth=16, 8 | with_last_pool=False, 9 | ceil_mode=True, 10 | out_indices=(3, 4), 11 | out_feature_indices=(22, 34), 12 | init_cfg=dict(type="Pretrained", checkpoint="open-mmlab://vgg16_caffe"), 13 | ), 14 | neck=dict( 15 | type="SSDNeck", 16 | in_channels=(512, 1024), 17 | out_channels=(512, 1024, 512, 256, 256, 256), 18 | level_strides=(2, 2, 1, 1), 19 | level_paddings=(1, 1, 0, 0), 20 | l2_norm_scale=20, 21 | ), 22 | bbox_head=dict( 23 | type="SSDHead", 24 | in_channels=(512, 1024, 512, 256, 256, 256), 25 | num_classes=80, 26 | anchor_generator=dict( 27 | type="SSDAnchorGenerator", 28 | scale_major=False, 29 | input_size=input_size, 30 | basesize_ratio_range=(0.15, 0.9), 31 | strides=[8, 16, 32, 64, 100, 300], 32 | ratios=[[2], [2, 3], [2, 3], [2, 3], [2], [2]], 33 | ), 34 | bbox_coder=dict( 35 | type="DeltaXYWHBBoxCoder", 36 | target_means=[0.0, 0.0, 0.0, 0.0], 37 | target_stds=[0.1, 0.1, 0.2, 0.2], 38 | ), 39 | ), 40 | # model training and testing settings 41 | train_cfg=dict( 42 | assigner=dict( 43 | type="MaxIoUAssigner", 44 | pos_iou_thr=0.5, 45 | neg_iou_thr=0.5, 46 | min_pos_iou=0.0, 47 | ignore_iof_thr=-1, 48 | gt_max_assign_all=False, 49 | ), 50 | smoothl1_beta=1.0, 51 | allowed_border=-1, 52 | pos_weight=-1, 53 | neg_pos_ratio=3, 54 | debug=False, 55 | ), 56 | test_cfg=dict( 57 | nms_pre=1000, 58 | nms=dict(type="nms", iou_threshold=0.45), 59 | min_bbox_size=0, 60 | score_thr=0.02, 61 | max_per_img=200, 62 | ), 63 | ) 64 | cudnn_benchmark = True 65 | -------------------------------------------------------------------------------- /yolov5/data/GlobalWheat2020.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | # Global Wheat 2020 dataset http://www.global-wheat.com/ by University of Saskatchewan 3 | # Example usage: python train.py --data GlobalWheat2020.yaml 4 | # parent 5 | # ├── yolov5 6 | # └── datasets 7 | # └── GlobalWheat2020 ← downloads here (7.0 GB) 8 | 9 | # 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, ..] 10 | path: ../datasets/GlobalWheat2020 # dataset root dir 11 | train: # train images (relative to 'path') 3422 images 12 | - images/arvalis_1 13 | - images/arvalis_2 14 | - images/arvalis_3 15 | - images/ethz_1 16 | - images/rres_1 17 | - images/inrae_1 18 | - images/usask_1 19 | val: # val images (relative to 'path') 748 images (WARNING: train set contains ethz_1) 20 | - images/ethz_1 21 | test: # test images (optional) 1276 images 22 | - images/utokyo_1 23 | - images/utokyo_2 24 | - images/nau_1 25 | - images/uq_1 26 | 27 | # Classes 28 | names: 29 | 0: wheat_head 30 | 31 | # Download script/URL (optional) --------------------------------------------------------------------------------------- 32 | download: | 33 | from utils.general import download, Path 34 | 35 | 36 | # Download 37 | dir = Path(yaml['path']) # dataset root dir 38 | urls = ['https://zenodo.org/record/4298502/files/global-wheat-codalab-official.zip', 39 | 'https://github.com/ultralytics/yolov5/releases/download/v1.0/GlobalWheat2020_labels.zip'] 40 | download(urls, dir=dir) 41 | 42 | # Make Directories 43 | for p in 'annotations', 'images', 'labels': 44 | (dir / p).mkdir(parents=True, exist_ok=True) 45 | 46 | # Move 47 | for p in 'arvalis_1', 'arvalis_2', 'arvalis_3', 'ethz_1', 'rres_1', 'inrae_1', 'usask_1', \ 48 | 'utokyo_1', 'utokyo_2', 'nau_1', 'uq_1': 49 | (dir / p).rename(dir / 'images' / p) # move to /images 50 | f = (dir / p).with_suffix('.json') # json file 51 | if f.exists(): 52 | f.rename((dir / 'annotations' / p).with_suffix('.json')) # move to /annotations 53 | -------------------------------------------------------------------------------- /vit/configs/_base_/models/retinanet_r50_fpn.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | model = dict( 3 | type="RetinaNet", 4 | backbone=dict( 5 | type="ResNet", 6 | depth=50, 7 | num_stages=4, 8 | out_indices=(0, 1, 2, 3), 9 | frozen_stages=1, 10 | norm_cfg=dict(type="BN", requires_grad=True), 11 | norm_eval=True, 12 | style="pytorch", 13 | init_cfg=dict(type="Pretrained", checkpoint="torchvision://resnet50"), 14 | ), 15 | neck=dict( 16 | type="FPN", 17 | in_channels=[256, 512, 1024, 2048], 18 | out_channels=256, 19 | start_level=1, 20 | add_extra_convs="on_input", 21 | num_outs=5, 22 | ), 23 | bbox_head=dict( 24 | type="RetinaHead", 25 | num_classes=80, 26 | in_channels=256, 27 | stacked_convs=4, 28 | feat_channels=256, 29 | anchor_generator=dict( 30 | type="AnchorGenerator", 31 | octave_base_scale=4, 32 | scales_per_octave=3, 33 | ratios=[0.5, 1.0, 2.0], 34 | strides=[8, 16, 32, 64, 128], 35 | ), 36 | bbox_coder=dict( 37 | type="DeltaXYWHBBoxCoder", 38 | target_means=[0.0, 0.0, 0.0, 0.0], 39 | target_stds=[1.0, 1.0, 1.0, 1.0], 40 | ), 41 | loss_cls=dict( 42 | type="FocalLoss", use_sigmoid=True, gamma=2.0, alpha=0.25, loss_weight=1.0 43 | ), 44 | loss_bbox=dict(type="L1Loss", loss_weight=1.0), 45 | ), 46 | # model training and testing settings 47 | train_cfg=dict( 48 | assigner=dict( 49 | type="MaxIoUAssigner", 50 | pos_iou_thr=0.5, 51 | neg_iou_thr=0.4, 52 | min_pos_iou=0, 53 | ignore_iof_thr=-1, 54 | ), 55 | allowed_border=-1, 56 | pos_weight=-1, 57 | debug=False, 58 | ), 59 | test_cfg=dict( 60 | nms_pre=1000, 61 | min_bbox_size=0, 62 | score_thr=0.05, 63 | nms=dict(type="nms", iou_threshold=0.5), 64 | max_per_img=100, 65 | ), 66 | ) 67 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5l6.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [19, 27, 44, 40, 38, 94] # P3/8 9 | - [96, 68, 86, 152, 180, 137] # P4/16 10 | - [140, 301, 303, 264, 238, 542] # P5/32 11 | - [436, 615, 739, 380, 925, 792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [ 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, anchors]], # Detect(P3, P4, P5, P6) 61 | ] 62 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5m6.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # model depth multiple 6 | width_multiple: 0.75 # layer channel multiple 7 | anchors: 8 | - [19, 27, 44, 40, 38, 94] # P3/8 9 | - [96, 68, 86, 152, 180, 137] # P4/16 10 | - [140, 301, 303, 264, 238, 542] # P5/32 11 | - [436, 615, 739, 380, 925, 792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [ 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, anchors]], # Detect(P3, P4, P5, P6) 61 | ] 62 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5n6.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.25 # layer channel multiple 7 | anchors: 8 | - [19, 27, 44, 40, 38, 94] # P3/8 9 | - [96, 68, 86, 152, 180, 137] # P4/16 10 | - [140, 301, 303, 264, 238, 542] # P5/32 11 | - [436, 615, 739, 380, 925, 792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [ 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, anchors]], # Detect(P3, P4, P5, P6) 61 | ] 62 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5s6.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [19, 27, 44, 40, 38, 94] # P3/8 9 | - [96, 68, 86, 152, 180, 137] # P4/16 10 | - [140, 301, 303, 264, 238, 542] # P5/32 11 | - [436, 615, 739, 380, 925, 792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [ 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, anchors]], # Detect(P3, P4, P5, P6) 61 | ] 62 | -------------------------------------------------------------------------------- /yolov5/models/hub/yolov5x6.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.33 # model depth multiple 6 | width_multiple: 1.25 # layer channel multiple 7 | anchors: 8 | - [19, 27, 44, 40, 38, 94] # P3/8 9 | - [96, 68, 86, 152, 180, 137] # P4/16 10 | - [140, 301, 303, 264, 238, 542] # P5/32 11 | - [436, 615, 739, 380, 925, 792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [ 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, anchors]], # Detect(P3, P4, P5, P6) 61 | ] 62 | -------------------------------------------------------------------------------- /yolo11/quant/dist_kd.py: -------------------------------------------------------------------------------- 1 | """copy from https://github.com/hunto/image_classification_sota/blob/d9662f7df68fe46b973c4580b7c9b896cedcd301/lib/models/losses/dist_kd.py""" 2 | 3 | import torch.nn as nn 4 | import torch 5 | 6 | 7 | def cosine_similarity(a, b, eps=1e-8): 8 | return (a * b).sum(1) / (a.norm(dim=1) * b.norm(dim=1) + eps) 9 | 10 | 11 | def pearson_correlation(a, b, eps=1e-8): 12 | return cosine_similarity( 13 | a - a.mean(1).unsqueeze(1), b - b.mean(1).unsqueeze(1), eps 14 | ) 15 | 16 | 17 | def inter_class_relation(y_s, y_t): 18 | return 1 - pearson_correlation(y_s, y_t).mean() 19 | 20 | 21 | def intra_class_relation(y_s, y_t): 22 | return inter_class_relation(y_s.transpose(0, 1), y_t.transpose(0, 1)) 23 | 24 | 25 | class DIST(nn.Module): 26 | """Knowledge Distillation From A Stronger Teacher 27 | 28 | https://arxiv.org/abs/2205.10536 29 | 30 | """ 31 | def __init__(self, beta=1.0, gamma=1.0, tau=1.0): 32 | """Create a DIST function 33 | 34 | Parameters 35 | ---------- 36 | beta : float, optional 37 | gamma : float, optional 38 | tau : float, optional 39 | """ 40 | super(DIST, self).__init__() 41 | self.beta = beta 42 | self.gamma = gamma 43 | self.tau = tau 44 | 45 | def forward(self, preds_S, preds_T): 46 | assert len(preds_S) == len(preds_T) 47 | dLoss = [] 48 | dLoss_items = [] 49 | for branchS, branchT in zip(preds_S, preds_T): 50 | y_s = (branchS / self.tau).softmax(dim=1) 51 | y_t = (branchT / self.tau).softmax(dim=1) 52 | inter_loss = self.tau**2 * inter_class_relation(y_s, y_t) 53 | intra_loss = self.tau**2 * intra_class_relation(y_s, y_t) 54 | kd_loss = self.beta * inter_loss + self.gamma * intra_loss 55 | dLoss.append(kd_loss) 56 | dLoss_items.append(kd_loss) 57 | dLoss = sum(dLoss) / len(dLoss) 58 | dLoss_items.append(dLoss) 59 | dLoss_items = torch.tensor(dLoss_items).to(dLoss.device) 60 | return dLoss, dLoss_items.detach() 61 | -------------------------------------------------------------------------------- /resnet/plot_curve.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import matplotlib.pyplot as plt 3 | 4 | 5 | def plot_loss_and_lr(train_loss, learning_rate, save_dir=None): 6 | try: 7 | x = list(range(len(train_loss))) 8 | fig, ax1 = plt.subplots(1, 1) 9 | ax1.plot(x, train_loss, "r", label="loss") 10 | ax1.set_xlabel("step") 11 | ax1.set_ylabel("loss") 12 | ax1.set_title("Train Loss and lr") 13 | plt.legend(loc="best") 14 | 15 | ax2 = ax1.twinx() 16 | ax2.plot(x, learning_rate, label="lr") 17 | ax2.set_ylabel("learning rate") 18 | ax2.set_xlim(0, len(train_loss)) # 设置横坐标整数间隔 19 | plt.legend(loc="best") 20 | 21 | handles1, labels1 = ax1.get_legend_handles_labels() 22 | handles2, labels2 = ax2.get_legend_handles_labels() 23 | plt.legend(handles1 + handles2, labels1 + labels2, loc="upper right") 24 | 25 | fig.subplots_adjust(right=0.8) # 防止出现保存图片显示不全的情况 26 | if save_dir is not None: 27 | fig.savefig( 28 | "{}/loss_and_lr{}.png".format( 29 | save_dir, datetime.datetime.now().strftime("%Y%m%d-%H%M%S") 30 | ) 31 | ) 32 | else: 33 | fig.savefig( 34 | "./loss_and_lr{}.png".format( 35 | datetime.datetime.now().strftime("%Y%m%d-%H%M%S") 36 | ) 37 | ) 38 | plt.close() 39 | print("successful save loss curve! ") 40 | except Exception as e: 41 | print(e) 42 | 43 | 44 | def plot_map(mAP, save_dir=None): 45 | try: 46 | x = list(range(len(mAP))) 47 | plt.plot(x, mAP, label="mAp") 48 | plt.xlabel("epoch") 49 | plt.ylabel("mAP") 50 | plt.title("Eval mAP") 51 | plt.xlim(0, len(mAP)) 52 | plt.legend(loc="best") 53 | if save_dir is not None: 54 | plt.savefig("{}/mAP.png".format(save_dir)) 55 | else: 56 | plt.savefig("./mAP.png") 57 | plt.close() 58 | print("successful save mAP curve!") 59 | except Exception as e: 60 | print(e) 61 | -------------------------------------------------------------------------------- /vit/configs/_base_/models/rpn_r50_fpn.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | model = dict( 3 | type="RPN", 4 | backbone=dict( 5 | type="ResNet", 6 | depth=50, 7 | num_stages=4, 8 | out_indices=(0, 1, 2, 3), 9 | frozen_stages=1, 10 | norm_cfg=dict(type="BN", requires_grad=True), 11 | norm_eval=True, 12 | style="pytorch", 13 | init_cfg=dict(type="Pretrained", checkpoint="torchvision://resnet50"), 14 | ), 15 | neck=dict( 16 | type="FPN", in_channels=[256, 512, 1024, 2048], out_channels=256, num_outs=5 17 | ), 18 | rpn_head=dict( 19 | type="RPNHead", 20 | in_channels=256, 21 | feat_channels=256, 22 | anchor_generator=dict( 23 | type="AnchorGenerator", 24 | scales=[8], 25 | ratios=[0.5, 1.0, 2.0], 26 | strides=[4, 8, 16, 32, 64], 27 | ), 28 | bbox_coder=dict( 29 | type="DeltaXYWHBBoxCoder", 30 | target_means=[0.0, 0.0, 0.0, 0.0], 31 | target_stds=[1.0, 1.0, 1.0, 1.0], 32 | ), 33 | loss_cls=dict(type="CrossEntropyLoss", use_sigmoid=True, loss_weight=1.0), 34 | loss_bbox=dict(type="L1Loss", loss_weight=1.0), 35 | ), 36 | # model training and testing settings 37 | train_cfg=dict( 38 | rpn=dict( 39 | assigner=dict( 40 | type="MaxIoUAssigner", 41 | pos_iou_thr=0.7, 42 | neg_iou_thr=0.3, 43 | min_pos_iou=0.3, 44 | ignore_iof_thr=-1, 45 | ), 46 | sampler=dict( 47 | type="RandomSampler", 48 | num=256, 49 | pos_fraction=0.5, 50 | neg_pos_ub=-1, 51 | add_gt_as_proposals=False, 52 | ), 53 | allowed_border=0, 54 | pos_weight=-1, 55 | debug=False, 56 | ) 57 | ), 58 | test_cfg=dict( 59 | rpn=dict( 60 | nms_pre=2000, 61 | max_per_img=1000, 62 | nms=dict(type="nms", iou_threshold=0.7), 63 | min_bbox_size=0, 64 | ) 65 | ), 66 | ) 67 | -------------------------------------------------------------------------------- /vit/configs/_base_/models/rpn_r50_caffe_c4.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | model = dict( 3 | type="RPN", 4 | backbone=dict( 5 | type="ResNet", 6 | depth=50, 7 | num_stages=3, 8 | strides=(1, 2, 2), 9 | dilations=(1, 1, 1), 10 | out_indices=(2,), 11 | frozen_stages=1, 12 | norm_cfg=dict(type="BN", requires_grad=False), 13 | norm_eval=True, 14 | style="caffe", 15 | init_cfg=dict( 16 | type="Pretrained", checkpoint="open-mmlab://detectron2/resnet50_caffe" 17 | ), 18 | ), 19 | neck=None, 20 | rpn_head=dict( 21 | type="RPNHead", 22 | in_channels=1024, 23 | feat_channels=1024, 24 | anchor_generator=dict( 25 | type="AnchorGenerator", 26 | scales=[2, 4, 8, 16, 32], 27 | ratios=[0.5, 1.0, 2.0], 28 | strides=[16], 29 | ), 30 | bbox_coder=dict( 31 | type="DeltaXYWHBBoxCoder", 32 | target_means=[0.0, 0.0, 0.0, 0.0], 33 | target_stds=[1.0, 1.0, 1.0, 1.0], 34 | ), 35 | loss_cls=dict(type="CrossEntropyLoss", use_sigmoid=True, loss_weight=1.0), 36 | loss_bbox=dict(type="L1Loss", loss_weight=1.0), 37 | ), 38 | # model training and testing settings 39 | train_cfg=dict( 40 | rpn=dict( 41 | assigner=dict( 42 | type="MaxIoUAssigner", 43 | pos_iou_thr=0.7, 44 | neg_iou_thr=0.3, 45 | min_pos_iou=0.3, 46 | ignore_iof_thr=-1, 47 | ), 48 | sampler=dict( 49 | type="RandomSampler", 50 | num=256, 51 | pos_fraction=0.5, 52 | neg_pos_ub=-1, 53 | add_gt_as_proposals=False, 54 | ), 55 | allowed_border=0, 56 | pos_weight=-1, 57 | debug=False, 58 | ) 59 | ), 60 | test_cfg=dict( 61 | rpn=dict( 62 | nms_pre=12000, 63 | max_per_img=2000, 64 | nms=dict(type="nms", iou_threshold=0.7), 65 | min_bbox_size=0, 66 | ) 67 | ), 68 | ) 69 | -------------------------------------------------------------------------------- /resnet/coco91_indices.json: -------------------------------------------------------------------------------- 1 | { 2 | "1": "person", 3 | "2": "bicycle", 4 | "3": "car", 5 | "4": "motorcycle", 6 | "5": "airplane", 7 | "6": "bus", 8 | "7": "train", 9 | "8": "truck", 10 | "9": "boat", 11 | "10": "traffic light", 12 | "11": "fire hydrant", 13 | "12": "N/A", 14 | "13": "stop sign", 15 | "14": "parking meter", 16 | "15": "bench", 17 | "16": "bird", 18 | "17": "cat", 19 | "18": "dog", 20 | "19": "horse", 21 | "20": "sheep", 22 | "21": "cow", 23 | "22": "elephant", 24 | "23": "bear", 25 | "24": "zebra", 26 | "25": "giraffe", 27 | "26": "N/A", 28 | "27": "backpack", 29 | "28": "umbrella", 30 | "29": "N/A", 31 | "30": "N/A", 32 | "31": "handbag", 33 | "32": "tie", 34 | "33": "suitcase", 35 | "34": "frisbee", 36 | "35": "skis", 37 | "36": "snowboard", 38 | "37": "sports ball", 39 | "38": "kite", 40 | "39": "baseball bat", 41 | "40": "baseball glove", 42 | "41": "skateboard", 43 | "42": "surfboard", 44 | "43": "tennis racket", 45 | "44": "bottle", 46 | "45": "N/A", 47 | "46": "wine glass", 48 | "47": "cup", 49 | "48": "fork", 50 | "49": "knife", 51 | "50": "spoon", 52 | "51": "bowl", 53 | "52": "banana", 54 | "53": "apple", 55 | "54": "sandwich", 56 | "55": "orange", 57 | "56": "broccoli", 58 | "57": "carrot", 59 | "58": "hot dog", 60 | "59": "pizza", 61 | "60": "donut", 62 | "61": "cake", 63 | "62": "chair", 64 | "63": "couch", 65 | "64": "potted plant", 66 | "65": "bed", 67 | "66": "N/A", 68 | "67": "dining table", 69 | "68": "N/A", 70 | "69": "N/A", 71 | "70": "toilet", 72 | "71": "N/A", 73 | "72": "tv", 74 | "73": "laptop", 75 | "74": "mouse", 76 | "75": "remote", 77 | "76": "keyboard", 78 | "77": "cell phone", 79 | "78": "microwave", 80 | "79": "oven", 81 | "80": "toaster", 82 | "81": "sink", 83 | "82": "refrigerator", 84 | "83": "N/A", 85 | "84": "book", 86 | "85": "clock", 87 | "86": "vase", 88 | "87": "scissors", 89 | "88": "teddy bear", 90 | "89": "hair drier", 91 | "90": "toothbrush" 92 | } -------------------------------------------------------------------------------- /yolov5/data/coco128.yaml: -------------------------------------------------------------------------------- 1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license 2 | # COCO128 dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics 3 | # Example usage: python train.py --data coco128.yaml 4 | # parent 5 | # ├── yolov5 6 | # └── datasets 7 | # └── coco128 ← downloads here (7 MB) 8 | 9 | # 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, ..] 10 | path: ../datasets/coco128 # dataset root dir 11 | train: images/train2017 # train images (relative to 'path') 128 images 12 | val: images/train2017 # val images (relative to 'path') 128 images 13 | test: # test images (optional) 14 | 15 | # Classes 16 | names: 17 | 0: person 18 | 1: bicycle 19 | 2: car 20 | 3: motorcycle 21 | 4: airplane 22 | 5: bus 23 | 6: train 24 | 7: truck 25 | 8: boat 26 | 9: traffic light 27 | 10: fire hydrant 28 | 11: stop sign 29 | 12: parking meter 30 | 13: bench 31 | 14: bird 32 | 15: cat 33 | 16: dog 34 | 17: horse 35 | 18: sheep 36 | 19: cow 37 | 20: elephant 38 | 21: bear 39 | 22: zebra 40 | 23: giraffe 41 | 24: backpack 42 | 25: umbrella 43 | 26: handbag 44 | 27: tie 45 | 28: suitcase 46 | 29: frisbee 47 | 30: skis 48 | 31: snowboard 49 | 32: sports ball 50 | 33: kite 51 | 34: baseball bat 52 | 35: baseball glove 53 | 36: skateboard 54 | 37: surfboard 55 | 38: tennis racket 56 | 39: bottle 57 | 40: wine glass 58 | 41: cup 59 | 42: fork 60 | 43: knife 61 | 44: spoon 62 | 45: bowl 63 | 46: banana 64 | 47: apple 65 | 48: sandwich 66 | 49: orange 67 | 50: broccoli 68 | 51: carrot 69 | 52: hot dog 70 | 53: pizza 71 | 54: donut 72 | 55: cake 73 | 56: chair 74 | 57: couch 75 | 58: potted plant 76 | 59: bed 77 | 60: dining table 78 | 61: toilet 79 | 62: tv 80 | 63: laptop 81 | 64: mouse 82 | 65: remote 83 | 66: keyboard 84 | 67: cell phone 85 | 68: microwave 86 | 69: oven 87 | 70: toaster 88 | 71: sink 89 | 72: refrigerator 90 | 73: book 91 | 74: clock 92 | 75: vase 93 | 76: scissors 94 | 77: teddy bear 95 | 78: hair drier 96 | 79: toothbrush 97 | 98 | # Download script/URL (optional) 99 | download: https://ultralytics.com/assets/coco128.zip 100 | --------------------------------------------------------------------------------