├── .gitignore ├── LICENSE.md ├── README.md ├── cfg ├── baseline │ ├── r50-csp.yaml │ ├── x50-csp.yaml │ ├── yolor-csp-x.yaml │ ├── yolor-csp.yaml │ ├── yolor-d6.yaml │ ├── yolor-e6.yaml │ ├── yolor-p6.yaml │ ├── yolor-w6.yaml │ ├── yolov3-spp.yaml │ ├── yolov3.yaml │ └── yolov4-csp.yaml ├── deploy │ ├── yolov7-d6.yaml │ ├── yolov7-e6.yaml │ ├── yolov7-e6e.yaml │ ├── yolov7-tiny-silu.yaml │ ├── yolov7-tiny.yaml │ ├── yolov7-w6.yaml │ ├── yolov7.yaml │ ├── yolov7_score.yaml │ └── yolov7x.yaml └── training │ ├── yolov7-tiny.yaml │ ├── yolov7.yaml │ ├── yolov7_score.yaml │ ├── yolov7d6.yaml │ ├── yolov7e6.yaml │ ├── yolov7e6e.yaml │ ├── yolov7w6.yaml │ └── yolov7x.yaml ├── data ├── coco.yaml ├── hyp.scratch.p5.yaml ├── hyp.scratch.p6.yaml ├── hyp.scratch.tiny.yaml └── score.yaml ├── dataset └── score │ ├── 01_check_img.py │ ├── 02_check_box.py │ ├── 03_train_val_split.py │ ├── 04_myData_label.py │ └── 05_copy_img.py ├── detect.py ├── figure ├── image1.jpg ├── image1_trt.jpg ├── image2.jpg ├── image2_trt.jpg ├── image3.jpg ├── image3_trt.jpg ├── onnx.png ├── onnx_0.png ├── onnx_1.png └── performance.png ├── hubconf.py ├── inference.py ├── inference └── images │ └── horses.jpg ├── models ├── __init__.py ├── common.py ├── experimental.py ├── export.py └── yolo.py ├── requirements.txt ├── scripts └── get_coco.sh ├── tensorrt ├── logging.h ├── yolov7.cpp ├── yolov7_add_nms.py └── yolov7_add_postprocess.py ├── test.py ├── test_img ├── image1.jpg ├── image2.jpg └── image3.jpg ├── train.py └── utils ├── __init__.py ├── activations.py ├── autoanchor.py ├── aws ├── __init__.py ├── mime.sh ├── resume.py └── userdata.sh ├── datasets.py ├── general.py ├── google_app_engine ├── Dockerfile ├── additional_requirements.txt └── app.yaml ├── google_utils.py ├── loss.py ├── metrics.py ├── plots.py ├── torch_utils.py └── wandb_logging ├── __init__.py ├── log_dataset.py └── wandb_utils.py /.gitignore: -------------------------------------------------------------------------------- 1 | tensorrt/yolov7/.vs 2 | .vs -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Official YOLOv7 训练自己的数据集(端到端TensorRT 模型部署) 2 | 3 | 目前适用的版本: `v0.1` 4 | 5 | > 我只能说太卷了! 6 | 7 | Implementation of paper - [YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors](https://arxiv.org/abs/2207.02696) 8 | 9 | 10 | 11 | 12 | #### Performance 13 | 14 | MS COCO 15 | 16 | | Model | Test Size | APtest | AP50test | AP75test | batch 1 fps | batch 32 average time | 17 | | :-- | :-: | :-: | :-: | :-: | :-: | :-: | 18 | | [**YOLOv7**](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt) | 640 | **51.4%** | **69.7%** | **55.9%** | 161 *fps* | 2.8 *ms* | 19 | | [**YOLOv7-X**](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7x.pt) | 640 | **53.1%** | **71.2%** | **57.8%** | 114 *fps* | 4.3 *ms* | 20 | | | | | | | | | 21 | | [**YOLOv7-W6**](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-w6.pt) | 1280 | **54.9%** | **72.6%** | **60.1%** | 84 *fps* | 7.6 *ms* | 22 | | [**YOLOv7-E6**](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-e6.pt) | 1280 | **56.0%** | **73.5%** | **61.2%** | 56 *fps* | 12.3 *ms* | 23 | | [**YOLOv7-D6**](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-d6.pt) | 1280 | **56.6%** | **74.0%** | **61.8%** | 44 *fps* | 15.0 *ms* | 24 | | [**YOLOv7-E6E**](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-e6e.pt) | 1280 | **56.8%** | **74.4%** | **62.1%** | 36 *fps* | 18.7 *ms* | 25 | 26 | ### 1.训练环境配置 27 | 28 | ```shell 29 | 30 | # create the docker container, you can change the share memory size if you have more. # 注意这个share memory尽量设置的大一点,训练的话! 31 | sudo nvidia-docker run --name yolov7 -it -v /home/myuser/xujing/hackathon2022:/yolov7 --shm-size=64g nvcr.io/nvidia/pytorch:21.08-py3 32 | 33 | # apt install required packages 34 | apt update 35 | apt install -y zip htop screen libgl1-mesa-glx 36 | 37 | # pip install required packages 38 | pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ 39 | 40 | # go to code folder 41 | cd /yolov7 42 | ``` 43 | 44 | 45 | ### 2.训练集准备 46 | 47 | YOLOv7类似于YOLOR支持YOLOv5类型的标注数据构建,如果你熟悉YOLOv5的训练集的构造过程,该部分可以直接跳过,这里我们提供了构建数据集的代码,将数据集存放在`./dataset`下: 48 | 49 | ```shell 50 | ./datasets/score # 存放的文件,score是数据集的名称 51 | ├─images # 训练图像,每个文件夹下存放了具体的训练图像 52 | │ ├─train 53 | │ └─val 54 | └─labels # label,每个文件夹下存放了具体的txt标注文件,格式满足YOLOv5 55 | ├─train 56 | └─val 57 | ``` 58 | 59 | 我们提供了VOC标注数据格式转换为YOLOv5标注的具体代码,存放在`./dataset`下,关于YOLOv5的标注细节可以参考: 60 | + https://github.com/DataXujing/YOLO-v5 61 | + https://github.com/DataXujing/YOLOv6#2%E6%95%B0%E6%8D%AE%E5%87%86%E5%A4%87 62 | 63 | 64 | ### 3.模型结构或配置文件修改 65 | 66 | + 1.修改模型的配置文件 67 | 68 | i.训练数据的配置:`./data/score.yaml` 69 | 70 | ```shell 71 | train: ./dataset/score/images/train # train images 72 | val: ./dataset/score/images/val # val images 73 | #test: ./dataset/score/images/test # test images (optional) 74 | 75 | # Classes 76 | nc: 4 # number of classes 77 | names: ['person','cat','dog','horse'] # class names 78 | ``` 79 | 80 | ii.模型结构的配置:`./cfg/training/yolov7_score.yaml` 81 | 82 | ```shell 83 | # parameters 84 | nc: 4 # number of classes 85 | depth_multiple: 1.0 # model depth multiple 86 | width_multiple: 1.0 # layer channel multiple 87 | 88 | # anchors 89 | anchors: 90 | - [12,16, 19,36, 40,28] # P3/8 91 | - [36,75, 76,55, 72,146] # P4/16 92 | - [142,110, 192,243, 459,401] # P5/32 93 | 94 | ... 95 | 96 | ``` 97 | 98 | 99 | ### 4.模型训练 100 | 101 | ```shell 102 | python3 train.py --workers 8 --device 0 --batch-size 32 --data data/score.yaml --img 640 640 --cfg cfg/training/yolov7_score.yaml --weights '' --name yolov7 --hyp data/hyp.scratch.p5.yaml 103 | 104 | # 一机多卡 105 | python3 -m torch.distributed.launch --nproc_per_node 4 --master_port 9527 train.py --workers 8 --device 0,1,2,3 --sync-bn --batch-size 128 --data data/score.yaml --img 640 640 --cfg cfg/training/yolov7_score.yaml --weights '' --name yolov7 --hyp data/hyp.scratch.p5.yaml 106 | 107 | ``` 108 | 109 | 110 | ### 5.模型评估 111 | 112 | ```shell 113 | python3 test.py --data data/score.yaml --img 640 --batch 32 --conf 0.001 --iou 0.45 --device 0 --weights ./runs/train/yolov7/weights/last.pt --name yolov7_640_val 114 | 115 | ``` 116 | 117 | ### 6.模型推断 118 | 119 | ```shell 120 | python3 inference.py 121 | 122 | ``` 123 | 124 | 推断效果如下: 125 | 126 |
127 | 128 | | | | | 129 | | :-----------------------------: | :------------------------------: | :------------------------------: | 130 | | | | | 131 | 132 |
133 | 134 | 135 | 136 | ### 7.TensorRT 模型加速 137 | 138 | 我们实现了端到端的TensorRT模型加速,将NMS通过Plugin放入TensorRT Engine中。 139 | 140 | 1. YOLOv7转ONNX 141 | 142 | 注意:如果直接转ONNX会出现`scatterND`节点,可以做如下修改 143 | 144 |
145 | 146 |
147 | 148 | ```shell 149 | python3 ./models/export.py --weights ./runs/train/yolov7/weights/last.pt --img-size 640 640 --grid 150 | 151 | ``` 152 | 153 |
154 | 155 |
156 | 157 | 1. YOLOv7的前处理 158 | 159 | YOLOv6, YOLOv7的前处理和YOLOv5是相同的。 160 | 161 | 其C++的实现如下: 162 | 163 | ```c++ 164 | void preprocess(cv::Mat& img, float data[]) { 165 | int w, h, x, y; 166 | float r_w = INPUT_W / (img.cols*1.0); 167 | float r_h = INPUT_H / (img.rows*1.0); 168 | if (r_h > r_w) { 169 | w = INPUT_W; 170 | h = r_w * img.rows; 171 | x = 0; 172 | y = (INPUT_H - h) / 2; 173 | } 174 | else { 175 | w = r_h * img.cols; 176 | h = INPUT_H; 177 | x = (INPUT_W - w) / 2; 178 | y = 0; 179 | } 180 | cv::Mat re(h, w, CV_8UC3); 181 | cv::resize(img, re, re.size(), 0, 0, cv::INTER_LINEAR); 182 | //cudaResize(img, re); 183 | cv::Mat out(INPUT_H, INPUT_W, CV_8UC3, cv::Scalar(114, 114, 114)); 184 | re.copyTo(out(cv::Rect(x, y, re.cols, re.rows))); 185 | 186 | int i = 0; 187 | for (int row = 0; row < INPUT_H; ++row) { 188 | uchar* uc_pixel = out.data + row * out.step; 189 | for (int col = 0; col < INPUT_W; ++col) { 190 | data[i] = (float)uc_pixel[2] / 255.0; 191 | data[i + INPUT_H * INPUT_W] = (float)uc_pixel[1] / 255.0; 192 | data[i + 2 * INPUT_H * INPUT_W] = (float)uc_pixel[0] / 255.0; 193 | uc_pixel += 3; 194 | ++i; 195 | } 196 | } 197 | 198 | } 199 | 200 | ``` 201 | 202 | 203 | 3. YOLOv7的后处理 204 | 205 | 不难发现,YOLOv5, YOLOv6, YOLOv7的后处理基本是完全相同的,TensorRT后处理的代码基本可以复用 206 | 207 | 增加后处理和NMS节点: 208 | 209 | ```shell 210 | 211 | python tensorrt/yolov7_add_postprocess.py 212 | python tensorrt/yolov7_add_nms.py 213 | 214 | ``` 215 | 216 | onnx中增加了如下节点: 217 | 218 |
219 | 220 |
221 | 222 | 223 | 4. TRT序列化Engine 224 | 225 | ```shell 226 | trtexec --onnx=last_1_nms.onnx --saveEngine=yolov7.engine --workspace=3000 --verbose 227 | ``` 228 | 229 | 5. `VS2017`下编译运行`./tensorrt/yolov7` 230 | 231 | 232 | 233 |
234 | 235 | | | | | 236 | | :-----------------------------: | :------------------------------: | :------------------------------: | 237 | | | | | 238 | 239 |
240 | 241 | 242 | -------------------------------------------------------------------------------- /cfg/baseline/r50-csp.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 7 | anchors: 8 | - [12,16, 19,36, 40,28] # P3/8 9 | - [36,75, 76,55, 72,146] # P4/16 10 | - [142,110, 192,243, 459,401] # P5/32 11 | 12 | # CSP-ResNet backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Stem, [128]], # 0-P1/2 16 | [-1, 3, ResCSPC, [128]], 17 | [-1, 1, Conv, [256, 3, 2]], # 2-P3/8 18 | [-1, 4, ResCSPC, [256]], 19 | [-1, 1, Conv, [512, 3, 2]], # 4-P3/8 20 | [-1, 6, ResCSPC, [512]], 21 | [-1, 1, Conv, [1024, 3, 2]], # 6-P3/8 22 | [-1, 3, ResCSPC, [1024]], # 7 23 | ] 24 | 25 | # CSP-Res-PAN head 26 | head: 27 | [[-1, 1, SPPCSPC, [512]], # 8 28 | [-1, 1, Conv, [256, 1, 1]], 29 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 30 | [5, 1, Conv, [256, 1, 1]], # route backbone P4 31 | [[-1, -2], 1, Concat, [1]], 32 | [-1, 2, ResCSPB, [256]], # 13 33 | [-1, 1, Conv, [128, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 35 | [3, 1, Conv, [128, 1, 1]], # route backbone P3 36 | [[-1, -2], 1, Concat, [1]], 37 | [-1, 2, ResCSPB, [128]], # 18 38 | [-1, 1, Conv, [256, 3, 1]], 39 | [-2, 1, Conv, [256, 3, 2]], 40 | [[-1, 13], 1, Concat, [1]], # cat 41 | [-1, 2, ResCSPB, [256]], # 22 42 | [-1, 1, Conv, [512, 3, 1]], 43 | [-2, 1, Conv, [512, 3, 2]], 44 | [[-1, 8], 1, Concat, [1]], # cat 45 | [-1, 2, ResCSPB, [512]], # 26 46 | [-1, 1, Conv, [1024, 3, 1]], 47 | 48 | [[19,23,27], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /cfg/baseline/x50-csp.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 7 | anchors: 8 | - [12,16, 19,36, 40,28] # P3/8 9 | - [36,75, 76,55, 72,146] # P4/16 10 | - [142,110, 192,243, 459,401] # P5/32 11 | 12 | # CSP-ResNeXt backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Stem, [128]], # 0-P1/2 16 | [-1, 3, ResXCSPC, [128]], 17 | [-1, 1, Conv, [256, 3, 2]], # 2-P3/8 18 | [-1, 4, ResXCSPC, [256]], 19 | [-1, 1, Conv, [512, 3, 2]], # 4-P3/8 20 | [-1, 6, ResXCSPC, [512]], 21 | [-1, 1, Conv, [1024, 3, 2]], # 6-P3/8 22 | [-1, 3, ResXCSPC, [1024]], # 7 23 | ] 24 | 25 | # CSP-ResX-PAN head 26 | head: 27 | [[-1, 1, SPPCSPC, [512]], # 8 28 | [-1, 1, Conv, [256, 1, 1]], 29 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 30 | [5, 1, Conv, [256, 1, 1]], # route backbone P4 31 | [[-1, -2], 1, Concat, [1]], 32 | [-1, 2, ResXCSPB, [256]], # 13 33 | [-1, 1, Conv, [128, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 35 | [3, 1, Conv, [128, 1, 1]], # route backbone P3 36 | [[-1, -2], 1, Concat, [1]], 37 | [-1, 2, ResXCSPB, [128]], # 18 38 | [-1, 1, Conv, [256, 3, 1]], 39 | [-2, 1, Conv, [256, 3, 2]], 40 | [[-1, 13], 1, Concat, [1]], # cat 41 | [-1, 2, ResXCSPB, [256]], # 22 42 | [-1, 1, Conv, [512, 3, 1]], 43 | [-2, 1, Conv, [512, 3, 2]], 44 | [[-1, 8], 1, Concat, [1]], # cat 45 | [-1, 2, ResXCSPB, [512]], # 26 46 | [-1, 1, Conv, [1024, 3, 1]], 47 | 48 | [[19,23,27], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /cfg/baseline/yolor-csp-x.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.33 # model depth multiple 4 | width_multiple: 1.25 # layer channel multiple 5 | 6 | # anchors 7 | anchors: 8 | - [12,16, 19,36, 40,28] # P3/8 9 | - [36,75, 76,55, 72,146] # P4/16 10 | - [142,110, 192,243, 459,401] # P5/32 11 | 12 | # CSP-Darknet backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [32, 3, 1]], # 0 16 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 17 | [-1, 1, Bottleneck, [64]], 18 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 19 | [-1, 2, BottleneckCSPC, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8 21 | [-1, 8, BottleneckCSPC, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16 23 | [-1, 8, BottleneckCSPC, [512]], 24 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32 25 | [-1, 4, BottleneckCSPC, [1024]], # 10 26 | ] 27 | 28 | # CSP-Dark-PAN head 29 | head: 30 | [[-1, 1, SPPCSPC, [512]], # 11 31 | [-1, 1, Conv, [256, 1, 1]], 32 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 33 | [8, 1, Conv, [256, 1, 1]], # route backbone P4 34 | [[-1, -2], 1, Concat, [1]], 35 | [-1, 2, BottleneckCSPB, [256]], # 16 36 | [-1, 1, Conv, [128, 1, 1]], 37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 38 | [6, 1, Conv, [128, 1, 1]], # route backbone P3 39 | [[-1, -2], 1, Concat, [1]], 40 | [-1, 2, BottleneckCSPB, [128]], # 21 41 | [-1, 1, Conv, [256, 3, 1]], 42 | [-2, 1, Conv, [256, 3, 2]], 43 | [[-1, 16], 1, Concat, [1]], # cat 44 | [-1, 2, BottleneckCSPB, [256]], # 25 45 | [-1, 1, Conv, [512, 3, 1]], 46 | [-2, 1, Conv, [512, 3, 2]], 47 | [[-1, 11], 1, Concat, [1]], # cat 48 | [-1, 2, BottleneckCSPB, [512]], # 29 49 | [-1, 1, Conv, [1024, 3, 1]], 50 | 51 | [[22,26,30], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5) 52 | ] 53 | -------------------------------------------------------------------------------- /cfg/baseline/yolor-csp.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 7 | anchors: 8 | - [12,16, 19,36, 40,28] # P3/8 9 | - [36,75, 76,55, 72,146] # P4/16 10 | - [142,110, 192,243, 459,401] # P5/32 11 | 12 | # CSP-Darknet backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [32, 3, 1]], # 0 16 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 17 | [-1, 1, Bottleneck, [64]], 18 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 19 | [-1, 2, BottleneckCSPC, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8 21 | [-1, 8, BottleneckCSPC, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16 23 | [-1, 8, BottleneckCSPC, [512]], 24 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32 25 | [-1, 4, BottleneckCSPC, [1024]], # 10 26 | ] 27 | 28 | # CSP-Dark-PAN head 29 | head: 30 | [[-1, 1, SPPCSPC, [512]], # 11 31 | [-1, 1, Conv, [256, 1, 1]], 32 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 33 | [8, 1, Conv, [256, 1, 1]], # route backbone P4 34 | [[-1, -2], 1, Concat, [1]], 35 | [-1, 2, BottleneckCSPB, [256]], # 16 36 | [-1, 1, Conv, [128, 1, 1]], 37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 38 | [6, 1, Conv, [128, 1, 1]], # route backbone P3 39 | [[-1, -2], 1, Concat, [1]], 40 | [-1, 2, BottleneckCSPB, [128]], # 21 41 | [-1, 1, Conv, [256, 3, 1]], 42 | [-2, 1, Conv, [256, 3, 2]], 43 | [[-1, 16], 1, Concat, [1]], # cat 44 | [-1, 2, BottleneckCSPB, [256]], # 25 45 | [-1, 1, Conv, [512, 3, 1]], 46 | [-2, 1, Conv, [512, 3, 2]], 47 | [[-1, 11], 1, Concat, [1]], # cat 48 | [-1, 2, BottleneckCSPB, [512]], # 29 49 | [-1, 1, Conv, [1024, 3, 1]], 50 | 51 | [[22,26,30], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5) 52 | ] 53 | -------------------------------------------------------------------------------- /cfg/baseline/yolor-d6.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # expand model depth 4 | width_multiple: 1.25 # expand layer channels 5 | 6 | # anchors 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 | # CSP-Darknet backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [[-1, 1, ReOrg, []], # 0 17 | [-1, 1, Conv, [64, 3, 1]], # 1-P1/2 18 | [-1, 1, DownC, [128]], # 2-P2/4 19 | [-1, 3, BottleneckCSPA, [128]], 20 | [-1, 1, DownC, [256]], # 4-P3/8 21 | [-1, 15, BottleneckCSPA, [256]], 22 | [-1, 1, DownC, [512]], # 6-P4/16 23 | [-1, 15, BottleneckCSPA, [512]], 24 | [-1, 1, DownC, [768]], # 8-P5/32 25 | [-1, 7, BottleneckCSPA, [768]], 26 | [-1, 1, DownC, [1024]], # 10-P6/64 27 | [-1, 7, BottleneckCSPA, [1024]], # 11 28 | ] 29 | 30 | # CSP-Dark-PAN head 31 | head: 32 | [[-1, 1, SPPCSPC, [512]], # 12 33 | [-1, 1, Conv, [384, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 35 | [-6, 1, Conv, [384, 1, 1]], # route backbone P5 36 | [[-1, -2], 1, Concat, [1]], 37 | [-1, 3, BottleneckCSPB, [384]], # 17 38 | [-1, 1, Conv, [256, 1, 1]], 39 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 40 | [-13, 1, Conv, [256, 1, 1]], # route backbone P4 41 | [[-1, -2], 1, Concat, [1]], 42 | [-1, 3, BottleneckCSPB, [256]], # 22 43 | [-1, 1, Conv, [128, 1, 1]], 44 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 45 | [-20, 1, Conv, [128, 1, 1]], # route backbone P3 46 | [[-1, -2], 1, Concat, [1]], 47 | [-1, 3, BottleneckCSPB, [128]], # 27 48 | [-1, 1, Conv, [256, 3, 1]], 49 | [-2, 1, DownC, [256]], 50 | [[-1, 22], 1, Concat, [1]], # cat 51 | [-1, 3, BottleneckCSPB, [256]], # 31 52 | [-1, 1, Conv, [512, 3, 1]], 53 | [-2, 1, DownC, [384]], 54 | [[-1, 17], 1, Concat, [1]], # cat 55 | [-1, 3, BottleneckCSPB, [384]], # 35 56 | [-1, 1, Conv, [768, 3, 1]], 57 | [-2, 1, DownC, [512]], 58 | [[-1, 12], 1, Concat, [1]], # cat 59 | [-1, 3, BottleneckCSPB, [512]], # 39 60 | [-1, 1, Conv, [1024, 3, 1]], 61 | 62 | [[28,32,36,40], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5, P6) 63 | ] -------------------------------------------------------------------------------- /cfg/baseline/yolor-e6.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # expand model depth 4 | width_multiple: 1.25 # expand layer channels 5 | 6 | # anchors 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 | # CSP-Darknet backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [[-1, 1, ReOrg, []], # 0 17 | [-1, 1, Conv, [64, 3, 1]], # 1-P1/2 18 | [-1, 1, DownC, [128]], # 2-P2/4 19 | [-1, 3, BottleneckCSPA, [128]], 20 | [-1, 1, DownC, [256]], # 4-P3/8 21 | [-1, 7, BottleneckCSPA, [256]], 22 | [-1, 1, DownC, [512]], # 6-P4/16 23 | [-1, 7, BottleneckCSPA, [512]], 24 | [-1, 1, DownC, [768]], # 8-P5/32 25 | [-1, 3, BottleneckCSPA, [768]], 26 | [-1, 1, DownC, [1024]], # 10-P6/64 27 | [-1, 3, BottleneckCSPA, [1024]], # 11 28 | ] 29 | 30 | # CSP-Dark-PAN head 31 | head: 32 | [[-1, 1, SPPCSPC, [512]], # 12 33 | [-1, 1, Conv, [384, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 35 | [-6, 1, Conv, [384, 1, 1]], # route backbone P5 36 | [[-1, -2], 1, Concat, [1]], 37 | [-1, 3, BottleneckCSPB, [384]], # 17 38 | [-1, 1, Conv, [256, 1, 1]], 39 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 40 | [-13, 1, Conv, [256, 1, 1]], # route backbone P4 41 | [[-1, -2], 1, Concat, [1]], 42 | [-1, 3, BottleneckCSPB, [256]], # 22 43 | [-1, 1, Conv, [128, 1, 1]], 44 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 45 | [-20, 1, Conv, [128, 1, 1]], # route backbone P3 46 | [[-1, -2], 1, Concat, [1]], 47 | [-1, 3, BottleneckCSPB, [128]], # 27 48 | [-1, 1, Conv, [256, 3, 1]], 49 | [-2, 1, DownC, [256]], 50 | [[-1, 22], 1, Concat, [1]], # cat 51 | [-1, 3, BottleneckCSPB, [256]], # 31 52 | [-1, 1, Conv, [512, 3, 1]], 53 | [-2, 1, DownC, [384]], 54 | [[-1, 17], 1, Concat, [1]], # cat 55 | [-1, 3, BottleneckCSPB, [384]], # 35 56 | [-1, 1, Conv, [768, 3, 1]], 57 | [-2, 1, DownC, [512]], 58 | [[-1, 12], 1, Concat, [1]], # cat 59 | [-1, 3, BottleneckCSPB, [512]], # 39 60 | [-1, 1, Conv, [1024, 3, 1]], 61 | 62 | [[28,32,36,40], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5, P6) 63 | ] -------------------------------------------------------------------------------- /cfg/baseline/yolor-p6.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # expand model depth 4 | width_multiple: 1.0 # expand layer channels 5 | 6 | # anchors 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 | # CSP-Darknet backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [[-1, 1, ReOrg, []], # 0 17 | [-1, 1, Conv, [64, 3, 1]], # 1-P1/2 18 | [-1, 1, Conv, [128, 3, 2]], # 2-P2/4 19 | [-1, 3, BottleneckCSPA, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 4-P3/8 21 | [-1, 7, BottleneckCSPA, [256]], 22 | [-1, 1, Conv, [384, 3, 2]], # 6-P4/16 23 | [-1, 7, BottleneckCSPA, [384]], 24 | [-1, 1, Conv, [512, 3, 2]], # 8-P5/32 25 | [-1, 3, BottleneckCSPA, [512]], 26 | [-1, 1, Conv, [640, 3, 2]], # 10-P6/64 27 | [-1, 3, BottleneckCSPA, [640]], # 11 28 | ] 29 | 30 | # CSP-Dark-PAN head 31 | head: 32 | [[-1, 1, SPPCSPC, [320]], # 12 33 | [-1, 1, Conv, [256, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 35 | [-6, 1, Conv, [256, 1, 1]], # route backbone P5 36 | [[-1, -2], 1, Concat, [1]], 37 | [-1, 3, BottleneckCSPB, [256]], # 17 38 | [-1, 1, Conv, [192, 1, 1]], 39 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 40 | [-13, 1, Conv, [192, 1, 1]], # route backbone P4 41 | [[-1, -2], 1, Concat, [1]], 42 | [-1, 3, BottleneckCSPB, [192]], # 22 43 | [-1, 1, Conv, [128, 1, 1]], 44 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 45 | [-20, 1, Conv, [128, 1, 1]], # route backbone P3 46 | [[-1, -2], 1, Concat, [1]], 47 | [-1, 3, BottleneckCSPB, [128]], # 27 48 | [-1, 1, Conv, [256, 3, 1]], 49 | [-2, 1, Conv, [192, 3, 2]], 50 | [[-1, 22], 1, Concat, [1]], # cat 51 | [-1, 3, BottleneckCSPB, [192]], # 31 52 | [-1, 1, Conv, [384, 3, 1]], 53 | [-2, 1, Conv, [256, 3, 2]], 54 | [[-1, 17], 1, Concat, [1]], # cat 55 | [-1, 3, BottleneckCSPB, [256]], # 35 56 | [-1, 1, Conv, [512, 3, 1]], 57 | [-2, 1, Conv, [320, 3, 2]], 58 | [[-1, 12], 1, Concat, [1]], # cat 59 | [-1, 3, BottleneckCSPB, [320]], # 39 60 | [-1, 1, Conv, [640, 3, 1]], 61 | 62 | [[28,32,36,40], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5, P6) 63 | ] -------------------------------------------------------------------------------- /cfg/baseline/yolor-w6.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # expand model depth 4 | width_multiple: 1.0 # expand layer channels 5 | 6 | # anchors 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 | # CSP-Darknet backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [[-1, 1, ReOrg, []], # 0 17 | [-1, 1, Conv, [64, 3, 1]], # 1-P1/2 18 | [-1, 1, Conv, [128, 3, 2]], # 2-P2/4 19 | [-1, 3, BottleneckCSPA, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 4-P3/8 21 | [-1, 7, BottleneckCSPA, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 6-P4/16 23 | [-1, 7, BottleneckCSPA, [512]], 24 | [-1, 1, Conv, [768, 3, 2]], # 8-P5/32 25 | [-1, 3, BottleneckCSPA, [768]], 26 | [-1, 1, Conv, [1024, 3, 2]], # 10-P6/64 27 | [-1, 3, BottleneckCSPA, [1024]], # 11 28 | ] 29 | 30 | # CSP-Dark-PAN head 31 | head: 32 | [[-1, 1, SPPCSPC, [512]], # 12 33 | [-1, 1, Conv, [384, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 35 | [-6, 1, Conv, [384, 1, 1]], # route backbone P5 36 | [[-1, -2], 1, Concat, [1]], 37 | [-1, 3, BottleneckCSPB, [384]], # 17 38 | [-1, 1, Conv, [256, 1, 1]], 39 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 40 | [-13, 1, Conv, [256, 1, 1]], # route backbone P4 41 | [[-1, -2], 1, Concat, [1]], 42 | [-1, 3, BottleneckCSPB, [256]], # 22 43 | [-1, 1, Conv, [128, 1, 1]], 44 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 45 | [-20, 1, Conv, [128, 1, 1]], # route backbone P3 46 | [[-1, -2], 1, Concat, [1]], 47 | [-1, 3, BottleneckCSPB, [128]], # 27 48 | [-1, 1, Conv, [256, 3, 1]], 49 | [-2, 1, Conv, [256, 3, 2]], 50 | [[-1, 22], 1, Concat, [1]], # cat 51 | [-1, 3, BottleneckCSPB, [256]], # 31 52 | [-1, 1, Conv, [512, 3, 1]], 53 | [-2, 1, Conv, [384, 3, 2]], 54 | [[-1, 17], 1, Concat, [1]], # cat 55 | [-1, 3, BottleneckCSPB, [384]], # 35 56 | [-1, 1, Conv, [768, 3, 1]], 57 | [-2, 1, Conv, [512, 3, 2]], 58 | [[-1, 12], 1, Concat, [1]], # cat 59 | [-1, 3, BottleneckCSPB, [512]], # 39 60 | [-1, 1, Conv, [1024, 3, 1]], 61 | 62 | [[28,32,36,40], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5, P6) 63 | ] -------------------------------------------------------------------------------- /cfg/baseline/yolov3-spp.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 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 | [[-1, 1, Conv, [32, 3, 1]], # 0 16 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 17 | [-1, 1, Bottleneck, [64]], 18 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 19 | [-1, 2, Bottleneck, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8 21 | [-1, 8, Bottleneck, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16 23 | [-1, 8, Bottleneck, [512]], 24 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32 25 | [-1, 4, Bottleneck, [1024]], # 10 26 | ] 27 | 28 | # YOLOv3-SPP head 29 | head: 30 | [[-1, 1, Bottleneck, [1024, False]], 31 | [-1, 1, SPP, [512, [5, 9, 13]]], 32 | [-1, 1, Conv, [1024, 3, 1]], 33 | [-1, 1, Conv, [512, 1, 1]], 34 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large) 35 | 36 | [-2, 1, Conv, [256, 1, 1]], 37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 38 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 39 | [-1, 1, Bottleneck, [512, False]], 40 | [-1, 1, Bottleneck, [512, False]], 41 | [-1, 1, Conv, [256, 1, 1]], 42 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium) 43 | 44 | [-2, 1, Conv, [128, 1, 1]], 45 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 46 | [[-1, 6], 1, Concat, [1]], # cat backbone P3 47 | [-1, 1, Bottleneck, [256, False]], 48 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small) 49 | 50 | [[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 51 | ] 52 | -------------------------------------------------------------------------------- /cfg/baseline/yolov3.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 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 | [[-1, 1, Conv, [32, 3, 1]], # 0 16 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 17 | [-1, 1, Bottleneck, [64]], 18 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 19 | [-1, 2, Bottleneck, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8 21 | [-1, 8, Bottleneck, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16 23 | [-1, 8, Bottleneck, [512]], 24 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32 25 | [-1, 4, Bottleneck, [1024]], # 10 26 | ] 27 | 28 | # YOLOv3 head 29 | head: 30 | [[-1, 1, Bottleneck, [1024, False]], 31 | [-1, 1, Conv, [512, [1, 1]]], 32 | [-1, 1, Conv, [1024, 3, 1]], 33 | [-1, 1, Conv, [512, 1, 1]], 34 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large) 35 | 36 | [-2, 1, Conv, [256, 1, 1]], 37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 38 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 39 | [-1, 1, Bottleneck, [512, False]], 40 | [-1, 1, Bottleneck, [512, False]], 41 | [-1, 1, Conv, [256, 1, 1]], 42 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium) 43 | 44 | [-2, 1, Conv, [128, 1, 1]], 45 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 46 | [[-1, 6], 1, Concat, [1]], # cat backbone P3 47 | [-1, 1, Bottleneck, [256, False]], 48 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small) 49 | 50 | [[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 51 | ] 52 | -------------------------------------------------------------------------------- /cfg/baseline/yolov4-csp.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 7 | anchors: 8 | - [12,16, 19,36, 40,28] # P3/8 9 | - [36,75, 76,55, 72,146] # P4/16 10 | - [142,110, 192,243, 459,401] # P5/32 11 | 12 | # CSP-Darknet backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [32, 3, 1]], # 0 16 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 17 | [-1, 1, Bottleneck, [64]], 18 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 19 | [-1, 2, BottleneckCSPC, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8 21 | [-1, 8, BottleneckCSPC, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16 23 | [-1, 8, BottleneckCSPC, [512]], 24 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32 25 | [-1, 4, BottleneckCSPC, [1024]], # 10 26 | ] 27 | 28 | # CSP-Dark-PAN head 29 | head: 30 | [[-1, 1, SPPCSPC, [512]], # 11 31 | [-1, 1, Conv, [256, 1, 1]], 32 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 33 | [8, 1, Conv, [256, 1, 1]], # route backbone P4 34 | [[-1, -2], 1, Concat, [1]], 35 | [-1, 2, BottleneckCSPB, [256]], # 16 36 | [-1, 1, Conv, [128, 1, 1]], 37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 38 | [6, 1, Conv, [128, 1, 1]], # route backbone P3 39 | [[-1, -2], 1, Concat, [1]], 40 | [-1, 2, BottleneckCSPB, [128]], # 21 41 | [-1, 1, Conv, [256, 3, 1]], 42 | [-2, 1, Conv, [256, 3, 2]], 43 | [[-1, 16], 1, Concat, [1]], # cat 44 | [-1, 2, BottleneckCSPB, [256]], # 25 45 | [-1, 1, Conv, [512, 3, 1]], 46 | [-2, 1, Conv, [512, 3, 2]], 47 | [[-1, 11], 1, Concat, [1]], # cat 48 | [-1, 2, BottleneckCSPB, [512]], # 29 49 | [-1, 1, Conv, [1024, 3, 1]], 50 | 51 | [[22,26,30], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 52 | ] 53 | -------------------------------------------------------------------------------- /cfg/deploy/yolov7-d6.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 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 | # yolov7-d6 backbone 14 | backbone: 15 | # [from, number, module, args], 16 | [[-1, 1, ReOrg, []], # 0 17 | [-1, 1, Conv, [96, 3, 1]], # 1-P1/2 18 | 19 | [-1, 1, DownC, [192]], # 2-P2/4 20 | [-1, 1, Conv, [64, 1, 1]], 21 | [-2, 1, Conv, [64, 1, 1]], 22 | [-1, 1, Conv, [64, 3, 1]], 23 | [-1, 1, Conv, [64, 3, 1]], 24 | [-1, 1, Conv, [64, 3, 1]], 25 | [-1, 1, Conv, [64, 3, 1]], 26 | [-1, 1, Conv, [64, 3, 1]], 27 | [-1, 1, Conv, [64, 3, 1]], 28 | [-1, 1, Conv, [64, 3, 1]], 29 | [-1, 1, Conv, [64, 3, 1]], 30 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]], 31 | [-1, 1, Conv, [192, 1, 1]], # 14 32 | 33 | [-1, 1, DownC, [384]], # 15-P3/8 34 | [-1, 1, Conv, [128, 1, 1]], 35 | [-2, 1, Conv, [128, 1, 1]], 36 | [-1, 1, Conv, [128, 3, 1]], 37 | [-1, 1, Conv, [128, 3, 1]], 38 | [-1, 1, Conv, [128, 3, 1]], 39 | [-1, 1, Conv, [128, 3, 1]], 40 | [-1, 1, Conv, [128, 3, 1]], 41 | [-1, 1, Conv, [128, 3, 1]], 42 | [-1, 1, Conv, [128, 3, 1]], 43 | [-1, 1, Conv, [128, 3, 1]], 44 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]], 45 | [-1, 1, Conv, [384, 1, 1]], # 27 46 | 47 | [-1, 1, DownC, [768]], # 28-P4/16 48 | [-1, 1, Conv, [256, 1, 1]], 49 | [-2, 1, Conv, [256, 1, 1]], 50 | [-1, 1, Conv, [256, 3, 1]], 51 | [-1, 1, Conv, [256, 3, 1]], 52 | [-1, 1, Conv, [256, 3, 1]], 53 | [-1, 1, Conv, [256, 3, 1]], 54 | [-1, 1, Conv, [256, 3, 1]], 55 | [-1, 1, Conv, [256, 3, 1]], 56 | [-1, 1, Conv, [256, 3, 1]], 57 | [-1, 1, Conv, [256, 3, 1]], 58 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]], 59 | [-1, 1, Conv, [768, 1, 1]], # 40 60 | 61 | [-1, 1, DownC, [1152]], # 41-P5/32 62 | [-1, 1, Conv, [384, 1, 1]], 63 | [-2, 1, Conv, [384, 1, 1]], 64 | [-1, 1, Conv, [384, 3, 1]], 65 | [-1, 1, Conv, [384, 3, 1]], 66 | [-1, 1, Conv, [384, 3, 1]], 67 | [-1, 1, Conv, [384, 3, 1]], 68 | [-1, 1, Conv, [384, 3, 1]], 69 | [-1, 1, Conv, [384, 3, 1]], 70 | [-1, 1, Conv, [384, 3, 1]], 71 | [-1, 1, Conv, [384, 3, 1]], 72 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]], 73 | [-1, 1, Conv, [1152, 1, 1]], # 53 74 | 75 | [-1, 1, DownC, [1536]], # 54-P6/64 76 | [-1, 1, Conv, [512, 1, 1]], 77 | [-2, 1, Conv, [512, 1, 1]], 78 | [-1, 1, Conv, [512, 3, 1]], 79 | [-1, 1, Conv, [512, 3, 1]], 80 | [-1, 1, Conv, [512, 3, 1]], 81 | [-1, 1, Conv, [512, 3, 1]], 82 | [-1, 1, Conv, [512, 3, 1]], 83 | [-1, 1, Conv, [512, 3, 1]], 84 | [-1, 1, Conv, [512, 3, 1]], 85 | [-1, 1, Conv, [512, 3, 1]], 86 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]], 87 | [-1, 1, Conv, [1536, 1, 1]], # 66 88 | ] 89 | 90 | # yolov7-d6 head 91 | head: 92 | [[-1, 1, SPPCSPC, [768]], # 67 93 | 94 | [-1, 1, Conv, [576, 1, 1]], 95 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 96 | [53, 1, Conv, [576, 1, 1]], # route backbone P5 97 | [[-1, -2], 1, Concat, [1]], 98 | 99 | [-1, 1, Conv, [384, 1, 1]], 100 | [-2, 1, Conv, [384, 1, 1]], 101 | [-1, 1, Conv, [192, 3, 1]], 102 | [-1, 1, Conv, [192, 3, 1]], 103 | [-1, 1, Conv, [192, 3, 1]], 104 | [-1, 1, Conv, [192, 3, 1]], 105 | [-1, 1, Conv, [192, 3, 1]], 106 | [-1, 1, Conv, [192, 3, 1]], 107 | [-1, 1, Conv, [192, 3, 1]], 108 | [-1, 1, Conv, [192, 3, 1]], 109 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]], 110 | [-1, 1, Conv, [576, 1, 1]], # 83 111 | 112 | [-1, 1, Conv, [384, 1, 1]], 113 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 114 | [40, 1, Conv, [384, 1, 1]], # route backbone P4 115 | [[-1, -2], 1, Concat, [1]], 116 | 117 | [-1, 1, Conv, [256, 1, 1]], 118 | [-2, 1, Conv, [256, 1, 1]], 119 | [-1, 1, Conv, [128, 3, 1]], 120 | [-1, 1, Conv, [128, 3, 1]], 121 | [-1, 1, Conv, [128, 3, 1]], 122 | [-1, 1, Conv, [128, 3, 1]], 123 | [-1, 1, Conv, [128, 3, 1]], 124 | [-1, 1, Conv, [128, 3, 1]], 125 | [-1, 1, Conv, [128, 3, 1]], 126 | [-1, 1, Conv, [128, 3, 1]], 127 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]], 128 | [-1, 1, Conv, [384, 1, 1]], # 99 129 | 130 | [-1, 1, Conv, [192, 1, 1]], 131 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 132 | [27, 1, Conv, [192, 1, 1]], # route backbone P3 133 | [[-1, -2], 1, Concat, [1]], 134 | 135 | [-1, 1, Conv, [128, 1, 1]], 136 | [-2, 1, Conv, [128, 1, 1]], 137 | [-1, 1, Conv, [64, 3, 1]], 138 | [-1, 1, Conv, [64, 3, 1]], 139 | [-1, 1, Conv, [64, 3, 1]], 140 | [-1, 1, Conv, [64, 3, 1]], 141 | [-1, 1, Conv, [64, 3, 1]], 142 | [-1, 1, Conv, [64, 3, 1]], 143 | [-1, 1, Conv, [64, 3, 1]], 144 | [-1, 1, Conv, [64, 3, 1]], 145 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]], 146 | [-1, 1, Conv, [192, 1, 1]], # 115 147 | 148 | [-1, 1, DownC, [384]], 149 | [[-1, 99], 1, Concat, [1]], 150 | 151 | [-1, 1, Conv, [256, 1, 1]], 152 | [-2, 1, Conv, [256, 1, 1]], 153 | [-1, 1, Conv, [128, 3, 1]], 154 | [-1, 1, Conv, [128, 3, 1]], 155 | [-1, 1, Conv, [128, 3, 1]], 156 | [-1, 1, Conv, [128, 3, 1]], 157 | [-1, 1, Conv, [128, 3, 1]], 158 | [-1, 1, Conv, [128, 3, 1]], 159 | [-1, 1, Conv, [128, 3, 1]], 160 | [-1, 1, Conv, [128, 3, 1]], 161 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]], 162 | [-1, 1, Conv, [384, 1, 1]], # 129 163 | 164 | [-1, 1, DownC, [576]], 165 | [[-1, 83], 1, Concat, [1]], 166 | 167 | [-1, 1, Conv, [384, 1, 1]], 168 | [-2, 1, Conv, [384, 1, 1]], 169 | [-1, 1, Conv, [192, 3, 1]], 170 | [-1, 1, Conv, [192, 3, 1]], 171 | [-1, 1, Conv, [192, 3, 1]], 172 | [-1, 1, Conv, [192, 3, 1]], 173 | [-1, 1, Conv, [192, 3, 1]], 174 | [-1, 1, Conv, [192, 3, 1]], 175 | [-1, 1, Conv, [192, 3, 1]], 176 | [-1, 1, Conv, [192, 3, 1]], 177 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]], 178 | [-1, 1, Conv, [576, 1, 1]], # 143 179 | 180 | [-1, 1, DownC, [768]], 181 | [[-1, 67], 1, Concat, [1]], 182 | 183 | [-1, 1, Conv, [512, 1, 1]], 184 | [-2, 1, Conv, [512, 1, 1]], 185 | [-1, 1, Conv, [256, 3, 1]], 186 | [-1, 1, Conv, [256, 3, 1]], 187 | [-1, 1, Conv, [256, 3, 1]], 188 | [-1, 1, Conv, [256, 3, 1]], 189 | [-1, 1, Conv, [256, 3, 1]], 190 | [-1, 1, Conv, [256, 3, 1]], 191 | [-1, 1, Conv, [256, 3, 1]], 192 | [-1, 1, Conv, [256, 3, 1]], 193 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]], 194 | [-1, 1, Conv, [768, 1, 1]], # 157 195 | 196 | [115, 1, Conv, [384, 3, 1]], 197 | [129, 1, Conv, [768, 3, 1]], 198 | [143, 1, Conv, [1152, 3, 1]], 199 | [157, 1, Conv, [1536, 3, 1]], 200 | 201 | [[158,159,160,161], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 202 | ] 203 | -------------------------------------------------------------------------------- /cfg/deploy/yolov7-e6.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 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 | # yolov7-e6 backbone 14 | backbone: 15 | # [from, number, module, args], 16 | [[-1, 1, ReOrg, []], # 0 17 | [-1, 1, Conv, [80, 3, 1]], # 1-P1/2 18 | 19 | [-1, 1, DownC, [160]], # 2-P2/4 20 | [-1, 1, Conv, [64, 1, 1]], 21 | [-2, 1, Conv, [64, 1, 1]], 22 | [-1, 1, Conv, [64, 3, 1]], 23 | [-1, 1, Conv, [64, 3, 1]], 24 | [-1, 1, Conv, [64, 3, 1]], 25 | [-1, 1, Conv, [64, 3, 1]], 26 | [-1, 1, Conv, [64, 3, 1]], 27 | [-1, 1, Conv, [64, 3, 1]], 28 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 29 | [-1, 1, Conv, [160, 1, 1]], # 12 30 | 31 | [-1, 1, DownC, [320]], # 13-P3/8 32 | [-1, 1, Conv, [128, 1, 1]], 33 | [-2, 1, Conv, [128, 1, 1]], 34 | [-1, 1, Conv, [128, 3, 1]], 35 | [-1, 1, Conv, [128, 3, 1]], 36 | [-1, 1, Conv, [128, 3, 1]], 37 | [-1, 1, Conv, [128, 3, 1]], 38 | [-1, 1, Conv, [128, 3, 1]], 39 | [-1, 1, Conv, [128, 3, 1]], 40 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 41 | [-1, 1, Conv, [320, 1, 1]], # 23 42 | 43 | [-1, 1, DownC, [640]], # 24-P4/16 44 | [-1, 1, Conv, [256, 1, 1]], 45 | [-2, 1, Conv, [256, 1, 1]], 46 | [-1, 1, Conv, [256, 3, 1]], 47 | [-1, 1, Conv, [256, 3, 1]], 48 | [-1, 1, Conv, [256, 3, 1]], 49 | [-1, 1, Conv, [256, 3, 1]], 50 | [-1, 1, Conv, [256, 3, 1]], 51 | [-1, 1, Conv, [256, 3, 1]], 52 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 53 | [-1, 1, Conv, [640, 1, 1]], # 34 54 | 55 | [-1, 1, DownC, [960]], # 35-P5/32 56 | [-1, 1, Conv, [384, 1, 1]], 57 | [-2, 1, Conv, [384, 1, 1]], 58 | [-1, 1, Conv, [384, 3, 1]], 59 | [-1, 1, Conv, [384, 3, 1]], 60 | [-1, 1, Conv, [384, 3, 1]], 61 | [-1, 1, Conv, [384, 3, 1]], 62 | [-1, 1, Conv, [384, 3, 1]], 63 | [-1, 1, Conv, [384, 3, 1]], 64 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 65 | [-1, 1, Conv, [960, 1, 1]], # 45 66 | 67 | [-1, 1, DownC, [1280]], # 46-P6/64 68 | [-1, 1, Conv, [512, 1, 1]], 69 | [-2, 1, Conv, [512, 1, 1]], 70 | [-1, 1, Conv, [512, 3, 1]], 71 | [-1, 1, Conv, [512, 3, 1]], 72 | [-1, 1, Conv, [512, 3, 1]], 73 | [-1, 1, Conv, [512, 3, 1]], 74 | [-1, 1, Conv, [512, 3, 1]], 75 | [-1, 1, Conv, [512, 3, 1]], 76 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 77 | [-1, 1, Conv, [1280, 1, 1]], # 56 78 | ] 79 | 80 | # yolov7-e6 head 81 | head: 82 | [[-1, 1, SPPCSPC, [640]], # 57 83 | 84 | [-1, 1, Conv, [480, 1, 1]], 85 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 86 | [45, 1, Conv, [480, 1, 1]], # route backbone P5 87 | [[-1, -2], 1, Concat, [1]], 88 | 89 | [-1, 1, Conv, [384, 1, 1]], 90 | [-2, 1, Conv, [384, 1, 1]], 91 | [-1, 1, Conv, [192, 3, 1]], 92 | [-1, 1, Conv, [192, 3, 1]], 93 | [-1, 1, Conv, [192, 3, 1]], 94 | [-1, 1, Conv, [192, 3, 1]], 95 | [-1, 1, Conv, [192, 3, 1]], 96 | [-1, 1, Conv, [192, 3, 1]], 97 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 98 | [-1, 1, Conv, [480, 1, 1]], # 71 99 | 100 | [-1, 1, Conv, [320, 1, 1]], 101 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 102 | [34, 1, Conv, [320, 1, 1]], # route backbone P4 103 | [[-1, -2], 1, Concat, [1]], 104 | 105 | [-1, 1, Conv, [256, 1, 1]], 106 | [-2, 1, Conv, [256, 1, 1]], 107 | [-1, 1, Conv, [128, 3, 1]], 108 | [-1, 1, Conv, [128, 3, 1]], 109 | [-1, 1, Conv, [128, 3, 1]], 110 | [-1, 1, Conv, [128, 3, 1]], 111 | [-1, 1, Conv, [128, 3, 1]], 112 | [-1, 1, Conv, [128, 3, 1]], 113 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 114 | [-1, 1, Conv, [320, 1, 1]], # 85 115 | 116 | [-1, 1, Conv, [160, 1, 1]], 117 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 118 | [23, 1, Conv, [160, 1, 1]], # route backbone P3 119 | [[-1, -2], 1, Concat, [1]], 120 | 121 | [-1, 1, Conv, [128, 1, 1]], 122 | [-2, 1, Conv, [128, 1, 1]], 123 | [-1, 1, Conv, [64, 3, 1]], 124 | [-1, 1, Conv, [64, 3, 1]], 125 | [-1, 1, Conv, [64, 3, 1]], 126 | [-1, 1, Conv, [64, 3, 1]], 127 | [-1, 1, Conv, [64, 3, 1]], 128 | [-1, 1, Conv, [64, 3, 1]], 129 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 130 | [-1, 1, Conv, [160, 1, 1]], # 99 131 | 132 | [-1, 1, DownC, [320]], 133 | [[-1, 85], 1, Concat, [1]], 134 | 135 | [-1, 1, Conv, [256, 1, 1]], 136 | [-2, 1, Conv, [256, 1, 1]], 137 | [-1, 1, Conv, [128, 3, 1]], 138 | [-1, 1, Conv, [128, 3, 1]], 139 | [-1, 1, Conv, [128, 3, 1]], 140 | [-1, 1, Conv, [128, 3, 1]], 141 | [-1, 1, Conv, [128, 3, 1]], 142 | [-1, 1, Conv, [128, 3, 1]], 143 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 144 | [-1, 1, Conv, [320, 1, 1]], # 111 145 | 146 | [-1, 1, DownC, [480]], 147 | [[-1, 71], 1, Concat, [1]], 148 | 149 | [-1, 1, Conv, [384, 1, 1]], 150 | [-2, 1, Conv, [384, 1, 1]], 151 | [-1, 1, Conv, [192, 3, 1]], 152 | [-1, 1, Conv, [192, 3, 1]], 153 | [-1, 1, Conv, [192, 3, 1]], 154 | [-1, 1, Conv, [192, 3, 1]], 155 | [-1, 1, Conv, [192, 3, 1]], 156 | [-1, 1, Conv, [192, 3, 1]], 157 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 158 | [-1, 1, Conv, [480, 1, 1]], # 123 159 | 160 | [-1, 1, DownC, [640]], 161 | [[-1, 57], 1, Concat, [1]], 162 | 163 | [-1, 1, Conv, [512, 1, 1]], 164 | [-2, 1, Conv, [512, 1, 1]], 165 | [-1, 1, Conv, [256, 3, 1]], 166 | [-1, 1, Conv, [256, 3, 1]], 167 | [-1, 1, Conv, [256, 3, 1]], 168 | [-1, 1, Conv, [256, 3, 1]], 169 | [-1, 1, Conv, [256, 3, 1]], 170 | [-1, 1, Conv, [256, 3, 1]], 171 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 172 | [-1, 1, Conv, [640, 1, 1]], # 135 173 | 174 | [99, 1, Conv, [320, 3, 1]], 175 | [111, 1, Conv, [640, 3, 1]], 176 | [123, 1, Conv, [960, 3, 1]], 177 | [135, 1, Conv, [1280, 3, 1]], 178 | 179 | [[136,137,138,139], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 180 | ] 181 | -------------------------------------------------------------------------------- /cfg/deploy/yolov7-e6e.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 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 | # yolov7-e6e backbone 14 | backbone: 15 | # [from, number, module, args], 16 | [[-1, 1, ReOrg, []], # 0 17 | [-1, 1, Conv, [80, 3, 1]], # 1-P1/2 18 | 19 | [-1, 1, DownC, [160]], # 2-P2/4 20 | [-1, 1, Conv, [64, 1, 1]], 21 | [-2, 1, Conv, [64, 1, 1]], 22 | [-1, 1, Conv, [64, 3, 1]], 23 | [-1, 1, Conv, [64, 3, 1]], 24 | [-1, 1, Conv, [64, 3, 1]], 25 | [-1, 1, Conv, [64, 3, 1]], 26 | [-1, 1, Conv, [64, 3, 1]], 27 | [-1, 1, Conv, [64, 3, 1]], 28 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 29 | [-1, 1, Conv, [160, 1, 1]], # 12 30 | [-11, 1, Conv, [64, 1, 1]], 31 | [-12, 1, Conv, [64, 1, 1]], 32 | [-1, 1, Conv, [64, 3, 1]], 33 | [-1, 1, Conv, [64, 3, 1]], 34 | [-1, 1, Conv, [64, 3, 1]], 35 | [-1, 1, Conv, [64, 3, 1]], 36 | [-1, 1, Conv, [64, 3, 1]], 37 | [-1, 1, Conv, [64, 3, 1]], 38 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 39 | [-1, 1, Conv, [160, 1, 1]], # 22 40 | [[-1, -11], 1, Shortcut, [1]], # 23 41 | 42 | [-1, 1, DownC, [320]], # 24-P3/8 43 | [-1, 1, Conv, [128, 1, 1]], 44 | [-2, 1, Conv, [128, 1, 1]], 45 | [-1, 1, Conv, [128, 3, 1]], 46 | [-1, 1, Conv, [128, 3, 1]], 47 | [-1, 1, Conv, [128, 3, 1]], 48 | [-1, 1, Conv, [128, 3, 1]], 49 | [-1, 1, Conv, [128, 3, 1]], 50 | [-1, 1, Conv, [128, 3, 1]], 51 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 52 | [-1, 1, Conv, [320, 1, 1]], # 34 53 | [-11, 1, Conv, [128, 1, 1]], 54 | [-12, 1, Conv, [128, 1, 1]], 55 | [-1, 1, Conv, [128, 3, 1]], 56 | [-1, 1, Conv, [128, 3, 1]], 57 | [-1, 1, Conv, [128, 3, 1]], 58 | [-1, 1, Conv, [128, 3, 1]], 59 | [-1, 1, Conv, [128, 3, 1]], 60 | [-1, 1, Conv, [128, 3, 1]], 61 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 62 | [-1, 1, Conv, [320, 1, 1]], # 44 63 | [[-1, -11], 1, Shortcut, [1]], # 45 64 | 65 | [-1, 1, DownC, [640]], # 46-P4/16 66 | [-1, 1, Conv, [256, 1, 1]], 67 | [-2, 1, Conv, [256, 1, 1]], 68 | [-1, 1, Conv, [256, 3, 1]], 69 | [-1, 1, Conv, [256, 3, 1]], 70 | [-1, 1, Conv, [256, 3, 1]], 71 | [-1, 1, Conv, [256, 3, 1]], 72 | [-1, 1, Conv, [256, 3, 1]], 73 | [-1, 1, Conv, [256, 3, 1]], 74 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 75 | [-1, 1, Conv, [640, 1, 1]], # 56 76 | [-11, 1, Conv, [256, 1, 1]], 77 | [-12, 1, Conv, [256, 1, 1]], 78 | [-1, 1, Conv, [256, 3, 1]], 79 | [-1, 1, Conv, [256, 3, 1]], 80 | [-1, 1, Conv, [256, 3, 1]], 81 | [-1, 1, Conv, [256, 3, 1]], 82 | [-1, 1, Conv, [256, 3, 1]], 83 | [-1, 1, Conv, [256, 3, 1]], 84 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 85 | [-1, 1, Conv, [640, 1, 1]], # 66 86 | [[-1, -11], 1, Shortcut, [1]], # 67 87 | 88 | [-1, 1, DownC, [960]], # 68-P5/32 89 | [-1, 1, Conv, [384, 1, 1]], 90 | [-2, 1, Conv, [384, 1, 1]], 91 | [-1, 1, Conv, [384, 3, 1]], 92 | [-1, 1, Conv, [384, 3, 1]], 93 | [-1, 1, Conv, [384, 3, 1]], 94 | [-1, 1, Conv, [384, 3, 1]], 95 | [-1, 1, Conv, [384, 3, 1]], 96 | [-1, 1, Conv, [384, 3, 1]], 97 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 98 | [-1, 1, Conv, [960, 1, 1]], # 78 99 | [-11, 1, Conv, [384, 1, 1]], 100 | [-12, 1, Conv, [384, 1, 1]], 101 | [-1, 1, Conv, [384, 3, 1]], 102 | [-1, 1, Conv, [384, 3, 1]], 103 | [-1, 1, Conv, [384, 3, 1]], 104 | [-1, 1, Conv, [384, 3, 1]], 105 | [-1, 1, Conv, [384, 3, 1]], 106 | [-1, 1, Conv, [384, 3, 1]], 107 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 108 | [-1, 1, Conv, [960, 1, 1]], # 88 109 | [[-1, -11], 1, Shortcut, [1]], # 89 110 | 111 | [-1, 1, DownC, [1280]], # 90-P6/64 112 | [-1, 1, Conv, [512, 1, 1]], 113 | [-2, 1, Conv, [512, 1, 1]], 114 | [-1, 1, Conv, [512, 3, 1]], 115 | [-1, 1, Conv, [512, 3, 1]], 116 | [-1, 1, Conv, [512, 3, 1]], 117 | [-1, 1, Conv, [512, 3, 1]], 118 | [-1, 1, Conv, [512, 3, 1]], 119 | [-1, 1, Conv, [512, 3, 1]], 120 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 121 | [-1, 1, Conv, [1280, 1, 1]], # 100 122 | [-11, 1, Conv, [512, 1, 1]], 123 | [-12, 1, Conv, [512, 1, 1]], 124 | [-1, 1, Conv, [512, 3, 1]], 125 | [-1, 1, Conv, [512, 3, 1]], 126 | [-1, 1, Conv, [512, 3, 1]], 127 | [-1, 1, Conv, [512, 3, 1]], 128 | [-1, 1, Conv, [512, 3, 1]], 129 | [-1, 1, Conv, [512, 3, 1]], 130 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 131 | [-1, 1, Conv, [1280, 1, 1]], # 110 132 | [[-1, -11], 1, Shortcut, [1]], # 111 133 | ] 134 | 135 | # yolov7-e6e head 136 | head: 137 | [[-1, 1, SPPCSPC, [640]], # 112 138 | 139 | [-1, 1, Conv, [480, 1, 1]], 140 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 141 | [89, 1, Conv, [480, 1, 1]], # route backbone P5 142 | [[-1, -2], 1, Concat, [1]], 143 | 144 | [-1, 1, Conv, [384, 1, 1]], 145 | [-2, 1, Conv, [384, 1, 1]], 146 | [-1, 1, Conv, [192, 3, 1]], 147 | [-1, 1, Conv, [192, 3, 1]], 148 | [-1, 1, Conv, [192, 3, 1]], 149 | [-1, 1, Conv, [192, 3, 1]], 150 | [-1, 1, Conv, [192, 3, 1]], 151 | [-1, 1, Conv, [192, 3, 1]], 152 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 153 | [-1, 1, Conv, [480, 1, 1]], # 126 154 | [-11, 1, Conv, [384, 1, 1]], 155 | [-12, 1, Conv, [384, 1, 1]], 156 | [-1, 1, Conv, [192, 3, 1]], 157 | [-1, 1, Conv, [192, 3, 1]], 158 | [-1, 1, Conv, [192, 3, 1]], 159 | [-1, 1, Conv, [192, 3, 1]], 160 | [-1, 1, Conv, [192, 3, 1]], 161 | [-1, 1, Conv, [192, 3, 1]], 162 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 163 | [-1, 1, Conv, [480, 1, 1]], # 136 164 | [[-1, -11], 1, Shortcut, [1]], # 137 165 | 166 | [-1, 1, Conv, [320, 1, 1]], 167 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 168 | [67, 1, Conv, [320, 1, 1]], # route backbone P4 169 | [[-1, -2], 1, Concat, [1]], 170 | 171 | [-1, 1, Conv, [256, 1, 1]], 172 | [-2, 1, Conv, [256, 1, 1]], 173 | [-1, 1, Conv, [128, 3, 1]], 174 | [-1, 1, Conv, [128, 3, 1]], 175 | [-1, 1, Conv, [128, 3, 1]], 176 | [-1, 1, Conv, [128, 3, 1]], 177 | [-1, 1, Conv, [128, 3, 1]], 178 | [-1, 1, Conv, [128, 3, 1]], 179 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 180 | [-1, 1, Conv, [320, 1, 1]], # 151 181 | [-11, 1, Conv, [256, 1, 1]], 182 | [-12, 1, Conv, [256, 1, 1]], 183 | [-1, 1, Conv, [128, 3, 1]], 184 | [-1, 1, Conv, [128, 3, 1]], 185 | [-1, 1, Conv, [128, 3, 1]], 186 | [-1, 1, Conv, [128, 3, 1]], 187 | [-1, 1, Conv, [128, 3, 1]], 188 | [-1, 1, Conv, [128, 3, 1]], 189 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 190 | [-1, 1, Conv, [320, 1, 1]], # 161 191 | [[-1, -11], 1, Shortcut, [1]], # 162 192 | 193 | [-1, 1, Conv, [160, 1, 1]], 194 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 195 | [45, 1, Conv, [160, 1, 1]], # route backbone P3 196 | [[-1, -2], 1, Concat, [1]], 197 | 198 | [-1, 1, Conv, [128, 1, 1]], 199 | [-2, 1, Conv, [128, 1, 1]], 200 | [-1, 1, Conv, [64, 3, 1]], 201 | [-1, 1, Conv, [64, 3, 1]], 202 | [-1, 1, Conv, [64, 3, 1]], 203 | [-1, 1, Conv, [64, 3, 1]], 204 | [-1, 1, Conv, [64, 3, 1]], 205 | [-1, 1, Conv, [64, 3, 1]], 206 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 207 | [-1, 1, Conv, [160, 1, 1]], # 176 208 | [-11, 1, Conv, [128, 1, 1]], 209 | [-12, 1, Conv, [128, 1, 1]], 210 | [-1, 1, Conv, [64, 3, 1]], 211 | [-1, 1, Conv, [64, 3, 1]], 212 | [-1, 1, Conv, [64, 3, 1]], 213 | [-1, 1, Conv, [64, 3, 1]], 214 | [-1, 1, Conv, [64, 3, 1]], 215 | [-1, 1, Conv, [64, 3, 1]], 216 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 217 | [-1, 1, Conv, [160, 1, 1]], # 186 218 | [[-1, -11], 1, Shortcut, [1]], # 187 219 | 220 | [-1, 1, DownC, [320]], 221 | [[-1, 162], 1, Concat, [1]], 222 | 223 | [-1, 1, Conv, [256, 1, 1]], 224 | [-2, 1, Conv, [256, 1, 1]], 225 | [-1, 1, Conv, [128, 3, 1]], 226 | [-1, 1, Conv, [128, 3, 1]], 227 | [-1, 1, Conv, [128, 3, 1]], 228 | [-1, 1, Conv, [128, 3, 1]], 229 | [-1, 1, Conv, [128, 3, 1]], 230 | [-1, 1, Conv, [128, 3, 1]], 231 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 232 | [-1, 1, Conv, [320, 1, 1]], # 199 233 | [-11, 1, Conv, [256, 1, 1]], 234 | [-12, 1, Conv, [256, 1, 1]], 235 | [-1, 1, Conv, [128, 3, 1]], 236 | [-1, 1, Conv, [128, 3, 1]], 237 | [-1, 1, Conv, [128, 3, 1]], 238 | [-1, 1, Conv, [128, 3, 1]], 239 | [-1, 1, Conv, [128, 3, 1]], 240 | [-1, 1, Conv, [128, 3, 1]], 241 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 242 | [-1, 1, Conv, [320, 1, 1]], # 209 243 | [[-1, -11], 1, Shortcut, [1]], # 210 244 | 245 | [-1, 1, DownC, [480]], 246 | [[-1, 137], 1, Concat, [1]], 247 | 248 | [-1, 1, Conv, [384, 1, 1]], 249 | [-2, 1, Conv, [384, 1, 1]], 250 | [-1, 1, Conv, [192, 3, 1]], 251 | [-1, 1, Conv, [192, 3, 1]], 252 | [-1, 1, Conv, [192, 3, 1]], 253 | [-1, 1, Conv, [192, 3, 1]], 254 | [-1, 1, Conv, [192, 3, 1]], 255 | [-1, 1, Conv, [192, 3, 1]], 256 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 257 | [-1, 1, Conv, [480, 1, 1]], # 222 258 | [-11, 1, Conv, [384, 1, 1]], 259 | [-12, 1, Conv, [384, 1, 1]], 260 | [-1, 1, Conv, [192, 3, 1]], 261 | [-1, 1, Conv, [192, 3, 1]], 262 | [-1, 1, Conv, [192, 3, 1]], 263 | [-1, 1, Conv, [192, 3, 1]], 264 | [-1, 1, Conv, [192, 3, 1]], 265 | [-1, 1, Conv, [192, 3, 1]], 266 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 267 | [-1, 1, Conv, [480, 1, 1]], # 232 268 | [[-1, -11], 1, Shortcut, [1]], # 233 269 | 270 | [-1, 1, DownC, [640]], 271 | [[-1, 112], 1, Concat, [1]], 272 | 273 | [-1, 1, Conv, [512, 1, 1]], 274 | [-2, 1, Conv, [512, 1, 1]], 275 | [-1, 1, Conv, [256, 3, 1]], 276 | [-1, 1, Conv, [256, 3, 1]], 277 | [-1, 1, Conv, [256, 3, 1]], 278 | [-1, 1, Conv, [256, 3, 1]], 279 | [-1, 1, Conv, [256, 3, 1]], 280 | [-1, 1, Conv, [256, 3, 1]], 281 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 282 | [-1, 1, Conv, [640, 1, 1]], # 245 283 | [-11, 1, Conv, [512, 1, 1]], 284 | [-12, 1, Conv, [512, 1, 1]], 285 | [-1, 1, Conv, [256, 3, 1]], 286 | [-1, 1, Conv, [256, 3, 1]], 287 | [-1, 1, Conv, [256, 3, 1]], 288 | [-1, 1, Conv, [256, 3, 1]], 289 | [-1, 1, Conv, [256, 3, 1]], 290 | [-1, 1, Conv, [256, 3, 1]], 291 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 292 | [-1, 1, Conv, [640, 1, 1]], # 255 293 | [[-1, -11], 1, Shortcut, [1]], # 256 294 | 295 | [187, 1, Conv, [320, 3, 1]], 296 | [210, 1, Conv, [640, 3, 1]], 297 | [233, 1, Conv, [960, 3, 1]], 298 | [256, 1, Conv, [1280, 3, 1]], 299 | 300 | [[257,258,259,260], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 301 | ] 302 | -------------------------------------------------------------------------------- /cfg/deploy/yolov7-tiny-silu.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 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 | # YOLOv7-tiny backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [32, 3, 2]], # 0-P1/2 16 | 17 | [-1, 1, Conv, [64, 3, 2]], # 1-P2/4 18 | 19 | [-1, 1, Conv, [32, 1, 1]], 20 | [-2, 1, Conv, [32, 1, 1]], 21 | [-1, 1, Conv, [32, 3, 1]], 22 | [-1, 1, Conv, [32, 3, 1]], 23 | [[-1, -2, -3, -4], 1, Concat, [1]], 24 | [-1, 1, Conv, [64, 1, 1]], # 7 25 | 26 | [-1, 1, MP, []], # 8-P3/8 27 | [-1, 1, Conv, [64, 1, 1]], 28 | [-2, 1, Conv, [64, 1, 1]], 29 | [-1, 1, Conv, [64, 3, 1]], 30 | [-1, 1, Conv, [64, 3, 1]], 31 | [[-1, -2, -3, -4], 1, Concat, [1]], 32 | [-1, 1, Conv, [128, 1, 1]], # 14 33 | 34 | [-1, 1, MP, []], # 15-P4/16 35 | [-1, 1, Conv, [128, 1, 1]], 36 | [-2, 1, Conv, [128, 1, 1]], 37 | [-1, 1, Conv, [128, 3, 1]], 38 | [-1, 1, Conv, [128, 3, 1]], 39 | [[-1, -2, -3, -4], 1, Concat, [1]], 40 | [-1, 1, Conv, [256, 1, 1]], # 21 41 | 42 | [-1, 1, MP, []], # 22-P5/32 43 | [-1, 1, Conv, [256, 1, 1]], 44 | [-2, 1, Conv, [256, 1, 1]], 45 | [-1, 1, Conv, [256, 3, 1]], 46 | [-1, 1, Conv, [256, 3, 1]], 47 | [[-1, -2, -3, -4], 1, Concat, [1]], 48 | [-1, 1, Conv, [512, 1, 1]], # 28 49 | ] 50 | 51 | # YOLOv7-tiny head 52 | head: 53 | [[-1, 1, Conv, [256, 1, 1]], 54 | [-2, 1, Conv, [256, 1, 1]], 55 | [-1, 1, SP, [5]], 56 | [-2, 1, SP, [9]], 57 | [-3, 1, SP, [13]], 58 | [[-1, -2, -3, -4], 1, Concat, [1]], 59 | [-1, 1, Conv, [256, 1, 1]], 60 | [[-1, -7], 1, Concat, [1]], 61 | [-1, 1, Conv, [256, 1, 1]], # 37 62 | 63 | [-1, 1, Conv, [128, 1, 1]], 64 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 65 | [21, 1, Conv, [128, 1, 1]], # route backbone P4 66 | [[-1, -2], 1, Concat, [1]], 67 | 68 | [-1, 1, Conv, [64, 1, 1]], 69 | [-2, 1, Conv, [64, 1, 1]], 70 | [-1, 1, Conv, [64, 3, 1]], 71 | [-1, 1, Conv, [64, 3, 1]], 72 | [[-1, -2, -3, -4], 1, Concat, [1]], 73 | [-1, 1, Conv, [128, 1, 1]], # 47 74 | 75 | [-1, 1, Conv, [64, 1, 1]], 76 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 77 | [14, 1, Conv, [64, 1, 1]], # route backbone P3 78 | [[-1, -2], 1, Concat, [1]], 79 | 80 | [-1, 1, Conv, [32, 1, 1]], 81 | [-2, 1, Conv, [32, 1, 1]], 82 | [-1, 1, Conv, [32, 3, 1]], 83 | [-1, 1, Conv, [32, 3, 1]], 84 | [[-1, -2, -3, -4], 1, Concat, [1]], 85 | [-1, 1, Conv, [64, 1, 1]], # 57 86 | 87 | [-1, 1, Conv, [128, 3, 2]], 88 | [[-1, 47], 1, Concat, [1]], 89 | 90 | [-1, 1, Conv, [64, 1, 1]], 91 | [-2, 1, Conv, [64, 1, 1]], 92 | [-1, 1, Conv, [64, 3, 1]], 93 | [-1, 1, Conv, [64, 3, 1]], 94 | [[-1, -2, -3, -4], 1, Concat, [1]], 95 | [-1, 1, Conv, [128, 1, 1]], # 65 96 | 97 | [-1, 1, Conv, [256, 3, 2]], 98 | [[-1, 37], 1, Concat, [1]], 99 | 100 | [-1, 1, Conv, [128, 1, 1]], 101 | [-2, 1, Conv, [128, 1, 1]], 102 | [-1, 1, Conv, [128, 3, 1]], 103 | [-1, 1, Conv, [128, 3, 1]], 104 | [[-1, -2, -3, -4], 1, Concat, [1]], 105 | [-1, 1, Conv, [256, 1, 1]], # 73 106 | 107 | [57, 1, Conv, [128, 3, 1]], 108 | [65, 1, Conv, [256, 3, 1]], 109 | [73, 1, Conv, [512, 3, 1]], 110 | 111 | [[74,75,76], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 112 | ] 113 | -------------------------------------------------------------------------------- /cfg/deploy/yolov7-tiny.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 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 | # yolov7-tiny backbone 13 | backbone: 14 | # [from, number, module, args] c2, k=1, s=1, p=None, g=1, act=True 15 | [[-1, 1, Conv, [32, 3, 2, None, 1, nn.LeakyReLU(0.1)]], # 0-P1/2 16 | 17 | [-1, 1, Conv, [64, 3, 2, None, 1, nn.LeakyReLU(0.1)]], # 1-P2/4 18 | 19 | [-1, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 20 | [-2, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 21 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 22 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 23 | [[-1, -2, -3, -4], 1, Concat, [1]], 24 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 7 25 | 26 | [-1, 1, MP, []], # 8-P3/8 27 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 28 | [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 29 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 30 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 31 | [[-1, -2, -3, -4], 1, Concat, [1]], 32 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 14 33 | 34 | [-1, 1, MP, []], # 15-P4/16 35 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 36 | [-2, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 37 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 38 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 39 | [[-1, -2, -3, -4], 1, Concat, [1]], 40 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 21 41 | 42 | [-1, 1, MP, []], # 22-P5/32 43 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 44 | [-2, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 45 | [-1, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 46 | [-1, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 47 | [[-1, -2, -3, -4], 1, Concat, [1]], 48 | [-1, 1, Conv, [512, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 28 49 | ] 50 | 51 | # yolov7-tiny head 52 | head: 53 | [[-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 54 | [-2, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 55 | [-1, 1, SP, [5]], 56 | [-2, 1, SP, [9]], 57 | [-3, 1, SP, [13]], 58 | [[-1, -2, -3, -4], 1, Concat, [1]], 59 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 60 | [[-1, -7], 1, Concat, [1]], 61 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 37 62 | 63 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 64 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 65 | [21, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # route backbone P4 66 | [[-1, -2], 1, Concat, [1]], 67 | 68 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 69 | [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 70 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 71 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 72 | [[-1, -2, -3, -4], 1, Concat, [1]], 73 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 47 74 | 75 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 76 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 77 | [14, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # route backbone P3 78 | [[-1, -2], 1, Concat, [1]], 79 | 80 | [-1, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 81 | [-2, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 82 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 83 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 84 | [[-1, -2, -3, -4], 1, Concat, [1]], 85 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 57 86 | 87 | [-1, 1, Conv, [128, 3, 2, None, 1, nn.LeakyReLU(0.1)]], 88 | [[-1, 47], 1, Concat, [1]], 89 | 90 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 91 | [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 92 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 93 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 94 | [[-1, -2, -3, -4], 1, Concat, [1]], 95 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 65 96 | 97 | [-1, 1, Conv, [256, 3, 2, None, 1, nn.LeakyReLU(0.1)]], 98 | [[-1, 37], 1, Concat, [1]], 99 | 100 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 101 | [-2, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 102 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 103 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 104 | [[-1, -2, -3, -4], 1, Concat, [1]], 105 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 73 106 | 107 | [57, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 108 | [65, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 109 | [73, 1, Conv, [512, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 110 | 111 | [[74,75,76], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 112 | ] 113 | -------------------------------------------------------------------------------- /cfg/deploy/yolov7-w6.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 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 | # yolov7-w6 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [[-1, 1, ReOrg, []], # 0 17 | [-1, 1, Conv, [64, 3, 1]], # 1-P1/2 18 | 19 | [-1, 1, Conv, [128, 3, 2]], # 2-P2/4 20 | [-1, 1, Conv, [64, 1, 1]], 21 | [-2, 1, Conv, [64, 1, 1]], 22 | [-1, 1, Conv, [64, 3, 1]], 23 | [-1, 1, Conv, [64, 3, 1]], 24 | [-1, 1, Conv, [64, 3, 1]], 25 | [-1, 1, Conv, [64, 3, 1]], 26 | [[-1, -3, -5, -6], 1, Concat, [1]], 27 | [-1, 1, Conv, [128, 1, 1]], # 10 28 | 29 | [-1, 1, Conv, [256, 3, 2]], # 11-P3/8 30 | [-1, 1, Conv, [128, 1, 1]], 31 | [-2, 1, Conv, [128, 1, 1]], 32 | [-1, 1, Conv, [128, 3, 1]], 33 | [-1, 1, Conv, [128, 3, 1]], 34 | [-1, 1, Conv, [128, 3, 1]], 35 | [-1, 1, Conv, [128, 3, 1]], 36 | [[-1, -3, -5, -6], 1, Concat, [1]], 37 | [-1, 1, Conv, [256, 1, 1]], # 19 38 | 39 | [-1, 1, Conv, [512, 3, 2]], # 20-P4/16 40 | [-1, 1, Conv, [256, 1, 1]], 41 | [-2, 1, Conv, [256, 1, 1]], 42 | [-1, 1, Conv, [256, 3, 1]], 43 | [-1, 1, Conv, [256, 3, 1]], 44 | [-1, 1, Conv, [256, 3, 1]], 45 | [-1, 1, Conv, [256, 3, 1]], 46 | [[-1, -3, -5, -6], 1, Concat, [1]], 47 | [-1, 1, Conv, [512, 1, 1]], # 28 48 | 49 | [-1, 1, Conv, [768, 3, 2]], # 29-P5/32 50 | [-1, 1, Conv, [384, 1, 1]], 51 | [-2, 1, Conv, [384, 1, 1]], 52 | [-1, 1, Conv, [384, 3, 1]], 53 | [-1, 1, Conv, [384, 3, 1]], 54 | [-1, 1, Conv, [384, 3, 1]], 55 | [-1, 1, Conv, [384, 3, 1]], 56 | [[-1, -3, -5, -6], 1, Concat, [1]], 57 | [-1, 1, Conv, [768, 1, 1]], # 37 58 | 59 | [-1, 1, Conv, [1024, 3, 2]], # 38-P6/64 60 | [-1, 1, Conv, [512, 1, 1]], 61 | [-2, 1, Conv, [512, 1, 1]], 62 | [-1, 1, Conv, [512, 3, 1]], 63 | [-1, 1, Conv, [512, 3, 1]], 64 | [-1, 1, Conv, [512, 3, 1]], 65 | [-1, 1, Conv, [512, 3, 1]], 66 | [[-1, -3, -5, -6], 1, Concat, [1]], 67 | [-1, 1, Conv, [1024, 1, 1]], # 46 68 | ] 69 | 70 | # yolov7-w6 head 71 | head: 72 | [[-1, 1, SPPCSPC, [512]], # 47 73 | 74 | [-1, 1, Conv, [384, 1, 1]], 75 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 76 | [37, 1, Conv, [384, 1, 1]], # route backbone P5 77 | [[-1, -2], 1, Concat, [1]], 78 | 79 | [-1, 1, Conv, [384, 1, 1]], 80 | [-2, 1, Conv, [384, 1, 1]], 81 | [-1, 1, Conv, [192, 3, 1]], 82 | [-1, 1, Conv, [192, 3, 1]], 83 | [-1, 1, Conv, [192, 3, 1]], 84 | [-1, 1, Conv, [192, 3, 1]], 85 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 86 | [-1, 1, Conv, [384, 1, 1]], # 59 87 | 88 | [-1, 1, Conv, [256, 1, 1]], 89 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 90 | [28, 1, Conv, [256, 1, 1]], # route backbone P4 91 | [[-1, -2], 1, Concat, [1]], 92 | 93 | [-1, 1, Conv, [256, 1, 1]], 94 | [-2, 1, Conv, [256, 1, 1]], 95 | [-1, 1, Conv, [128, 3, 1]], 96 | [-1, 1, Conv, [128, 3, 1]], 97 | [-1, 1, Conv, [128, 3, 1]], 98 | [-1, 1, Conv, [128, 3, 1]], 99 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 100 | [-1, 1, Conv, [256, 1, 1]], # 71 101 | 102 | [-1, 1, Conv, [128, 1, 1]], 103 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 104 | [19, 1, Conv, [128, 1, 1]], # route backbone P3 105 | [[-1, -2], 1, Concat, [1]], 106 | 107 | [-1, 1, Conv, [128, 1, 1]], 108 | [-2, 1, Conv, [128, 1, 1]], 109 | [-1, 1, Conv, [64, 3, 1]], 110 | [-1, 1, Conv, [64, 3, 1]], 111 | [-1, 1, Conv, [64, 3, 1]], 112 | [-1, 1, Conv, [64, 3, 1]], 113 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 114 | [-1, 1, Conv, [128, 1, 1]], # 83 115 | 116 | [-1, 1, Conv, [256, 3, 2]], 117 | [[-1, 71], 1, Concat, [1]], # cat 118 | 119 | [-1, 1, Conv, [256, 1, 1]], 120 | [-2, 1, Conv, [256, 1, 1]], 121 | [-1, 1, Conv, [128, 3, 1]], 122 | [-1, 1, Conv, [128, 3, 1]], 123 | [-1, 1, Conv, [128, 3, 1]], 124 | [-1, 1, Conv, [128, 3, 1]], 125 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 126 | [-1, 1, Conv, [256, 1, 1]], # 93 127 | 128 | [-1, 1, Conv, [384, 3, 2]], 129 | [[-1, 59], 1, Concat, [1]], # cat 130 | 131 | [-1, 1, Conv, [384, 1, 1]], 132 | [-2, 1, Conv, [384, 1, 1]], 133 | [-1, 1, Conv, [192, 3, 1]], 134 | [-1, 1, Conv, [192, 3, 1]], 135 | [-1, 1, Conv, [192, 3, 1]], 136 | [-1, 1, Conv, [192, 3, 1]], 137 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 138 | [-1, 1, Conv, [384, 1, 1]], # 103 139 | 140 | [-1, 1, Conv, [512, 3, 2]], 141 | [[-1, 47], 1, Concat, [1]], # cat 142 | 143 | [-1, 1, Conv, [512, 1, 1]], 144 | [-2, 1, Conv, [512, 1, 1]], 145 | [-1, 1, Conv, [256, 3, 1]], 146 | [-1, 1, Conv, [256, 3, 1]], 147 | [-1, 1, Conv, [256, 3, 1]], 148 | [-1, 1, Conv, [256, 3, 1]], 149 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 150 | [-1, 1, Conv, [512, 1, 1]], # 113 151 | 152 | [83, 1, Conv, [256, 3, 1]], 153 | [93, 1, Conv, [512, 3, 1]], 154 | [103, 1, Conv, [768, 3, 1]], 155 | [113, 1, Conv, [1024, 3, 1]], 156 | 157 | [[114,115,116,117], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 158 | ] 159 | -------------------------------------------------------------------------------- /cfg/deploy/yolov7.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 7 | anchors: 8 | - [12,16, 19,36, 40,28] # P3/8 9 | - [36,75, 76,55, 72,146] # P4/16 10 | - [142,110, 192,243, 459,401] # P5/32 11 | 12 | # yolov7 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [32, 3, 1]], # 0 16 | 17 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 18 | [-1, 1, Conv, [64, 3, 1]], 19 | 20 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 21 | [-1, 1, Conv, [64, 1, 1]], 22 | [-2, 1, Conv, [64, 1, 1]], 23 | [-1, 1, Conv, [64, 3, 1]], 24 | [-1, 1, Conv, [64, 3, 1]], 25 | [-1, 1, Conv, [64, 3, 1]], 26 | [-1, 1, Conv, [64, 3, 1]], 27 | [[-1, -3, -5, -6], 1, Concat, [1]], 28 | [-1, 1, Conv, [256, 1, 1]], # 11 29 | 30 | [-1, 1, MP, []], 31 | [-1, 1, Conv, [128, 1, 1]], 32 | [-3, 1, Conv, [128, 1, 1]], 33 | [-1, 1, Conv, [128, 3, 2]], 34 | [[-1, -3], 1, Concat, [1]], # 16-P3/8 35 | [-1, 1, Conv, [128, 1, 1]], 36 | [-2, 1, Conv, [128, 1, 1]], 37 | [-1, 1, Conv, [128, 3, 1]], 38 | [-1, 1, Conv, [128, 3, 1]], 39 | [-1, 1, Conv, [128, 3, 1]], 40 | [-1, 1, Conv, [128, 3, 1]], 41 | [[-1, -3, -5, -6], 1, Concat, [1]], 42 | [-1, 1, Conv, [512, 1, 1]], # 24 43 | 44 | [-1, 1, MP, []], 45 | [-1, 1, Conv, [256, 1, 1]], 46 | [-3, 1, Conv, [256, 1, 1]], 47 | [-1, 1, Conv, [256, 3, 2]], 48 | [[-1, -3], 1, Concat, [1]], # 29-P4/16 49 | [-1, 1, Conv, [256, 1, 1]], 50 | [-2, 1, Conv, [256, 1, 1]], 51 | [-1, 1, Conv, [256, 3, 1]], 52 | [-1, 1, Conv, [256, 3, 1]], 53 | [-1, 1, Conv, [256, 3, 1]], 54 | [-1, 1, Conv, [256, 3, 1]], 55 | [[-1, -3, -5, -6], 1, Concat, [1]], 56 | [-1, 1, Conv, [1024, 1, 1]], # 37 57 | 58 | [-1, 1, MP, []], 59 | [-1, 1, Conv, [512, 1, 1]], 60 | [-3, 1, Conv, [512, 1, 1]], 61 | [-1, 1, Conv, [512, 3, 2]], 62 | [[-1, -3], 1, Concat, [1]], # 42-P5/32 63 | [-1, 1, Conv, [256, 1, 1]], 64 | [-2, 1, Conv, [256, 1, 1]], 65 | [-1, 1, Conv, [256, 3, 1]], 66 | [-1, 1, Conv, [256, 3, 1]], 67 | [-1, 1, Conv, [256, 3, 1]], 68 | [-1, 1, Conv, [256, 3, 1]], 69 | [[-1, -3, -5, -6], 1, Concat, [1]], 70 | [-1, 1, Conv, [1024, 1, 1]], # 50 71 | ] 72 | 73 | # yolov7 head 74 | head: 75 | [[-1, 1, SPPCSPC, [512]], # 51 76 | 77 | [-1, 1, Conv, [256, 1, 1]], 78 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 79 | [37, 1, Conv, [256, 1, 1]], # route backbone P4 80 | [[-1, -2], 1, Concat, [1]], 81 | 82 | [-1, 1, Conv, [256, 1, 1]], 83 | [-2, 1, Conv, [256, 1, 1]], 84 | [-1, 1, Conv, [128, 3, 1]], 85 | [-1, 1, Conv, [128, 3, 1]], 86 | [-1, 1, Conv, [128, 3, 1]], 87 | [-1, 1, Conv, [128, 3, 1]], 88 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 89 | [-1, 1, Conv, [256, 1, 1]], # 63 90 | 91 | [-1, 1, Conv, [128, 1, 1]], 92 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 93 | [24, 1, Conv, [128, 1, 1]], # route backbone P3 94 | [[-1, -2], 1, Concat, [1]], 95 | 96 | [-1, 1, Conv, [128, 1, 1]], 97 | [-2, 1, Conv, [128, 1, 1]], 98 | [-1, 1, Conv, [64, 3, 1]], 99 | [-1, 1, Conv, [64, 3, 1]], 100 | [-1, 1, Conv, [64, 3, 1]], 101 | [-1, 1, Conv, [64, 3, 1]], 102 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 103 | [-1, 1, Conv, [128, 1, 1]], # 75 104 | 105 | [-1, 1, MP, []], 106 | [-1, 1, Conv, [128, 1, 1]], 107 | [-3, 1, Conv, [128, 1, 1]], 108 | [-1, 1, Conv, [128, 3, 2]], 109 | [[-1, -3, 63], 1, Concat, [1]], 110 | 111 | [-1, 1, Conv, [256, 1, 1]], 112 | [-2, 1, Conv, [256, 1, 1]], 113 | [-1, 1, Conv, [128, 3, 1]], 114 | [-1, 1, Conv, [128, 3, 1]], 115 | [-1, 1, Conv, [128, 3, 1]], 116 | [-1, 1, Conv, [128, 3, 1]], 117 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 118 | [-1, 1, Conv, [256, 1, 1]], # 88 119 | 120 | [-1, 1, MP, []], 121 | [-1, 1, Conv, [256, 1, 1]], 122 | [-3, 1, Conv, [256, 1, 1]], 123 | [-1, 1, Conv, [256, 3, 2]], 124 | [[-1, -3, 51], 1, Concat, [1]], 125 | 126 | [-1, 1, Conv, [512, 1, 1]], 127 | [-2, 1, Conv, [512, 1, 1]], 128 | [-1, 1, Conv, [256, 3, 1]], 129 | [-1, 1, Conv, [256, 3, 1]], 130 | [-1, 1, Conv, [256, 3, 1]], 131 | [-1, 1, Conv, [256, 3, 1]], 132 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 133 | [-1, 1, Conv, [512, 1, 1]], # 101 134 | 135 | [75, 1, RepConv, [256, 3, 1]], 136 | [88, 1, RepConv, [512, 3, 1]], 137 | [101, 1, RepConv, [1024, 3, 1]], 138 | 139 | [[102,103,104], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 140 | ] 141 | -------------------------------------------------------------------------------- /cfg/deploy/yolov7_score.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 4 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 7 | anchors: 8 | - [12,16, 19,36, 40,28] # P3/8 9 | - [36,75, 76,55, 72,146] # P4/16 10 | - [142,110, 192,243, 459,401] # P5/32 11 | 12 | # yolov7 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [32, 3, 1]], # 0 16 | 17 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 18 | [-1, 1, Conv, [64, 3, 1]], 19 | 20 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 21 | [-1, 1, Conv, [64, 1, 1]], 22 | [-2, 1, Conv, [64, 1, 1]], 23 | [-1, 1, Conv, [64, 3, 1]], 24 | [-1, 1, Conv, [64, 3, 1]], 25 | [-1, 1, Conv, [64, 3, 1]], 26 | [-1, 1, Conv, [64, 3, 1]], 27 | [[-1, -3, -5, -6], 1, Concat, [1]], 28 | [-1, 1, Conv, [256, 1, 1]], # 11 29 | 30 | [-1, 1, MP, []], 31 | [-1, 1, Conv, [128, 1, 1]], 32 | [-3, 1, Conv, [128, 1, 1]], 33 | [-1, 1, Conv, [128, 3, 2]], 34 | [[-1, -3], 1, Concat, [1]], # 16-P3/8 35 | [-1, 1, Conv, [128, 1, 1]], 36 | [-2, 1, Conv, [128, 1, 1]], 37 | [-1, 1, Conv, [128, 3, 1]], 38 | [-1, 1, Conv, [128, 3, 1]], 39 | [-1, 1, Conv, [128, 3, 1]], 40 | [-1, 1, Conv, [128, 3, 1]], 41 | [[-1, -3, -5, -6], 1, Concat, [1]], 42 | [-1, 1, Conv, [512, 1, 1]], # 24 43 | 44 | [-1, 1, MP, []], 45 | [-1, 1, Conv, [256, 1, 1]], 46 | [-3, 1, Conv, [256, 1, 1]], 47 | [-1, 1, Conv, [256, 3, 2]], 48 | [[-1, -3], 1, Concat, [1]], # 29-P4/16 49 | [-1, 1, Conv, [256, 1, 1]], 50 | [-2, 1, Conv, [256, 1, 1]], 51 | [-1, 1, Conv, [256, 3, 1]], 52 | [-1, 1, Conv, [256, 3, 1]], 53 | [-1, 1, Conv, [256, 3, 1]], 54 | [-1, 1, Conv, [256, 3, 1]], 55 | [[-1, -3, -5, -6], 1, Concat, [1]], 56 | [-1, 1, Conv, [1024, 1, 1]], # 37 57 | 58 | [-1, 1, MP, []], 59 | [-1, 1, Conv, [512, 1, 1]], 60 | [-3, 1, Conv, [512, 1, 1]], 61 | [-1, 1, Conv, [512, 3, 2]], 62 | [[-1, -3], 1, Concat, [1]], # 42-P5/32 63 | [-1, 1, Conv, [256, 1, 1]], 64 | [-2, 1, Conv, [256, 1, 1]], 65 | [-1, 1, Conv, [256, 3, 1]], 66 | [-1, 1, Conv, [256, 3, 1]], 67 | [-1, 1, Conv, [256, 3, 1]], 68 | [-1, 1, Conv, [256, 3, 1]], 69 | [[-1, -3, -5, -6], 1, Concat, [1]], 70 | [-1, 1, Conv, [1024, 1, 1]], # 50 71 | ] 72 | 73 | # yolov7 head 74 | head: 75 | [[-1, 1, SPPCSPC, [512]], # 51 76 | 77 | [-1, 1, Conv, [256, 1, 1]], 78 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 79 | [37, 1, Conv, [256, 1, 1]], # route backbone P4 80 | [[-1, -2], 1, Concat, [1]], 81 | 82 | [-1, 1, Conv, [256, 1, 1]], 83 | [-2, 1, Conv, [256, 1, 1]], 84 | [-1, 1, Conv, [128, 3, 1]], 85 | [-1, 1, Conv, [128, 3, 1]], 86 | [-1, 1, Conv, [128, 3, 1]], 87 | [-1, 1, Conv, [128, 3, 1]], 88 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 89 | [-1, 1, Conv, [256, 1, 1]], # 63 90 | 91 | [-1, 1, Conv, [128, 1, 1]], 92 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 93 | [24, 1, Conv, [128, 1, 1]], # route backbone P3 94 | [[-1, -2], 1, Concat, [1]], 95 | 96 | [-1, 1, Conv, [128, 1, 1]], 97 | [-2, 1, Conv, [128, 1, 1]], 98 | [-1, 1, Conv, [64, 3, 1]], 99 | [-1, 1, Conv, [64, 3, 1]], 100 | [-1, 1, Conv, [64, 3, 1]], 101 | [-1, 1, Conv, [64, 3, 1]], 102 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 103 | [-1, 1, Conv, [128, 1, 1]], # 75 104 | 105 | [-1, 1, MP, []], 106 | [-1, 1, Conv, [128, 1, 1]], 107 | [-3, 1, Conv, [128, 1, 1]], 108 | [-1, 1, Conv, [128, 3, 2]], 109 | [[-1, -3, 63], 1, Concat, [1]], 110 | 111 | [-1, 1, Conv, [256, 1, 1]], 112 | [-2, 1, Conv, [256, 1, 1]], 113 | [-1, 1, Conv, [128, 3, 1]], 114 | [-1, 1, Conv, [128, 3, 1]], 115 | [-1, 1, Conv, [128, 3, 1]], 116 | [-1, 1, Conv, [128, 3, 1]], 117 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 118 | [-1, 1, Conv, [256, 1, 1]], # 88 119 | 120 | [-1, 1, MP, []], 121 | [-1, 1, Conv, [256, 1, 1]], 122 | [-3, 1, Conv, [256, 1, 1]], 123 | [-1, 1, Conv, [256, 3, 2]], 124 | [[-1, -3, 51], 1, Concat, [1]], 125 | 126 | [-1, 1, Conv, [512, 1, 1]], 127 | [-2, 1, Conv, [512, 1, 1]], 128 | [-1, 1, Conv, [256, 3, 1]], 129 | [-1, 1, Conv, [256, 3, 1]], 130 | [-1, 1, Conv, [256, 3, 1]], 131 | [-1, 1, Conv, [256, 3, 1]], 132 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 133 | [-1, 1, Conv, [512, 1, 1]], # 101 134 | 135 | [75, 1, RepConv, [256, 3, 1]], 136 | [88, 1, RepConv, [512, 3, 1]], 137 | [101, 1, RepConv, [1024, 3, 1]], 138 | 139 | [[102,103,104], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 140 | ] 141 | -------------------------------------------------------------------------------- /cfg/deploy/yolov7x.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 7 | anchors: 8 | - [12,16, 19,36, 40,28] # P3/8 9 | - [36,75, 76,55, 72,146] # P4/16 10 | - [142,110, 192,243, 459,401] # P5/32 11 | 12 | # yolov7x backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [40, 3, 1]], # 0 16 | 17 | [-1, 1, Conv, [80, 3, 2]], # 1-P1/2 18 | [-1, 1, Conv, [80, 3, 1]], 19 | 20 | [-1, 1, Conv, [160, 3, 2]], # 3-P2/4 21 | [-1, 1, Conv, [64, 1, 1]], 22 | [-2, 1, Conv, [64, 1, 1]], 23 | [-1, 1, Conv, [64, 3, 1]], 24 | [-1, 1, Conv, [64, 3, 1]], 25 | [-1, 1, Conv, [64, 3, 1]], 26 | [-1, 1, Conv, [64, 3, 1]], 27 | [-1, 1, Conv, [64, 3, 1]], 28 | [-1, 1, Conv, [64, 3, 1]], 29 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 30 | [-1, 1, Conv, [320, 1, 1]], # 13 31 | 32 | [-1, 1, MP, []], 33 | [-1, 1, Conv, [160, 1, 1]], 34 | [-3, 1, Conv, [160, 1, 1]], 35 | [-1, 1, Conv, [160, 3, 2]], 36 | [[-1, -3], 1, Concat, [1]], # 18-P3/8 37 | [-1, 1, Conv, [128, 1, 1]], 38 | [-2, 1, Conv, [128, 1, 1]], 39 | [-1, 1, Conv, [128, 3, 1]], 40 | [-1, 1, Conv, [128, 3, 1]], 41 | [-1, 1, Conv, [128, 3, 1]], 42 | [-1, 1, Conv, [128, 3, 1]], 43 | [-1, 1, Conv, [128, 3, 1]], 44 | [-1, 1, Conv, [128, 3, 1]], 45 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 46 | [-1, 1, Conv, [640, 1, 1]], # 28 47 | 48 | [-1, 1, MP, []], 49 | [-1, 1, Conv, [320, 1, 1]], 50 | [-3, 1, Conv, [320, 1, 1]], 51 | [-1, 1, Conv, [320, 3, 2]], 52 | [[-1, -3], 1, Concat, [1]], # 33-P4/16 53 | [-1, 1, Conv, [256, 1, 1]], 54 | [-2, 1, Conv, [256, 1, 1]], 55 | [-1, 1, Conv, [256, 3, 1]], 56 | [-1, 1, Conv, [256, 3, 1]], 57 | [-1, 1, Conv, [256, 3, 1]], 58 | [-1, 1, Conv, [256, 3, 1]], 59 | [-1, 1, Conv, [256, 3, 1]], 60 | [-1, 1, Conv, [256, 3, 1]], 61 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 62 | [-1, 1, Conv, [1280, 1, 1]], # 43 63 | 64 | [-1, 1, MP, []], 65 | [-1, 1, Conv, [640, 1, 1]], 66 | [-3, 1, Conv, [640, 1, 1]], 67 | [-1, 1, Conv, [640, 3, 2]], 68 | [[-1, -3], 1, Concat, [1]], # 48-P5/32 69 | [-1, 1, Conv, [256, 1, 1]], 70 | [-2, 1, Conv, [256, 1, 1]], 71 | [-1, 1, Conv, [256, 3, 1]], 72 | [-1, 1, Conv, [256, 3, 1]], 73 | [-1, 1, Conv, [256, 3, 1]], 74 | [-1, 1, Conv, [256, 3, 1]], 75 | [-1, 1, Conv, [256, 3, 1]], 76 | [-1, 1, Conv, [256, 3, 1]], 77 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 78 | [-1, 1, Conv, [1280, 1, 1]], # 58 79 | ] 80 | 81 | # yolov7x head 82 | head: 83 | [[-1, 1, SPPCSPC, [640]], # 59 84 | 85 | [-1, 1, Conv, [320, 1, 1]], 86 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 87 | [43, 1, Conv, [320, 1, 1]], # route backbone P4 88 | [[-1, -2], 1, Concat, [1]], 89 | 90 | [-1, 1, Conv, [256, 1, 1]], 91 | [-2, 1, Conv, [256, 1, 1]], 92 | [-1, 1, Conv, [256, 3, 1]], 93 | [-1, 1, Conv, [256, 3, 1]], 94 | [-1, 1, Conv, [256, 3, 1]], 95 | [-1, 1, Conv, [256, 3, 1]], 96 | [-1, 1, Conv, [256, 3, 1]], 97 | [-1, 1, Conv, [256, 3, 1]], 98 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 99 | [-1, 1, Conv, [320, 1, 1]], # 73 100 | 101 | [-1, 1, Conv, [160, 1, 1]], 102 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 103 | [28, 1, Conv, [160, 1, 1]], # route backbone P3 104 | [[-1, -2], 1, Concat, [1]], 105 | 106 | [-1, 1, Conv, [128, 1, 1]], 107 | [-2, 1, Conv, [128, 1, 1]], 108 | [-1, 1, Conv, [128, 3, 1]], 109 | [-1, 1, Conv, [128, 3, 1]], 110 | [-1, 1, Conv, [128, 3, 1]], 111 | [-1, 1, Conv, [128, 3, 1]], 112 | [-1, 1, Conv, [128, 3, 1]], 113 | [-1, 1, Conv, [128, 3, 1]], 114 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 115 | [-1, 1, Conv, [160, 1, 1]], # 87 116 | 117 | [-1, 1, MP, []], 118 | [-1, 1, Conv, [160, 1, 1]], 119 | [-3, 1, Conv, [160, 1, 1]], 120 | [-1, 1, Conv, [160, 3, 2]], 121 | [[-1, -3, 73], 1, Concat, [1]], 122 | 123 | [-1, 1, Conv, [256, 1, 1]], 124 | [-2, 1, Conv, [256, 1, 1]], 125 | [-1, 1, Conv, [256, 3, 1]], 126 | [-1, 1, Conv, [256, 3, 1]], 127 | [-1, 1, Conv, [256, 3, 1]], 128 | [-1, 1, Conv, [256, 3, 1]], 129 | [-1, 1, Conv, [256, 3, 1]], 130 | [-1, 1, Conv, [256, 3, 1]], 131 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 132 | [-1, 1, Conv, [320, 1, 1]], # 102 133 | 134 | [-1, 1, MP, []], 135 | [-1, 1, Conv, [320, 1, 1]], 136 | [-3, 1, Conv, [320, 1, 1]], 137 | [-1, 1, Conv, [320, 3, 2]], 138 | [[-1, -3, 59], 1, Concat, [1]], 139 | 140 | [-1, 1, Conv, [512, 1, 1]], 141 | [-2, 1, Conv, [512, 1, 1]], 142 | [-1, 1, Conv, [512, 3, 1]], 143 | [-1, 1, Conv, [512, 3, 1]], 144 | [-1, 1, Conv, [512, 3, 1]], 145 | [-1, 1, Conv, [512, 3, 1]], 146 | [-1, 1, Conv, [512, 3, 1]], 147 | [-1, 1, Conv, [512, 3, 1]], 148 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 149 | [-1, 1, Conv, [640, 1, 1]], # 117 150 | 151 | [87, 1, Conv, [320, 3, 1]], 152 | [102, 1, Conv, [640, 3, 1]], 153 | [117, 1, Conv, [1280, 3, 1]], 154 | 155 | [[118,119,120], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 156 | ] 157 | -------------------------------------------------------------------------------- /cfg/training/yolov7-tiny.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 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 | # yolov7-tiny backbone 13 | backbone: 14 | # [from, number, module, args] c2, k=1, s=1, p=None, g=1, act=True 15 | [[-1, 1, Conv, [32, 3, 2, None, 1, nn.LeakyReLU(0.1)]], # 0-P1/2 16 | 17 | [-1, 1, Conv, [64, 3, 2, None, 1, nn.LeakyReLU(0.1)]], # 1-P2/4 18 | 19 | [-1, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 20 | [-2, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 21 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 22 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 23 | [[-1, -2, -3, -4], 1, Concat, [1]], 24 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 7 25 | 26 | [-1, 1, MP, []], # 8-P3/8 27 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 28 | [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 29 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 30 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 31 | [[-1, -2, -3, -4], 1, Concat, [1]], 32 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 14 33 | 34 | [-1, 1, MP, []], # 15-P4/16 35 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 36 | [-2, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 37 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 38 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 39 | [[-1, -2, -3, -4], 1, Concat, [1]], 40 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 21 41 | 42 | [-1, 1, MP, []], # 22-P5/32 43 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 44 | [-2, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 45 | [-1, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 46 | [-1, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 47 | [[-1, -2, -3, -4], 1, Concat, [1]], 48 | [-1, 1, Conv, [512, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 28 49 | ] 50 | 51 | # yolov7-tiny head 52 | head: 53 | [[-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 54 | [-2, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 55 | [-1, 1, SP, [5]], 56 | [-2, 1, SP, [9]], 57 | [-3, 1, SP, [13]], 58 | [[-1, -2, -3, -4], 1, Concat, [1]], 59 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 60 | [[-1, -7], 1, Concat, [1]], 61 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 37 62 | 63 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 64 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 65 | [21, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # route backbone P4 66 | [[-1, -2], 1, Concat, [1]], 67 | 68 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 69 | [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 70 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 71 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 72 | [[-1, -2, -3, -4], 1, Concat, [1]], 73 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 47 74 | 75 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 76 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 77 | [14, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # route backbone P3 78 | [[-1, -2], 1, Concat, [1]], 79 | 80 | [-1, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 81 | [-2, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 82 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 83 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 84 | [[-1, -2, -3, -4], 1, Concat, [1]], 85 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 57 86 | 87 | [-1, 1, Conv, [128, 3, 2, None, 1, nn.LeakyReLU(0.1)]], 88 | [[-1, 47], 1, Concat, [1]], 89 | 90 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 91 | [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 92 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 93 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 94 | [[-1, -2, -3, -4], 1, Concat, [1]], 95 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 65 96 | 97 | [-1, 1, Conv, [256, 3, 2, None, 1, nn.LeakyReLU(0.1)]], 98 | [[-1, 37], 1, Concat, [1]], 99 | 100 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 101 | [-2, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], 102 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 103 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 104 | [[-1, -2, -3, -4], 1, Concat, [1]], 105 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 73 106 | 107 | [57, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 108 | [65, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 109 | [73, 1, Conv, [512, 3, 1, None, 1, nn.LeakyReLU(0.1)]], 110 | 111 | [[74,75,76], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5) 112 | ] 113 | -------------------------------------------------------------------------------- /cfg/training/yolov7.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 7 | anchors: 8 | - [12,16, 19,36, 40,28] # P3/8 9 | - [36,75, 76,55, 72,146] # P4/16 10 | - [142,110, 192,243, 459,401] # P5/32 11 | 12 | # yolov7 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [32, 3, 1]], # 0 16 | 17 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 18 | [-1, 1, Conv, [64, 3, 1]], 19 | 20 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 21 | [-1, 1, Conv, [64, 1, 1]], 22 | [-2, 1, Conv, [64, 1, 1]], 23 | [-1, 1, Conv, [64, 3, 1]], 24 | [-1, 1, Conv, [64, 3, 1]], 25 | [-1, 1, Conv, [64, 3, 1]], 26 | [-1, 1, Conv, [64, 3, 1]], 27 | [[-1, -3, -5, -6], 1, Concat, [1]], 28 | [-1, 1, Conv, [256, 1, 1]], # 11 29 | 30 | [-1, 1, MP, []], 31 | [-1, 1, Conv, [128, 1, 1]], 32 | [-3, 1, Conv, [128, 1, 1]], 33 | [-1, 1, Conv, [128, 3, 2]], 34 | [[-1, -3], 1, Concat, [1]], # 16-P3/8 35 | [-1, 1, Conv, [128, 1, 1]], 36 | [-2, 1, Conv, [128, 1, 1]], 37 | [-1, 1, Conv, [128, 3, 1]], 38 | [-1, 1, Conv, [128, 3, 1]], 39 | [-1, 1, Conv, [128, 3, 1]], 40 | [-1, 1, Conv, [128, 3, 1]], 41 | [[-1, -3, -5, -6], 1, Concat, [1]], 42 | [-1, 1, Conv, [512, 1, 1]], # 24 43 | 44 | [-1, 1, MP, []], 45 | [-1, 1, Conv, [256, 1, 1]], 46 | [-3, 1, Conv, [256, 1, 1]], 47 | [-1, 1, Conv, [256, 3, 2]], 48 | [[-1, -3], 1, Concat, [1]], # 29-P4/16 49 | [-1, 1, Conv, [256, 1, 1]], 50 | [-2, 1, Conv, [256, 1, 1]], 51 | [-1, 1, Conv, [256, 3, 1]], 52 | [-1, 1, Conv, [256, 3, 1]], 53 | [-1, 1, Conv, [256, 3, 1]], 54 | [-1, 1, Conv, [256, 3, 1]], 55 | [[-1, -3, -5, -6], 1, Concat, [1]], 56 | [-1, 1, Conv, [1024, 1, 1]], # 37 57 | 58 | [-1, 1, MP, []], 59 | [-1, 1, Conv, [512, 1, 1]], 60 | [-3, 1, Conv, [512, 1, 1]], 61 | [-1, 1, Conv, [512, 3, 2]], 62 | [[-1, -3], 1, Concat, [1]], # 42-P5/32 63 | [-1, 1, Conv, [256, 1, 1]], 64 | [-2, 1, Conv, [256, 1, 1]], 65 | [-1, 1, Conv, [256, 3, 1]], 66 | [-1, 1, Conv, [256, 3, 1]], 67 | [-1, 1, Conv, [256, 3, 1]], 68 | [-1, 1, Conv, [256, 3, 1]], 69 | [[-1, -3, -5, -6], 1, Concat, [1]], 70 | [-1, 1, Conv, [1024, 1, 1]], # 50 71 | ] 72 | 73 | # yolov7 head 74 | head: 75 | [[-1, 1, SPPCSPC, [512]], # 51 76 | 77 | [-1, 1, Conv, [256, 1, 1]], 78 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 79 | [37, 1, Conv, [256, 1, 1]], # route backbone P4 80 | [[-1, -2], 1, Concat, [1]], 81 | 82 | [-1, 1, Conv, [256, 1, 1]], 83 | [-2, 1, Conv, [256, 1, 1]], 84 | [-1, 1, Conv, [128, 3, 1]], 85 | [-1, 1, Conv, [128, 3, 1]], 86 | [-1, 1, Conv, [128, 3, 1]], 87 | [-1, 1, Conv, [128, 3, 1]], 88 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 89 | [-1, 1, Conv, [256, 1, 1]], # 63 90 | 91 | [-1, 1, Conv, [128, 1, 1]], 92 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 93 | [24, 1, Conv, [128, 1, 1]], # route backbone P3 94 | [[-1, -2], 1, Concat, [1]], 95 | 96 | [-1, 1, Conv, [128, 1, 1]], 97 | [-2, 1, Conv, [128, 1, 1]], 98 | [-1, 1, Conv, [64, 3, 1]], 99 | [-1, 1, Conv, [64, 3, 1]], 100 | [-1, 1, Conv, [64, 3, 1]], 101 | [-1, 1, Conv, [64, 3, 1]], 102 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 103 | [-1, 1, Conv, [128, 1, 1]], # 75 104 | 105 | [-1, 1, MP, []], 106 | [-1, 1, Conv, [128, 1, 1]], 107 | [-3, 1, Conv, [128, 1, 1]], 108 | [-1, 1, Conv, [128, 3, 2]], 109 | [[-1, -3, 63], 1, Concat, [1]], 110 | 111 | [-1, 1, Conv, [256, 1, 1]], 112 | [-2, 1, Conv, [256, 1, 1]], 113 | [-1, 1, Conv, [128, 3, 1]], 114 | [-1, 1, Conv, [128, 3, 1]], 115 | [-1, 1, Conv, [128, 3, 1]], 116 | [-1, 1, Conv, [128, 3, 1]], 117 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 118 | [-1, 1, Conv, [256, 1, 1]], # 88 119 | 120 | [-1, 1, MP, []], 121 | [-1, 1, Conv, [256, 1, 1]], 122 | [-3, 1, Conv, [256, 1, 1]], 123 | [-1, 1, Conv, [256, 3, 2]], 124 | [[-1, -3, 51], 1, Concat, [1]], 125 | 126 | [-1, 1, Conv, [512, 1, 1]], 127 | [-2, 1, Conv, [512, 1, 1]], 128 | [-1, 1, Conv, [256, 3, 1]], 129 | [-1, 1, Conv, [256, 3, 1]], 130 | [-1, 1, Conv, [256, 3, 1]], 131 | [-1, 1, Conv, [256, 3, 1]], 132 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 133 | [-1, 1, Conv, [512, 1, 1]], # 101 134 | 135 | [75, 1, RepConv, [256, 3, 1]], 136 | [88, 1, RepConv, [512, 3, 1]], 137 | [101, 1, RepConv, [1024, 3, 1]], 138 | 139 | [[102,103,104], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5) 140 | ] 141 | -------------------------------------------------------------------------------- /cfg/training/yolov7_score.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 4 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 7 | anchors: 8 | - [12,16, 19,36, 40,28] # P3/8 9 | - [36,75, 76,55, 72,146] # P4/16 10 | - [142,110, 192,243, 459,401] # P5/32 11 | 12 | # yolov7 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [32, 3, 1]], # 0 16 | 17 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 18 | [-1, 1, Conv, [64, 3, 1]], 19 | 20 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 21 | [-1, 1, Conv, [64, 1, 1]], 22 | [-2, 1, Conv, [64, 1, 1]], 23 | [-1, 1, Conv, [64, 3, 1]], 24 | [-1, 1, Conv, [64, 3, 1]], 25 | [-1, 1, Conv, [64, 3, 1]], 26 | [-1, 1, Conv, [64, 3, 1]], 27 | [[-1, -3, -5, -6], 1, Concat, [1]], 28 | [-1, 1, Conv, [256, 1, 1]], # 11 29 | 30 | [-1, 1, MP, []], 31 | [-1, 1, Conv, [128, 1, 1]], 32 | [-3, 1, Conv, [128, 1, 1]], 33 | [-1, 1, Conv, [128, 3, 2]], 34 | [[-1, -3], 1, Concat, [1]], # 16-P3/8 35 | [-1, 1, Conv, [128, 1, 1]], 36 | [-2, 1, Conv, [128, 1, 1]], 37 | [-1, 1, Conv, [128, 3, 1]], 38 | [-1, 1, Conv, [128, 3, 1]], 39 | [-1, 1, Conv, [128, 3, 1]], 40 | [-1, 1, Conv, [128, 3, 1]], 41 | [[-1, -3, -5, -6], 1, Concat, [1]], 42 | [-1, 1, Conv, [512, 1, 1]], # 24 43 | 44 | [-1, 1, MP, []], 45 | [-1, 1, Conv, [256, 1, 1]], 46 | [-3, 1, Conv, [256, 1, 1]], 47 | [-1, 1, Conv, [256, 3, 2]], 48 | [[-1, -3], 1, Concat, [1]], # 29-P4/16 49 | [-1, 1, Conv, [256, 1, 1]], 50 | [-2, 1, Conv, [256, 1, 1]], 51 | [-1, 1, Conv, [256, 3, 1]], 52 | [-1, 1, Conv, [256, 3, 1]], 53 | [-1, 1, Conv, [256, 3, 1]], 54 | [-1, 1, Conv, [256, 3, 1]], 55 | [[-1, -3, -5, -6], 1, Concat, [1]], 56 | [-1, 1, Conv, [1024, 1, 1]], # 37 57 | 58 | [-1, 1, MP, []], 59 | [-1, 1, Conv, [512, 1, 1]], 60 | [-3, 1, Conv, [512, 1, 1]], 61 | [-1, 1, Conv, [512, 3, 2]], 62 | [[-1, -3], 1, Concat, [1]], # 42-P5/32 63 | [-1, 1, Conv, [256, 1, 1]], 64 | [-2, 1, Conv, [256, 1, 1]], 65 | [-1, 1, Conv, [256, 3, 1]], 66 | [-1, 1, Conv, [256, 3, 1]], 67 | [-1, 1, Conv, [256, 3, 1]], 68 | [-1, 1, Conv, [256, 3, 1]], 69 | [[-1, -3, -5, -6], 1, Concat, [1]], 70 | [-1, 1, Conv, [1024, 1, 1]], # 50 71 | ] 72 | 73 | # yolov7 head 74 | head: 75 | [[-1, 1, SPPCSPC, [512]], # 51 76 | 77 | [-1, 1, Conv, [256, 1, 1]], 78 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 79 | [37, 1, Conv, [256, 1, 1]], # route backbone P4 80 | [[-1, -2], 1, Concat, [1]], 81 | 82 | [-1, 1, Conv, [256, 1, 1]], 83 | [-2, 1, Conv, [256, 1, 1]], 84 | [-1, 1, Conv, [128, 3, 1]], 85 | [-1, 1, Conv, [128, 3, 1]], 86 | [-1, 1, Conv, [128, 3, 1]], 87 | [-1, 1, Conv, [128, 3, 1]], 88 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 89 | [-1, 1, Conv, [256, 1, 1]], # 63 90 | 91 | [-1, 1, Conv, [128, 1, 1]], 92 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 93 | [24, 1, Conv, [128, 1, 1]], # route backbone P3 94 | [[-1, -2], 1, Concat, [1]], 95 | 96 | [-1, 1, Conv, [128, 1, 1]], 97 | [-2, 1, Conv, [128, 1, 1]], 98 | [-1, 1, Conv, [64, 3, 1]], 99 | [-1, 1, Conv, [64, 3, 1]], 100 | [-1, 1, Conv, [64, 3, 1]], 101 | [-1, 1, Conv, [64, 3, 1]], 102 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 103 | [-1, 1, Conv, [128, 1, 1]], # 75 104 | 105 | [-1, 1, MP, []], 106 | [-1, 1, Conv, [128, 1, 1]], 107 | [-3, 1, Conv, [128, 1, 1]], 108 | [-1, 1, Conv, [128, 3, 2]], 109 | [[-1, -3, 63], 1, Concat, [1]], 110 | 111 | [-1, 1, Conv, [256, 1, 1]], 112 | [-2, 1, Conv, [256, 1, 1]], 113 | [-1, 1, Conv, [128, 3, 1]], 114 | [-1, 1, Conv, [128, 3, 1]], 115 | [-1, 1, Conv, [128, 3, 1]], 116 | [-1, 1, Conv, [128, 3, 1]], 117 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 118 | [-1, 1, Conv, [256, 1, 1]], # 88 119 | 120 | [-1, 1, MP, []], 121 | [-1, 1, Conv, [256, 1, 1]], 122 | [-3, 1, Conv, [256, 1, 1]], 123 | [-1, 1, Conv, [256, 3, 2]], 124 | [[-1, -3, 51], 1, Concat, [1]], 125 | 126 | [-1, 1, Conv, [512, 1, 1]], 127 | [-2, 1, Conv, [512, 1, 1]], 128 | [-1, 1, Conv, [256, 3, 1]], 129 | [-1, 1, Conv, [256, 3, 1]], 130 | [-1, 1, Conv, [256, 3, 1]], 131 | [-1, 1, Conv, [256, 3, 1]], 132 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 133 | [-1, 1, Conv, [512, 1, 1]], # 101 134 | 135 | [75, 1, RepConv, [256, 3, 1]], 136 | [88, 1, RepConv, [512, 3, 1]], 137 | [101, 1, RepConv, [1024, 3, 1]], 138 | 139 | [[102,103,104], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5) 140 | ] 141 | -------------------------------------------------------------------------------- /cfg/training/yolov7d6.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 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 | # yolov7 backbone 14 | backbone: 15 | # [from, number, module, args], 16 | [[-1, 1, ReOrg, []], # 0 17 | [-1, 1, Conv, [96, 3, 1]], # 1-P1/2 18 | 19 | [-1, 1, DownC, [192]], # 2-P2/4 20 | [-1, 1, Conv, [64, 1, 1]], 21 | [-2, 1, Conv, [64, 1, 1]], 22 | [-1, 1, Conv, [64, 3, 1]], 23 | [-1, 1, Conv, [64, 3, 1]], 24 | [-1, 1, Conv, [64, 3, 1]], 25 | [-1, 1, Conv, [64, 3, 1]], 26 | [-1, 1, Conv, [64, 3, 1]], 27 | [-1, 1, Conv, [64, 3, 1]], 28 | [-1, 1, Conv, [64, 3, 1]], 29 | [-1, 1, Conv, [64, 3, 1]], 30 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]], 31 | [-1, 1, Conv, [192, 1, 1]], # 14 32 | 33 | [-1, 1, DownC, [384]], # 15-P3/8 34 | [-1, 1, Conv, [128, 1, 1]], 35 | [-2, 1, Conv, [128, 1, 1]], 36 | [-1, 1, Conv, [128, 3, 1]], 37 | [-1, 1, Conv, [128, 3, 1]], 38 | [-1, 1, Conv, [128, 3, 1]], 39 | [-1, 1, Conv, [128, 3, 1]], 40 | [-1, 1, Conv, [128, 3, 1]], 41 | [-1, 1, Conv, [128, 3, 1]], 42 | [-1, 1, Conv, [128, 3, 1]], 43 | [-1, 1, Conv, [128, 3, 1]], 44 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]], 45 | [-1, 1, Conv, [384, 1, 1]], # 27 46 | 47 | [-1, 1, DownC, [768]], # 28-P4/16 48 | [-1, 1, Conv, [256, 1, 1]], 49 | [-2, 1, Conv, [256, 1, 1]], 50 | [-1, 1, Conv, [256, 3, 1]], 51 | [-1, 1, Conv, [256, 3, 1]], 52 | [-1, 1, Conv, [256, 3, 1]], 53 | [-1, 1, Conv, [256, 3, 1]], 54 | [-1, 1, Conv, [256, 3, 1]], 55 | [-1, 1, Conv, [256, 3, 1]], 56 | [-1, 1, Conv, [256, 3, 1]], 57 | [-1, 1, Conv, [256, 3, 1]], 58 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]], 59 | [-1, 1, Conv, [768, 1, 1]], # 40 60 | 61 | [-1, 1, DownC, [1152]], # 41-P5/32 62 | [-1, 1, Conv, [384, 1, 1]], 63 | [-2, 1, Conv, [384, 1, 1]], 64 | [-1, 1, Conv, [384, 3, 1]], 65 | [-1, 1, Conv, [384, 3, 1]], 66 | [-1, 1, Conv, [384, 3, 1]], 67 | [-1, 1, Conv, [384, 3, 1]], 68 | [-1, 1, Conv, [384, 3, 1]], 69 | [-1, 1, Conv, [384, 3, 1]], 70 | [-1, 1, Conv, [384, 3, 1]], 71 | [-1, 1, Conv, [384, 3, 1]], 72 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]], 73 | [-1, 1, Conv, [1152, 1, 1]], # 53 74 | 75 | [-1, 1, DownC, [1536]], # 54-P6/64 76 | [-1, 1, Conv, [512, 1, 1]], 77 | [-2, 1, Conv, [512, 1, 1]], 78 | [-1, 1, Conv, [512, 3, 1]], 79 | [-1, 1, Conv, [512, 3, 1]], 80 | [-1, 1, Conv, [512, 3, 1]], 81 | [-1, 1, Conv, [512, 3, 1]], 82 | [-1, 1, Conv, [512, 3, 1]], 83 | [-1, 1, Conv, [512, 3, 1]], 84 | [-1, 1, Conv, [512, 3, 1]], 85 | [-1, 1, Conv, [512, 3, 1]], 86 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]], 87 | [-1, 1, Conv, [1536, 1, 1]], # 66 88 | ] 89 | 90 | # yolov7 head 91 | head: 92 | [[-1, 1, SPPCSPC, [768]], # 67 93 | 94 | [-1, 1, Conv, [576, 1, 1]], 95 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 96 | [53, 1, Conv, [576, 1, 1]], # route backbone P5 97 | [[-1, -2], 1, Concat, [1]], 98 | 99 | [-1, 1, Conv, [384, 1, 1]], 100 | [-2, 1, Conv, [384, 1, 1]], 101 | [-1, 1, Conv, [192, 3, 1]], 102 | [-1, 1, Conv, [192, 3, 1]], 103 | [-1, 1, Conv, [192, 3, 1]], 104 | [-1, 1, Conv, [192, 3, 1]], 105 | [-1, 1, Conv, [192, 3, 1]], 106 | [-1, 1, Conv, [192, 3, 1]], 107 | [-1, 1, Conv, [192, 3, 1]], 108 | [-1, 1, Conv, [192, 3, 1]], 109 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]], 110 | [-1, 1, Conv, [576, 1, 1]], # 83 111 | 112 | [-1, 1, Conv, [384, 1, 1]], 113 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 114 | [40, 1, Conv, [384, 1, 1]], # route backbone P4 115 | [[-1, -2], 1, Concat, [1]], 116 | 117 | [-1, 1, Conv, [256, 1, 1]], 118 | [-2, 1, Conv, [256, 1, 1]], 119 | [-1, 1, Conv, [128, 3, 1]], 120 | [-1, 1, Conv, [128, 3, 1]], 121 | [-1, 1, Conv, [128, 3, 1]], 122 | [-1, 1, Conv, [128, 3, 1]], 123 | [-1, 1, Conv, [128, 3, 1]], 124 | [-1, 1, Conv, [128, 3, 1]], 125 | [-1, 1, Conv, [128, 3, 1]], 126 | [-1, 1, Conv, [128, 3, 1]], 127 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]], 128 | [-1, 1, Conv, [384, 1, 1]], # 99 129 | 130 | [-1, 1, Conv, [192, 1, 1]], 131 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 132 | [27, 1, Conv, [192, 1, 1]], # route backbone P3 133 | [[-1, -2], 1, Concat, [1]], 134 | 135 | [-1, 1, Conv, [128, 1, 1]], 136 | [-2, 1, Conv, [128, 1, 1]], 137 | [-1, 1, Conv, [64, 3, 1]], 138 | [-1, 1, Conv, [64, 3, 1]], 139 | [-1, 1, Conv, [64, 3, 1]], 140 | [-1, 1, Conv, [64, 3, 1]], 141 | [-1, 1, Conv, [64, 3, 1]], 142 | [-1, 1, Conv, [64, 3, 1]], 143 | [-1, 1, Conv, [64, 3, 1]], 144 | [-1, 1, Conv, [64, 3, 1]], 145 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]], 146 | [-1, 1, Conv, [192, 1, 1]], # 115 147 | 148 | [-1, 1, DownC, [384]], 149 | [[-1, 99], 1, Concat, [1]], 150 | 151 | [-1, 1, Conv, [256, 1, 1]], 152 | [-2, 1, Conv, [256, 1, 1]], 153 | [-1, 1, Conv, [128, 3, 1]], 154 | [-1, 1, Conv, [128, 3, 1]], 155 | [-1, 1, Conv, [128, 3, 1]], 156 | [-1, 1, Conv, [128, 3, 1]], 157 | [-1, 1, Conv, [128, 3, 1]], 158 | [-1, 1, Conv, [128, 3, 1]], 159 | [-1, 1, Conv, [128, 3, 1]], 160 | [-1, 1, Conv, [128, 3, 1]], 161 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]], 162 | [-1, 1, Conv, [384, 1, 1]], # 129 163 | 164 | [-1, 1, DownC, [576]], 165 | [[-1, 83], 1, Concat, [1]], 166 | 167 | [-1, 1, Conv, [384, 1, 1]], 168 | [-2, 1, Conv, [384, 1, 1]], 169 | [-1, 1, Conv, [192, 3, 1]], 170 | [-1, 1, Conv, [192, 3, 1]], 171 | [-1, 1, Conv, [192, 3, 1]], 172 | [-1, 1, Conv, [192, 3, 1]], 173 | [-1, 1, Conv, [192, 3, 1]], 174 | [-1, 1, Conv, [192, 3, 1]], 175 | [-1, 1, Conv, [192, 3, 1]], 176 | [-1, 1, Conv, [192, 3, 1]], 177 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]], 178 | [-1, 1, Conv, [576, 1, 1]], # 143 179 | 180 | [-1, 1, DownC, [768]], 181 | [[-1, 67], 1, Concat, [1]], 182 | 183 | [-1, 1, Conv, [512, 1, 1]], 184 | [-2, 1, Conv, [512, 1, 1]], 185 | [-1, 1, Conv, [256, 3, 1]], 186 | [-1, 1, Conv, [256, 3, 1]], 187 | [-1, 1, Conv, [256, 3, 1]], 188 | [-1, 1, Conv, [256, 3, 1]], 189 | [-1, 1, Conv, [256, 3, 1]], 190 | [-1, 1, Conv, [256, 3, 1]], 191 | [-1, 1, Conv, [256, 3, 1]], 192 | [-1, 1, Conv, [256, 3, 1]], 193 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]], 194 | [-1, 1, Conv, [768, 1, 1]], # 157 195 | 196 | [115, 1, Conv, [384, 3, 1]], 197 | [129, 1, Conv, [768, 3, 1]], 198 | [143, 1, Conv, [1152, 3, 1]], 199 | [157, 1, Conv, [1536, 3, 1]], 200 | 201 | [115, 1, Conv, [384, 3, 1]], 202 | [99, 1, Conv, [768, 3, 1]], 203 | [83, 1, Conv, [1152, 3, 1]], 204 | [67, 1, Conv, [1536, 3, 1]], 205 | 206 | [[158,159,160,161,162,163,164,165], 1, IAuxDetect, [nc, anchors]], # Detect(P3, P4, P5, P6) 207 | ] 208 | -------------------------------------------------------------------------------- /cfg/training/yolov7e6.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 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 | # yolov7 backbone 14 | backbone: 15 | # [from, number, module, args], 16 | [[-1, 1, ReOrg, []], # 0 17 | [-1, 1, Conv, [80, 3, 1]], # 1-P1/2 18 | 19 | [-1, 1, DownC, [160]], # 2-P2/4 20 | [-1, 1, Conv, [64, 1, 1]], 21 | [-2, 1, Conv, [64, 1, 1]], 22 | [-1, 1, Conv, [64, 3, 1]], 23 | [-1, 1, Conv, [64, 3, 1]], 24 | [-1, 1, Conv, [64, 3, 1]], 25 | [-1, 1, Conv, [64, 3, 1]], 26 | [-1, 1, Conv, [64, 3, 1]], 27 | [-1, 1, Conv, [64, 3, 1]], 28 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 29 | [-1, 1, Conv, [160, 1, 1]], # 12 30 | 31 | [-1, 1, DownC, [320]], # 13-P3/8 32 | [-1, 1, Conv, [128, 1, 1]], 33 | [-2, 1, Conv, [128, 1, 1]], 34 | [-1, 1, Conv, [128, 3, 1]], 35 | [-1, 1, Conv, [128, 3, 1]], 36 | [-1, 1, Conv, [128, 3, 1]], 37 | [-1, 1, Conv, [128, 3, 1]], 38 | [-1, 1, Conv, [128, 3, 1]], 39 | [-1, 1, Conv, [128, 3, 1]], 40 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 41 | [-1, 1, Conv, [320, 1, 1]], # 23 42 | 43 | [-1, 1, DownC, [640]], # 24-P4/16 44 | [-1, 1, Conv, [256, 1, 1]], 45 | [-2, 1, Conv, [256, 1, 1]], 46 | [-1, 1, Conv, [256, 3, 1]], 47 | [-1, 1, Conv, [256, 3, 1]], 48 | [-1, 1, Conv, [256, 3, 1]], 49 | [-1, 1, Conv, [256, 3, 1]], 50 | [-1, 1, Conv, [256, 3, 1]], 51 | [-1, 1, Conv, [256, 3, 1]], 52 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 53 | [-1, 1, Conv, [640, 1, 1]], # 34 54 | 55 | [-1, 1, DownC, [960]], # 35-P5/32 56 | [-1, 1, Conv, [384, 1, 1]], 57 | [-2, 1, Conv, [384, 1, 1]], 58 | [-1, 1, Conv, [384, 3, 1]], 59 | [-1, 1, Conv, [384, 3, 1]], 60 | [-1, 1, Conv, [384, 3, 1]], 61 | [-1, 1, Conv, [384, 3, 1]], 62 | [-1, 1, Conv, [384, 3, 1]], 63 | [-1, 1, Conv, [384, 3, 1]], 64 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 65 | [-1, 1, Conv, [960, 1, 1]], # 45 66 | 67 | [-1, 1, DownC, [1280]], # 46-P6/64 68 | [-1, 1, Conv, [512, 1, 1]], 69 | [-2, 1, Conv, [512, 1, 1]], 70 | [-1, 1, Conv, [512, 3, 1]], 71 | [-1, 1, Conv, [512, 3, 1]], 72 | [-1, 1, Conv, [512, 3, 1]], 73 | [-1, 1, Conv, [512, 3, 1]], 74 | [-1, 1, Conv, [512, 3, 1]], 75 | [-1, 1, Conv, [512, 3, 1]], 76 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 77 | [-1, 1, Conv, [1280, 1, 1]], # 56 78 | ] 79 | 80 | # yolov7 head 81 | head: 82 | [[-1, 1, SPPCSPC, [640]], # 57 83 | 84 | [-1, 1, Conv, [480, 1, 1]], 85 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 86 | [45, 1, Conv, [480, 1, 1]], # route backbone P5 87 | [[-1, -2], 1, Concat, [1]], 88 | 89 | [-1, 1, Conv, [384, 1, 1]], 90 | [-2, 1, Conv, [384, 1, 1]], 91 | [-1, 1, Conv, [192, 3, 1]], 92 | [-1, 1, Conv, [192, 3, 1]], 93 | [-1, 1, Conv, [192, 3, 1]], 94 | [-1, 1, Conv, [192, 3, 1]], 95 | [-1, 1, Conv, [192, 3, 1]], 96 | [-1, 1, Conv, [192, 3, 1]], 97 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 98 | [-1, 1, Conv, [480, 1, 1]], # 71 99 | 100 | [-1, 1, Conv, [320, 1, 1]], 101 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 102 | [34, 1, Conv, [320, 1, 1]], # route backbone P4 103 | [[-1, -2], 1, Concat, [1]], 104 | 105 | [-1, 1, Conv, [256, 1, 1]], 106 | [-2, 1, Conv, [256, 1, 1]], 107 | [-1, 1, Conv, [128, 3, 1]], 108 | [-1, 1, Conv, [128, 3, 1]], 109 | [-1, 1, Conv, [128, 3, 1]], 110 | [-1, 1, Conv, [128, 3, 1]], 111 | [-1, 1, Conv, [128, 3, 1]], 112 | [-1, 1, Conv, [128, 3, 1]], 113 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 114 | [-1, 1, Conv, [320, 1, 1]], # 85 115 | 116 | [-1, 1, Conv, [160, 1, 1]], 117 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 118 | [23, 1, Conv, [160, 1, 1]], # route backbone P3 119 | [[-1, -2], 1, Concat, [1]], 120 | 121 | [-1, 1, Conv, [128, 1, 1]], 122 | [-2, 1, Conv, [128, 1, 1]], 123 | [-1, 1, Conv, [64, 3, 1]], 124 | [-1, 1, Conv, [64, 3, 1]], 125 | [-1, 1, Conv, [64, 3, 1]], 126 | [-1, 1, Conv, [64, 3, 1]], 127 | [-1, 1, Conv, [64, 3, 1]], 128 | [-1, 1, Conv, [64, 3, 1]], 129 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 130 | [-1, 1, Conv, [160, 1, 1]], # 99 131 | 132 | [-1, 1, DownC, [320]], 133 | [[-1, 85], 1, Concat, [1]], 134 | 135 | [-1, 1, Conv, [256, 1, 1]], 136 | [-2, 1, Conv, [256, 1, 1]], 137 | [-1, 1, Conv, [128, 3, 1]], 138 | [-1, 1, Conv, [128, 3, 1]], 139 | [-1, 1, Conv, [128, 3, 1]], 140 | [-1, 1, Conv, [128, 3, 1]], 141 | [-1, 1, Conv, [128, 3, 1]], 142 | [-1, 1, Conv, [128, 3, 1]], 143 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 144 | [-1, 1, Conv, [320, 1, 1]], # 111 145 | 146 | [-1, 1, DownC, [480]], 147 | [[-1, 71], 1, Concat, [1]], 148 | 149 | [-1, 1, Conv, [384, 1, 1]], 150 | [-2, 1, Conv, [384, 1, 1]], 151 | [-1, 1, Conv, [192, 3, 1]], 152 | [-1, 1, Conv, [192, 3, 1]], 153 | [-1, 1, Conv, [192, 3, 1]], 154 | [-1, 1, Conv, [192, 3, 1]], 155 | [-1, 1, Conv, [192, 3, 1]], 156 | [-1, 1, Conv, [192, 3, 1]], 157 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 158 | [-1, 1, Conv, [480, 1, 1]], # 123 159 | 160 | [-1, 1, DownC, [640]], 161 | [[-1, 57], 1, Concat, [1]], 162 | 163 | [-1, 1, Conv, [512, 1, 1]], 164 | [-2, 1, Conv, [512, 1, 1]], 165 | [-1, 1, Conv, [256, 3, 1]], 166 | [-1, 1, Conv, [256, 3, 1]], 167 | [-1, 1, Conv, [256, 3, 1]], 168 | [-1, 1, Conv, [256, 3, 1]], 169 | [-1, 1, Conv, [256, 3, 1]], 170 | [-1, 1, Conv, [256, 3, 1]], 171 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]], 172 | [-1, 1, Conv, [640, 1, 1]], # 135 173 | 174 | [99, 1, Conv, [320, 3, 1]], 175 | [111, 1, Conv, [640, 3, 1]], 176 | [123, 1, Conv, [960, 3, 1]], 177 | [135, 1, Conv, [1280, 3, 1]], 178 | 179 | [99, 1, Conv, [320, 3, 1]], 180 | [85, 1, Conv, [640, 3, 1]], 181 | [71, 1, Conv, [960, 3, 1]], 182 | [57, 1, Conv, [1280, 3, 1]], 183 | 184 | [[136,137,138,139,140,141,142,143], 1, IAuxDetect, [nc, anchors]], # Detect(P3, P4, P5, P6) 185 | ] 186 | -------------------------------------------------------------------------------- /cfg/training/yolov7w6.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 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 | # yolov7 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [[-1, 1, ReOrg, []], # 0 17 | [-1, 1, Conv, [64, 3, 1]], # 1-P1/2 18 | 19 | [-1, 1, Conv, [128, 3, 2]], # 2-P2/4 20 | [-1, 1, Conv, [64, 1, 1]], 21 | [-2, 1, Conv, [64, 1, 1]], 22 | [-1, 1, Conv, [64, 3, 1]], 23 | [-1, 1, Conv, [64, 3, 1]], 24 | [-1, 1, Conv, [64, 3, 1]], 25 | [-1, 1, Conv, [64, 3, 1]], 26 | [[-1, -3, -5, -6], 1, Concat, [1]], 27 | [-1, 1, Conv, [128, 1, 1]], # 10 28 | 29 | [-1, 1, Conv, [256, 3, 2]], # 11-P3/8 30 | [-1, 1, Conv, [128, 1, 1]], 31 | [-2, 1, Conv, [128, 1, 1]], 32 | [-1, 1, Conv, [128, 3, 1]], 33 | [-1, 1, Conv, [128, 3, 1]], 34 | [-1, 1, Conv, [128, 3, 1]], 35 | [-1, 1, Conv, [128, 3, 1]], 36 | [[-1, -3, -5, -6], 1, Concat, [1]], 37 | [-1, 1, Conv, [256, 1, 1]], # 19 38 | 39 | [-1, 1, Conv, [512, 3, 2]], # 20-P4/16 40 | [-1, 1, Conv, [256, 1, 1]], 41 | [-2, 1, Conv, [256, 1, 1]], 42 | [-1, 1, Conv, [256, 3, 1]], 43 | [-1, 1, Conv, [256, 3, 1]], 44 | [-1, 1, Conv, [256, 3, 1]], 45 | [-1, 1, Conv, [256, 3, 1]], 46 | [[-1, -3, -5, -6], 1, Concat, [1]], 47 | [-1, 1, Conv, [512, 1, 1]], # 28 48 | 49 | [-1, 1, Conv, [768, 3, 2]], # 29-P5/32 50 | [-1, 1, Conv, [384, 1, 1]], 51 | [-2, 1, Conv, [384, 1, 1]], 52 | [-1, 1, Conv, [384, 3, 1]], 53 | [-1, 1, Conv, [384, 3, 1]], 54 | [-1, 1, Conv, [384, 3, 1]], 55 | [-1, 1, Conv, [384, 3, 1]], 56 | [[-1, -3, -5, -6], 1, Concat, [1]], 57 | [-1, 1, Conv, [768, 1, 1]], # 37 58 | 59 | [-1, 1, Conv, [1024, 3, 2]], # 38-P6/64 60 | [-1, 1, Conv, [512, 1, 1]], 61 | [-2, 1, Conv, [512, 1, 1]], 62 | [-1, 1, Conv, [512, 3, 1]], 63 | [-1, 1, Conv, [512, 3, 1]], 64 | [-1, 1, Conv, [512, 3, 1]], 65 | [-1, 1, Conv, [512, 3, 1]], 66 | [[-1, -3, -5, -6], 1, Concat, [1]], 67 | [-1, 1, Conv, [1024, 1, 1]], # 46 68 | ] 69 | 70 | # yolov7 head 71 | head: 72 | [[-1, 1, SPPCSPC, [512]], # 47 73 | 74 | [-1, 1, Conv, [384, 1, 1]], 75 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 76 | [37, 1, Conv, [384, 1, 1]], # route backbone P5 77 | [[-1, -2], 1, Concat, [1]], 78 | 79 | [-1, 1, Conv, [384, 1, 1]], 80 | [-2, 1, Conv, [384, 1, 1]], 81 | [-1, 1, Conv, [192, 3, 1]], 82 | [-1, 1, Conv, [192, 3, 1]], 83 | [-1, 1, Conv, [192, 3, 1]], 84 | [-1, 1, Conv, [192, 3, 1]], 85 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 86 | [-1, 1, Conv, [384, 1, 1]], # 59 87 | 88 | [-1, 1, Conv, [256, 1, 1]], 89 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 90 | [28, 1, Conv, [256, 1, 1]], # route backbone P4 91 | [[-1, -2], 1, Concat, [1]], 92 | 93 | [-1, 1, Conv, [256, 1, 1]], 94 | [-2, 1, Conv, [256, 1, 1]], 95 | [-1, 1, Conv, [128, 3, 1]], 96 | [-1, 1, Conv, [128, 3, 1]], 97 | [-1, 1, Conv, [128, 3, 1]], 98 | [-1, 1, Conv, [128, 3, 1]], 99 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 100 | [-1, 1, Conv, [256, 1, 1]], # 71 101 | 102 | [-1, 1, Conv, [128, 1, 1]], 103 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 104 | [19, 1, Conv, [128, 1, 1]], # route backbone P3 105 | [[-1, -2], 1, Concat, [1]], 106 | 107 | [-1, 1, Conv, [128, 1, 1]], 108 | [-2, 1, Conv, [128, 1, 1]], 109 | [-1, 1, Conv, [64, 3, 1]], 110 | [-1, 1, Conv, [64, 3, 1]], 111 | [-1, 1, Conv, [64, 3, 1]], 112 | [-1, 1, Conv, [64, 3, 1]], 113 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 114 | [-1, 1, Conv, [128, 1, 1]], # 83 115 | 116 | [-1, 1, Conv, [256, 3, 2]], 117 | [[-1, 71], 1, Concat, [1]], # cat 118 | 119 | [-1, 1, Conv, [256, 1, 1]], 120 | [-2, 1, Conv, [256, 1, 1]], 121 | [-1, 1, Conv, [128, 3, 1]], 122 | [-1, 1, Conv, [128, 3, 1]], 123 | [-1, 1, Conv, [128, 3, 1]], 124 | [-1, 1, Conv, [128, 3, 1]], 125 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 126 | [-1, 1, Conv, [256, 1, 1]], # 93 127 | 128 | [-1, 1, Conv, [384, 3, 2]], 129 | [[-1, 59], 1, Concat, [1]], # cat 130 | 131 | [-1, 1, Conv, [384, 1, 1]], 132 | [-2, 1, Conv, [384, 1, 1]], 133 | [-1, 1, Conv, [192, 3, 1]], 134 | [-1, 1, Conv, [192, 3, 1]], 135 | [-1, 1, Conv, [192, 3, 1]], 136 | [-1, 1, Conv, [192, 3, 1]], 137 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 138 | [-1, 1, Conv, [384, 1, 1]], # 103 139 | 140 | [-1, 1, Conv, [512, 3, 2]], 141 | [[-1, 47], 1, Concat, [1]], # cat 142 | 143 | [-1, 1, Conv, [512, 1, 1]], 144 | [-2, 1, Conv, [512, 1, 1]], 145 | [-1, 1, Conv, [256, 3, 1]], 146 | [-1, 1, Conv, [256, 3, 1]], 147 | [-1, 1, Conv, [256, 3, 1]], 148 | [-1, 1, Conv, [256, 3, 1]], 149 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]], 150 | [-1, 1, Conv, [512, 1, 1]], # 113 151 | 152 | [83, 1, Conv, [256, 3, 1]], 153 | [93, 1, Conv, [512, 3, 1]], 154 | [103, 1, Conv, [768, 3, 1]], 155 | [113, 1, Conv, [1024, 3, 1]], 156 | 157 | [83, 1, Conv, [320, 3, 1]], 158 | [71, 1, Conv, [640, 3, 1]], 159 | [59, 1, Conv, [960, 3, 1]], 160 | [47, 1, Conv, [1280, 3, 1]], 161 | 162 | [[114,115,116,117,118,119,120,121], 1, IAuxDetect, [nc, anchors]], # Detect(P3, P4, P5, P6) 163 | ] 164 | -------------------------------------------------------------------------------- /cfg/training/yolov7x.yaml: -------------------------------------------------------------------------------- 1 | # parameters 2 | nc: 80 # number of classes 3 | depth_multiple: 1.0 # model depth multiple 4 | width_multiple: 1.0 # layer channel multiple 5 | 6 | # anchors 7 | anchors: 8 | - [12,16, 19,36, 40,28] # P3/8 9 | - [36,75, 76,55, 72,146] # P4/16 10 | - [142,110, 192,243, 459,401] # P5/32 11 | 12 | # yolov7 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [[-1, 1, Conv, [40, 3, 1]], # 0 16 | 17 | [-1, 1, Conv, [80, 3, 2]], # 1-P1/2 18 | [-1, 1, Conv, [80, 3, 1]], 19 | 20 | [-1, 1, Conv, [160, 3, 2]], # 3-P2/4 21 | [-1, 1, Conv, [64, 1, 1]], 22 | [-2, 1, Conv, [64, 1, 1]], 23 | [-1, 1, Conv, [64, 3, 1]], 24 | [-1, 1, Conv, [64, 3, 1]], 25 | [-1, 1, Conv, [64, 3, 1]], 26 | [-1, 1, Conv, [64, 3, 1]], 27 | [-1, 1, Conv, [64, 3, 1]], 28 | [-1, 1, Conv, [64, 3, 1]], 29 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 30 | [-1, 1, Conv, [320, 1, 1]], # 13 31 | 32 | [-1, 1, MP, []], 33 | [-1, 1, Conv, [160, 1, 1]], 34 | [-3, 1, Conv, [160, 1, 1]], 35 | [-1, 1, Conv, [160, 3, 2]], 36 | [[-1, -3], 1, Concat, [1]], # 18-P3/8 37 | [-1, 1, Conv, [128, 1, 1]], 38 | [-2, 1, Conv, [128, 1, 1]], 39 | [-1, 1, Conv, [128, 3, 1]], 40 | [-1, 1, Conv, [128, 3, 1]], 41 | [-1, 1, Conv, [128, 3, 1]], 42 | [-1, 1, Conv, [128, 3, 1]], 43 | [-1, 1, Conv, [128, 3, 1]], 44 | [-1, 1, Conv, [128, 3, 1]], 45 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 46 | [-1, 1, Conv, [640, 1, 1]], # 28 47 | 48 | [-1, 1, MP, []], 49 | [-1, 1, Conv, [320, 1, 1]], 50 | [-3, 1, Conv, [320, 1, 1]], 51 | [-1, 1, Conv, [320, 3, 2]], 52 | [[-1, -3], 1, Concat, [1]], # 33-P4/16 53 | [-1, 1, Conv, [256, 1, 1]], 54 | [-2, 1, Conv, [256, 1, 1]], 55 | [-1, 1, Conv, [256, 3, 1]], 56 | [-1, 1, Conv, [256, 3, 1]], 57 | [-1, 1, Conv, [256, 3, 1]], 58 | [-1, 1, Conv, [256, 3, 1]], 59 | [-1, 1, Conv, [256, 3, 1]], 60 | [-1, 1, Conv, [256, 3, 1]], 61 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 62 | [-1, 1, Conv, [1280, 1, 1]], # 43 63 | 64 | [-1, 1, MP, []], 65 | [-1, 1, Conv, [640, 1, 1]], 66 | [-3, 1, Conv, [640, 1, 1]], 67 | [-1, 1, Conv, [640, 3, 2]], 68 | [[-1, -3], 1, Concat, [1]], # 48-P5/32 69 | [-1, 1, Conv, [256, 1, 1]], 70 | [-2, 1, Conv, [256, 1, 1]], 71 | [-1, 1, Conv, [256, 3, 1]], 72 | [-1, 1, Conv, [256, 3, 1]], 73 | [-1, 1, Conv, [256, 3, 1]], 74 | [-1, 1, Conv, [256, 3, 1]], 75 | [-1, 1, Conv, [256, 3, 1]], 76 | [-1, 1, Conv, [256, 3, 1]], 77 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 78 | [-1, 1, Conv, [1280, 1, 1]], # 58 79 | ] 80 | 81 | # yolov7 head 82 | head: 83 | [[-1, 1, SPPCSPC, [640]], # 59 84 | 85 | [-1, 1, Conv, [320, 1, 1]], 86 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 87 | [43, 1, Conv, [320, 1, 1]], # route backbone P4 88 | [[-1, -2], 1, Concat, [1]], 89 | 90 | [-1, 1, Conv, [256, 1, 1]], 91 | [-2, 1, Conv, [256, 1, 1]], 92 | [-1, 1, Conv, [256, 3, 1]], 93 | [-1, 1, Conv, [256, 3, 1]], 94 | [-1, 1, Conv, [256, 3, 1]], 95 | [-1, 1, Conv, [256, 3, 1]], 96 | [-1, 1, Conv, [256, 3, 1]], 97 | [-1, 1, Conv, [256, 3, 1]], 98 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 99 | [-1, 1, Conv, [320, 1, 1]], # 73 100 | 101 | [-1, 1, Conv, [160, 1, 1]], 102 | [-1, 1, nn.Upsample, [None, 2, 'nearest']], 103 | [28, 1, Conv, [160, 1, 1]], # route backbone P3 104 | [[-1, -2], 1, Concat, [1]], 105 | 106 | [-1, 1, Conv, [128, 1, 1]], 107 | [-2, 1, Conv, [128, 1, 1]], 108 | [-1, 1, Conv, [128, 3, 1]], 109 | [-1, 1, Conv, [128, 3, 1]], 110 | [-1, 1, Conv, [128, 3, 1]], 111 | [-1, 1, Conv, [128, 3, 1]], 112 | [-1, 1, Conv, [128, 3, 1]], 113 | [-1, 1, Conv, [128, 3, 1]], 114 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 115 | [-1, 1, Conv, [160, 1, 1]], # 87 116 | 117 | [-1, 1, MP, []], 118 | [-1, 1, Conv, [160, 1, 1]], 119 | [-3, 1, Conv, [160, 1, 1]], 120 | [-1, 1, Conv, [160, 3, 2]], 121 | [[-1, -3, 73], 1, Concat, [1]], 122 | 123 | [-1, 1, Conv, [256, 1, 1]], 124 | [-2, 1, Conv, [256, 1, 1]], 125 | [-1, 1, Conv, [256, 3, 1]], 126 | [-1, 1, Conv, [256, 3, 1]], 127 | [-1, 1, Conv, [256, 3, 1]], 128 | [-1, 1, Conv, [256, 3, 1]], 129 | [-1, 1, Conv, [256, 3, 1]], 130 | [-1, 1, Conv, [256, 3, 1]], 131 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 132 | [-1, 1, Conv, [320, 1, 1]], # 102 133 | 134 | [-1, 1, MP, []], 135 | [-1, 1, Conv, [320, 1, 1]], 136 | [-3, 1, Conv, [320, 1, 1]], 137 | [-1, 1, Conv, [320, 3, 2]], 138 | [[-1, -3, 59], 1, Concat, [1]], 139 | 140 | [-1, 1, Conv, [512, 1, 1]], 141 | [-2, 1, Conv, [512, 1, 1]], 142 | [-1, 1, Conv, [512, 3, 1]], 143 | [-1, 1, Conv, [512, 3, 1]], 144 | [-1, 1, Conv, [512, 3, 1]], 145 | [-1, 1, Conv, [512, 3, 1]], 146 | [-1, 1, Conv, [512, 3, 1]], 147 | [-1, 1, Conv, [512, 3, 1]], 148 | [[-1, -3, -5, -7, -8], 1, Concat, [1]], 149 | [-1, 1, Conv, [640, 1, 1]], # 117 150 | 151 | [87, 1, Conv, [320, 3, 1]], 152 | [102, 1, Conv, [640, 3, 1]], 153 | [117, 1, Conv, [1280, 3, 1]], 154 | 155 | [[118,119,120], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5) 156 | ] 157 | -------------------------------------------------------------------------------- /data/coco.yaml: -------------------------------------------------------------------------------- 1 | # COCO 2017 dataset http://cocodataset.org 2 | 3 | # download command/URL (optional) 4 | download: bash ./scripts/get_coco.sh 5 | 6 | # train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/] 7 | train: ./coco/train2017.txt # 118287 images 8 | val: ./coco/val2017.txt # 5000 images 9 | test: ./coco/test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794 10 | 11 | # number of classes 12 | nc: 80 13 | 14 | # class names 15 | names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 16 | 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 17 | 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 18 | 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 19 | 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 20 | 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 21 | 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 22 | 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 23 | 'hair drier', 'toothbrush' ] 24 | -------------------------------------------------------------------------------- /data/hyp.scratch.p5.yaml: -------------------------------------------------------------------------------- 1 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 2 | lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) 3 | momentum: 0.937 # SGD momentum/Adam beta1 4 | weight_decay: 0.0005 # optimizer weight decay 5e-4 5 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 6 | warmup_momentum: 0.8 # warmup initial momentum 7 | warmup_bias_lr: 0.1 # warmup initial bias lr 8 | box: 0.05 # box loss gain 9 | cls: 0.3 # cls loss gain 10 | cls_pw: 1.0 # cls BCELoss positive_weight 11 | obj: 0.7 # obj loss gain (scale with pixels) 12 | obj_pw: 1.0 # obj BCELoss positive_weight 13 | iou_t: 0.20 # IoU training threshold 14 | anchor_t: 4.0 # anchor-multiple threshold 15 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 16 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 17 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 18 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 19 | degrees: 0.0 # image rotation (+/- deg) 20 | translate: 0.2 # image translation (+/- fraction) 21 | scale: 0.9 # image scale (+/- gain) 22 | shear: 0.0 # image shear (+/- deg) 23 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 24 | flipud: 0.0 # image flip up-down (probability) 25 | fliplr: 0.5 # image flip left-right (probability) 26 | mosaic: 1.0 # image mosaic (probability) 27 | mixup: 0.15 # image mixup (probability) 28 | copy_paste: 0.0 # image copy paste (probability) 29 | paste_in: 0.15 # image copy paste (probability) 30 | -------------------------------------------------------------------------------- /data/hyp.scratch.p6.yaml: -------------------------------------------------------------------------------- 1 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 2 | lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) 3 | momentum: 0.937 # SGD momentum/Adam beta1 4 | weight_decay: 0.0005 # optimizer weight decay 5e-4 5 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 6 | warmup_momentum: 0.8 # warmup initial momentum 7 | warmup_bias_lr: 0.1 # warmup initial bias lr 8 | box: 0.05 # box loss gain 9 | cls: 0.3 # cls loss gain 10 | cls_pw: 1.0 # cls BCELoss positive_weight 11 | obj: 0.7 # obj loss gain (scale with pixels) 12 | obj_pw: 1.0 # obj BCELoss positive_weight 13 | iou_t: 0.20 # IoU training threshold 14 | anchor_t: 4.0 # anchor-multiple threshold 15 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 16 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 17 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 18 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 19 | degrees: 0.0 # image rotation (+/- deg) 20 | translate: 0.2 # image translation (+/- fraction) 21 | scale: 0.9 # image scale (+/- gain) 22 | shear: 0.0 # image shear (+/- deg) 23 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 24 | flipud: 0.0 # image flip up-down (probability) 25 | fliplr: 0.5 # image flip left-right (probability) 26 | mosaic: 1.0 # image mosaic (probability) 27 | mixup: 0.15 # image mixup (probability) 28 | copy_paste: 0.0 # image copy paste (probability) 29 | paste_in: 0.15 # image copy paste (probability) 30 | -------------------------------------------------------------------------------- /data/hyp.scratch.tiny.yaml: -------------------------------------------------------------------------------- 1 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 2 | lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf) 3 | momentum: 0.937 # SGD momentum/Adam beta1 4 | weight_decay: 0.0005 # optimizer weight decay 5e-4 5 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 6 | warmup_momentum: 0.8 # warmup initial momentum 7 | warmup_bias_lr: 0.1 # warmup initial bias lr 8 | box: 0.05 # box loss gain 9 | cls: 0.5 # cls loss gain 10 | cls_pw: 1.0 # cls BCELoss positive_weight 11 | obj: 1.0 # obj loss gain (scale with pixels) 12 | obj_pw: 1.0 # obj BCELoss positive_weight 13 | iou_t: 0.20 # IoU training threshold 14 | anchor_t: 4.0 # anchor-multiple threshold 15 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 16 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 17 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 18 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 19 | degrees: 0.0 # image rotation (+/- deg) 20 | translate: 0.1 # image translation (+/- fraction) 21 | scale: 0.5 # image scale (+/- gain) 22 | shear: 0.0 # image shear (+/- deg) 23 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 24 | flipud: 0.0 # image flip up-down (probability) 25 | fliplr: 0.5 # image flip left-right (probability) 26 | mosaic: 1.0 # image mosaic (probability) 27 | mixup: 0.05 # image mixup (probability) 28 | copy_paste: 0.0 # image copy paste (probability) 29 | paste_in: 0.05 # image copy paste (probability) 30 | -------------------------------------------------------------------------------- /data/score.yaml: -------------------------------------------------------------------------------- 1 | train: ./dataset/score/images/train # train images 2 | val: ./dataset/score/images/val # val images 3 | #test: ./dataset/score/images/test # test images (optional) 4 | 5 | # Classes 6 | nc: 4 # number of classes 7 | names: ['person','cat','dog','horse'] # class names -------------------------------------------------------------------------------- /dataset/score/01_check_img.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import os 3 | import shutil 4 | 5 | def check_img(img_path): 6 | imgs = os.listdir(img_path) 7 | for img in imgs: 8 | if img.split(".")[-1] !="jpg": 9 | print(img) 10 | shutil.move(img_path+"/"+img,"./error/"+img) 11 | 12 | def check_anno(anno_path): 13 | anno_files = os.listdir(anno_path) 14 | for file in anno_files: 15 | if file.split(".")[-1] !="xml": 16 | print(file) 17 | shutil.move(anno_path+"/"+file,"./error/"+file) 18 | 19 | def ckeck_img_label(img_path,anno_path): 20 | imgs = os.listdir(img_path) 21 | anno_files = os.listdir(anno_path) 22 | 23 | files = [i.split(".")[0] for i in anno_files] 24 | 25 | 26 | for img in imgs: 27 | if img.split(".")[0] not in files: 28 | print(img) 29 | shutil.move(img_path+"/"+img,"./error/"+img) 30 | 31 | imgs = os.listdir(img_path) 32 | images = [j.split(".")[0] for j in imgs] 33 | 34 | for file in anno_files: 35 | if file.split(".")[0] not in images: 36 | print(file) 37 | shutil.move(anno_path+"/"+file,"./error/"+file) 38 | 39 | 40 | if __name__ == "__main__": 41 | img_path = "./JPEGImages" 42 | anno_path = "./Annotations" 43 | 44 | print("============check image=========") 45 | check_img(img_path) 46 | 47 | print("============check anno==========") 48 | check_anno(anno_path) 49 | print("============check both==========") 50 | ckeck_img_label(img_path,anno_path) 51 | -------------------------------------------------------------------------------- /dataset/score/02_check_box.py: -------------------------------------------------------------------------------- 1 | import xml.etree.ElementTree as xml_tree 2 | import pandas as pd 3 | import numpy as np 4 | import os 5 | import shutil 6 | 7 | 8 | def check_box(path): 9 | files = os.listdir(path) 10 | i = 0 11 | for anna_file in files: 12 | tree = xml_tree.parse(path+"/"+anna_file) 13 | root = tree.getroot() 14 | 15 | # Image shape. 16 | size = root.find('size') 17 | shape = [int(size.find('height').text), 18 | int(size.find('width').text), 19 | int(size.find('depth').text)] 20 | # Find annotations. 21 | bboxes = [] 22 | labels = [] 23 | labels_text = [] 24 | difficult = [] 25 | truncated = [] 26 | 27 | for obj in root.findall('object'): 28 | # label = obj.find('name').text 29 | # labels.append(int(dataset_common.VOC_LABELS[label][0])) 30 | # # labels_text.append(label.encode('ascii')) 31 | # labels_text.append(label.encode('utf-8')) 32 | 33 | 34 | # isdifficult = obj.find('difficult') 35 | # if isdifficult is not None: 36 | # difficult.append(int(isdifficult.text)) 37 | # else: 38 | # difficult.append(0) 39 | 40 | # istruncated = obj.find('truncated') 41 | # if istruncated is not None: 42 | # truncated.append(int(istruncated.text)) 43 | # else: 44 | # truncated.append(0) 45 | 46 | bbox = obj.find('bndbox') 47 | # bboxes.append((float(bbox.find('ymin').text) / shape[0], 48 | # float(bbox.find('xmin').text) / shape[1], 49 | # float(bbox.find('ymax').text) / shape[0], 50 | # float(bbox.find('xmax').text) / shape[1] 51 | # )) 52 | if (float(bbox.find('ymin').text) >= float(bbox.find('ymax').text)) or (float(bbox.find('xmin').text) >= float(bbox.find('xmax').text)): 53 | print(anna_file) 54 | print((bbox.find('ymin').text,bbox.find('ymax').text,bbox.find('xmin').text,bbox.find('xmax').text)) 55 | i += 1 56 | try: 57 | shutil.move(path+"/"+anna_file,"./error2/"+anna_file) 58 | shutil.move("./JPEGImages/"+anna_file.split(".")[0]+".jpg","./error2/"+anna_file.split(".")[0]+".jpg") 59 | except: 60 | pass 61 | 62 | print(i) 63 | 64 | 65 | 66 | if __name__ == "__main__": 67 | check_box("./Annotations") -------------------------------------------------------------------------------- /dataset/score/03_train_val_split.py: -------------------------------------------------------------------------------- 1 | import os 2 | import random 3 | 4 | trainval_percent = 0.05 5 | train_percent = 0.95 6 | xmlfilepath = 'Annotations' 7 | txtsavepath = 'ImageSets/Main' 8 | total_xml = os.listdir(xmlfilepath) 9 | 10 | num = len(total_xml) 11 | lists = range(num) 12 | 13 | tr = int(num * train_percent) 14 | train = random.sample(lists, tr) 15 | 16 | 17 | ftrain = open('./ImageSets/Main/train.txt', 'w') 18 | fval = open('./ImageSets/Main/val.txt', 'w') 19 | 20 | for i in lists: 21 | name = total_xml[i][:-4] + '\n' 22 | if i in train: 23 | ftrain.write(name) 24 | else: 25 | fval.write(name) 26 | 27 | 28 | 29 | ftrain.close() 30 | fval.close() 31 | 32 | # voc Main/train,val 图像名生成 -------------------------------------------------------------------------------- /dataset/score/04_myData_label.py: -------------------------------------------------------------------------------- 1 | 2 | # _*_ coding:utf-8 _*_ 3 | import xml.etree.ElementTree as ET 4 | import pickle 5 | import os 6 | from os import listdir, getcwd 7 | from os.path import join 8 | import shutil 9 | import cv2 10 | 11 | # sets=[('myData', 'train'),('myData', 'val'), ('myData', 'test')] # 根据自己数据去定义 12 | sets=[('myData', 'train'),('myData', 'val')] # 根据自己数据去定义 13 | 14 | class2id = { 15 | 'person':0, 'cat':1, 'dog':2, 'horse':3 16 | 17 | } 18 | 19 | def convert(size, box): 20 | dw = 1./(size[0]) 21 | dh = 1./(size[1]) 22 | x = (box[0] + box[1])/2.0 - 1 23 | y = (box[2] + box[3])/2.0 - 1 24 | w = box[1] - box[0] 25 | h = box[3] - box[2] 26 | x = x*dw 27 | w = w*dw 28 | y = y*dh 29 | h = h*dh 30 | return (x,y,w,h) 31 | 32 | def convert_annotation(year, image_id): 33 | in_file = open('./Annotations/%s.xml'%(image_id),encoding='utf-8') 34 | out_file = open('./labels/%s/%s.txt'%(year,image_id), 'w') 35 | # print(in_file) 36 | tree=ET.parse(in_file) 37 | root = tree.getroot() 38 | size = root.find('size') 39 | w = int(size.find('width').text) 40 | h = int(size.find('height').text) 41 | 42 | img = cv2.imread("./JPEGImages/"+image_id+".jpg") 43 | # shutil.copy("./JPEGImages/"+image_id+".jpg","./images/%s/%s.jpg"%(year,image_id)) 44 | 45 | sp = img.shape 46 | 47 | h = sp[0] #height(rows) of image 48 | w = sp[1] #width(colums) of image 49 | 50 | for obj in root.iter('object'): 51 | difficult = obj.find('difficult').text 52 | cls_ = obj.find('name').text 53 | if cls_ not in list(class2id.keys()): 54 | print("没有该label: {}".format(cls_)) 55 | continue 56 | cls_id = class2id[cls_] 57 | xmlbox = obj.find('bndbox') 58 | x1 = float(xmlbox.find('xmin').text) 59 | x2 = float(xmlbox.find('xmax').text) 60 | y1 = float(xmlbox.find('ymin').text) 61 | y2 = float(xmlbox.find('ymax').text) 62 | 63 | # 64 | if x1 <= 0: 65 | x1 = 10 66 | if y1 <= 0: 67 | y1 = 10 68 | 69 | if x2 >= w: 70 | x2 = w-10 71 | if y2 >= h: 72 | y2 = h-10 73 | 74 | if x1 > x2: 75 | x1,x2 = x2,x1 76 | if y1 > y2: 77 | y1,y2 = y2,y1 78 | b = (x1, x2, y1 ,y2) 79 | bb = convert((w,h), b) 80 | out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n') 81 | 82 | wd = getcwd() 83 | 84 | for year, image_set in sets: 85 | if not os.path.exists('./labels/'): 86 | os.makedirs('./labels/') 87 | image_ids = open('./ImageSets/Main/%s.txt'%(image_set)).read().strip().split() 88 | # list_file = open('./%s_%s.txt'%(year, image_set), 'w') 89 | for image_id in image_ids: 90 | # list_file.write('%s/JPEGImages/%s.jpg\n'%(wd, image_id)) # 写了train或val的list 91 | convert_annotation(image_set, image_id) 92 | # list_file.close() 93 | 94 | 95 | # labels/标注数据有了 96 | # train val的list数据也有了 97 | -------------------------------------------------------------------------------- /dataset/score/05_copy_img.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | 4 | 5 | with open("./ImageSets/Main/val.txt",'r') as f: 6 | lines = f.readlines() 7 | for line in lines: 8 | print(line.strip()) 9 | 10 | img_file = line.strip() + ".jpg" 11 | print(img_file) 12 | 13 | shutil.copy("./JPEGImages/"+img_file,"./images/val/"+img_file) 14 | 15 | 16 | with open("./ImageSets/Main/train.txt",'r') as f: 17 | lines = f.readlines() 18 | for line in lines: 19 | print(line.strip()) 20 | 21 | img_file = line.strip() + ".jpg" 22 | print(img_file) 23 | 24 | shutil.copy("./JPEGImages/"+img_file,"./images/train/"+img_file) -------------------------------------------------------------------------------- /detect.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import time 3 | from pathlib import Path 4 | 5 | import cv2 6 | import torch 7 | import torch.backends.cudnn as cudnn 8 | from numpy import random 9 | 10 | from models.experimental import attempt_load 11 | from utils.datasets import LoadStreams, LoadImages 12 | from utils.general import check_img_size, check_requirements, check_imshow, non_max_suppression, apply_classifier, \ 13 | scale_coords, xyxy2xywh, strip_optimizer, set_logging, increment_path 14 | from utils.plots import plot_one_box 15 | from utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel 16 | 17 | 18 | def detect(save_img=False): 19 | source, weights, view_img, save_txt, imgsz, trace = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size, not opt.no_trace 20 | save_img = not opt.nosave and not source.endswith('.txt') # save inference images 21 | webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith( 22 | ('rtsp://', 'rtmp://', 'http://', 'https://')) 23 | 24 | # Directories 25 | save_dir = Path(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok)) # increment run 26 | (save_dir / 'labels' if save_txt else save_dir).mkdir(parents=True, exist_ok=True) # make dir 27 | 28 | # Initialize 29 | set_logging() 30 | device = select_device(opt.device) 31 | half = device.type != 'cpu' # half precision only supported on CUDA 32 | 33 | # Load model 34 | model = attempt_load(weights, map_location=device) # load FP32 model 35 | stride = int(model.stride.max()) # model stride 36 | imgsz = check_img_size(imgsz, s=stride) # check img_size 37 | 38 | if trace: 39 | model = TracedModel(model, device, opt.img_size) 40 | 41 | if half: 42 | model.half() # to FP16 43 | 44 | # Second-stage classifier 45 | classify = False 46 | if classify: 47 | modelc = load_classifier(name='resnet101', n=2) # initialize 48 | modelc.load_state_dict(torch.load('weights/resnet101.pt', map_location=device)['model']).to(device).eval() 49 | 50 | # Set Dataloader 51 | vid_path, vid_writer = None, None 52 | if webcam: 53 | view_img = check_imshow() 54 | cudnn.benchmark = True # set True to speed up constant image size inference 55 | dataset = LoadStreams(source, img_size=imgsz, stride=stride) 56 | else: 57 | dataset = LoadImages(source, img_size=imgsz, stride=stride) 58 | 59 | # Get names and colors 60 | names = model.module.names if hasattr(model, 'module') else model.names 61 | colors = [[random.randint(0, 255) for _ in range(3)] for _ in names] 62 | 63 | # Run inference 64 | if device.type != 'cpu': 65 | model(torch.zeros(1, 3, imgsz, imgsz).to(device).type_as(next(model.parameters()))) # run once 66 | t0 = time.time() 67 | for path, img, im0s, vid_cap in dataset: 68 | img = torch.from_numpy(img).to(device) 69 | img = img.half() if half else img.float() # uint8 to fp16/32 70 | img /= 255.0 # 0 - 255 to 0.0 - 1.0 71 | if img.ndimension() == 3: 72 | img = img.unsqueeze(0) 73 | 74 | # Inference 75 | t1 = time_synchronized() 76 | pred = model(img, augment=opt.augment)[0] 77 | 78 | # Apply NMS 79 | pred = non_max_suppression(pred, opt.conf_thres, opt.iou_thres, classes=opt.classes, agnostic=opt.agnostic_nms) 80 | t2 = time_synchronized() 81 | 82 | # Apply Classifier 83 | if classify: 84 | pred = apply_classifier(pred, modelc, img, im0s) 85 | 86 | # Process detections 87 | for i, det in enumerate(pred): # detections per image 88 | if webcam: # batch_size >= 1 89 | p, s, im0, frame = path[i], '%g: ' % i, im0s[i].copy(), dataset.count 90 | else: 91 | p, s, im0, frame = path, '', im0s, getattr(dataset, 'frame', 0) 92 | 93 | p = Path(p) # to Path 94 | save_path = str(save_dir / p.name) # img.jpg 95 | txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}') # img.txt 96 | s += '%gx%g ' % img.shape[2:] # print string 97 | gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh 98 | if len(det): 99 | # Rescale boxes from img_size to im0 size 100 | det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round() 101 | 102 | # Print results 103 | for c in det[:, -1].unique(): 104 | n = (det[:, -1] == c).sum() # detections per class 105 | s += f"{n} {names[int(c)]}{'s' * (n > 1)}, " # add to string 106 | 107 | # Write results 108 | for *xyxy, conf, cls in reversed(det): 109 | if save_txt: # Write to file 110 | xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh 111 | line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh) # label format 112 | with open(txt_path + '.txt', 'a') as f: 113 | f.write(('%g ' * len(line)).rstrip() % line + '\n') 114 | 115 | if save_img or view_img: # Add bbox to image 116 | label = f'{names[int(cls)]} {conf:.2f}' 117 | plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=3) 118 | 119 | # Print time (inference + NMS) 120 | #print(f'{s}Done. ({t2 - t1:.3f}s)') 121 | 122 | # Stream results 123 | if view_img: 124 | cv2.imshow(str(p), im0) 125 | cv2.waitKey(1) # 1 millisecond 126 | 127 | # Save results (image with detections) 128 | if save_img: 129 | if dataset.mode == 'image': 130 | cv2.imwrite(save_path, im0) 131 | print(f" The image with the result is saved in: {save_path}") 132 | else: # 'video' or 'stream' 133 | if vid_path != save_path: # new video 134 | vid_path = save_path 135 | if isinstance(vid_writer, cv2.VideoWriter): 136 | vid_writer.release() # release previous video writer 137 | if vid_cap: # video 138 | fps = vid_cap.get(cv2.CAP_PROP_FPS) 139 | w = int(vid_cap.get(cv2.CAP_PROP_FRAME_WIDTH)) 140 | h = int(vid_cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) 141 | else: # stream 142 | fps, w, h = 30, im0.shape[1], im0.shape[0] 143 | save_path += '.mp4' 144 | vid_writer = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h)) 145 | vid_writer.write(im0) 146 | 147 | if save_txt or save_img: 148 | s = f"\n{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}" if save_txt else '' 149 | #print(f"Results saved to {save_dir}{s}") 150 | 151 | print(f'Done. ({time.time() - t0:.3f}s)') 152 | 153 | 154 | if __name__ == '__main__': 155 | parser = argparse.ArgumentParser() 156 | parser.add_argument('--weights', nargs='+', type=str, default='yolov7.pt', help='model.pt path(s)') 157 | parser.add_argument('--source', type=str, default='inference/images', help='source') # file/folder, 0 for webcam 158 | parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)') 159 | parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold') 160 | parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS') 161 | parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') 162 | parser.add_argument('--view-img', action='store_true', help='display results') 163 | parser.add_argument('--save-txt', action='store_true', help='save results to *.txt') 164 | parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels') 165 | parser.add_argument('--nosave', action='store_true', help='do not save images/videos') 166 | parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --class 0, or --class 0 2 3') 167 | parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS') 168 | parser.add_argument('--augment', action='store_true', help='augmented inference') 169 | parser.add_argument('--update', action='store_true', help='update all models') 170 | parser.add_argument('--project', default='runs/detect', help='save results to project/name') 171 | parser.add_argument('--name', default='exp', help='save results to project/name') 172 | parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') 173 | parser.add_argument('--no-trace', action='store_true', help='don`t trace model') 174 | opt = parser.parse_args() 175 | print(opt) 176 | #check_requirements(exclude=('pycocotools', 'thop')) 177 | 178 | with torch.no_grad(): 179 | if opt.update: # update all models (to fix SourceChangeWarning) 180 | for opt.weights in ['yolov7.pt']: 181 | detect() 182 | strip_optimizer(opt.weights) 183 | else: 184 | detect() 185 | -------------------------------------------------------------------------------- /figure/image1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/figure/image1.jpg -------------------------------------------------------------------------------- /figure/image1_trt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/figure/image1_trt.jpg -------------------------------------------------------------------------------- /figure/image2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/figure/image2.jpg -------------------------------------------------------------------------------- /figure/image2_trt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/figure/image2_trt.jpg -------------------------------------------------------------------------------- /figure/image3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/figure/image3.jpg -------------------------------------------------------------------------------- /figure/image3_trt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/figure/image3_trt.jpg -------------------------------------------------------------------------------- /figure/onnx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/figure/onnx.png -------------------------------------------------------------------------------- /figure/onnx_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/figure/onnx_0.png -------------------------------------------------------------------------------- /figure/onnx_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/figure/onnx_1.png -------------------------------------------------------------------------------- /figure/performance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/figure/performance.png -------------------------------------------------------------------------------- /hubconf.py: -------------------------------------------------------------------------------- 1 | """PyTorch Hub models 2 | 3 | Usage: 4 | import torch 5 | model = torch.hub.load('repo', 'model') 6 | """ 7 | 8 | from pathlib import Path 9 | 10 | import torch 11 | 12 | from models.yolo import Model 13 | from utils.general import check_requirements, set_logging 14 | from utils.google_utils import attempt_download 15 | from utils.torch_utils import select_device 16 | 17 | dependencies = ['torch', 'yaml'] 18 | check_requirements(Path(__file__).parent / 'requirements.txt', exclude=('pycocotools', 'thop')) 19 | set_logging() 20 | 21 | 22 | def create(name, pretrained, channels, classes, autoshape): 23 | """Creates a specified model 24 | 25 | Arguments: 26 | name (str): name of model, i.e. 'yolov7' 27 | pretrained (bool): load pretrained weights into the model 28 | channels (int): number of input channels 29 | classes (int): number of model classes 30 | 31 | Returns: 32 | pytorch model 33 | """ 34 | try: 35 | cfg = list((Path(__file__).parent / 'cfg').rglob(f'{name}.yaml'))[0] # model.yaml path 36 | model = Model(cfg, channels, classes) 37 | if pretrained: 38 | fname = f'{name}.pt' # checkpoint filename 39 | attempt_download(fname) # download if not found locally 40 | ckpt = torch.load(fname, map_location=torch.device('cpu')) # load 41 | msd = model.state_dict() # model state_dict 42 | csd = ckpt['model'].float().state_dict() # checkpoint state_dict as FP32 43 | csd = {k: v for k, v in csd.items() if msd[k].shape == v.shape} # filter 44 | model.load_state_dict(csd, strict=False) # load 45 | if len(ckpt['model'].names) == classes: 46 | model.names = ckpt['model'].names # set class names attribute 47 | if autoshape: 48 | model = model.autoshape() # for file/URI/PIL/cv2/np inputs and NMS 49 | device = select_device('0' if torch.cuda.is_available() else 'cpu') # default to GPU if available 50 | return model.to(device) 51 | 52 | except Exception as e: 53 | s = 'Cache maybe be out of date, try force_reload=True.' 54 | raise Exception(s) from e 55 | 56 | 57 | def custom(path_or_model='path/to/model.pt', autoshape=True): 58 | """custom mode 59 | 60 | Arguments (3 options): 61 | path_or_model (str): 'path/to/model.pt' 62 | path_or_model (dict): torch.load('path/to/model.pt') 63 | path_or_model (nn.Module): torch.load('path/to/model.pt')['model'] 64 | 65 | Returns: 66 | pytorch model 67 | """ 68 | model = torch.load(path_or_model) if isinstance(path_or_model, str) else path_or_model # load checkpoint 69 | if isinstance(model, dict): 70 | model = model['ema' if model.get('ema') else 'model'] # load model 71 | 72 | hub_model = Model(model.yaml).to(next(model.parameters()).device) # create 73 | hub_model.load_state_dict(model.float().state_dict()) # load state_dict 74 | hub_model.names = model.names # class names 75 | if autoshape: 76 | hub_model = hub_model.autoshape() # for file/URI/PIL/cv2/np inputs and NMS 77 | device = select_device('0' if torch.cuda.is_available() else 'cpu') # default to GPU if available 78 | return hub_model.to(device) 79 | 80 | 81 | def yolov7(pretrained=True, channels=3, classes=80, autoshape=True): 82 | return create('yolov7', pretrained, channels, classes, autoshape) 83 | 84 | 85 | if __name__ == '__main__': 86 | model = custom(path_or_model='yolov7.pt') # custom example 87 | # model = create(name='yolov7', pretrained=True, channels=3, classes=80, autoshape=True) # pretrained example 88 | 89 | # Verify inference 90 | import numpy as np 91 | from PIL import Image 92 | 93 | imgs = [np.zeros((640, 480, 3))] 94 | 95 | results = model(imgs) # batched inference 96 | results.print() 97 | results.save() 98 | -------------------------------------------------------------------------------- /inference.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import time 3 | from pathlib import Path 4 | import os 5 | import numpy as np 6 | 7 | import cv2 8 | import torch 9 | import torch.backends.cudnn as cudnn 10 | from numpy import random 11 | 12 | from models.experimental import attempt_load 13 | from utils.datasets import LoadStreams, LoadImages,letterbox 14 | from utils.general import check_img_size, check_requirements, check_imshow, non_max_suppression, apply_classifier, \ 15 | scale_coords, xyxy2xywh, strip_optimizer, set_logging, increment_path 16 | from utils.plots import plot_one_box 17 | from utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel 18 | 19 | 20 | half = False 21 | save_img = True 22 | save_txt = True 23 | 24 | conf_thres = 0.25 25 | iou_thres=0.45 26 | 27 | weights = "./runs/train/yolov7/weights/last.pt" 28 | 29 | test_path = "./test_img" 30 | 31 | device = select_device("0") 32 | model = attempt_load(weights, map_location=device) # load FP32 model 33 | 34 | if half: 35 | model.half() # to FP16 36 | 37 | # stride = int(model.stride.max()) # model stride 38 | # imgsz = check_img_size(imgsz, s=stride) # check img_size 39 | 40 | # Get names and colors 41 | names = model.module.names if hasattr(model, 'module') else model.names 42 | colors = [[random.randint(0, 255) for _ in range(3)] for _ in names] 43 | 44 | 45 | files = os.listdir(test_path) 46 | 47 | for file in files: 48 | img_path = os.path.join(test_path,file) 49 | img0 = cv2.imread(img_path) 50 | img = letterbox(img0,new_shape=(640, 640), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True, stride=32)[0] 51 | 52 | # Convert 53 | img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x416x416 54 | img = np.ascontiguousarray(img) 55 | 56 | img = torch.from_numpy(img).to(device) 57 | img = img.half() if half else img.float() # uint8 to fp16/32 58 | img /= 255.0 # 0 - 255 to 0.0 - 1.0 59 | if img.ndimension() == 3: 60 | img = img.unsqueeze(0) 61 | 62 | 63 | pred = model(img, augment=False)[0] 64 | 65 | # Apply NMS 66 | # (center x, center y, width, height) 67 | pred = non_max_suppression(pred, conf_thres=conf_thres, iou_thres=iou_thres, classes=None, agnostic=False) 68 | 69 | 70 | # Process detections 71 | for i, det in enumerate(pred): # detections per image 72 | save_path = os.path.join("./res",file) 73 | txt_path = os.path.join("./res/labels",file[:-4]) 74 | 75 | gn = torch.tensor(img0.shape)[[1, 0, 1, 0]] # normalization gain whwh 76 | 77 | if len(det): 78 | # Rescale boxes from img_size to im0 size 79 | det[:, :4] = scale_coords(img.shape[2:], det[:, :4], img0.shape).round() # 映射到原图,这个可以在NMS后做 80 | 81 | # # Print results 82 | # for c in det[:, -1].unique(): 83 | # n = (det[:, -1] == c).sum() # detections per class 84 | # s += f"{n} {names[int(c)]}{'s' * (n > 1)}, " # add to string 85 | 86 | # Write results 87 | for *xyxy, conf, cls in reversed(det): 88 | if save_txt: # Write to file 89 | xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh 90 | # line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh) # label format 91 | line = (cls, *xywh, conf) # label format 92 | 93 | with open(txt_path + '.txt', 'a') as f: 94 | f.write(('%g ' * len(line)).rstrip() % line + '\n') 95 | 96 | if save_img: # Add bbox to image 97 | label = f'{names[int(cls)]} {conf:.2f}' 98 | plot_one_box(xyxy, img0, label=label, color=colors[int(cls)], line_thickness=3) 99 | 100 | # Print time (inference + NMS) 101 | #print(f'{s}Done. ({t2 - t1:.3f}s)') 102 | 103 | # # Stream results 104 | # if view_img: 105 | # cv2.imshow(str(p), im0) 106 | # cv2.waitKey(1) # 1 millisecond 107 | 108 | # Save results (image with detections) 109 | if save_img: 110 | cv2.imwrite(save_path, img0) 111 | print(file) 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /inference/images/horses.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/inference/images/horses.jpg -------------------------------------------------------------------------------- /models/__init__.py: -------------------------------------------------------------------------------- 1 | # init -------------------------------------------------------------------------------- /models/experimental.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import torch 3 | import torch.nn as nn 4 | 5 | from models.common import Conv, DWConv 6 | from utils.google_utils import attempt_download 7 | 8 | 9 | class CrossConv(nn.Module): 10 | # Cross Convolution Downsample 11 | def __init__(self, c1, c2, k=3, s=1, g=1, e=1.0, shortcut=False): 12 | # ch_in, ch_out, kernel, stride, groups, expansion, shortcut 13 | super(CrossConv, self).__init__() 14 | c_ = int(c2 * e) # hidden channels 15 | self.cv1 = Conv(c1, c_, (1, k), (1, s)) 16 | self.cv2 = Conv(c_, c2, (k, 1), (s, 1), g=g) 17 | self.add = shortcut and c1 == c2 18 | 19 | def forward(self, x): 20 | return x + self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x)) 21 | 22 | 23 | class Sum(nn.Module): 24 | # Weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 25 | def __init__(self, n, weight=False): # n: number of inputs 26 | super(Sum, self).__init__() 27 | self.weight = weight # apply weights boolean 28 | self.iter = range(n - 1) # iter object 29 | if weight: 30 | self.w = nn.Parameter(-torch.arange(1., n) / 2, requires_grad=True) # layer weights 31 | 32 | def forward(self, x): 33 | y = x[0] # no weight 34 | if self.weight: 35 | w = torch.sigmoid(self.w) * 2 36 | for i in self.iter: 37 | y = y + x[i + 1] * w[i] 38 | else: 39 | for i in self.iter: 40 | y = y + x[i + 1] 41 | return y 42 | 43 | 44 | class MixConv2d(nn.Module): 45 | # Mixed Depthwise Conv https://arxiv.org/abs/1907.09595 46 | def __init__(self, c1, c2, k=(1, 3), s=1, equal_ch=True): 47 | super(MixConv2d, self).__init__() 48 | groups = len(k) 49 | if equal_ch: # equal c_ per group 50 | i = torch.linspace(0, groups - 1E-6, c2).floor() # c2 indices 51 | c_ = [(i == g).sum() for g in range(groups)] # intermediate channels 52 | else: # equal weight.numel() per group 53 | b = [c2] + [0] * groups 54 | a = np.eye(groups + 1, groups, k=-1) 55 | a -= np.roll(a, 1, axis=1) 56 | a *= np.array(k) ** 2 57 | a[0] = 1 58 | c_ = np.linalg.lstsq(a, b, rcond=None)[0].round() # solve for equal weight indices, ax = b 59 | 60 | self.m = nn.ModuleList([nn.Conv2d(c1, int(c_[g]), k[g], s, k[g] // 2, bias=False) for g in range(groups)]) 61 | self.bn = nn.BatchNorm2d(c2) 62 | self.act = nn.LeakyReLU(0.1, inplace=True) 63 | 64 | def forward(self, x): 65 | return x + self.act(self.bn(torch.cat([m(x) for m in self.m], 1))) 66 | 67 | 68 | class Ensemble(nn.ModuleList): 69 | # Ensemble of models 70 | def __init__(self): 71 | super(Ensemble, self).__init__() 72 | 73 | def forward(self, x, augment=False): 74 | y = [] 75 | for module in self: 76 | y.append(module(x, augment)[0]) 77 | # y = torch.stack(y).max(0)[0] # max ensemble 78 | # y = torch.stack(y).mean(0) # mean ensemble 79 | y = torch.cat(y, 1) # nms ensemble 80 | return y, None # inference, train output 81 | 82 | 83 | def attempt_load(weights, map_location=None): 84 | # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a 85 | model = Ensemble() 86 | for w in weights if isinstance(weights, list) else [weights]: 87 | attempt_download(w) 88 | ckpt = torch.load(w, map_location=map_location) # load 89 | model.append(ckpt['ema' if ckpt.get('ema') else 'model'].float().fuse().eval()) # FP32 model 90 | 91 | # Compatibility updates 92 | for m in model.modules(): 93 | if type(m) in [nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU]: 94 | m.inplace = True # pytorch 1.7.0 compatibility 95 | elif type(m) is nn.Upsample: 96 | m.recompute_scale_factor = None # torch 1.11.0 compatibility 97 | elif type(m) is Conv: 98 | m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatibility 99 | 100 | if len(model) == 1: 101 | return model[-1] # return model 102 | else: 103 | print('Ensemble created with %s\n' % weights) 104 | for k in ['names', 'stride']: 105 | setattr(model, k, getattr(model[-1], k)) 106 | return model # return ensemble 107 | -------------------------------------------------------------------------------- /models/export.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import sys 3 | import time 4 | 5 | sys.path.append('./') # to run '$ python *.py' files in subdirectories 6 | 7 | import torch 8 | import torch.nn as nn 9 | 10 | import models 11 | from models.experimental import attempt_load 12 | from utils.activations import Hardswish, SiLU 13 | from utils.general import set_logging, check_img_size 14 | from utils.torch_utils import select_device 15 | 16 | if __name__ == '__main__': 17 | parser = argparse.ArgumentParser() 18 | parser.add_argument('--weights', type=str, default='./yolor-csp-c.pt', help='weights path') 19 | parser.add_argument('--img-size', nargs='+', type=int, default=[640, 640], help='image size') # height, width 20 | parser.add_argument('--batch-size', type=int, default=1, help='batch size') 21 | parser.add_argument('--dynamic', action='store_true', help='dynamic ONNX axes') 22 | parser.add_argument('--grid', action='store_true', help='export Detect() layer grid') 23 | parser.add_argument('--device', default='cpu', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') 24 | opt = parser.parse_args() 25 | opt.img_size *= 2 if len(opt.img_size) == 1 else 1 # expand 26 | print(opt) 27 | set_logging() 28 | t = time.time() 29 | 30 | # Load PyTorch model 31 | device = select_device(opt.device) 32 | model = attempt_load(opt.weights, map_location=device) # load FP32 model 33 | labels = model.names 34 | 35 | # Checks 36 | gs = int(max(model.stride)) # grid size (max stride) 37 | opt.img_size = [check_img_size(x, gs) for x in opt.img_size] # verify img_size are gs-multiples 38 | 39 | # Input 40 | img = torch.zeros(opt.batch_size, 3, *opt.img_size).to(device) # image size(1,3,320,192) iDetection 41 | 42 | # Update model 43 | for k, m in model.named_modules(): 44 | m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatibility 45 | if isinstance(m, models.common.Conv): # assign export-friendly activations 46 | if isinstance(m.act, nn.Hardswish): 47 | m.act = Hardswish() 48 | elif isinstance(m.act, nn.SiLU): 49 | m.act = SiLU() 50 | # elif isinstance(m, models.yolo.Detect): 51 | # m.forward = m.forward_export # assign forward (optional) 52 | model.model[-1].export = not opt.grid # set Detect() layer grid export 53 | y = model(img) # dry run 54 | 55 | # TorchScript export 56 | try: 57 | print('\nStarting TorchScript export with torch %s...' % torch.__version__) 58 | f = opt.weights.replace('.pt', '.torchscript.pt') # filename 59 | ts = torch.jit.trace(model, img, strict=False) 60 | ts.save(f) 61 | print('TorchScript export success, saved as %s' % f) 62 | except Exception as e: 63 | print('TorchScript export failure: %s' % e) 64 | 65 | # ONNX export 66 | try: 67 | import onnx 68 | 69 | print('\nStarting ONNX export with onnx %s...' % onnx.__version__) 70 | f = opt.weights.replace('.pt', '.onnx') # filename 71 | torch.onnx.export(model, img, f, verbose=False, opset_version=12, input_names=['images'], 72 | output_names=['classes', 'boxes'] if y is None else ['output'], 73 | dynamic_axes={'images': {0: 'batch', 2: 'height', 3: 'width'}, # size(1,3,640,640) 74 | 'output': {0: 'batch', 2: 'y', 3: 'x'}} if opt.dynamic else None) 75 | 76 | # Checks 77 | onnx_model = onnx.load(f) # load onnx model 78 | onnx.checker.check_model(onnx_model) # check onnx model 79 | # print(onnx.helper.printable_graph(onnx_model.graph)) # print a human readable model 80 | print('ONNX export success, saved as %s' % f) 81 | except Exception as e: 82 | print('ONNX export failure: %s' % e) 83 | 84 | # CoreML export 85 | try: 86 | import coremltools as ct 87 | 88 | print('\nStarting CoreML export with coremltools %s...' % ct.__version__) 89 | # convert model from torchscript and apply pixel scaling as per detect.py 90 | model = ct.convert(ts, inputs=[ct.ImageType(name='image', shape=img.shape, scale=1 / 255.0, bias=[0, 0, 0])]) 91 | f = opt.weights.replace('.pt', '.mlmodel') # filename 92 | model.save(f) 93 | print('CoreML export success, saved as %s' % f) 94 | except Exception as e: 95 | print('CoreML export failure: %s' % e) 96 | 97 | # Finish 98 | print('\nExport complete (%.2fs). Visualize with https://github.com/lutzroeder/netron.' % (time.time() - t)) 99 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # Usage: pip install -r requirements.txt 2 | 3 | # Base ---------------------------------------- 4 | matplotlib>=3.2.2 5 | seaborn 6 | numpy>=1.18.5 7 | opencv-python>=4.1.1 8 | Pillow>=7.1.2 9 | PyYAML>=5.3.1 10 | requests>=2.23.0 11 | scipy>=1.4.1 12 | torch>=1.7.0,!=1.12.0 13 | torchvision>=0.8.1,!=0.13.0 14 | tqdm>=4.41.0 15 | protobuf<4.21.3 16 | opencv-contrib-python 17 | 18 | # Logging ------------------------------------- 19 | tensorboard>=2.4.1 20 | # wandb 21 | 22 | # Plotting ------------------------------------ 23 | pandas>=1.1.4 24 | seaborn>=0.11.0 25 | 26 | # Export -------------------------------------- 27 | # coremltools>=4.1 # CoreML export 28 | # onnx>=1.9.0 # ONNX export 29 | # onnx-simplifier>=0.3.6 # ONNX simplifier 30 | # scikit-learn==0.19.2 # CoreML quantization 31 | # tensorflow>=2.4.1 # TFLite export 32 | # tensorflowjs>=3.9.0 # TF.js export 33 | # openvino-dev # OpenVINO export 34 | 35 | # Extras -------------------------------------- 36 | ipython # interactive notebook 37 | psutil # system utilization 38 | thop # FLOPs computation 39 | # albumentations>=1.0.3 40 | # pycocotools>=2.0 # COCO mAP 41 | # roboflow 42 | -------------------------------------------------------------------------------- /scripts/get_coco.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # COCO 2017 dataset http://cocodataset.org 3 | # Download command: bash ./scripts/get_coco.sh 4 | 5 | # Download/unzip labels 6 | d='./' # unzip directory 7 | url=https://github.com/ultralytics/yolov5/releases/download/v1.0/ 8 | f='coco2017labels-segments.zip' # or 'coco2017labels.zip', 68 MB 9 | echo 'Downloading' $url$f ' ...' 10 | curl -L $url$f -o $f && unzip -q $f -d $d && rm $f & # download, unzip, remove in background 11 | 12 | # Download/unzip images 13 | d='./coco/images' # unzip directory 14 | url=http://images.cocodataset.org/zips/ 15 | f1='train2017.zip' # 19G, 118k images 16 | f2='val2017.zip' # 1G, 5k images 17 | f3='test2017.zip' # 7G, 41k images (optional) 18 | for f in $f1 $f2 $f3; do 19 | echo 'Downloading' $url$f '...' 20 | curl -L $url$f -o $f && unzip -q $f -d $d && rm $f & # download, unzip, remove in background 21 | done 22 | wait # finish background tasks 23 | -------------------------------------------------------------------------------- /tensorrt/yolov7.cpp: -------------------------------------------------------------------------------- 1 | // xujing 2 | // 2021-12-19 3 | //把YOLOv5的后处理通过NMSPluin 和网络一体调用 4 | // 没有了后处理 5 | 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include "opencv2/highgui/highgui.hpp" 16 | #include "opencv2/imgproc/imgproc.hpp" 17 | 18 | #include "cuda_runtime_api.h" 19 | #include "NvOnnxParser.h" 20 | #include "NvInfer.h" 21 | #include "NvInferPlugin.h" 22 | 23 | #include 24 | #include "logging.h" 25 | 26 | using namespace sample; 27 | 28 | #define BATCH_SIZE 1 29 | #define INPUT_W 640 30 | #define INPUT_H 640 31 | #define INPUT_SIZE 640 32 | #define IsPadding 1 33 | //#define NUM_CLASS 20 34 | //#define NMS_THRESH 0.45 35 | //#define CONF_THRESH 0.25 36 | //#define PROB_THRESH 0.80 37 | 38 | using namespace std; 39 | using namespace cv; 40 | 41 | std::vector class_names = { "person","cat","dog","horse" }; 42 | 43 | 44 | // 中点坐标宽高 45 | struct Bbox { 46 | float x; 47 | float y; 48 | float w; 49 | float h; 50 | float score; 51 | int classes; 52 | }; 53 | 54 | //前处理 55 | 56 | void preprocess(cv::Mat& img, float data[]) { 57 | int w, h, x, y; 58 | float r_w = INPUT_W / (img.cols*1.0); 59 | float r_h = INPUT_H / (img.rows*1.0); 60 | if (r_h > r_w) { 61 | w = INPUT_W; 62 | h = r_w * img.rows; 63 | x = 0; 64 | y = (INPUT_H - h) / 2; 65 | } 66 | else { 67 | w = r_h * img.cols; 68 | h = INPUT_H; 69 | x = (INPUT_W - w) / 2; 70 | y = 0; 71 | } 72 | cv::Mat re(h, w, CV_8UC3); 73 | cv::resize(img, re, re.size(), 0, 0, cv::INTER_LINEAR); 74 | //cudaResize(img, re); 75 | cv::Mat out(INPUT_H, INPUT_W, CV_8UC3, cv::Scalar(114, 114, 114)); 76 | re.copyTo(out(cv::Rect(x, y, re.cols, re.rows))); 77 | 78 | int i = 0; 79 | for (int row = 0; row < INPUT_H; ++row) { 80 | uchar* uc_pixel = out.data + row * out.step; 81 | for (int col = 0; col < INPUT_W; ++col) { 82 | data[i] = (float)uc_pixel[2] / 255.0; 83 | data[i + INPUT_H * INPUT_W] = (float)uc_pixel[1] / 255.0; 84 | data[i + 2 * INPUT_H * INPUT_W] = (float)uc_pixel[0] / 255.0; 85 | uc_pixel += 3; 86 | ++i; 87 | } 88 | } 89 | 90 | } 91 | 92 | //只需把box映射回原图 93 | std::vector rescale_box(std::vector &out, int width, int height) { 94 | float gain = 640.0 / std::max(width, height); 95 | float pad_x = (640.0 - width * gain) / 2; 96 | float pad_y = (640.0 - height * gain) / 2; 97 | 98 | std::vector boxs; 99 | Bbox box; 100 | for (int i = 0; i < (int)out.size(); i++) { 101 | box.x = (out[i].x - pad_x) / gain; 102 | box.y = (out[i].y - pad_y) / gain; 103 | box.w = out[i].w / gain; 104 | box.h = out[i].h / gain; 105 | box.score = out[i].score; 106 | box.classes = out[i].classes; 107 | 108 | boxs.push_back(box); 109 | } 110 | 111 | return boxs; 112 | 113 | } 114 | 115 | //可视化 116 | cv::Mat renderBoundingBox(cv::Mat image, const std::vector &bboxes) { 117 | for (const auto &rect : bboxes) 118 | { 119 | 120 | cv::Rect rst(rect.x - rect.w / 2, rect.y - rect.h / 2, rect.w, rect.h); 121 | cv::rectangle(image, rst, cv::Scalar(255, 204, 0), 2, cv::LINE_8, 0); 122 | //cv::rectangle(image, cv::Point(rect.x - rect.w / 2, rect.y - rect.h / 2), cv::Point(rect.x + rect.w / 2, rect.y + rect.h / 2), cv::Scalar(255, 204,0), 3); 123 | 124 | int baseLine; 125 | std::string label = class_names[rect.classes] + ": " + std::to_string(rect.score * 100).substr(0, 4) + "%"; 126 | 127 | cv::Size labelSize = getTextSize(label, cv::FONT_HERSHEY_TRIPLEX, 0.5, 1, &baseLine); 128 | //int newY = std::max(rect.y, labelSize.height); 129 | rectangle(image, cv::Point(rect.x - rect.w / 2, rect.y - rect.h / 2 - round(1.5*labelSize.height)), 130 | cv::Point(rect.x - rect.w / 2 + round(1.0*labelSize.width), rect.y - rect.h / 2 + baseLine), cv::Scalar(255, 204, 0), cv::FILLED); 131 | cv::putText(image, label, cv::Point(rect.x - rect.w / 2, rect.y - rect.h / 2), cv::FONT_HERSHEY_TRIPLEX, 0.5, cv::Scalar(0, 204, 255)); 132 | 133 | 134 | } 135 | return image; 136 | } 137 | 138 | 139 | float h_input[INPUT_SIZE * INPUT_SIZE * 3]; 140 | int h_output_0[1]; //1 141 | float h_output_1[1 * 20 * 4]; //1 142 | float h_output_2[1 * 20]; //1 143 | float h_output_3[1 * 20]; //1 144 | 145 | 146 | int main() 147 | { 148 | Logger gLogger; 149 | //初始化插件,调用plugin必须初始化plugin respo 150 | nvinfer1:initLibNvInferPlugins(&gLogger, ""); 151 | 152 | 153 | nvinfer1::IRuntime* engine_runtime = nvinfer1::createInferRuntime(gLogger); 154 | std::string engine_filepath = "./model/yolov7.engine"; 155 | 156 | std::ifstream file; 157 | file.open(engine_filepath, std::ios::binary | std::ios::in); 158 | file.seekg(0, std::ios::end); 159 | int length = file.tellg(); 160 | file.seekg(0, std::ios::beg); 161 | 162 | std::shared_ptr data(new char[length], std::default_delete()); 163 | file.read(data.get(), length); 164 | file.close(); 165 | 166 | //nvinfer1::ICudaEngine* engine_infer = engine_runtime->deserializeCudaEngine(cached_engine.data(), cached_engine.size(), nullptr); 167 | nvinfer1::ICudaEngine* engine_infer = engine_runtime->deserializeCudaEngine(data.get(), length, nullptr); 168 | nvinfer1::IExecutionContext* engine_context = engine_infer->createExecutionContext(); 169 | 170 | int input_index = engine_infer->getBindingIndex("images"); //1x3x640x640 171 | //std::string input_name = engine_infer->getBindingName(0) 172 | int output_index_1 = engine_infer->getBindingIndex("num_detections"); //1 173 | int output_index_2 = engine_infer->getBindingIndex("nmsed_boxes"); // 2 174 | int output_index_3 = engine_infer->getBindingIndex("nmsed_scores"); //3 175 | int output_index_4 = engine_infer->getBindingIndex("nmsed_classes"); //5 176 | 177 | 178 | std::cout << "输入的index: " << input_index << " 输出的num_detections-> " << output_index_1 << " 输出的nmsed_boxes-> " << output_index_2 179 | << " 输出的nmsed_scores-> " << output_index_3 << " 输出的nmsed_classes-> " << output_index_4 << std::endl; 180 | 181 | if (engine_context == nullptr) 182 | { 183 | std::cerr << "Failed to create TensorRT Execution Context." << std::endl; 184 | } 185 | 186 | // cached_engine->destroy(); 187 | std::cout << "loaded trt model , do inference" << std::endl; 188 | 189 | 190 | cv::String pattern = "./test/*.jpg"; 191 | std::vector fn; 192 | cv::glob(pattern, fn, false); 193 | std::vector images; 194 | size_t count = fn.size(); //number of png files in images folde 195 | 196 | std::cout << count << std::endl; 197 | 198 | for (size_t i = 0; i < count; i++) 199 | { 200 | cv::Mat image = cv::imread(fn[i]); 201 | cv::Mat image_origin = image.clone(); 202 | 203 | ////cv2读图片 204 | //cv::Mat image; 205 | //image = cv::imread("./test.jpg", 1); 206 | std::cout << fn[i] << std::endl; 207 | 208 | preprocess(image, h_input); 209 | 210 | void* buffers[5]; 211 | cudaMalloc(&buffers[0], INPUT_SIZE * INPUT_SIZE * 3 * sizeof(float)); //<- input 212 | cudaMalloc(&buffers[1], 1 * sizeof(int)); //<- num_detections 213 | cudaMalloc(&buffers[2], 1 * 20 * 4 * sizeof(float)); //<- nmsed_boxes 214 | cudaMalloc(&buffers[3], 1 * 20 * sizeof(float)); //<- nmsed_scores 215 | cudaMalloc(&buffers[4], 1 * 20 * sizeof(float)); //<- nmsed_classes 216 | 217 | cudaMemcpy(buffers[0], h_input, INPUT_SIZE * INPUT_SIZE * 3 * sizeof(float), cudaMemcpyHostToDevice); 218 | 219 | // -- do execute --------// 220 | engine_context->executeV2(buffers); 221 | 222 | cudaMemcpy(h_output_0, buffers[1], 1 * sizeof(int), cudaMemcpyDeviceToHost); 223 | cudaMemcpy(h_output_1, buffers[2], 1 * 20 * 4 * sizeof(float), cudaMemcpyDeviceToHost); 224 | cudaMemcpy(h_output_2, buffers[3], 1 * 20 * sizeof(float), cudaMemcpyDeviceToHost); 225 | cudaMemcpy(h_output_3, buffers[4], 1 * 20 * sizeof(float), cudaMemcpyDeviceToHost); 226 | 227 | std::cout << h_output_0[0] << std::endl; 228 | std::vector pred_box; 229 | for (int i = 0; i < h_output_0[0]; i++) { 230 | 231 | Bbox box; 232 | box.x = (h_output_1[i * 4 + 2] + h_output_1[i * 4]) / 2.0; 233 | box.y = (h_output_1[i * 4 + 3] + h_output_1[i * 4 + 1]) / 2.0; 234 | box.w = h_output_1[i * 4 + 2] - h_output_1[i * 4]; 235 | box.h = h_output_1[i * 4 + 3] - h_output_1[i * 4 + 1]; 236 | box.score = h_output_2[i]; 237 | box.classes = (int)h_output_3[i]; 238 | 239 | std::cout << box.classes << "," << box.score << std::endl; 240 | 241 | pred_box.push_back(box); 242 | 243 | 244 | } 245 | 246 | std::vector out = rescale_box(pred_box, image.cols, image.rows); 247 | 248 | cv::Mat img = renderBoundingBox(image, out); 249 | 250 | //cv::imwrite("final.jpg", img); 251 | 252 | cv::namedWindow("Image", 1);//创建窗口 253 | cv::imshow("Image", img);//显示图像 254 | 255 | cv::waitKey(0); //等待按键 256 | 257 | std::string x = fn[i].substr(6); 258 | std::cout << x << std::endl; 259 | std::string save_index = "./res/" + x; 260 | cv::imwrite(save_index, img); 261 | 262 | cudaFree(buffers[0]); 263 | cudaFree(buffers[1]); 264 | cudaFree(buffers[2]); 265 | cudaFree(buffers[3]); 266 | cudaFree(buffers[4]); 267 | 268 | 269 | 270 | } 271 | 272 | engine_runtime->destroy(); 273 | engine_infer->destroy(); 274 | 275 | return 0; 276 | } 277 | 278 | -------------------------------------------------------------------------------- /tensorrt/yolov7_add_nms.py: -------------------------------------------------------------------------------- 1 | ''' 2 | xujing 3 | 4 | 把NMSPlugin对应的结点添加到 ONNX 5 | 6 | ''' 7 | import onnx_graphsurgeon as gs 8 | import argparse 9 | import onnx 10 | import numpy as np 11 | 12 | def create_and_add_plugin_node(graph, topK, keepTopK): 13 | 14 | batch_size = graph.inputs[0].shape[0] 15 | print("The batch size is: ", batch_size) 16 | input_h = graph.inputs[0].shape[2] 17 | input_w = graph.inputs[0].shape[3] 18 | 19 | tensors = graph.tensors() 20 | boxes_tensor = tensors["boxes"] 21 | confs_tensor = tensors["scores"] 22 | 23 | num_detections = gs.Variable(name="num_detections").to_variable(dtype=np.int32, shape=[batch_size, 1]) 24 | nmsed_boxes = gs.Variable(name="nmsed_boxes").to_variable(dtype=np.float32, shape=[batch_size, keepTopK, 4]) 25 | nmsed_scores = gs.Variable(name="nmsed_scores").to_variable(dtype=np.float32, shape=[batch_size, keepTopK]) 26 | nmsed_classes = gs.Variable(name="nmsed_classes").to_variable(dtype=np.float32, shape=[batch_size, keepTopK]) 27 | 28 | new_outputs = [num_detections, nmsed_boxes, nmsed_scores, nmsed_classes] 29 | 30 | mns_node = gs.Node( 31 | op="BatchedNMS_TRT", 32 | attrs=create_attrs(topK, keepTopK), 33 | inputs=[boxes_tensor, confs_tensor], 34 | outputs=new_outputs) 35 | 36 | graph.nodes.append(mns_node) 37 | graph.outputs = new_outputs 38 | 39 | return graph.cleanup().toposort() 40 | 41 | 42 | def create_attrs(topK, keepTopK): 43 | 44 | # num_anchors = 3 45 | 46 | # h1 = input_h // 8 47 | # h2 = input_h // 16 48 | # h3 = input_h // 32 49 | 50 | # w1 = input_w // 8 51 | # w2 = input_w // 16 52 | # w3 = input_w // 32 53 | 54 | # num_boxes = num_anchors * (h1 * w1 + h2 * w2 + h3 * w3) 55 | 56 | attrs = {} 57 | 58 | attrs["shareLocation"] = 1 59 | attrs["backgroundLabelId"] = -1 60 | attrs["numClasses"] = 4 61 | attrs["topK"] = topK # number of bounding boxes for nms eg 1000s 62 | attrs["keepTopK"] = keepTopK # bounding boxes to be kept per image eg 20 63 | attrs["scoreThreshold"] = 0.20 #0.70 64 | attrs["iouThreshold"] = 0.45 65 | attrs["isNormalized"] = 0 66 | attrs["clipBoxes"] = 0 67 | attrs['scoreBits'] = 16 68 | 69 | # 001 is the default plugin version the parser will search for, and therefore can be omitted, 70 | # but we include it here for illustrative purposes. 71 | attrs["plugin_version"] = "1" 72 | 73 | return attrs 74 | 75 | 76 | def main(): 77 | parser = argparse.ArgumentParser(description="Add batchedNMSPlugin") 78 | parser.add_argument("-f", "--model", help="Path to the ONNX model generated by export_model.py", default="./tensorrt/last_1.onnx") 79 | parser.add_argument("-t", "--topK", help="number of bounding boxes for nms", default=1000) 80 | parser.add_argument("-k", "--keepTopK", help="bounding boxes to be kept per image", default=20) 81 | 82 | args, _ = parser.parse_known_args() 83 | 84 | graph = gs.import_onnx(onnx.load(args.model)) 85 | 86 | graph = create_and_add_plugin_node(graph, int(args.topK), int(args.keepTopK)) 87 | 88 | onnx.save(gs.export_onnx(graph), args.model[:-5] + "_nms.onnx") 89 | 90 | 91 | if __name__ == '__main__': 92 | main() 93 | 94 | -------------------------------------------------------------------------------- /tensorrt/yolov7_add_postprocess.py: -------------------------------------------------------------------------------- 1 | ''' 2 | xujing 3 | 4 | 为了使用batchNMSPlugin!!! 5 | 6 | 给yolov7 的onnx拼接几个操作 7 | 实现将yolov7 的output: [1, 25200,85] # 85在我们这里是9 8 | 9 | 经切片和reshape操作 变为2个节点 10 | 11 | boxes input : [batch_size, number_boxes, number_classes, number_box_parameters] 12 | [x_min, y_min, x_max, y_max] 13 | [8732, 100, 4] 8732个box, 100个类别, 4个坐标 14 | scores input: [batch_size, number_boxes, number_classes] 15 | 16 | # 对于上述问题: 17 | 18 | boxes input: [1,25200, 1, 4] 19 | scores_input: [1, 25200, 80] # 80是类别个数,我们是4个人类别 20 | 21 | 22 | # 需要如何处理呢? 23 | 24 | 85这个维度的排列是:[x1_center,y_center,w,h, prob,80个类别的conf] 4, 1, 80 == [1,25200,4], [1,25200,1], [1,25200,80] 25 | 26 | boxes: [1,25200,1,4] # x_center,y_center, w,h--> x1,y1,x2,y2 27 | 28 | socres: [1,25200,80] # 80个类别的概率 29 | 30 | 31 | 32 | ''' 33 | 34 | import onnx_graphsurgeon as gs 35 | import numpy as np 36 | import onnx 37 | 38 | graph = gs.import_onnx(onnx.load("./tensorrt/last.onnx")) 39 | 40 | 41 | # 添加计算类别概率的结点 42 | 43 | # input 44 | origin_output = [node for node in graph.nodes if node.name == "Concat_318"][0] 45 | print(origin_output.outputs) 46 | 47 | starts_wh = gs.Constant("starts_wh",values=np.array([0,0,0],dtype=np.int64)) 48 | ends_wh = gs.Constant("ends_wh",values=np.array([1,25200,4],dtype=np.int64)) 49 | # axes = gs.Constant("axes",values=np.array([2],dtype=np.int64)) 50 | # steps = gs.Constant("steps",values=np.array([4,1,80],dtype=np.int64)) 51 | # split = gs.Constant("split",values=np.array([4,1,80],dtype=np.int64)) 52 | 53 | starts_object = gs.Constant("starts_object",values=np.array([0,0,4],dtype=np.int64)) 54 | ends_object = gs.Constant("ends_object",values=np.array([1,25200,5],dtype=np.int64)) 55 | 56 | starts_conf = gs.Constant("starts_conf",values=np.array([0,0,5],dtype=np.int64)) 57 | ends_conf = gs.Constant("ends_conf",values=np.array([1,25200,9],dtype=np.int64)) 58 | 59 | # output 60 | box_xywh_0 = gs.Variable(name="box_xywh_0",shape=(1,25200,4),dtype=np.float32) 61 | object_prob_0 = gs.Variable(name="object_prob_0",shape=(1,25200,1),dtype=np.float32) 62 | label_conf_0 = gs.Variable(name='label_conf_0',shape=(1,25200,4),dtype=np.float32) 63 | 64 | # trt不支持 65 | # split_node = gs.Node(op="Split",inputs=[origin_output.outputs[0],split],outputs= [ box_xywh_0,object_prob_0,label_conf_0] ) 66 | # slice 67 | box_xywh_node = gs.Node(op="Slice",inputs=[origin_output.outputs[0],starts_wh,ends_wh],outputs= [ box_xywh_0]) 68 | box_prob_node = gs.Node(op="Slice",inputs=[origin_output.outputs[0],starts_object,ends_object],outputs= [ object_prob_0]) 69 | box_conf_node = gs.Node(op="Slice",inputs=[origin_output.outputs[0],starts_conf,ends_conf],outputs= [ label_conf_0]) 70 | 71 | 72 | # identity 73 | box_xywh = gs.Variable(name="box_xywh",shape=(1,25200,4),dtype=np.float32) 74 | object_prob = gs.Variable(name="object_prob",shape=(1,25200,1),dtype=np.float32) 75 | label_conf = gs.Variable(name='label_conf',shape=(1,25200,4),dtype=np.float32) 76 | 77 | identity_node_wh = gs.Node(op="Identity",inputs=[box_xywh_0],outputs= [ box_xywh] ) 78 | identity_node_prob = gs.Node(op="Identity",inputs=[object_prob_0],outputs= [object_prob] ) 79 | identity_node_conf = gs.Node(op="Identity",inputs=[label_conf_0],outputs= [ label_conf] ) 80 | 81 | 82 | print(identity_node_wh) 83 | 84 | # graph.nodes.extend([split_node]) 85 | 86 | # graph.outputs = [ box_xywh,object_prob,label_conf ] 87 | 88 | # graph.cleanup().toposort() 89 | 90 | 91 | 92 | # onnx.save(gs.export_onnx(graph),"test0.onnx") 93 | 94 | 95 | # #-----------------------重新加载模型------------- 96 | 97 | # graph = gs.import_onnx(onnx.load("./test0.onnx")) 98 | 99 | 100 | # # 添加计算类别概率的结点 101 | 102 | # # input 103 | # origin_output = [node for node in graph.nodes ][-1] 104 | # print(origin_output.outputs) 105 | 106 | # 添加xywh->x1y1x2y2的结点 107 | 108 | # input 109 | starts_1 = gs.Constant("starts_x",values=np.array([0,0,0],dtype=np.int64)) 110 | ends_1 = gs.Constant("ends_x",values=np.array([1,25200,1],dtype=np.int64)) 111 | # axes_1 = gs.Constant("axes",values=np.array([2],dtype=np.int64)) 112 | # steps_1 = gs.Constant("steps",values=np.array([1],dtype=np.int64)) 113 | 114 | starts_2 = gs.Constant("starts_y",values=np.array([0,0,1],dtype=np.int64)) 115 | ends_2 = gs.Constant("ends_y",values=np.array([1,25200,2],dtype=np.int64)) 116 | 117 | starts_3 = gs.Constant("starts_w",values=np.array([0,0,2],dtype=np.int64)) 118 | ends_3 = gs.Constant("ends_w",values=np.array([1,25200,3],dtype=np.int64)) 119 | 120 | starts_4 = gs.Constant("starts_h",values=np.array([0,0,3],dtype=np.int64)) 121 | ends_4 = gs.Constant("ends_h",values=np.array([1,25200,4],dtype=np.int64)) 122 | 123 | # output 124 | x = gs.Variable(name="x_center",shape=(1,25200,1),dtype=np.float32) 125 | y = gs.Variable(name="y_center",shape=(1,25200,1),dtype=np.float32) 126 | w = gs.Variable(name="w",shape=(1,25200,1),dtype=np.float32) 127 | h = gs.Variable(name="h",shape=(1,25200,1),dtype=np.float32) 128 | 129 | # xywh_split_node = gs.Node(op="Split",inputs=[box_xywh],outputs= [x,y,w,h] ) 130 | x_node = gs.Node(op="Slice",inputs=[box_xywh,starts_1,ends_1],outputs=[x]) 131 | y_node = gs.Node(op="Slice",inputs=[box_xywh,starts_2,ends_2],outputs=[y]) 132 | w_node = gs.Node(op="Slice",inputs=[box_xywh,starts_3,ends_3],outputs=[w]) 133 | h_node = gs.Node(op="Slice",inputs=[box_xywh,starts_4,ends_4],outputs=[h]) 134 | 135 | 136 | 137 | # 变换1 138 | # input 139 | div_val = gs.Constant("div_val",values=np.array([2],dtype=np.float32)) 140 | div_val_ = gs.Constant("div_val_",values=np.array([-2],dtype=np.float32)) 141 | # output 142 | w_ = gs.Variable(name="w_half_",shape=(1,25200,1),dtype=np.float32) 143 | wplus = gs.Variable(name="w_half_plus",shape=(1,25200,1),dtype=np.float32) 144 | h_ = gs.Variable(name="h_half_",shape=(1,25200,1),dtype=np.float32) 145 | hplus = gs.Variable(name="h_half_plus",shape=(1,25200,1),dtype=np.float32) 146 | 147 | 148 | w_node_ = gs.Node(op="Div",inputs=[w,div_val_],outputs= [w_] ) 149 | w_node_plus = gs.Node(op="Div",inputs=[w,div_val],outputs= [wplus] ) 150 | h_node_ = gs.Node(op="Div",inputs=[h,div_val_],outputs= [h_] ) 151 | h_node_plus = gs.Node(op="Div",inputs=[h,div_val],outputs= [hplus] ) 152 | 153 | 154 | #变换2 155 | # output 156 | x1 = gs.Variable(name="x1",shape=(1,25200,1),dtype=np.float32) 157 | y1 = gs.Variable(name="y1",shape=(1,25200,1),dtype=np.float32) 158 | x2 = gs.Variable(name="x2",shape=(1,25200,1),dtype=np.float32) 159 | y2 = gs.Variable(name="y2",shape=(1,25200,1),dtype=np.float32) 160 | 161 | 162 | x1_node = gs.Node(op="Add",inputs=[x,w_],outputs= [x1] ) 163 | x2_node = gs.Node(op="Add",inputs=[x,wplus],outputs= [x2] ) 164 | y1_node = gs.Node(op="Add",inputs=[y,h_],outputs= [y1] ) 165 | y2_node= gs.Node(op="Add",inputs=[y,hplus],outputs= [y2] ) 166 | 167 | 168 | # concat 169 | # output 170 | 171 | boxes_0 = gs.Variable(name="boxes_0",shape=(1,25200,4),dtype=np.float32) 172 | 173 | # print(help(gs.Node)) 174 | 175 | boxes_node_0 = gs.Node(op="Concat",inputs=[x1,y1,x2,y2],outputs= [boxes_0] ,attrs={"axis":2}) 176 | # print(boxes_node_0) 177 | 178 | # # Unsqueeze tensorrt不支持 179 | # axis_squeeze = gs.Constant("axes",values=np.array([2],dtype=np.int64)) 180 | shapes = gs.Constant("shape",values=np.array([1,25200,1,4],dtype=np.int64)) 181 | 182 | # output 183 | boxes = gs.Variable(name="boxes",shape=(1,25200,1,4),dtype=np.float32) 184 | 185 | 186 | # boxes_node = gs.Node(op="Unsqueeze",inputs=[boxes_0,axis_squeeze],outputs= [boxes]) 187 | # print(boxes_node) 188 | boxes_node = gs.Node(op="Reshape",inputs=[boxes_0,shapes],outputs= [boxes]) 189 | 190 | #----处理prob 191 | scores = gs.Variable(name="scores",shape=(1,25200,4),dtype=np.float32) 192 | 193 | # Mul是矩阵中逐点相乘 194 | scores_node = gs.Node(op="Mul",inputs=[label_conf,object_prob],outputs=[scores]) 195 | 196 | 197 | graph.nodes.extend([box_xywh_node,box_prob_node,box_conf_node,identity_node_wh,identity_node_prob,identity_node_conf, 198 | x_node,y_node,w_node,h_node, 199 | w_node_,w_node_plus,h_node_,h_node_plus,x1_node,x2_node,y1_node,y2_node,boxes_node_0,boxes_node,scores_node]) 200 | # graph.nodes.extend([split_node,xywh_split_node,w_node_,w_node_plus,h_node_,h_node_plus,x1_node,x2_node,y1_node,y2_node,boxes_node,scores_node]) 201 | 202 | graph.outputs = [ boxes,scores ] 203 | 204 | graph.cleanup().toposort() 205 | 206 | 207 | onnx.save(gs.export_onnx(graph),"./last_1.onnx") 208 | 209 | -------------------------------------------------------------------------------- /test_img/image1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/test_img/image1.jpg -------------------------------------------------------------------------------- /test_img/image2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/test_img/image2.jpg -------------------------------------------------------------------------------- /test_img/image3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/YOLOv7/5b16e7970d4a8661ebfab3d382b832dfff6049f1/test_img/image3.jpg -------------------------------------------------------------------------------- /utils/__init__.py: -------------------------------------------------------------------------------- 1 | # init -------------------------------------------------------------------------------- /utils/activations.py: -------------------------------------------------------------------------------- 1 | # Activation functions 2 | 3 | import torch 4 | import torch.nn as nn 5 | import torch.nn.functional as F 6 | 7 | 8 | # SiLU https://arxiv.org/pdf/1606.08415.pdf ---------------------------------------------------------------------------- 9 | class SiLU(nn.Module): # export-friendly version of nn.SiLU() 10 | @staticmethod 11 | def forward(x): 12 | return x * torch.sigmoid(x) 13 | 14 | 15 | class Hardswish(nn.Module): # export-friendly version of nn.Hardswish() 16 | @staticmethod 17 | def forward(x): 18 | # return x * F.hardsigmoid(x) # for torchscript and CoreML 19 | return x * F.hardtanh(x + 3, 0., 6.) / 6. # for torchscript, CoreML and ONNX 20 | 21 | 22 | class MemoryEfficientSwish(nn.Module): 23 | class F(torch.autograd.Function): 24 | @staticmethod 25 | def forward(ctx, x): 26 | ctx.save_for_backward(x) 27 | return x * torch.sigmoid(x) 28 | 29 | @staticmethod 30 | def backward(ctx, grad_output): 31 | x = ctx.saved_tensors[0] 32 | sx = torch.sigmoid(x) 33 | return grad_output * (sx * (1 + x * (1 - sx))) 34 | 35 | def forward(self, x): 36 | return self.F.apply(x) 37 | 38 | 39 | # Mish https://github.com/digantamisra98/Mish -------------------------------------------------------------------------- 40 | class Mish(nn.Module): 41 | @staticmethod 42 | def forward(x): 43 | return x * F.softplus(x).tanh() 44 | 45 | 46 | class MemoryEfficientMish(nn.Module): 47 | class F(torch.autograd.Function): 48 | @staticmethod 49 | def forward(ctx, x): 50 | ctx.save_for_backward(x) 51 | return x.mul(torch.tanh(F.softplus(x))) # x * tanh(ln(1 + exp(x))) 52 | 53 | @staticmethod 54 | def backward(ctx, grad_output): 55 | x = ctx.saved_tensors[0] 56 | sx = torch.sigmoid(x) 57 | fx = F.softplus(x).tanh() 58 | return grad_output * (fx + x * sx * (1 - fx * fx)) 59 | 60 | def forward(self, x): 61 | return self.F.apply(x) 62 | 63 | 64 | # FReLU https://arxiv.org/abs/2007.11824 ------------------------------------------------------------------------------- 65 | class FReLU(nn.Module): 66 | def __init__(self, c1, k=3): # ch_in, kernel 67 | super().__init__() 68 | self.conv = nn.Conv2d(c1, c1, k, 1, 1, groups=c1, bias=False) 69 | self.bn = nn.BatchNorm2d(c1) 70 | 71 | def forward(self, x): 72 | return torch.max(x, self.bn(self.conv(x))) 73 | -------------------------------------------------------------------------------- /utils/autoanchor.py: -------------------------------------------------------------------------------- 1 | # Auto-anchor utils 2 | 3 | import numpy as np 4 | import torch 5 | import yaml 6 | from scipy.cluster.vq import kmeans 7 | from tqdm import tqdm 8 | 9 | from utils.general import colorstr 10 | 11 | 12 | def check_anchor_order(m): 13 | # Check anchor order against stride order for YOLO Detect() module m, and correct if necessary 14 | a = m.anchor_grid.prod(-1).view(-1) # anchor area 15 | da = a[-1] - a[0] # delta a 16 | ds = m.stride[-1] - m.stride[0] # delta s 17 | if da.sign() != ds.sign(): # same order 18 | print('Reversing anchor order') 19 | m.anchors[:] = m.anchors.flip(0) 20 | m.anchor_grid[:] = m.anchor_grid.flip(0) 21 | 22 | 23 | def check_anchors(dataset, model, thr=4.0, imgsz=640): 24 | # Check anchor fit to data, recompute if necessary 25 | prefix = colorstr('autoanchor: ') 26 | print(f'\n{prefix}Analyzing anchors... ', end='') 27 | m = model.module.model[-1] if hasattr(model, 'module') else model.model[-1] # Detect() 28 | shapes = imgsz * dataset.shapes / dataset.shapes.max(1, keepdims=True) 29 | scale = np.random.uniform(0.9, 1.1, size=(shapes.shape[0], 1)) # augment scale 30 | wh = torch.tensor(np.concatenate([l[:, 3:5] * s for s, l in zip(shapes * scale, dataset.labels)])).float() # wh 31 | 32 | def metric(k): # compute metric 33 | r = wh[:, None] / k[None] 34 | x = torch.min(r, 1. / r).min(2)[0] # ratio metric 35 | best = x.max(1)[0] # best_x 36 | aat = (x > 1. / thr).float().sum(1).mean() # anchors above threshold 37 | bpr = (best > 1. / thr).float().mean() # best possible recall 38 | return bpr, aat 39 | 40 | anchors = m.anchor_grid.clone().cpu().view(-1, 2) # current anchors 41 | bpr, aat = metric(anchors) 42 | print(f'anchors/target = {aat:.2f}, Best Possible Recall (BPR) = {bpr:.4f}', end='') 43 | if bpr < 0.98: # threshold to recompute 44 | print('. Attempting to improve anchors, please wait...') 45 | na = m.anchor_grid.numel() // 2 # number of anchors 46 | try: 47 | anchors = kmean_anchors(dataset, n=na, img_size=imgsz, thr=thr, gen=1000, verbose=False) 48 | except Exception as e: 49 | print(f'{prefix}ERROR: {e}') 50 | new_bpr = metric(anchors)[0] 51 | if new_bpr > bpr: # replace anchors 52 | anchors = torch.tensor(anchors, device=m.anchors.device).type_as(m.anchors) 53 | m.anchor_grid[:] = anchors.clone().view_as(m.anchor_grid) # for inference 54 | m.anchors[:] = anchors.clone().view_as(m.anchors) / m.stride.to(m.anchors.device).view(-1, 1, 1) # loss 55 | check_anchor_order(m) 56 | print(f'{prefix}New anchors saved to model. Update model *.yaml to use these anchors in the future.') 57 | else: 58 | print(f'{prefix}Original anchors better than new anchors. Proceeding with original anchors.') 59 | print('') # newline 60 | 61 | 62 | def kmean_anchors(path='./data/coco.yaml', n=9, img_size=640, thr=4.0, gen=1000, verbose=True): 63 | """ Creates kmeans-evolved anchors from training dataset 64 | 65 | Arguments: 66 | path: path to dataset *.yaml, or a loaded dataset 67 | n: number of anchors 68 | img_size: image size used for training 69 | thr: anchor-label wh ratio threshold hyperparameter hyp['anchor_t'] used for training, default=4.0 70 | gen: generations to evolve anchors using genetic algorithm 71 | verbose: print all results 72 | 73 | Return: 74 | k: kmeans evolved anchors 75 | 76 | Usage: 77 | from utils.autoanchor import *; _ = kmean_anchors() 78 | """ 79 | thr = 1. / thr 80 | prefix = colorstr('autoanchor: ') 81 | 82 | def metric(k, wh): # compute metrics 83 | r = wh[:, None] / k[None] 84 | x = torch.min(r, 1. / r).min(2)[0] # ratio metric 85 | # x = wh_iou(wh, torch.tensor(k)) # iou metric 86 | return x, x.max(1)[0] # x, best_x 87 | 88 | def anchor_fitness(k): # mutation fitness 89 | _, best = metric(torch.tensor(k, dtype=torch.float32), wh) 90 | return (best * (best > thr).float()).mean() # fitness 91 | 92 | def print_results(k): 93 | k = k[np.argsort(k.prod(1))] # sort small to large 94 | x, best = metric(k, wh0) 95 | bpr, aat = (best > thr).float().mean(), (x > thr).float().mean() * n # best possible recall, anch > thr 96 | print(f'{prefix}thr={thr:.2f}: {bpr:.4f} best possible recall, {aat:.2f} anchors past thr') 97 | print(f'{prefix}n={n}, img_size={img_size}, metric_all={x.mean():.3f}/{best.mean():.3f}-mean/best, ' 98 | f'past_thr={x[x > thr].mean():.3f}-mean: ', end='') 99 | for i, x in enumerate(k): 100 | print('%i,%i' % (round(x[0]), round(x[1])), end=', ' if i < len(k) - 1 else '\n') # use in *.cfg 101 | return k 102 | 103 | if isinstance(path, str): # *.yaml file 104 | with open(path) as f: 105 | data_dict = yaml.load(f, Loader=yaml.SafeLoader) # model dict 106 | from utils.datasets import LoadImagesAndLabels 107 | dataset = LoadImagesAndLabels(data_dict['train'], augment=True, rect=True) 108 | else: 109 | dataset = path # dataset 110 | 111 | # Get label wh 112 | shapes = img_size * dataset.shapes / dataset.shapes.max(1, keepdims=True) 113 | wh0 = np.concatenate([l[:, 3:5] * s for s, l in zip(shapes, dataset.labels)]) # wh 114 | 115 | # Filter 116 | i = (wh0 < 3.0).any(1).sum() 117 | if i: 118 | print(f'{prefix}WARNING: Extremely small objects found. {i} of {len(wh0)} labels are < 3 pixels in size.') 119 | wh = wh0[(wh0 >= 2.0).any(1)] # filter > 2 pixels 120 | # wh = wh * (np.random.rand(wh.shape[0], 1) * 0.9 + 0.1) # multiply by random scale 0-1 121 | 122 | # Kmeans calculation 123 | print(f'{prefix}Running kmeans for {n} anchors on {len(wh)} points...') 124 | s = wh.std(0) # sigmas for whitening 125 | k, dist = kmeans(wh / s, n, iter=30) # points, mean distance 126 | assert len(k) == n, print(f'{prefix}ERROR: scipy.cluster.vq.kmeans requested {n} points but returned only {len(k)}') 127 | k *= s 128 | wh = torch.tensor(wh, dtype=torch.float32) # filtered 129 | wh0 = torch.tensor(wh0, dtype=torch.float32) # unfiltered 130 | k = print_results(k) 131 | 132 | # Plot 133 | # k, d = [None] * 20, [None] * 20 134 | # for i in tqdm(range(1, 21)): 135 | # k[i-1], d[i-1] = kmeans(wh / s, i) # points, mean distance 136 | # fig, ax = plt.subplots(1, 2, figsize=(14, 7), tight_layout=True) 137 | # ax = ax.ravel() 138 | # ax[0].plot(np.arange(1, 21), np.array(d) ** 2, marker='.') 139 | # fig, ax = plt.subplots(1, 2, figsize=(14, 7)) # plot wh 140 | # ax[0].hist(wh[wh[:, 0]<100, 0],400) 141 | # ax[1].hist(wh[wh[:, 1]<100, 1],400) 142 | # fig.savefig('wh.png', dpi=200) 143 | 144 | # Evolve 145 | npr = np.random 146 | f, sh, mp, s = anchor_fitness(k), k.shape, 0.9, 0.1 # fitness, generations, mutation prob, sigma 147 | pbar = tqdm(range(gen), desc=f'{prefix}Evolving anchors with Genetic Algorithm:') # progress bar 148 | for _ in pbar: 149 | v = np.ones(sh) 150 | while (v == 1).all(): # mutate until a change occurs (prevent duplicates) 151 | v = ((npr.random(sh) < mp) * npr.random() * npr.randn(*sh) * s + 1).clip(0.3, 3.0) 152 | kg = (k.copy() * v).clip(min=2.0) 153 | fg = anchor_fitness(kg) 154 | if fg > f: 155 | f, k = fg, kg.copy() 156 | pbar.desc = f'{prefix}Evolving anchors with Genetic Algorithm: fitness = {f:.4f}' 157 | if verbose: 158 | print_results(k) 159 | 160 | return print_results(k) 161 | -------------------------------------------------------------------------------- /utils/aws/__init__.py: -------------------------------------------------------------------------------- 1 | #init -------------------------------------------------------------------------------- /utils/aws/mime.sh: -------------------------------------------------------------------------------- 1 | # AWS EC2 instance startup 'MIME' script https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/ 2 | # This script will run on every instance restart, not only on first start 3 | # --- DO NOT COPY ABOVE COMMENTS WHEN PASTING INTO USERDATA --- 4 | 5 | Content-Type: multipart/mixed; boundary="//" 6 | MIME-Version: 1.0 7 | 8 | --// 9 | Content-Type: text/cloud-config; charset="us-ascii" 10 | MIME-Version: 1.0 11 | Content-Transfer-Encoding: 7bit 12 | Content-Disposition: attachment; filename="cloud-config.txt" 13 | 14 | #cloud-config 15 | cloud_final_modules: 16 | - [scripts-user, always] 17 | 18 | --// 19 | Content-Type: text/x-shellscript; charset="us-ascii" 20 | MIME-Version: 1.0 21 | Content-Transfer-Encoding: 7bit 22 | Content-Disposition: attachment; filename="userdata.txt" 23 | 24 | #!/bin/bash 25 | # --- paste contents of userdata.sh here --- 26 | --// 27 | -------------------------------------------------------------------------------- /utils/aws/resume.py: -------------------------------------------------------------------------------- 1 | # Resume all interrupted trainings in yolor/ 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 | sys.path.append('./') # to run '$ python *.py' files in subdirectories 12 | 13 | port = 0 # --master_port 14 | path = Path('').resolve() 15 | for last in path.rglob('*/**/last.pt'): 16 | ckpt = torch.load(last) 17 | if ckpt['optimizer'] is None: 18 | continue 19 | 20 | # Load opt.yaml 21 | with open(last.parent.parent / 'opt.yaml') as f: 22 | opt = yaml.load(f, Loader=yaml.SafeLoader) 23 | 24 | # Get device count 25 | d = opt['device'].split(',') # devices 26 | nd = len(d) # number of devices 27 | ddp = nd > 1 or (nd == 0 and torch.cuda.device_count() > 1) # distributed data parallel 28 | 29 | if ddp: # multi-GPU 30 | port += 1 31 | cmd = f'python -m torch.distributed.launch --nproc_per_node {nd} --master_port {port} train.py --resume {last}' 32 | else: # single-GPU 33 | cmd = f'python train.py --resume {last}' 34 | 35 | cmd += ' > /dev/null 2>&1 &' # redirect output to dev/null and run in daemon thread 36 | print(cmd) 37 | os.system(cmd) 38 | -------------------------------------------------------------------------------- /utils/aws/userdata.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # AWS EC2 instance startup script https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html 3 | # This script will run only once on first instance start (for a re-start script see mime.sh) 4 | # /home/ubuntu (ubuntu) or /home/ec2-user (amazon-linux) is working dir 5 | # Use >300 GB SSD 6 | 7 | cd home/ubuntu 8 | if [ ! -d yolor ]; then 9 | echo "Running first-time script." # install dependencies, download COCO, pull Docker 10 | git clone -b paper https://github.com/WongKinYiu/yolor && sudo chmod -R 777 yolor 11 | cd yolor 12 | bash data/scripts/get_coco.sh && echo "Data done." & 13 | sudo docker pull nvcr.io/nvidia/pytorch:21.08-py3 && echo "Docker done." & 14 | python -m pip install --upgrade pip && pip install -r requirements.txt && python detect.py && echo "Requirements done." & 15 | wait && echo "All tasks done." # finish background tasks 16 | else 17 | echo "Running re-start script." # resume interrupted runs 18 | i=0 19 | list=$(sudo docker ps -qa) # container list i.e. $'one\ntwo\nthree\nfour' 20 | while IFS= read -r id; do 21 | ((i++)) 22 | echo "restarting container $i: $id" 23 | sudo docker start $id 24 | # sudo docker exec -it $id python train.py --resume # single-GPU 25 | sudo docker exec -d $id python utils/aws/resume.py # multi-scenario 26 | done <<<"$list" 27 | fi 28 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /utils/google_app_engine/additional_requirements.txt: -------------------------------------------------------------------------------- 1 | # add these requirements in your app on top of the existing ones 2 | pip==18.1 3 | Flask==1.0.2 4 | gunicorn==19.9.0 5 | -------------------------------------------------------------------------------- /utils/google_app_engine/app.yaml: -------------------------------------------------------------------------------- 1 | runtime: custom 2 | env: flex 3 | 4 | service: yolorapp 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 -------------------------------------------------------------------------------- /utils/google_utils.py: -------------------------------------------------------------------------------- 1 | # Google utils: https://cloud.google.com/storage/docs/reference/libraries 2 | 3 | import os 4 | import platform 5 | import subprocess 6 | import time 7 | from pathlib import Path 8 | 9 | import requests 10 | import torch 11 | 12 | 13 | def gsutil_getsize(url=''): 14 | # gs://bucket/file size https://cloud.google.com/storage/docs/gsutil/commands/du 15 | s = subprocess.check_output(f'gsutil du {url}', shell=True).decode('utf-8') 16 | return eval(s.split(' ')[0]) if len(s) else 0 # bytes 17 | 18 | 19 | def attempt_download(file, repo='WongKinYiu/yolov6'): 20 | # Attempt file download if does not exist 21 | file = Path(str(file).strip().replace("'", '').lower()) 22 | 23 | if not file.exists(): 24 | try: 25 | response = requests.get(f'https://api.github.com/repos/{repo}/releases/weights').json() # github api 26 | assets = [x['name'] for x in response['assets']] # release assets 27 | tag = response['tag_name'] # i.e. 'v1.0' 28 | except: # fallback plan 29 | assets = ['yolov6.pt'] 30 | tag = subprocess.check_output('git tag', shell=True).decode().split()[-1] 31 | 32 | name = file.name 33 | if name in assets: 34 | msg = f'{file} missing, try downloading from https://github.com/{repo}/releases/' 35 | redundant = False # second download option 36 | try: # GitHub 37 | url = f'https://github.com/{repo}/releases/download/{tag}/{name}' 38 | print(f'Downloading {url} to {file}...') 39 | torch.hub.download_url_to_file(url, file) 40 | assert file.exists() and file.stat().st_size > 1E6 # check 41 | except Exception as e: # GCP 42 | print(f'Download error: {e}') 43 | assert redundant, 'No secondary mirror' 44 | url = f'https://storage.googleapis.com/{repo}/ckpt/{name}' 45 | print(f'Downloading {url} to {file}...') 46 | os.system(f'curl -L {url} -o {file}') # torch.hub.download_url_to_file(url, weights) 47 | finally: 48 | if not file.exists() or file.stat().st_size < 1E6: # check 49 | file.unlink(missing_ok=True) # remove partial downloads 50 | print(f'ERROR: Download failure: {msg}') 51 | print('') 52 | return 53 | 54 | 55 | def gdrive_download(id='', file='tmp.zip'): 56 | # Downloads a file from Google Drive. from yolov6.utils.google_utils import *; gdrive_download() 57 | t = time.time() 58 | file = Path(file) 59 | cookie = Path('cookie') # gdrive cookie 60 | print(f'Downloading https://drive.google.com/uc?export=download&id={id} as {file}... ', end='') 61 | file.unlink(missing_ok=True) # remove existing file 62 | cookie.unlink(missing_ok=True) # remove existing cookie 63 | 64 | # Attempt file download 65 | out = "NUL" if platform.system() == "Windows" else "/dev/null" 66 | os.system(f'curl -c ./cookie -s -L "drive.google.com/uc?export=download&id={id}" > {out}') 67 | if os.path.exists('cookie'): # large file 68 | s = f'curl -Lb ./cookie "drive.google.com/uc?export=download&confirm={get_token()}&id={id}" -o {file}' 69 | else: # small file 70 | s = f'curl -s -L -o {file} "drive.google.com/uc?export=download&id={id}"' 71 | r = os.system(s) # execute, capture return 72 | cookie.unlink(missing_ok=True) # remove existing cookie 73 | 74 | # Error check 75 | if r != 0: 76 | file.unlink(missing_ok=True) # remove partial 77 | print('Download error ') # raise Exception('Download error') 78 | return r 79 | 80 | # Unzip if archive 81 | if file.suffix == '.zip': 82 | print('unzipping... ', end='') 83 | os.system(f'unzip -q {file}') # unzip 84 | file.unlink() # remove zip to free space 85 | 86 | print(f'Done ({time.time() - t:.1f}s)') 87 | return r 88 | 89 | 90 | def get_token(cookie="./cookie"): 91 | with open(cookie) as f: 92 | for line in f: 93 | if "download" in line: 94 | return line.split()[-1] 95 | return "" 96 | 97 | # def upload_blob(bucket_name, source_file_name, destination_blob_name): 98 | # # Uploads a file to a bucket 99 | # # https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-python 100 | # 101 | # storage_client = storage.Client() 102 | # bucket = storage_client.get_bucket(bucket_name) 103 | # blob = bucket.blob(destination_blob_name) 104 | # 105 | # blob.upload_from_filename(source_file_name) 106 | # 107 | # print('File {} uploaded to {}.'.format( 108 | # source_file_name, 109 | # destination_blob_name)) 110 | # 111 | # 112 | # def download_blob(bucket_name, source_blob_name, destination_file_name): 113 | # # Uploads a blob from a bucket 114 | # storage_client = storage.Client() 115 | # bucket = storage_client.get_bucket(bucket_name) 116 | # blob = bucket.blob(source_blob_name) 117 | # 118 | # blob.download_to_filename(destination_file_name) 119 | # 120 | # print('Blob {} downloaded to {}.'.format( 121 | # source_blob_name, 122 | # destination_file_name)) 123 | -------------------------------------------------------------------------------- /utils/metrics.py: -------------------------------------------------------------------------------- 1 | # Model validation metrics 2 | 3 | from pathlib import Path 4 | 5 | import matplotlib.pyplot as plt 6 | import numpy as np 7 | import torch 8 | 9 | from . import general 10 | 11 | 12 | def fitness(x): 13 | # Model fitness as a weighted combination of metrics 14 | w = [0.0, 0.0, 0.1, 0.9] # weights for [P, R, mAP@0.5, mAP@0.5:0.95] 15 | return (x[:, :4] * w).sum(1) 16 | 17 | 18 | def ap_per_class(tp, conf, pred_cls, target_cls, plot=False, save_dir='.', names=()): 19 | """ Compute the average precision, given the recall and precision curves. 20 | Source: https://github.com/rafaelpadilla/Object-Detection-Metrics. 21 | # Arguments 22 | tp: True positives (nparray, nx1 or nx10). 23 | conf: Objectness value from 0-1 (nparray). 24 | pred_cls: Predicted object classes (nparray). 25 | target_cls: True object classes (nparray). 26 | plot: Plot precision-recall curve at mAP@0.5 27 | save_dir: Plot save directory 28 | # Returns 29 | The average precision as computed in py-faster-rcnn. 30 | """ 31 | 32 | # Sort by objectness 33 | i = np.argsort(-conf) 34 | tp, conf, pred_cls = tp[i], conf[i], pred_cls[i] 35 | 36 | # Find unique classes 37 | unique_classes = np.unique(target_cls) 38 | nc = unique_classes.shape[0] # number of classes, number of detections 39 | 40 | # Create Precision-Recall curve and compute AP for each class 41 | px, py = np.linspace(0, 1, 1000), [] # for plotting 42 | ap, p, r = np.zeros((nc, tp.shape[1])), np.zeros((nc, 1000)), np.zeros((nc, 1000)) 43 | for ci, c in enumerate(unique_classes): 44 | i = pred_cls == c 45 | n_l = (target_cls == c).sum() # number of labels 46 | n_p = i.sum() # number of predictions 47 | 48 | if n_p == 0 or n_l == 0: 49 | continue 50 | else: 51 | # Accumulate FPs and TPs 52 | fpc = (1 - tp[i]).cumsum(0) 53 | tpc = tp[i].cumsum(0) 54 | 55 | # Recall 56 | recall = tpc / (n_l + 1e-16) # recall curve 57 | r[ci] = np.interp(-px, -conf[i], recall[:, 0], left=0) # negative x, xp because xp decreases 58 | 59 | # Precision 60 | precision = tpc / (tpc + fpc) # precision curve 61 | p[ci] = np.interp(-px, -conf[i], precision[:, 0], left=1) # p at pr_score 62 | 63 | # AP from recall-precision curve 64 | for j in range(tp.shape[1]): 65 | ap[ci, j], mpre, mrec = compute_ap(recall[:, j], precision[:, j]) 66 | if plot and j == 0: 67 | py.append(np.interp(px, mrec, mpre)) # precision at mAP@0.5 68 | 69 | # Compute F1 (harmonic mean of precision and recall) 70 | f1 = 2 * p * r / (p + r + 1e-16) 71 | if plot: 72 | plot_pr_curve(px, py, ap, Path(save_dir) / 'PR_curve.png', names) 73 | plot_mc_curve(px, f1, Path(save_dir) / 'F1_curve.png', names, ylabel='F1') 74 | plot_mc_curve(px, p, Path(save_dir) / 'P_curve.png', names, ylabel='Precision') 75 | plot_mc_curve(px, r, Path(save_dir) / 'R_curve.png', names, ylabel='Recall') 76 | 77 | i = f1.mean(0).argmax() # max F1 index 78 | return p[:, i], r[:, i], ap, f1[:, i], unique_classes.astype('int32') 79 | 80 | 81 | def compute_ap(recall, precision): 82 | """ Compute the average precision, given the recall and precision curves 83 | # Arguments 84 | recall: The recall curve (list) 85 | precision: The precision curve (list) 86 | # Returns 87 | Average precision, precision curve, recall curve 88 | """ 89 | 90 | # Append sentinel values to beginning and end 91 | mrec = np.concatenate(([0.], recall, [recall[-1] + 0.01])) 92 | mpre = np.concatenate(([1.], precision, [0.])) 93 | 94 | # Compute the precision envelope 95 | mpre = np.flip(np.maximum.accumulate(np.flip(mpre))) 96 | 97 | # Integrate area under curve 98 | method = 'interp' # methods: 'continuous', 'interp' 99 | if method == 'interp': 100 | x = np.linspace(0, 1, 101) # 101-point interp (COCO) 101 | ap = np.trapz(np.interp(x, mrec, mpre), x) # integrate 102 | else: # 'continuous' 103 | i = np.where(mrec[1:] != mrec[:-1])[0] # points where x axis (recall) changes 104 | ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1]) # area under curve 105 | 106 | return ap, mpre, mrec 107 | 108 | 109 | class ConfusionMatrix: 110 | # Updated version of https://github.com/kaanakan/object_detection_confusion_matrix 111 | def __init__(self, nc, conf=0.25, iou_thres=0.45): 112 | self.matrix = np.zeros((nc + 1, nc + 1)) 113 | self.nc = nc # number of classes 114 | self.conf = conf 115 | self.iou_thres = iou_thres 116 | 117 | def process_batch(self, detections, labels): 118 | """ 119 | Return intersection-over-union (Jaccard index) of boxes. 120 | Both sets of boxes are expected to be in (x1, y1, x2, y2) format. 121 | Arguments: 122 | detections (Array[N, 6]), x1, y1, x2, y2, conf, class 123 | labels (Array[M, 5]), class, x1, y1, x2, y2 124 | Returns: 125 | None, updates confusion matrix accordingly 126 | """ 127 | detections = detections[detections[:, 4] > self.conf] 128 | gt_classes = labels[:, 0].int() 129 | detection_classes = detections[:, 5].int() 130 | iou = general.box_iou(labels[:, 1:], detections[:, :4]) 131 | 132 | x = torch.where(iou > self.iou_thres) 133 | if x[0].shape[0]: 134 | matches = torch.cat((torch.stack(x, 1), iou[x[0], x[1]][:, None]), 1).cpu().numpy() 135 | if x[0].shape[0] > 1: 136 | matches = matches[matches[:, 2].argsort()[::-1]] 137 | matches = matches[np.unique(matches[:, 1], return_index=True)[1]] 138 | matches = matches[matches[:, 2].argsort()[::-1]] 139 | matches = matches[np.unique(matches[:, 0], return_index=True)[1]] 140 | else: 141 | matches = np.zeros((0, 3)) 142 | 143 | n = matches.shape[0] > 0 144 | m0, m1, _ = matches.transpose().astype(np.int16) 145 | for i, gc in enumerate(gt_classes): 146 | j = m0 == i 147 | if n and sum(j) == 1: 148 | self.matrix[gc, detection_classes[m1[j]]] += 1 # correct 149 | else: 150 | self.matrix[self.nc, gc] += 1 # background FP 151 | 152 | if n: 153 | for i, dc in enumerate(detection_classes): 154 | if not any(m1 == i): 155 | self.matrix[dc, self.nc] += 1 # background FN 156 | 157 | def matrix(self): 158 | return self.matrix 159 | 160 | def plot(self, save_dir='', names=()): 161 | try: 162 | import seaborn as sn 163 | 164 | array = self.matrix / (self.matrix.sum(0).reshape(1, self.nc + 1) + 1E-6) # normalize 165 | array[array < 0.005] = np.nan # don't annotate (would appear as 0.00) 166 | 167 | fig = plt.figure(figsize=(12, 9), tight_layout=True) 168 | sn.set(font_scale=1.0 if self.nc < 50 else 0.8) # for label size 169 | labels = (0 < len(names) < 99) and len(names) == self.nc # apply names to ticklabels 170 | sn.heatmap(array, annot=self.nc < 30, annot_kws={"size": 8}, cmap='Blues', fmt='.2f', square=True, 171 | xticklabels=names + ['background FP'] if labels else "auto", 172 | yticklabels=names + ['background FN'] if labels else "auto").set_facecolor((1, 1, 1)) 173 | fig.axes[0].set_xlabel('True') 174 | fig.axes[0].set_ylabel('Predicted') 175 | fig.savefig(Path(save_dir) / 'confusion_matrix.png', dpi=250) 176 | except Exception as e: 177 | pass 178 | 179 | def print(self): 180 | for i in range(self.nc + 1): 181 | print(' '.join(map(str, self.matrix[i]))) 182 | 183 | 184 | # Plots ---------------------------------------------------------------------------------------------------------------- 185 | 186 | def plot_pr_curve(px, py, ap, save_dir='pr_curve.png', names=()): 187 | # Precision-recall curve 188 | fig, ax = plt.subplots(1, 1, figsize=(9, 6), tight_layout=True) 189 | py = np.stack(py, axis=1) 190 | 191 | if 0 < len(names) < 21: # display per-class legend if < 21 classes 192 | for i, y in enumerate(py.T): 193 | ax.plot(px, y, linewidth=1, label=f'{names[i]} {ap[i, 0]:.3f}') # plot(recall, precision) 194 | else: 195 | ax.plot(px, py, linewidth=1, color='grey') # plot(recall, precision) 196 | 197 | ax.plot(px, py.mean(1), linewidth=3, color='blue', label='all classes %.3f mAP@0.5' % ap[:, 0].mean()) 198 | ax.set_xlabel('Recall') 199 | ax.set_ylabel('Precision') 200 | ax.set_xlim(0, 1) 201 | ax.set_ylim(0, 1) 202 | plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left") 203 | fig.savefig(Path(save_dir), dpi=250) 204 | 205 | 206 | def plot_mc_curve(px, py, save_dir='mc_curve.png', names=(), xlabel='Confidence', ylabel='Metric'): 207 | # Metric-confidence curve 208 | fig, ax = plt.subplots(1, 1, figsize=(9, 6), tight_layout=True) 209 | 210 | if 0 < len(names) < 21: # display per-class legend if < 21 classes 211 | for i, y in enumerate(py): 212 | ax.plot(px, y, linewidth=1, label=f'{names[i]}') # plot(confidence, metric) 213 | else: 214 | ax.plot(px, py.T, linewidth=1, color='grey') # plot(confidence, metric) 215 | 216 | y = py.mean(0) 217 | ax.plot(px, y, linewidth=3, color='blue', label=f'all classes {y.max():.2f} at {px[y.argmax()]:.3f}') 218 | ax.set_xlabel(xlabel) 219 | ax.set_ylabel(ylabel) 220 | ax.set_xlim(0, 1) 221 | ax.set_ylim(0, 1) 222 | plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left") 223 | fig.savefig(Path(save_dir), dpi=250) 224 | -------------------------------------------------------------------------------- /utils/wandb_logging/__init__.py: -------------------------------------------------------------------------------- 1 | # init -------------------------------------------------------------------------------- /utils/wandb_logging/log_dataset.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | import yaml 4 | 5 | from wandb_utils import WandbLogger 6 | 7 | WANDB_ARTIFACT_PREFIX = 'wandb-artifact://' 8 | 9 | 10 | def create_dataset_artifact(opt): 11 | with open(opt.data) as f: 12 | data = yaml.load(f, Loader=yaml.SafeLoader) # data dict 13 | logger = WandbLogger(opt, '', None, data, job_type='Dataset Creation') 14 | 15 | 16 | if __name__ == '__main__': 17 | parser = argparse.ArgumentParser() 18 | parser.add_argument('--data', type=str, default='data/coco.yaml', help='data.yaml path') 19 | parser.add_argument('--single-cls', action='store_true', help='train as single-class dataset') 20 | parser.add_argument('--project', type=str, default='YOLOR', help='name of W&B Project') 21 | opt = parser.parse_args() 22 | opt.resume = False # Explicitly disallow resume check for dataset upload job 23 | 24 | create_dataset_artifact(opt) 25 | --------------------------------------------------------------------------------