├── README.md ├── yolov7_caffe ├── ReadMe.md ├── result.jpg ├── test.jpg ├── yolov7.caffemodel ├── yolov7.prototxt └── yolov7_caffe_demo.py ├── yolov7_horizon ├── 01_check.sh ├── 02_preprocess.sh ├── 03_build.sh ├── 04_inference.sh ├── 05_evaluate.sh ├── ReadMe.md ├── cal_data │ └── test.jpg ├── data_preprocess.py ├── inference_image_demo.py ├── model │ └── yolov7.onnx ├── model_output │ ├── torch-jit-export_subgraph_0.json │ ├── yolov7.bin │ ├── yolov7_optimized_float_model.onnx │ ├── yolov7_original_float_model.onnx │ └── yolov7_quantized_model.onnx ├── preprocess.py ├── result.jpg ├── src_data │ └── test.jpg ├── test.jpg └── yolov7_config.yaml ├── yolov7_onnx ├── ReadMe.md ├── result.jpg ├── test.jpg ├── yolov7.onnx └── yolov7_onnx_demo.py ├── yolov7_rknn ├── ReadMe.md ├── dataset.txt ├── onnx2rknn_demo.py ├── result_rknn.jpg ├── test.jpg ├── yolov7.onnx └── yolov7.rknn └── yolov7_tensorRT ├── ReadMe.md ├── onnx2trt_rt7.py ├── tensorRT_inferenc_demo.py ├── test.jpg ├── test_result.jpg ├── yolov7.onnx └── yolov7.trt /README.md: -------------------------------------------------------------------------------- 1 | # yolov7_caffe_onnx_tensorRT_rknn_Horizon 2 | 3 | yolov7 部署版本,后处理用python语言和C++语言形式进行改写,便于移植不同平台(caffe、onnx、tensorRT、rknn、Horizon)。 4 | 5 | # 文件夹结构说明 6 | 7 | yolov7_caffe:去除维度变换层的prototxt、caffeModel、测试图像、测试结果、测试demo脚本 8 | 9 | yolov7_onnx:onnx模型、测试图像、测试结果、测试demo脚本 10 | 11 | yolov7_TensorRT:TensorRT版本模型、测试图像、测试结果、测试demo脚本、onnx模型、onnx2tensorRT脚本(tensorRT-7.2.3.4) 12 | 13 | yolov7_rknn:rknn模型、测试(量化)图像、测试结果、onnx2rknn转换测试脚本 14 | 15 | yolov7_horizon:地平线模型、测试(量化)图像、测试结果、转换测试脚本、测试量化后onnx模型脚本 16 | 17 | # 测试结果 18 | ![image](https://github.com/cqu20160901/yolov7_caffe_onnx_tensorRT/blob/main/yolov7_caffe/result.jpg) 19 | 20 | 说明:预处理没有考虑等比率缩放,激活函数 SiLU 用 Relu 进行了替换。 21 | 22 | 导出onnx模型参考 [导出onnx模型](https://blog.csdn.net/zhangqian_1/article/details/129138325) 23 | -------------------------------------------------------------------------------- /yolov7_caffe/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Yolov7_caffe 2 | 3 | ![image](https://github.com/cqu20160901/yolov7_caffe_onnx_tensorRT/blob/main/yolov7_caffe/result.jpg) 4 | -------------------------------------------------------------------------------- /yolov7_caffe/result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_caffe/result.jpg -------------------------------------------------------------------------------- /yolov7_caffe/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_caffe/test.jpg -------------------------------------------------------------------------------- /yolov7_caffe/yolov7.caffemodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_caffe/yolov7.caffemodel -------------------------------------------------------------------------------- /yolov7_caffe/yolov7.prototxt: -------------------------------------------------------------------------------- 1 | name: "yolov7_zq" 2 | input: "blob1" 3 | input_dim: 1 4 | input_dim: 3 5 | input_dim: 640 6 | input_dim: 640 7 | layer { 8 | name: "conv1" 9 | type: "Convolution" 10 | bottom: "blob1" 11 | top: "conv_blob1" 12 | convolution_param { 13 | num_output: 8 14 | bias_term: true 15 | pad: 1 16 | kernel_size: 3 17 | group: 1 18 | stride: 1 19 | weight_filler { 20 | type: "xavier" 21 | } 22 | bias_filler { 23 | type: "constant" 24 | } 25 | dilation: 1 26 | } 27 | } 28 | layer { 29 | name: "relu1" 30 | type: "ReLU" 31 | bottom: "conv_blob1" 32 | top: "relu_blob1" 33 | } 34 | layer { 35 | name: "conv2" 36 | type: "Convolution" 37 | bottom: "relu_blob1" 38 | top: "conv_blob2" 39 | convolution_param { 40 | num_output: 16 41 | bias_term: true 42 | pad: 1 43 | kernel_size: 3 44 | group: 1 45 | stride: 2 46 | weight_filler { 47 | type: "xavier" 48 | } 49 | bias_filler { 50 | type: "constant" 51 | } 52 | dilation: 1 53 | } 54 | } 55 | layer { 56 | name: "relu2" 57 | type: "ReLU" 58 | bottom: "conv_blob2" 59 | top: "relu_blob2" 60 | } 61 | layer { 62 | name: "conv3" 63 | type: "Convolution" 64 | bottom: "relu_blob2" 65 | top: "conv_blob3" 66 | convolution_param { 67 | num_output: 16 68 | bias_term: true 69 | pad: 1 70 | kernel_size: 3 71 | group: 1 72 | stride: 1 73 | weight_filler { 74 | type: "xavier" 75 | } 76 | bias_filler { 77 | type: "constant" 78 | } 79 | dilation: 1 80 | } 81 | } 82 | layer { 83 | name: "relu3" 84 | type: "ReLU" 85 | bottom: "conv_blob3" 86 | top: "relu_blob3" 87 | } 88 | layer { 89 | name: "conv4" 90 | type: "Convolution" 91 | bottom: "relu_blob3" 92 | top: "conv_blob4" 93 | convolution_param { 94 | num_output: 32 95 | bias_term: true 96 | pad: 1 97 | kernel_size: 3 98 | group: 1 99 | stride: 2 100 | weight_filler { 101 | type: "xavier" 102 | } 103 | bias_filler { 104 | type: "constant" 105 | } 106 | dilation: 1 107 | } 108 | } 109 | layer { 110 | name: "relu4" 111 | type: "ReLU" 112 | bottom: "conv_blob4" 113 | top: "relu_blob4" 114 | } 115 | layer { 116 | name: "conv5" 117 | type: "Convolution" 118 | bottom: "relu_blob4" 119 | top: "conv_blob5" 120 | convolution_param { 121 | num_output: 16 122 | bias_term: true 123 | pad: 0 124 | kernel_size: 1 125 | group: 1 126 | stride: 1 127 | weight_filler { 128 | type: "xavier" 129 | } 130 | bias_filler { 131 | type: "constant" 132 | } 133 | dilation: 1 134 | } 135 | } 136 | layer { 137 | name: "relu5" 138 | type: "ReLU" 139 | bottom: "conv_blob5" 140 | top: "relu_blob5" 141 | } 142 | layer { 143 | name: "conv6" 144 | type: "Convolution" 145 | bottom: "relu_blob4" 146 | top: "conv_blob6" 147 | convolution_param { 148 | num_output: 16 149 | bias_term: true 150 | pad: 0 151 | kernel_size: 1 152 | group: 1 153 | stride: 1 154 | weight_filler { 155 | type: "xavier" 156 | } 157 | bias_filler { 158 | type: "constant" 159 | } 160 | dilation: 1 161 | } 162 | } 163 | layer { 164 | name: "relu6" 165 | type: "ReLU" 166 | bottom: "conv_blob6" 167 | top: "relu_blob6" 168 | } 169 | layer { 170 | name: "conv7" 171 | type: "Convolution" 172 | bottom: "relu_blob6" 173 | top: "conv_blob7" 174 | convolution_param { 175 | num_output: 16 176 | bias_term: true 177 | pad: 1 178 | kernel_size: 3 179 | group: 1 180 | stride: 1 181 | weight_filler { 182 | type: "xavier" 183 | } 184 | bias_filler { 185 | type: "constant" 186 | } 187 | dilation: 1 188 | } 189 | } 190 | layer { 191 | name: "relu7" 192 | type: "ReLU" 193 | bottom: "conv_blob7" 194 | top: "relu_blob7" 195 | } 196 | layer { 197 | name: "conv8" 198 | type: "Convolution" 199 | bottom: "relu_blob7" 200 | top: "conv_blob8" 201 | convolution_param { 202 | num_output: 16 203 | bias_term: true 204 | pad: 1 205 | kernel_size: 3 206 | group: 1 207 | stride: 1 208 | weight_filler { 209 | type: "xavier" 210 | } 211 | bias_filler { 212 | type: "constant" 213 | } 214 | dilation: 1 215 | } 216 | } 217 | layer { 218 | name: "relu8" 219 | type: "ReLU" 220 | bottom: "conv_blob8" 221 | top: "relu_blob8" 222 | } 223 | layer { 224 | name: "conv9" 225 | type: "Convolution" 226 | bottom: "relu_blob8" 227 | top: "conv_blob9" 228 | convolution_param { 229 | num_output: 16 230 | bias_term: true 231 | pad: 1 232 | kernel_size: 3 233 | group: 1 234 | stride: 1 235 | weight_filler { 236 | type: "xavier" 237 | } 238 | bias_filler { 239 | type: "constant" 240 | } 241 | dilation: 1 242 | } 243 | } 244 | layer { 245 | name: "relu9" 246 | type: "ReLU" 247 | bottom: "conv_blob9" 248 | top: "relu_blob9" 249 | } 250 | layer { 251 | name: "conv10" 252 | type: "Convolution" 253 | bottom: "relu_blob9" 254 | top: "conv_blob10" 255 | convolution_param { 256 | num_output: 16 257 | bias_term: true 258 | pad: 1 259 | kernel_size: 3 260 | group: 1 261 | stride: 1 262 | weight_filler { 263 | type: "xavier" 264 | } 265 | bias_filler { 266 | type: "constant" 267 | } 268 | dilation: 1 269 | } 270 | } 271 | layer { 272 | name: "relu10" 273 | type: "ReLU" 274 | bottom: "conv_blob10" 275 | top: "relu_blob10" 276 | } 277 | layer { 278 | name: "cat1" 279 | type: "Concat" 280 | bottom: "relu_blob10" 281 | bottom: "relu_blob8" 282 | bottom: "relu_blob6" 283 | bottom: "relu_blob5" 284 | top: "cat_blob1" 285 | concat_param { 286 | axis: 1 287 | } 288 | } 289 | layer { 290 | name: "conv11" 291 | type: "Convolution" 292 | bottom: "cat_blob1" 293 | top: "conv_blob11" 294 | convolution_param { 295 | num_output: 64 296 | bias_term: true 297 | pad: 0 298 | kernel_size: 1 299 | group: 1 300 | stride: 1 301 | weight_filler { 302 | type: "xavier" 303 | } 304 | bias_filler { 305 | type: "constant" 306 | } 307 | dilation: 1 308 | } 309 | } 310 | layer { 311 | name: "relu11" 312 | type: "ReLU" 313 | bottom: "conv_blob11" 314 | top: "relu_blob11" 315 | } 316 | layer { 317 | name: "max_pool1" 318 | type: "Pooling" 319 | bottom: "relu_blob11" 320 | top: "max_pool_blob1" 321 | pooling_param { 322 | pool: MAX 323 | kernel_size: 2 324 | stride: 2 325 | ceil_mode: false 326 | } 327 | } 328 | layer { 329 | name: "conv12" 330 | type: "Convolution" 331 | bottom: "max_pool_blob1" 332 | top: "conv_blob12" 333 | convolution_param { 334 | num_output: 32 335 | bias_term: true 336 | pad: 0 337 | kernel_size: 1 338 | group: 1 339 | stride: 1 340 | weight_filler { 341 | type: "xavier" 342 | } 343 | bias_filler { 344 | type: "constant" 345 | } 346 | dilation: 1 347 | } 348 | } 349 | layer { 350 | name: "relu12" 351 | type: "ReLU" 352 | bottom: "conv_blob12" 353 | top: "relu_blob12" 354 | } 355 | layer { 356 | name: "conv13" 357 | type: "Convolution" 358 | bottom: "relu_blob11" 359 | top: "conv_blob13" 360 | convolution_param { 361 | num_output: 32 362 | bias_term: true 363 | pad: 0 364 | kernel_size: 1 365 | group: 1 366 | stride: 1 367 | weight_filler { 368 | type: "xavier" 369 | } 370 | bias_filler { 371 | type: "constant" 372 | } 373 | dilation: 1 374 | } 375 | } 376 | layer { 377 | name: "relu13" 378 | type: "ReLU" 379 | bottom: "conv_blob13" 380 | top: "relu_blob13" 381 | } 382 | layer { 383 | name: "conv14" 384 | type: "Convolution" 385 | bottom: "relu_blob13" 386 | top: "conv_blob14" 387 | convolution_param { 388 | num_output: 32 389 | bias_term: true 390 | pad: 1 391 | kernel_size: 3 392 | group: 1 393 | stride: 2 394 | weight_filler { 395 | type: "xavier" 396 | } 397 | bias_filler { 398 | type: "constant" 399 | } 400 | dilation: 1 401 | } 402 | } 403 | layer { 404 | name: "relu14" 405 | type: "ReLU" 406 | bottom: "conv_blob14" 407 | top: "relu_blob14" 408 | } 409 | layer { 410 | name: "cat2" 411 | type: "Concat" 412 | bottom: "relu_blob14" 413 | bottom: "relu_blob12" 414 | top: "cat_blob2" 415 | concat_param { 416 | axis: 1 417 | } 418 | } 419 | layer { 420 | name: "conv15" 421 | type: "Convolution" 422 | bottom: "cat_blob2" 423 | top: "conv_blob15" 424 | convolution_param { 425 | num_output: 32 426 | bias_term: true 427 | pad: 0 428 | kernel_size: 1 429 | group: 1 430 | stride: 1 431 | weight_filler { 432 | type: "xavier" 433 | } 434 | bias_filler { 435 | type: "constant" 436 | } 437 | dilation: 1 438 | } 439 | } 440 | layer { 441 | name: "relu15" 442 | type: "ReLU" 443 | bottom: "conv_blob15" 444 | top: "relu_blob15" 445 | } 446 | layer { 447 | name: "conv16" 448 | type: "Convolution" 449 | bottom: "cat_blob2" 450 | top: "conv_blob16" 451 | convolution_param { 452 | num_output: 32 453 | bias_term: true 454 | pad: 0 455 | kernel_size: 1 456 | group: 1 457 | stride: 1 458 | weight_filler { 459 | type: "xavier" 460 | } 461 | bias_filler { 462 | type: "constant" 463 | } 464 | dilation: 1 465 | } 466 | } 467 | layer { 468 | name: "relu16" 469 | type: "ReLU" 470 | bottom: "conv_blob16" 471 | top: "relu_blob16" 472 | } 473 | layer { 474 | name: "conv17" 475 | type: "Convolution" 476 | bottom: "relu_blob16" 477 | top: "conv_blob17" 478 | convolution_param { 479 | num_output: 32 480 | bias_term: true 481 | pad: 1 482 | kernel_size: 3 483 | group: 1 484 | stride: 1 485 | weight_filler { 486 | type: "xavier" 487 | } 488 | bias_filler { 489 | type: "constant" 490 | } 491 | dilation: 1 492 | } 493 | } 494 | layer { 495 | name: "relu17" 496 | type: "ReLU" 497 | bottom: "conv_blob17" 498 | top: "relu_blob17" 499 | } 500 | layer { 501 | name: "conv18" 502 | type: "Convolution" 503 | bottom: "relu_blob17" 504 | top: "conv_blob18" 505 | convolution_param { 506 | num_output: 32 507 | bias_term: true 508 | pad: 1 509 | kernel_size: 3 510 | group: 1 511 | stride: 1 512 | weight_filler { 513 | type: "xavier" 514 | } 515 | bias_filler { 516 | type: "constant" 517 | } 518 | dilation: 1 519 | } 520 | } 521 | layer { 522 | name: "relu18" 523 | type: "ReLU" 524 | bottom: "conv_blob18" 525 | top: "relu_blob18" 526 | } 527 | layer { 528 | name: "conv19" 529 | type: "Convolution" 530 | bottom: "relu_blob18" 531 | top: "conv_blob19" 532 | convolution_param { 533 | num_output: 32 534 | bias_term: true 535 | pad: 1 536 | kernel_size: 3 537 | group: 1 538 | stride: 1 539 | weight_filler { 540 | type: "xavier" 541 | } 542 | bias_filler { 543 | type: "constant" 544 | } 545 | dilation: 1 546 | } 547 | } 548 | layer { 549 | name: "relu19" 550 | type: "ReLU" 551 | bottom: "conv_blob19" 552 | top: "relu_blob19" 553 | } 554 | layer { 555 | name: "conv20" 556 | type: "Convolution" 557 | bottom: "relu_blob19" 558 | top: "conv_blob20" 559 | convolution_param { 560 | num_output: 32 561 | bias_term: true 562 | pad: 1 563 | kernel_size: 3 564 | group: 1 565 | stride: 1 566 | weight_filler { 567 | type: "xavier" 568 | } 569 | bias_filler { 570 | type: "constant" 571 | } 572 | dilation: 1 573 | } 574 | } 575 | layer { 576 | name: "relu20" 577 | type: "ReLU" 578 | bottom: "conv_blob20" 579 | top: "relu_blob20" 580 | } 581 | layer { 582 | name: "cat3" 583 | type: "Concat" 584 | bottom: "relu_blob20" 585 | bottom: "relu_blob18" 586 | bottom: "relu_blob16" 587 | bottom: "relu_blob15" 588 | top: "cat_blob3" 589 | concat_param { 590 | axis: 1 591 | } 592 | } 593 | layer { 594 | name: "conv21" 595 | type: "Convolution" 596 | bottom: "cat_blob3" 597 | top: "conv_blob21" 598 | convolution_param { 599 | num_output: 128 600 | bias_term: true 601 | pad: 0 602 | kernel_size: 1 603 | group: 1 604 | stride: 1 605 | weight_filler { 606 | type: "xavier" 607 | } 608 | bias_filler { 609 | type: "constant" 610 | } 611 | dilation: 1 612 | } 613 | } 614 | layer { 615 | name: "relu21" 616 | type: "ReLU" 617 | bottom: "conv_blob21" 618 | top: "relu_blob21" 619 | } 620 | layer { 621 | name: "max_pool2" 622 | type: "Pooling" 623 | bottom: "relu_blob21" 624 | top: "max_pool_blob2" 625 | pooling_param { 626 | pool: MAX 627 | kernel_size: 2 628 | stride: 2 629 | ceil_mode: false 630 | } 631 | } 632 | layer { 633 | name: "conv22" 634 | type: "Convolution" 635 | bottom: "max_pool_blob2" 636 | top: "conv_blob22" 637 | convolution_param { 638 | num_output: 64 639 | bias_term: true 640 | pad: 0 641 | kernel_size: 1 642 | group: 1 643 | stride: 1 644 | weight_filler { 645 | type: "xavier" 646 | } 647 | bias_filler { 648 | type: "constant" 649 | } 650 | dilation: 1 651 | } 652 | } 653 | layer { 654 | name: "relu22" 655 | type: "ReLU" 656 | bottom: "conv_blob22" 657 | top: "relu_blob22" 658 | } 659 | layer { 660 | name: "conv23" 661 | type: "Convolution" 662 | bottom: "relu_blob21" 663 | top: "conv_blob23" 664 | convolution_param { 665 | num_output: 64 666 | bias_term: true 667 | pad: 0 668 | kernel_size: 1 669 | group: 1 670 | stride: 1 671 | weight_filler { 672 | type: "xavier" 673 | } 674 | bias_filler { 675 | type: "constant" 676 | } 677 | dilation: 1 678 | } 679 | } 680 | layer { 681 | name: "relu23" 682 | type: "ReLU" 683 | bottom: "conv_blob23" 684 | top: "relu_blob23" 685 | } 686 | layer { 687 | name: "conv24" 688 | type: "Convolution" 689 | bottom: "relu_blob23" 690 | top: "conv_blob24" 691 | convolution_param { 692 | num_output: 64 693 | bias_term: true 694 | pad: 1 695 | kernel_size: 3 696 | group: 1 697 | stride: 2 698 | weight_filler { 699 | type: "xavier" 700 | } 701 | bias_filler { 702 | type: "constant" 703 | } 704 | dilation: 1 705 | } 706 | } 707 | layer { 708 | name: "relu24" 709 | type: "ReLU" 710 | bottom: "conv_blob24" 711 | top: "relu_blob24" 712 | } 713 | layer { 714 | name: "cat4" 715 | type: "Concat" 716 | bottom: "relu_blob24" 717 | bottom: "relu_blob22" 718 | top: "cat_blob4" 719 | concat_param { 720 | axis: 1 721 | } 722 | } 723 | layer { 724 | name: "conv25" 725 | type: "Convolution" 726 | bottom: "cat_blob4" 727 | top: "conv_blob25" 728 | convolution_param { 729 | num_output: 64 730 | bias_term: true 731 | pad: 0 732 | kernel_size: 1 733 | group: 1 734 | stride: 1 735 | weight_filler { 736 | type: "xavier" 737 | } 738 | bias_filler { 739 | type: "constant" 740 | } 741 | dilation: 1 742 | } 743 | } 744 | layer { 745 | name: "relu25" 746 | type: "ReLU" 747 | bottom: "conv_blob25" 748 | top: "relu_blob25" 749 | } 750 | layer { 751 | name: "conv26" 752 | type: "Convolution" 753 | bottom: "cat_blob4" 754 | top: "conv_blob26" 755 | convolution_param { 756 | num_output: 64 757 | bias_term: true 758 | pad: 0 759 | kernel_size: 1 760 | group: 1 761 | stride: 1 762 | weight_filler { 763 | type: "xavier" 764 | } 765 | bias_filler { 766 | type: "constant" 767 | } 768 | dilation: 1 769 | } 770 | } 771 | layer { 772 | name: "relu26" 773 | type: "ReLU" 774 | bottom: "conv_blob26" 775 | top: "relu_blob26" 776 | } 777 | layer { 778 | name: "conv27" 779 | type: "Convolution" 780 | bottom: "relu_blob26" 781 | top: "conv_blob27" 782 | convolution_param { 783 | num_output: 64 784 | bias_term: true 785 | pad: 1 786 | kernel_size: 3 787 | group: 1 788 | stride: 1 789 | weight_filler { 790 | type: "xavier" 791 | } 792 | bias_filler { 793 | type: "constant" 794 | } 795 | dilation: 1 796 | } 797 | } 798 | layer { 799 | name: "relu27" 800 | type: "ReLU" 801 | bottom: "conv_blob27" 802 | top: "relu_blob27" 803 | } 804 | layer { 805 | name: "conv28" 806 | type: "Convolution" 807 | bottom: "relu_blob27" 808 | top: "conv_blob28" 809 | convolution_param { 810 | num_output: 64 811 | bias_term: true 812 | pad: 1 813 | kernel_size: 3 814 | group: 1 815 | stride: 1 816 | weight_filler { 817 | type: "xavier" 818 | } 819 | bias_filler { 820 | type: "constant" 821 | } 822 | dilation: 1 823 | } 824 | } 825 | layer { 826 | name: "relu28" 827 | type: "ReLU" 828 | bottom: "conv_blob28" 829 | top: "relu_blob28" 830 | } 831 | layer { 832 | name: "conv29" 833 | type: "Convolution" 834 | bottom: "relu_blob28" 835 | top: "conv_blob29" 836 | convolution_param { 837 | num_output: 64 838 | bias_term: true 839 | pad: 1 840 | kernel_size: 3 841 | group: 1 842 | stride: 1 843 | weight_filler { 844 | type: "xavier" 845 | } 846 | bias_filler { 847 | type: "constant" 848 | } 849 | dilation: 1 850 | } 851 | } 852 | layer { 853 | name: "relu29" 854 | type: "ReLU" 855 | bottom: "conv_blob29" 856 | top: "relu_blob29" 857 | } 858 | layer { 859 | name: "conv30" 860 | type: "Convolution" 861 | bottom: "relu_blob29" 862 | top: "conv_blob30" 863 | convolution_param { 864 | num_output: 64 865 | bias_term: true 866 | pad: 1 867 | kernel_size: 3 868 | group: 1 869 | stride: 1 870 | weight_filler { 871 | type: "xavier" 872 | } 873 | bias_filler { 874 | type: "constant" 875 | } 876 | dilation: 1 877 | } 878 | } 879 | layer { 880 | name: "relu30" 881 | type: "ReLU" 882 | bottom: "conv_blob30" 883 | top: "relu_blob30" 884 | } 885 | layer { 886 | name: "cat5" 887 | type: "Concat" 888 | bottom: "relu_blob30" 889 | bottom: "relu_blob28" 890 | bottom: "relu_blob26" 891 | bottom: "relu_blob25" 892 | top: "cat_blob5" 893 | concat_param { 894 | axis: 1 895 | } 896 | } 897 | layer { 898 | name: "conv31" 899 | type: "Convolution" 900 | bottom: "cat_blob5" 901 | top: "conv_blob31" 902 | convolution_param { 903 | num_output: 256 904 | bias_term: true 905 | pad: 0 906 | kernel_size: 1 907 | group: 1 908 | stride: 1 909 | weight_filler { 910 | type: "xavier" 911 | } 912 | bias_filler { 913 | type: "constant" 914 | } 915 | dilation: 1 916 | } 917 | } 918 | layer { 919 | name: "relu31" 920 | type: "ReLU" 921 | bottom: "conv_blob31" 922 | top: "relu_blob31" 923 | } 924 | layer { 925 | name: "max_pool3" 926 | type: "Pooling" 927 | bottom: "relu_blob31" 928 | top: "max_pool_blob3" 929 | pooling_param { 930 | pool: MAX 931 | kernel_size: 2 932 | stride: 2 933 | ceil_mode: false 934 | } 935 | } 936 | layer { 937 | name: "conv32" 938 | type: "Convolution" 939 | bottom: "max_pool_blob3" 940 | top: "conv_blob32" 941 | convolution_param { 942 | num_output: 128 943 | bias_term: true 944 | pad: 0 945 | kernel_size: 1 946 | group: 1 947 | stride: 1 948 | weight_filler { 949 | type: "xavier" 950 | } 951 | bias_filler { 952 | type: "constant" 953 | } 954 | dilation: 1 955 | } 956 | } 957 | layer { 958 | name: "relu32" 959 | type: "ReLU" 960 | bottom: "conv_blob32" 961 | top: "relu_blob32" 962 | } 963 | layer { 964 | name: "conv33" 965 | type: "Convolution" 966 | bottom: "relu_blob31" 967 | top: "conv_blob33" 968 | convolution_param { 969 | num_output: 128 970 | bias_term: true 971 | pad: 0 972 | kernel_size: 1 973 | group: 1 974 | stride: 1 975 | weight_filler { 976 | type: "xavier" 977 | } 978 | bias_filler { 979 | type: "constant" 980 | } 981 | dilation: 1 982 | } 983 | } 984 | layer { 985 | name: "relu33" 986 | type: "ReLU" 987 | bottom: "conv_blob33" 988 | top: "relu_blob33" 989 | } 990 | layer { 991 | name: "conv34" 992 | type: "Convolution" 993 | bottom: "relu_blob33" 994 | top: "conv_blob34" 995 | convolution_param { 996 | num_output: 128 997 | bias_term: true 998 | pad: 1 999 | kernel_size: 3 1000 | group: 1 1001 | stride: 2 1002 | weight_filler { 1003 | type: "xavier" 1004 | } 1005 | bias_filler { 1006 | type: "constant" 1007 | } 1008 | dilation: 1 1009 | } 1010 | } 1011 | layer { 1012 | name: "relu34" 1013 | type: "ReLU" 1014 | bottom: "conv_blob34" 1015 | top: "relu_blob34" 1016 | } 1017 | layer { 1018 | name: "cat6" 1019 | type: "Concat" 1020 | bottom: "relu_blob34" 1021 | bottom: "relu_blob32" 1022 | top: "cat_blob6" 1023 | concat_param { 1024 | axis: 1 1025 | } 1026 | } 1027 | layer { 1028 | name: "conv35" 1029 | type: "Convolution" 1030 | bottom: "cat_blob6" 1031 | top: "conv_blob35" 1032 | convolution_param { 1033 | num_output: 64 1034 | bias_term: true 1035 | pad: 0 1036 | kernel_size: 1 1037 | group: 1 1038 | stride: 1 1039 | weight_filler { 1040 | type: "xavier" 1041 | } 1042 | bias_filler { 1043 | type: "constant" 1044 | } 1045 | dilation: 1 1046 | } 1047 | } 1048 | layer { 1049 | name: "relu35" 1050 | type: "ReLU" 1051 | bottom: "conv_blob35" 1052 | top: "relu_blob35" 1053 | } 1054 | layer { 1055 | name: "conv36" 1056 | type: "Convolution" 1057 | bottom: "cat_blob6" 1058 | top: "conv_blob36" 1059 | convolution_param { 1060 | num_output: 64 1061 | bias_term: true 1062 | pad: 0 1063 | kernel_size: 1 1064 | group: 1 1065 | stride: 1 1066 | weight_filler { 1067 | type: "xavier" 1068 | } 1069 | bias_filler { 1070 | type: "constant" 1071 | } 1072 | dilation: 1 1073 | } 1074 | } 1075 | layer { 1076 | name: "relu36" 1077 | type: "ReLU" 1078 | bottom: "conv_blob36" 1079 | top: "relu_blob36" 1080 | } 1081 | layer { 1082 | name: "conv37" 1083 | type: "Convolution" 1084 | bottom: "relu_blob36" 1085 | top: "conv_blob37" 1086 | convolution_param { 1087 | num_output: 64 1088 | bias_term: true 1089 | pad: 1 1090 | kernel_size: 3 1091 | group: 1 1092 | stride: 1 1093 | weight_filler { 1094 | type: "xavier" 1095 | } 1096 | bias_filler { 1097 | type: "constant" 1098 | } 1099 | dilation: 1 1100 | } 1101 | } 1102 | layer { 1103 | name: "relu37" 1104 | type: "ReLU" 1105 | bottom: "conv_blob37" 1106 | top: "relu_blob37" 1107 | } 1108 | layer { 1109 | name: "conv38" 1110 | type: "Convolution" 1111 | bottom: "relu_blob37" 1112 | top: "conv_blob38" 1113 | convolution_param { 1114 | num_output: 64 1115 | bias_term: true 1116 | pad: 1 1117 | kernel_size: 3 1118 | group: 1 1119 | stride: 1 1120 | weight_filler { 1121 | type: "xavier" 1122 | } 1123 | bias_filler { 1124 | type: "constant" 1125 | } 1126 | dilation: 1 1127 | } 1128 | } 1129 | layer { 1130 | name: "relu38" 1131 | type: "ReLU" 1132 | bottom: "conv_blob38" 1133 | top: "relu_blob38" 1134 | } 1135 | layer { 1136 | name: "conv39" 1137 | type: "Convolution" 1138 | bottom: "relu_blob38" 1139 | top: "conv_blob39" 1140 | convolution_param { 1141 | num_output: 64 1142 | bias_term: true 1143 | pad: 1 1144 | kernel_size: 3 1145 | group: 1 1146 | stride: 1 1147 | weight_filler { 1148 | type: "xavier" 1149 | } 1150 | bias_filler { 1151 | type: "constant" 1152 | } 1153 | dilation: 1 1154 | } 1155 | } 1156 | layer { 1157 | name: "relu39" 1158 | type: "ReLU" 1159 | bottom: "conv_blob39" 1160 | top: "relu_blob39" 1161 | } 1162 | layer { 1163 | name: "conv40" 1164 | type: "Convolution" 1165 | bottom: "relu_blob39" 1166 | top: "conv_blob40" 1167 | convolution_param { 1168 | num_output: 64 1169 | bias_term: true 1170 | pad: 1 1171 | kernel_size: 3 1172 | group: 1 1173 | stride: 1 1174 | weight_filler { 1175 | type: "xavier" 1176 | } 1177 | bias_filler { 1178 | type: "constant" 1179 | } 1180 | dilation: 1 1181 | } 1182 | } 1183 | layer { 1184 | name: "relu40" 1185 | type: "ReLU" 1186 | bottom: "conv_blob40" 1187 | top: "relu_blob40" 1188 | } 1189 | layer { 1190 | name: "cat7" 1191 | type: "Concat" 1192 | bottom: "relu_blob40" 1193 | bottom: "relu_blob38" 1194 | bottom: "relu_blob36" 1195 | bottom: "relu_blob35" 1196 | top: "cat_blob7" 1197 | concat_param { 1198 | axis: 1 1199 | } 1200 | } 1201 | layer { 1202 | name: "conv41" 1203 | type: "Convolution" 1204 | bottom: "cat_blob7" 1205 | top: "conv_blob41" 1206 | convolution_param { 1207 | num_output: 256 1208 | bias_term: true 1209 | pad: 0 1210 | kernel_size: 1 1211 | group: 1 1212 | stride: 1 1213 | weight_filler { 1214 | type: "xavier" 1215 | } 1216 | bias_filler { 1217 | type: "constant" 1218 | } 1219 | dilation: 1 1220 | } 1221 | } 1222 | layer { 1223 | name: "relu41" 1224 | type: "ReLU" 1225 | bottom: "conv_blob41" 1226 | top: "relu_blob41" 1227 | } 1228 | layer { 1229 | name: "conv42" 1230 | type: "Convolution" 1231 | bottom: "relu_blob41" 1232 | top: "conv_blob42" 1233 | convolution_param { 1234 | num_output: 128 1235 | bias_term: true 1236 | pad: 0 1237 | kernel_size: 1 1238 | group: 1 1239 | stride: 1 1240 | weight_filler { 1241 | type: "xavier" 1242 | } 1243 | bias_filler { 1244 | type: "constant" 1245 | } 1246 | dilation: 1 1247 | } 1248 | } 1249 | layer { 1250 | name: "relu42" 1251 | type: "ReLU" 1252 | bottom: "conv_blob42" 1253 | top: "relu_blob42" 1254 | } 1255 | layer { 1256 | name: "conv43" 1257 | type: "Convolution" 1258 | bottom: "relu_blob42" 1259 | top: "conv_blob43" 1260 | convolution_param { 1261 | num_output: 128 1262 | bias_term: true 1263 | pad: 1 1264 | kernel_size: 3 1265 | group: 1 1266 | stride: 1 1267 | weight_filler { 1268 | type: "xavier" 1269 | } 1270 | bias_filler { 1271 | type: "constant" 1272 | } 1273 | dilation: 1 1274 | } 1275 | } 1276 | layer { 1277 | name: "relu43" 1278 | type: "ReLU" 1279 | bottom: "conv_blob43" 1280 | top: "relu_blob43" 1281 | } 1282 | layer { 1283 | name: "conv44" 1284 | type: "Convolution" 1285 | bottom: "relu_blob43" 1286 | top: "conv_blob44" 1287 | convolution_param { 1288 | num_output: 128 1289 | bias_term: true 1290 | pad: 0 1291 | kernel_size: 1 1292 | group: 1 1293 | stride: 1 1294 | weight_filler { 1295 | type: "xavier" 1296 | } 1297 | bias_filler { 1298 | type: "constant" 1299 | } 1300 | dilation: 1 1301 | } 1302 | } 1303 | layer { 1304 | name: "relu44" 1305 | type: "ReLU" 1306 | bottom: "conv_blob44" 1307 | top: "relu_blob44" 1308 | } 1309 | layer { 1310 | name: "max_pool4" 1311 | type: "Pooling" 1312 | bottom: "relu_blob44" 1313 | top: "max_pool_blob4" 1314 | pooling_param { 1315 | pool: MAX 1316 | kernel_size: 5 1317 | stride: 1 1318 | pad: 2 1319 | ceil_mode: false 1320 | } 1321 | } 1322 | layer { 1323 | name: "max_pool5" 1324 | type: "Pooling" 1325 | bottom: "relu_blob44" 1326 | top: "max_pool_blob5" 1327 | pooling_param { 1328 | pool: MAX 1329 | kernel_size: 9 1330 | stride: 1 1331 | pad: 4 1332 | ceil_mode: false 1333 | } 1334 | } 1335 | layer { 1336 | name: "max_pool6" 1337 | type: "Pooling" 1338 | bottom: "relu_blob44" 1339 | top: "max_pool_blob6" 1340 | pooling_param { 1341 | pool: MAX 1342 | kernel_size: 13 1343 | stride: 1 1344 | pad: 6 1345 | ceil_mode: false 1346 | } 1347 | } 1348 | layer { 1349 | name: "cat8" 1350 | type: "Concat" 1351 | bottom: "relu_blob44" 1352 | bottom: "max_pool_blob4" 1353 | bottom: "max_pool_blob5" 1354 | bottom: "max_pool_blob6" 1355 | top: "cat_blob8" 1356 | concat_param { 1357 | axis: 1 1358 | } 1359 | } 1360 | layer { 1361 | name: "conv45" 1362 | type: "Convolution" 1363 | bottom: "cat_blob8" 1364 | top: "conv_blob45" 1365 | convolution_param { 1366 | num_output: 128 1367 | bias_term: true 1368 | pad: 0 1369 | kernel_size: 1 1370 | group: 1 1371 | stride: 1 1372 | weight_filler { 1373 | type: "xavier" 1374 | } 1375 | bias_filler { 1376 | type: "constant" 1377 | } 1378 | dilation: 1 1379 | } 1380 | } 1381 | layer { 1382 | name: "relu45" 1383 | type: "ReLU" 1384 | bottom: "conv_blob45" 1385 | top: "relu_blob45" 1386 | } 1387 | layer { 1388 | name: "conv46" 1389 | type: "Convolution" 1390 | bottom: "relu_blob45" 1391 | top: "conv_blob46" 1392 | convolution_param { 1393 | num_output: 128 1394 | bias_term: true 1395 | pad: 1 1396 | kernel_size: 3 1397 | group: 1 1398 | stride: 1 1399 | weight_filler { 1400 | type: "xavier" 1401 | } 1402 | bias_filler { 1403 | type: "constant" 1404 | } 1405 | dilation: 1 1406 | } 1407 | } 1408 | layer { 1409 | name: "relu46" 1410 | type: "ReLU" 1411 | bottom: "conv_blob46" 1412 | top: "relu_blob46" 1413 | } 1414 | layer { 1415 | name: "conv47" 1416 | type: "Convolution" 1417 | bottom: "relu_blob41" 1418 | top: "conv_blob47" 1419 | convolution_param { 1420 | num_output: 128 1421 | bias_term: true 1422 | pad: 0 1423 | kernel_size: 1 1424 | group: 1 1425 | stride: 1 1426 | weight_filler { 1427 | type: "xavier" 1428 | } 1429 | bias_filler { 1430 | type: "constant" 1431 | } 1432 | dilation: 1 1433 | } 1434 | } 1435 | layer { 1436 | name: "relu47" 1437 | type: "ReLU" 1438 | bottom: "conv_blob47" 1439 | top: "relu_blob47" 1440 | } 1441 | layer { 1442 | name: "cat9" 1443 | type: "Concat" 1444 | bottom: "relu_blob46" 1445 | bottom: "relu_blob47" 1446 | top: "cat_blob9" 1447 | concat_param { 1448 | axis: 1 1449 | } 1450 | } 1451 | layer { 1452 | name: "conv48" 1453 | type: "Convolution" 1454 | bottom: "cat_blob9" 1455 | top: "conv_blob48" 1456 | convolution_param { 1457 | num_output: 128 1458 | bias_term: true 1459 | pad: 0 1460 | kernel_size: 1 1461 | group: 1 1462 | stride: 1 1463 | weight_filler { 1464 | type: "xavier" 1465 | } 1466 | bias_filler { 1467 | type: "constant" 1468 | } 1469 | dilation: 1 1470 | } 1471 | } 1472 | layer { 1473 | name: "relu48" 1474 | type: "ReLU" 1475 | bottom: "conv_blob48" 1476 | top: "relu_blob48" 1477 | } 1478 | layer { 1479 | name: "conv49" 1480 | type: "Convolution" 1481 | bottom: "relu_blob48" 1482 | top: "conv_blob49" 1483 | convolution_param { 1484 | num_output: 64 1485 | bias_term: true 1486 | pad: 0 1487 | kernel_size: 1 1488 | group: 1 1489 | stride: 1 1490 | weight_filler { 1491 | type: "xavier" 1492 | } 1493 | bias_filler { 1494 | type: "constant" 1495 | } 1496 | dilation: 1 1497 | } 1498 | } 1499 | layer { 1500 | name: "relu49" 1501 | type: "ReLU" 1502 | bottom: "conv_blob49" 1503 | top: "relu_blob49" 1504 | } 1505 | layer { 1506 | name: "conv_transpose1" 1507 | type: "Deconvolution" 1508 | bottom: "relu_blob49" 1509 | top: "conv_transpose_blob1" 1510 | convolution_param { 1511 | num_output: 64 1512 | bias_term: true 1513 | pad: 0 1514 | kernel_size: 2 1515 | group: 1 1516 | stride: 2 1517 | weight_filler { 1518 | type: "xavier" 1519 | } 1520 | bias_filler { 1521 | type: "constant" 1522 | } 1523 | dilation: 1 1524 | } 1525 | } 1526 | layer { 1527 | name: "conv50" 1528 | type: "Convolution" 1529 | bottom: "relu_blob31" 1530 | top: "conv_blob50" 1531 | convolution_param { 1532 | num_output: 64 1533 | bias_term: true 1534 | pad: 0 1535 | kernel_size: 1 1536 | group: 1 1537 | stride: 1 1538 | weight_filler { 1539 | type: "xavier" 1540 | } 1541 | bias_filler { 1542 | type: "constant" 1543 | } 1544 | dilation: 1 1545 | } 1546 | } 1547 | layer { 1548 | name: "relu50" 1549 | type: "ReLU" 1550 | bottom: "conv_blob50" 1551 | top: "relu_blob50" 1552 | } 1553 | layer { 1554 | name: "cat10" 1555 | type: "Concat" 1556 | bottom: "relu_blob50" 1557 | bottom: "conv_transpose_blob1" 1558 | top: "cat_blob10" 1559 | concat_param { 1560 | axis: 1 1561 | } 1562 | } 1563 | layer { 1564 | name: "conv51" 1565 | type: "Convolution" 1566 | bottom: "cat_blob10" 1567 | top: "conv_blob51" 1568 | convolution_param { 1569 | num_output: 64 1570 | bias_term: true 1571 | pad: 0 1572 | kernel_size: 1 1573 | group: 1 1574 | stride: 1 1575 | weight_filler { 1576 | type: "xavier" 1577 | } 1578 | bias_filler { 1579 | type: "constant" 1580 | } 1581 | dilation: 1 1582 | } 1583 | } 1584 | layer { 1585 | name: "relu51" 1586 | type: "ReLU" 1587 | bottom: "conv_blob51" 1588 | top: "relu_blob51" 1589 | } 1590 | layer { 1591 | name: "conv52" 1592 | type: "Convolution" 1593 | bottom: "cat_blob10" 1594 | top: "conv_blob52" 1595 | convolution_param { 1596 | num_output: 64 1597 | bias_term: true 1598 | pad: 0 1599 | kernel_size: 1 1600 | group: 1 1601 | stride: 1 1602 | weight_filler { 1603 | type: "xavier" 1604 | } 1605 | bias_filler { 1606 | type: "constant" 1607 | } 1608 | dilation: 1 1609 | } 1610 | } 1611 | layer { 1612 | name: "relu52" 1613 | type: "ReLU" 1614 | bottom: "conv_blob52" 1615 | top: "relu_blob52" 1616 | } 1617 | layer { 1618 | name: "conv53" 1619 | type: "Convolution" 1620 | bottom: "relu_blob52" 1621 | top: "conv_blob53" 1622 | convolution_param { 1623 | num_output: 32 1624 | bias_term: true 1625 | pad: 1 1626 | kernel_size: 3 1627 | group: 1 1628 | stride: 1 1629 | weight_filler { 1630 | type: "xavier" 1631 | } 1632 | bias_filler { 1633 | type: "constant" 1634 | } 1635 | dilation: 1 1636 | } 1637 | } 1638 | layer { 1639 | name: "relu53" 1640 | type: "ReLU" 1641 | bottom: "conv_blob53" 1642 | top: "relu_blob53" 1643 | } 1644 | layer { 1645 | name: "conv54" 1646 | type: "Convolution" 1647 | bottom: "relu_blob53" 1648 | top: "conv_blob54" 1649 | convolution_param { 1650 | num_output: 32 1651 | bias_term: true 1652 | pad: 1 1653 | kernel_size: 3 1654 | group: 1 1655 | stride: 1 1656 | weight_filler { 1657 | type: "xavier" 1658 | } 1659 | bias_filler { 1660 | type: "constant" 1661 | } 1662 | dilation: 1 1663 | } 1664 | } 1665 | layer { 1666 | name: "relu54" 1667 | type: "ReLU" 1668 | bottom: "conv_blob54" 1669 | top: "relu_blob54" 1670 | } 1671 | layer { 1672 | name: "conv55" 1673 | type: "Convolution" 1674 | bottom: "relu_blob54" 1675 | top: "conv_blob55" 1676 | convolution_param { 1677 | num_output: 32 1678 | bias_term: true 1679 | pad: 1 1680 | kernel_size: 3 1681 | group: 1 1682 | stride: 1 1683 | weight_filler { 1684 | type: "xavier" 1685 | } 1686 | bias_filler { 1687 | type: "constant" 1688 | } 1689 | dilation: 1 1690 | } 1691 | } 1692 | layer { 1693 | name: "relu55" 1694 | type: "ReLU" 1695 | bottom: "conv_blob55" 1696 | top: "relu_blob55" 1697 | } 1698 | layer { 1699 | name: "conv56" 1700 | type: "Convolution" 1701 | bottom: "relu_blob55" 1702 | top: "conv_blob56" 1703 | convolution_param { 1704 | num_output: 32 1705 | bias_term: true 1706 | pad: 1 1707 | kernel_size: 3 1708 | group: 1 1709 | stride: 1 1710 | weight_filler { 1711 | type: "xavier" 1712 | } 1713 | bias_filler { 1714 | type: "constant" 1715 | } 1716 | dilation: 1 1717 | } 1718 | } 1719 | layer { 1720 | name: "relu56" 1721 | type: "ReLU" 1722 | bottom: "conv_blob56" 1723 | top: "relu_blob56" 1724 | } 1725 | layer { 1726 | name: "cat11" 1727 | type: "Concat" 1728 | bottom: "relu_blob56" 1729 | bottom: "relu_blob55" 1730 | bottom: "relu_blob54" 1731 | bottom: "relu_blob53" 1732 | bottom: "relu_blob52" 1733 | bottom: "relu_blob51" 1734 | top: "cat_blob11" 1735 | concat_param { 1736 | axis: 1 1737 | } 1738 | } 1739 | layer { 1740 | name: "conv57" 1741 | type: "Convolution" 1742 | bottom: "cat_blob11" 1743 | top: "conv_blob57" 1744 | convolution_param { 1745 | num_output: 64 1746 | bias_term: true 1747 | pad: 0 1748 | kernel_size: 1 1749 | group: 1 1750 | stride: 1 1751 | weight_filler { 1752 | type: "xavier" 1753 | } 1754 | bias_filler { 1755 | type: "constant" 1756 | } 1757 | dilation: 1 1758 | } 1759 | } 1760 | layer { 1761 | name: "relu57" 1762 | type: "ReLU" 1763 | bottom: "conv_blob57" 1764 | top: "relu_blob57" 1765 | } 1766 | layer { 1767 | name: "conv58" 1768 | type: "Convolution" 1769 | bottom: "relu_blob57" 1770 | top: "conv_blob58" 1771 | convolution_param { 1772 | num_output: 32 1773 | bias_term: true 1774 | pad: 0 1775 | kernel_size: 1 1776 | group: 1 1777 | stride: 1 1778 | weight_filler { 1779 | type: "xavier" 1780 | } 1781 | bias_filler { 1782 | type: "constant" 1783 | } 1784 | dilation: 1 1785 | } 1786 | } 1787 | layer { 1788 | name: "relu58" 1789 | type: "ReLU" 1790 | bottom: "conv_blob58" 1791 | top: "relu_blob58" 1792 | } 1793 | layer { 1794 | name: "conv_transpose2" 1795 | type: "Deconvolution" 1796 | bottom: "relu_blob58" 1797 | top: "conv_transpose_blob2" 1798 | convolution_param { 1799 | num_output: 32 1800 | bias_term: true 1801 | pad: 0 1802 | kernel_size: 2 1803 | group: 1 1804 | stride: 2 1805 | weight_filler { 1806 | type: "xavier" 1807 | } 1808 | bias_filler { 1809 | type: "constant" 1810 | } 1811 | dilation: 1 1812 | } 1813 | } 1814 | layer { 1815 | name: "conv59" 1816 | type: "Convolution" 1817 | bottom: "relu_blob21" 1818 | top: "conv_blob59" 1819 | convolution_param { 1820 | num_output: 32 1821 | bias_term: true 1822 | pad: 0 1823 | kernel_size: 1 1824 | group: 1 1825 | stride: 1 1826 | weight_filler { 1827 | type: "xavier" 1828 | } 1829 | bias_filler { 1830 | type: "constant" 1831 | } 1832 | dilation: 1 1833 | } 1834 | } 1835 | layer { 1836 | name: "relu59" 1837 | type: "ReLU" 1838 | bottom: "conv_blob59" 1839 | top: "relu_blob59" 1840 | } 1841 | layer { 1842 | name: "cat12" 1843 | type: "Concat" 1844 | bottom: "relu_blob59" 1845 | bottom: "conv_transpose_blob2" 1846 | top: "cat_blob12" 1847 | concat_param { 1848 | axis: 1 1849 | } 1850 | } 1851 | layer { 1852 | name: "conv60" 1853 | type: "Convolution" 1854 | bottom: "cat_blob12" 1855 | top: "conv_blob60" 1856 | convolution_param { 1857 | num_output: 32 1858 | bias_term: true 1859 | pad: 0 1860 | kernel_size: 1 1861 | group: 1 1862 | stride: 1 1863 | weight_filler { 1864 | type: "xavier" 1865 | } 1866 | bias_filler { 1867 | type: "constant" 1868 | } 1869 | dilation: 1 1870 | } 1871 | } 1872 | layer { 1873 | name: "relu60" 1874 | type: "ReLU" 1875 | bottom: "conv_blob60" 1876 | top: "relu_blob60" 1877 | } 1878 | layer { 1879 | name: "conv61" 1880 | type: "Convolution" 1881 | bottom: "cat_blob12" 1882 | top: "conv_blob61" 1883 | convolution_param { 1884 | num_output: 32 1885 | bias_term: true 1886 | pad: 0 1887 | kernel_size: 1 1888 | group: 1 1889 | stride: 1 1890 | weight_filler { 1891 | type: "xavier" 1892 | } 1893 | bias_filler { 1894 | type: "constant" 1895 | } 1896 | dilation: 1 1897 | } 1898 | } 1899 | layer { 1900 | name: "relu61" 1901 | type: "ReLU" 1902 | bottom: "conv_blob61" 1903 | top: "relu_blob61" 1904 | } 1905 | layer { 1906 | name: "conv62" 1907 | type: "Convolution" 1908 | bottom: "relu_blob61" 1909 | top: "conv_blob62" 1910 | convolution_param { 1911 | num_output: 16 1912 | bias_term: true 1913 | pad: 1 1914 | kernel_size: 3 1915 | group: 1 1916 | stride: 1 1917 | weight_filler { 1918 | type: "xavier" 1919 | } 1920 | bias_filler { 1921 | type: "constant" 1922 | } 1923 | dilation: 1 1924 | } 1925 | } 1926 | layer { 1927 | name: "relu62" 1928 | type: "ReLU" 1929 | bottom: "conv_blob62" 1930 | top: "relu_blob62" 1931 | } 1932 | layer { 1933 | name: "conv63" 1934 | type: "Convolution" 1935 | bottom: "relu_blob62" 1936 | top: "conv_blob63" 1937 | convolution_param { 1938 | num_output: 16 1939 | bias_term: true 1940 | pad: 1 1941 | kernel_size: 3 1942 | group: 1 1943 | stride: 1 1944 | weight_filler { 1945 | type: "xavier" 1946 | } 1947 | bias_filler { 1948 | type: "constant" 1949 | } 1950 | dilation: 1 1951 | } 1952 | } 1953 | layer { 1954 | name: "relu63" 1955 | type: "ReLU" 1956 | bottom: "conv_blob63" 1957 | top: "relu_blob63" 1958 | } 1959 | layer { 1960 | name: "conv64" 1961 | type: "Convolution" 1962 | bottom: "relu_blob63" 1963 | top: "conv_blob64" 1964 | convolution_param { 1965 | num_output: 16 1966 | bias_term: true 1967 | pad: 1 1968 | kernel_size: 3 1969 | group: 1 1970 | stride: 1 1971 | weight_filler { 1972 | type: "xavier" 1973 | } 1974 | bias_filler { 1975 | type: "constant" 1976 | } 1977 | dilation: 1 1978 | } 1979 | } 1980 | layer { 1981 | name: "relu64" 1982 | type: "ReLU" 1983 | bottom: "conv_blob64" 1984 | top: "relu_blob64" 1985 | } 1986 | layer { 1987 | name: "conv65" 1988 | type: "Convolution" 1989 | bottom: "relu_blob64" 1990 | top: "conv_blob65" 1991 | convolution_param { 1992 | num_output: 16 1993 | bias_term: true 1994 | pad: 1 1995 | kernel_size: 3 1996 | group: 1 1997 | stride: 1 1998 | weight_filler { 1999 | type: "xavier" 2000 | } 2001 | bias_filler { 2002 | type: "constant" 2003 | } 2004 | dilation: 1 2005 | } 2006 | } 2007 | layer { 2008 | name: "relu65" 2009 | type: "ReLU" 2010 | bottom: "conv_blob65" 2011 | top: "relu_blob65" 2012 | } 2013 | layer { 2014 | name: "cat13" 2015 | type: "Concat" 2016 | bottom: "relu_blob65" 2017 | bottom: "relu_blob64" 2018 | bottom: "relu_blob63" 2019 | bottom: "relu_blob62" 2020 | bottom: "relu_blob61" 2021 | bottom: "relu_blob60" 2022 | top: "cat_blob13" 2023 | concat_param { 2024 | axis: 1 2025 | } 2026 | } 2027 | layer { 2028 | name: "conv66" 2029 | type: "Convolution" 2030 | bottom: "cat_blob13" 2031 | top: "conv_blob66" 2032 | convolution_param { 2033 | num_output: 32 2034 | bias_term: true 2035 | pad: 0 2036 | kernel_size: 1 2037 | group: 1 2038 | stride: 1 2039 | weight_filler { 2040 | type: "xavier" 2041 | } 2042 | bias_filler { 2043 | type: "constant" 2044 | } 2045 | dilation: 1 2046 | } 2047 | } 2048 | layer { 2049 | name: "relu66" 2050 | type: "ReLU" 2051 | bottom: "conv_blob66" 2052 | top: "relu_blob66" 2053 | } 2054 | layer { 2055 | name: "max_pool7" 2056 | type: "Pooling" 2057 | bottom: "relu_blob66" 2058 | top: "max_pool_blob7" 2059 | pooling_param { 2060 | pool: MAX 2061 | kernel_size: 2 2062 | stride: 2 2063 | ceil_mode: false 2064 | } 2065 | } 2066 | layer { 2067 | name: "conv67" 2068 | type: "Convolution" 2069 | bottom: "max_pool_blob7" 2070 | top: "conv_blob67" 2071 | convolution_param { 2072 | num_output: 32 2073 | bias_term: true 2074 | pad: 0 2075 | kernel_size: 1 2076 | group: 1 2077 | stride: 1 2078 | weight_filler { 2079 | type: "xavier" 2080 | } 2081 | bias_filler { 2082 | type: "constant" 2083 | } 2084 | dilation: 1 2085 | } 2086 | } 2087 | layer { 2088 | name: "relu67" 2089 | type: "ReLU" 2090 | bottom: "conv_blob67" 2091 | top: "relu_blob67" 2092 | } 2093 | layer { 2094 | name: "conv68" 2095 | type: "Convolution" 2096 | bottom: "relu_blob66" 2097 | top: "conv_blob68" 2098 | convolution_param { 2099 | num_output: 32 2100 | bias_term: true 2101 | pad: 0 2102 | kernel_size: 1 2103 | group: 1 2104 | stride: 1 2105 | weight_filler { 2106 | type: "xavier" 2107 | } 2108 | bias_filler { 2109 | type: "constant" 2110 | } 2111 | dilation: 1 2112 | } 2113 | } 2114 | layer { 2115 | name: "relu68" 2116 | type: "ReLU" 2117 | bottom: "conv_blob68" 2118 | top: "relu_blob68" 2119 | } 2120 | layer { 2121 | name: "conv69" 2122 | type: "Convolution" 2123 | bottom: "relu_blob68" 2124 | top: "conv_blob69" 2125 | convolution_param { 2126 | num_output: 32 2127 | bias_term: true 2128 | pad: 1 2129 | kernel_size: 3 2130 | group: 1 2131 | stride: 2 2132 | weight_filler { 2133 | type: "xavier" 2134 | } 2135 | bias_filler { 2136 | type: "constant" 2137 | } 2138 | dilation: 1 2139 | } 2140 | } 2141 | layer { 2142 | name: "relu69" 2143 | type: "ReLU" 2144 | bottom: "conv_blob69" 2145 | top: "relu_blob69" 2146 | } 2147 | layer { 2148 | name: "cat14" 2149 | type: "Concat" 2150 | bottom: "relu_blob69" 2151 | bottom: "relu_blob67" 2152 | bottom: "relu_blob57" 2153 | top: "cat_blob14" 2154 | concat_param { 2155 | axis: 1 2156 | } 2157 | } 2158 | layer { 2159 | name: "conv70" 2160 | type: "Convolution" 2161 | bottom: "cat_blob14" 2162 | top: "conv_blob70" 2163 | convolution_param { 2164 | num_output: 64 2165 | bias_term: true 2166 | pad: 0 2167 | kernel_size: 1 2168 | group: 1 2169 | stride: 1 2170 | weight_filler { 2171 | type: "xavier" 2172 | } 2173 | bias_filler { 2174 | type: "constant" 2175 | } 2176 | dilation: 1 2177 | } 2178 | } 2179 | layer { 2180 | name: "relu70" 2181 | type: "ReLU" 2182 | bottom: "conv_blob70" 2183 | top: "relu_blob70" 2184 | } 2185 | layer { 2186 | name: "conv71" 2187 | type: "Convolution" 2188 | bottom: "cat_blob14" 2189 | top: "conv_blob71" 2190 | convolution_param { 2191 | num_output: 64 2192 | bias_term: true 2193 | pad: 0 2194 | kernel_size: 1 2195 | group: 1 2196 | stride: 1 2197 | weight_filler { 2198 | type: "xavier" 2199 | } 2200 | bias_filler { 2201 | type: "constant" 2202 | } 2203 | dilation: 1 2204 | } 2205 | } 2206 | layer { 2207 | name: "relu71" 2208 | type: "ReLU" 2209 | bottom: "conv_blob71" 2210 | top: "relu_blob71" 2211 | } 2212 | layer { 2213 | name: "conv72" 2214 | type: "Convolution" 2215 | bottom: "relu_blob71" 2216 | top: "conv_blob72" 2217 | convolution_param { 2218 | num_output: 32 2219 | bias_term: true 2220 | pad: 1 2221 | kernel_size: 3 2222 | group: 1 2223 | stride: 1 2224 | weight_filler { 2225 | type: "xavier" 2226 | } 2227 | bias_filler { 2228 | type: "constant" 2229 | } 2230 | dilation: 1 2231 | } 2232 | } 2233 | layer { 2234 | name: "relu72" 2235 | type: "ReLU" 2236 | bottom: "conv_blob72" 2237 | top: "relu_blob72" 2238 | } 2239 | layer { 2240 | name: "conv73" 2241 | type: "Convolution" 2242 | bottom: "relu_blob72" 2243 | top: "conv_blob73" 2244 | convolution_param { 2245 | num_output: 32 2246 | bias_term: true 2247 | pad: 1 2248 | kernel_size: 3 2249 | group: 1 2250 | stride: 1 2251 | weight_filler { 2252 | type: "xavier" 2253 | } 2254 | bias_filler { 2255 | type: "constant" 2256 | } 2257 | dilation: 1 2258 | } 2259 | } 2260 | layer { 2261 | name: "relu73" 2262 | type: "ReLU" 2263 | bottom: "conv_blob73" 2264 | top: "relu_blob73" 2265 | } 2266 | layer { 2267 | name: "conv74" 2268 | type: "Convolution" 2269 | bottom: "relu_blob73" 2270 | top: "conv_blob74" 2271 | convolution_param { 2272 | num_output: 32 2273 | bias_term: true 2274 | pad: 1 2275 | kernel_size: 3 2276 | group: 1 2277 | stride: 1 2278 | weight_filler { 2279 | type: "xavier" 2280 | } 2281 | bias_filler { 2282 | type: "constant" 2283 | } 2284 | dilation: 1 2285 | } 2286 | } 2287 | layer { 2288 | name: "relu74" 2289 | type: "ReLU" 2290 | bottom: "conv_blob74" 2291 | top: "relu_blob74" 2292 | } 2293 | layer { 2294 | name: "conv75" 2295 | type: "Convolution" 2296 | bottom: "relu_blob74" 2297 | top: "conv_blob75" 2298 | convolution_param { 2299 | num_output: 32 2300 | bias_term: true 2301 | pad: 1 2302 | kernel_size: 3 2303 | group: 1 2304 | stride: 1 2305 | weight_filler { 2306 | type: "xavier" 2307 | } 2308 | bias_filler { 2309 | type: "constant" 2310 | } 2311 | dilation: 1 2312 | } 2313 | } 2314 | layer { 2315 | name: "relu75" 2316 | type: "ReLU" 2317 | bottom: "conv_blob75" 2318 | top: "relu_blob75" 2319 | } 2320 | layer { 2321 | name: "cat15" 2322 | type: "Concat" 2323 | bottom: "relu_blob75" 2324 | bottom: "relu_blob74" 2325 | bottom: "relu_blob73" 2326 | bottom: "relu_blob72" 2327 | bottom: "relu_blob71" 2328 | bottom: "relu_blob70" 2329 | top: "cat_blob15" 2330 | concat_param { 2331 | axis: 1 2332 | } 2333 | } 2334 | layer { 2335 | name: "conv76" 2336 | type: "Convolution" 2337 | bottom: "cat_blob15" 2338 | top: "conv_blob76" 2339 | convolution_param { 2340 | num_output: 64 2341 | bias_term: true 2342 | pad: 0 2343 | kernel_size: 1 2344 | group: 1 2345 | stride: 1 2346 | weight_filler { 2347 | type: "xavier" 2348 | } 2349 | bias_filler { 2350 | type: "constant" 2351 | } 2352 | dilation: 1 2353 | } 2354 | } 2355 | layer { 2356 | name: "relu76" 2357 | type: "ReLU" 2358 | bottom: "conv_blob76" 2359 | top: "relu_blob76" 2360 | } 2361 | layer { 2362 | name: "max_pool8" 2363 | type: "Pooling" 2364 | bottom: "relu_blob76" 2365 | top: "max_pool_blob8" 2366 | pooling_param { 2367 | pool: MAX 2368 | kernel_size: 2 2369 | stride: 2 2370 | ceil_mode: false 2371 | } 2372 | } 2373 | layer { 2374 | name: "conv77" 2375 | type: "Convolution" 2376 | bottom: "max_pool_blob8" 2377 | top: "conv_blob77" 2378 | convolution_param { 2379 | num_output: 64 2380 | bias_term: true 2381 | pad: 0 2382 | kernel_size: 1 2383 | group: 1 2384 | stride: 1 2385 | weight_filler { 2386 | type: "xavier" 2387 | } 2388 | bias_filler { 2389 | type: "constant" 2390 | } 2391 | dilation: 1 2392 | } 2393 | } 2394 | layer { 2395 | name: "relu77" 2396 | type: "ReLU" 2397 | bottom: "conv_blob77" 2398 | top: "relu_blob77" 2399 | } 2400 | layer { 2401 | name: "conv78" 2402 | type: "Convolution" 2403 | bottom: "relu_blob76" 2404 | top: "conv_blob78" 2405 | convolution_param { 2406 | num_output: 64 2407 | bias_term: true 2408 | pad: 0 2409 | kernel_size: 1 2410 | group: 1 2411 | stride: 1 2412 | weight_filler { 2413 | type: "xavier" 2414 | } 2415 | bias_filler { 2416 | type: "constant" 2417 | } 2418 | dilation: 1 2419 | } 2420 | } 2421 | layer { 2422 | name: "relu78" 2423 | type: "ReLU" 2424 | bottom: "conv_blob78" 2425 | top: "relu_blob78" 2426 | } 2427 | layer { 2428 | name: "conv79" 2429 | type: "Convolution" 2430 | bottom: "relu_blob78" 2431 | top: "conv_blob79" 2432 | convolution_param { 2433 | num_output: 64 2434 | bias_term: true 2435 | pad: 1 2436 | kernel_size: 3 2437 | group: 1 2438 | stride: 2 2439 | weight_filler { 2440 | type: "xavier" 2441 | } 2442 | bias_filler { 2443 | type: "constant" 2444 | } 2445 | dilation: 1 2446 | } 2447 | } 2448 | layer { 2449 | name: "relu79" 2450 | type: "ReLU" 2451 | bottom: "conv_blob79" 2452 | top: "relu_blob79" 2453 | } 2454 | layer { 2455 | name: "cat16" 2456 | type: "Concat" 2457 | bottom: "relu_blob79" 2458 | bottom: "relu_blob77" 2459 | bottom: "relu_blob48" 2460 | top: "cat_blob16" 2461 | concat_param { 2462 | axis: 1 2463 | } 2464 | } 2465 | layer { 2466 | name: "conv80" 2467 | type: "Convolution" 2468 | bottom: "cat_blob16" 2469 | top: "conv_blob80" 2470 | convolution_param { 2471 | num_output: 128 2472 | bias_term: true 2473 | pad: 0 2474 | kernel_size: 1 2475 | group: 1 2476 | stride: 1 2477 | weight_filler { 2478 | type: "xavier" 2479 | } 2480 | bias_filler { 2481 | type: "constant" 2482 | } 2483 | dilation: 1 2484 | } 2485 | } 2486 | layer { 2487 | name: "relu80" 2488 | type: "ReLU" 2489 | bottom: "conv_blob80" 2490 | top: "relu_blob80" 2491 | } 2492 | layer { 2493 | name: "conv81" 2494 | type: "Convolution" 2495 | bottom: "cat_blob16" 2496 | top: "conv_blob81" 2497 | convolution_param { 2498 | num_output: 128 2499 | bias_term: true 2500 | pad: 0 2501 | kernel_size: 1 2502 | group: 1 2503 | stride: 1 2504 | weight_filler { 2505 | type: "xavier" 2506 | } 2507 | bias_filler { 2508 | type: "constant" 2509 | } 2510 | dilation: 1 2511 | } 2512 | } 2513 | layer { 2514 | name: "relu81" 2515 | type: "ReLU" 2516 | bottom: "conv_blob81" 2517 | top: "relu_blob81" 2518 | } 2519 | layer { 2520 | name: "conv82" 2521 | type: "Convolution" 2522 | bottom: "relu_blob81" 2523 | top: "conv_blob82" 2524 | convolution_param { 2525 | num_output: 64 2526 | bias_term: true 2527 | pad: 1 2528 | kernel_size: 3 2529 | group: 1 2530 | stride: 1 2531 | weight_filler { 2532 | type: "xavier" 2533 | } 2534 | bias_filler { 2535 | type: "constant" 2536 | } 2537 | dilation: 1 2538 | } 2539 | } 2540 | layer { 2541 | name: "relu82" 2542 | type: "ReLU" 2543 | bottom: "conv_blob82" 2544 | top: "relu_blob82" 2545 | } 2546 | layer { 2547 | name: "conv83" 2548 | type: "Convolution" 2549 | bottom: "relu_blob82" 2550 | top: "conv_blob83" 2551 | convolution_param { 2552 | num_output: 64 2553 | bias_term: true 2554 | pad: 1 2555 | kernel_size: 3 2556 | group: 1 2557 | stride: 1 2558 | weight_filler { 2559 | type: "xavier" 2560 | } 2561 | bias_filler { 2562 | type: "constant" 2563 | } 2564 | dilation: 1 2565 | } 2566 | } 2567 | layer { 2568 | name: "relu83" 2569 | type: "ReLU" 2570 | bottom: "conv_blob83" 2571 | top: "relu_blob83" 2572 | } 2573 | layer { 2574 | name: "conv84" 2575 | type: "Convolution" 2576 | bottom: "relu_blob83" 2577 | top: "conv_blob84" 2578 | convolution_param { 2579 | num_output: 64 2580 | bias_term: true 2581 | pad: 1 2582 | kernel_size: 3 2583 | group: 1 2584 | stride: 1 2585 | weight_filler { 2586 | type: "xavier" 2587 | } 2588 | bias_filler { 2589 | type: "constant" 2590 | } 2591 | dilation: 1 2592 | } 2593 | } 2594 | layer { 2595 | name: "relu84" 2596 | type: "ReLU" 2597 | bottom: "conv_blob84" 2598 | top: "relu_blob84" 2599 | } 2600 | layer { 2601 | name: "conv85" 2602 | type: "Convolution" 2603 | bottom: "relu_blob84" 2604 | top: "conv_blob85" 2605 | convolution_param { 2606 | num_output: 64 2607 | bias_term: true 2608 | pad: 1 2609 | kernel_size: 3 2610 | group: 1 2611 | stride: 1 2612 | weight_filler { 2613 | type: "xavier" 2614 | } 2615 | bias_filler { 2616 | type: "constant" 2617 | } 2618 | dilation: 1 2619 | } 2620 | } 2621 | layer { 2622 | name: "relu85" 2623 | type: "ReLU" 2624 | bottom: "conv_blob85" 2625 | top: "relu_blob85" 2626 | } 2627 | layer { 2628 | name: "cat17" 2629 | type: "Concat" 2630 | bottom: "relu_blob85" 2631 | bottom: "relu_blob84" 2632 | bottom: "relu_blob83" 2633 | bottom: "relu_blob82" 2634 | bottom: "relu_blob81" 2635 | bottom: "relu_blob80" 2636 | top: "cat_blob17" 2637 | concat_param { 2638 | axis: 1 2639 | } 2640 | } 2641 | layer { 2642 | name: "conv86" 2643 | type: "Convolution" 2644 | bottom: "cat_blob17" 2645 | top: "conv_blob86" 2646 | convolution_param { 2647 | num_output: 128 2648 | bias_term: true 2649 | pad: 0 2650 | kernel_size: 1 2651 | group: 1 2652 | stride: 1 2653 | weight_filler { 2654 | type: "xavier" 2655 | } 2656 | bias_filler { 2657 | type: "constant" 2658 | } 2659 | dilation: 1 2660 | } 2661 | } 2662 | layer { 2663 | name: "relu86" 2664 | type: "ReLU" 2665 | bottom: "conv_blob86" 2666 | top: "relu_blob86" 2667 | } 2668 | layer { 2669 | name: "conv87" 2670 | type: "Convolution" 2671 | bottom: "relu_blob66" 2672 | top: "conv_blob87" 2673 | convolution_param { 2674 | num_output: 64 2675 | bias_term: true 2676 | pad: 1 2677 | kernel_size: 3 2678 | group: 1 2679 | stride: 1 2680 | weight_filler { 2681 | type: "xavier" 2682 | } 2683 | bias_filler { 2684 | type: "constant" 2685 | } 2686 | dilation: 1 2687 | } 2688 | } 2689 | layer { 2690 | name: "relu87" 2691 | type: "ReLU" 2692 | bottom: "conv_blob87" 2693 | top: "relu_blob87" 2694 | } 2695 | layer { 2696 | name: "conv88" 2697 | type: "Convolution" 2698 | bottom: "relu_blob76" 2699 | top: "conv_blob88" 2700 | convolution_param { 2701 | num_output: 128 2702 | bias_term: true 2703 | pad: 1 2704 | kernel_size: 3 2705 | group: 1 2706 | stride: 1 2707 | weight_filler { 2708 | type: "xavier" 2709 | } 2710 | bias_filler { 2711 | type: "constant" 2712 | } 2713 | dilation: 1 2714 | } 2715 | } 2716 | layer { 2717 | name: "relu88" 2718 | type: "ReLU" 2719 | bottom: "conv_blob88" 2720 | top: "relu_blob88" 2721 | } 2722 | layer { 2723 | name: "conv89" 2724 | type: "Convolution" 2725 | bottom: "relu_blob86" 2726 | top: "conv_blob89" 2727 | convolution_param { 2728 | num_output: 256 2729 | bias_term: true 2730 | pad: 1 2731 | kernel_size: 3 2732 | group: 1 2733 | stride: 1 2734 | weight_filler { 2735 | type: "xavier" 2736 | } 2737 | bias_filler { 2738 | type: "constant" 2739 | } 2740 | dilation: 1 2741 | } 2742 | } 2743 | layer { 2744 | name: "relu89" 2745 | type: "ReLU" 2746 | bottom: "conv_blob89" 2747 | top: "relu_blob89" 2748 | } 2749 | layer { 2750 | name: "conv90" 2751 | type: "Convolution" 2752 | bottom: "relu_blob87" 2753 | top: "conv_blob90" 2754 | convolution_param { 2755 | num_output: 30 2756 | bias_term: true 2757 | pad: 0 2758 | kernel_size: 1 2759 | group: 1 2760 | stride: 1 2761 | weight_filler { 2762 | type: "xavier" 2763 | } 2764 | bias_filler { 2765 | type: "constant" 2766 | } 2767 | dilation: 1 2768 | } 2769 | } 2770 | layer { 2771 | name: "conv91" 2772 | type: "Convolution" 2773 | bottom: "relu_blob88" 2774 | top: "conv_blob91" 2775 | convolution_param { 2776 | num_output: 30 2777 | bias_term: true 2778 | pad: 0 2779 | kernel_size: 1 2780 | group: 1 2781 | stride: 1 2782 | weight_filler { 2783 | type: "xavier" 2784 | } 2785 | bias_filler { 2786 | type: "constant" 2787 | } 2788 | dilation: 1 2789 | } 2790 | } 2791 | layer { 2792 | name: "conv92" 2793 | type: "Convolution" 2794 | bottom: "relu_blob89" 2795 | top: "conv_blob92" 2796 | convolution_param { 2797 | num_output: 30 2798 | bias_term: true 2799 | pad: 0 2800 | kernel_size: 1 2801 | group: 1 2802 | stride: 1 2803 | weight_filler { 2804 | type: "xavier" 2805 | } 2806 | bias_filler { 2807 | type: "constant" 2808 | } 2809 | dilation: 1 2810 | } 2811 | } 2812 | -------------------------------------------------------------------------------- /yolov7_caffe/yolov7_caffe_demo.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import sys, os 3 | from math import sqrt 4 | from math import exp 5 | import cv2 6 | 7 | caffe_root = '/root/caffe-master/' 8 | sys.path.insert(0, caffe_root + 'python') 9 | import caffe 10 | 11 | net_file = './yolov7.prototxt' 12 | caffe_model = './yolov7.caffemodel' 13 | 14 | if not os.path.exists(caffe_model): 15 | print(caffe_model + " does not exist") 16 | exit() 17 | if not os.path.exists(net_file): 18 | print(net_file + " does not exist") 19 | exit() 20 | 21 | net = caffe.Net(net_file, caffe_model, caffe.TEST) 22 | 23 | 24 | CLASSES = ['car', 'tail', 'tailB', 'person', 'cyclist'] 25 | 26 | class_num = len(CLASSES) 27 | anchor_num = 3 28 | output_head = 3 29 | 30 | cell_size = [[80, 80], [40, 40], [20, 20]] 31 | 32 | anchor_size = [ 33 | [[17,5], [10,29], [19,16]], 34 | [[45,15], [39,33], [26,93]], 35 | [[75,53], [111,104], [258,203]]] 36 | 37 | stride = [8, 16, 32] 38 | grid_cell = np.zeros(shape=(3, 80, 80, 2)) 39 | 40 | nms_thre = 0.45 41 | obj_thre = [0.4, 0.4, 0.4, 0.4, 0.4] 42 | 43 | input_imgW = 640 44 | input_imgH = 640 45 | 46 | 47 | class DetectBox: 48 | def __init__(self, classId, score, xmin, ymin, xmax, ymax): 49 | self.classId = classId 50 | self.score = score 51 | self.xmin = xmin 52 | self.ymin = ymin 53 | self.xmax = xmax 54 | self.ymax = ymax 55 | 56 | 57 | def grid_cell_init(): 58 | for index in range(output_head): 59 | for w in range(cell_size[index][1]): 60 | for h in range(cell_size[index][0]): 61 | grid_cell[index][h][w][0] = w 62 | grid_cell[index][h][w][1] = h 63 | 64 | 65 | def IOU(xmin1, ymin1, xmax1, ymax1, xmin2, ymin2, xmax2, ymax2): 66 | xmin = max(xmin1, xmin2) 67 | ymin = max(ymin1, ymin2) 68 | xmax = min(xmax1, xmax2) 69 | ymax = min(ymax1, ymax2) 70 | 71 | innerWidth = xmax - xmin 72 | innerHeight = ymax - ymin 73 | 74 | innerWidth = innerWidth if innerWidth > 0 else 0 75 | innerHeight = innerHeight if innerHeight > 0 else 0 76 | 77 | innerArea = innerWidth * innerHeight 78 | 79 | area1 = (xmax1 - xmin1) * (ymax1 - ymin1) 80 | area2 = (xmax2 - xmin2) * (ymax2 - ymin2) 81 | 82 | total = area1 + area2 - innerArea 83 | 84 | return innerArea / total 85 | 86 | 87 | def NMS(detectResult): 88 | predBoxs = [] 89 | 90 | sort_detectboxs = sorted(detectResult, key=lambda x: x.score, reverse=True) 91 | 92 | for i in range(len(sort_detectboxs)): 93 | xmin1 = sort_detectboxs[i].xmin 94 | ymin1 = sort_detectboxs[i].ymin 95 | xmax1 = sort_detectboxs[i].xmax 96 | ymax1 = sort_detectboxs[i].ymax 97 | classId = sort_detectboxs[i].classId 98 | 99 | if sort_detectboxs[i].classId != -1: 100 | predBoxs.append(sort_detectboxs[i]) 101 | for j in range(i + 1, len(sort_detectboxs), 1): 102 | if classId == sort_detectboxs[j].classId: 103 | xmin2 = sort_detectboxs[j].xmin 104 | ymin2 = sort_detectboxs[j].ymin 105 | xmax2 = sort_detectboxs[j].xmax 106 | ymax2 = sort_detectboxs[j].ymax 107 | iou = IOU(xmin1, ymin1, xmax1, ymax1, xmin2, ymin2, xmax2, ymax2) 108 | if iou > nms_thre: 109 | sort_detectboxs[j].classId = -1 110 | return predBoxs 111 | 112 | 113 | def sigmoid(x): 114 | return 1 / (1 + exp(-x)) 115 | 116 | 117 | def postprocess(out, img_h, img_w): 118 | print('postprocess ... ') 119 | 120 | detectResult = [] 121 | 122 | output = [] 123 | output.append(out['conv_blob90'].reshape((-1))) 124 | output.append(out['conv_blob91'].reshape((-1))) 125 | output.append(out['conv_blob92'].reshape((-1))) 126 | 127 | gs = 4 + 1 + class_num 128 | scale_h = img_h / input_imgH 129 | scale_w = img_w / input_imgW 130 | 131 | for head in range(output_head): 132 | y = output[head] 133 | for h in range(cell_size[head][0]): 134 | 135 | for w in range(cell_size[head][1]): 136 | for a in range(anchor_num): 137 | conf_scale = sigmoid(y[((a * gs + 4) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) 138 | for cl in range(class_num): 139 | if class_num > 1: 140 | conf = sigmoid(y[((a * gs + 5 + cl) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * conf_scale 141 | else: 142 | conf = conf_scale 143 | 144 | if conf > obj_thre[cl]: 145 | bx = (sigmoid(y[((a * gs + 0) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2.0 - 0.5 + grid_cell[head][h][w][0]) * stride[head] 146 | by = (sigmoid(y[((a * gs + 1) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2.0 - 0.5 + grid_cell[head][h][w][1]) * stride[head] 147 | bw = pow((sigmoid(y[((a * gs + 2) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2), 2) * anchor_size[head][a][0] 148 | bh = pow((sigmoid(y[((a * gs + 3) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2), 2) * anchor_size[head][a][1] 149 | 150 | xmin = (bx - bw / 2) * scale_w 151 | ymin = (by - bh / 2) * scale_h 152 | xmax = (bx + bw / 2) * scale_w 153 | ymax = (by + bh / 2) * scale_h 154 | 155 | xmin = xmin if xmin > 0 else 0 156 | ymin = ymin if ymin > 0 else 0 157 | xmax = xmax if xmax < img_w else img_w 158 | ymax = ymax if ymax < img_h else img_h 159 | 160 | if xmin >= 0 and ymin >= 0 and xmax <= img_w and ymax <= img_h: 161 | box = DetectBox(cl, conf, xmin, ymin, xmax, ymax) 162 | detectResult.append(box) 163 | 164 | # NMS 过程 165 | print('detectResult:', len(detectResult)) 166 | predBox = NMS(detectResult) 167 | return predBox 168 | 169 | 170 | 171 | def preprocess(src): 172 | img = cv2.resize(src, (input_imgW, input_imgH), interpolation=cv2.INTER_LINEAR) 173 | img = img.astype(np.float32) 174 | img = img * 0.00392156 175 | return img 176 | 177 | 178 | def detect(imgfile): 179 | origimg = cv2.imread(imgfile) 180 | origimg = cv2.cvtColor(origimg, cv2.COLOR_BGR2RGB) 181 | img_h, img_w = origimg.shape[:2] 182 | img = preprocess(origimg) 183 | 184 | img = img.astype(np.float32) 185 | img = img.transpose((2, 0, 1)) 186 | 187 | net.blobs['blob1'].data[...] = img 188 | out = net.forward() 189 | predbox = postprocess(out, img_h, img_w) 190 | 191 | print(len(predbox)) 192 | 193 | for i in range(len(predbox)): 194 | xmin = int(predbox[i].xmin) 195 | ymin = int(predbox[i].ymin) 196 | xmax = int(predbox[i].xmax) 197 | ymax = int(predbox[i].ymax) 198 | classId = predbox[i].classId 199 | score = predbox[i].score 200 | 201 | cv2.rectangle(origimg, (xmin, ymin), (xmax, ymax), (0, 255, 0), 2) 202 | ptext = (xmin, ymin) 203 | title = CLASSES[classId] + "%.2f" % score 204 | cv2.putText(origimg, title, ptext, cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2, cv2.LINE_AA) 205 | 206 | cv2.imwrite('./result.jpg', origimg) 207 | # cv2.imshow("test", origimg) 208 | # cv2.waitKey(0) 209 | 210 | 211 | if __name__ == '__main__': 212 | print('This is main .... ') 213 | grid_cell_init() 214 | detect('./test.jpg') 215 | -------------------------------------------------------------------------------- /yolov7_horizon/01_check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # Copyright (c) 2020 Horizon Robotics.All Rights Reserved. 3 | # 4 | # The material in this file is confidential and contains trade secrets 5 | # of Horizon Robotics Inc. This is proprietary information owned by 6 | # Horizon Robotics Inc. No part of this work may be disclosed, 7 | # reproduced, copied, transmitted, or used in any way for any purpose, 8 | # without the express written permission of Horizon Robotics Inc. 9 | 10 | set -e -v 11 | cd $(dirname $0) || exit 12 | 13 | model_type="onnx" 14 | onnx_model="./model/yolov7.onnx" 15 | output="./yolov7_checker.log" 16 | march="bernoulli2" 17 | 18 | hb_mapper checker --model-type ${model_type} \ 19 | --model ${onnx_model} \ 20 | --output ${output} --march ${march} 21 | -------------------------------------------------------------------------------- /yolov7_horizon/02_preprocess.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) 2020 Horizon Robotics.All Rights Reserved. 3 | # 4 | # The material in this file is confidential and contains trade secrets 5 | # of Horizon Robotics Inc. This is proprietary information owned by 6 | # Horizon Robotics Inc. No part of this work may be disclosed, 7 | # reproduced, copied, transmitted, or used in any way for any purpose, 8 | # without the express written permission of Horizon Robotics Inc. 9 | 10 | set -e -v 11 | cd $(dirname $0) || exit 12 | 13 | python3 data_preprocess.py \ 14 | --src_dir ./src_data \ 15 | --dst_dir ./cal_data \ 16 | --pic_ext .rgb \ 17 | --read_mode opencv 18 | -------------------------------------------------------------------------------- /yolov7_horizon/03_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2020 Horizon Robotics.All Rights Reserved. 3 | # 4 | # The material in this file is confidential and contains trade secrets 5 | # of Horizon Robotics Inc. This is proprietary information owned by 6 | # Horizon Robotics Inc. No part of this work may be disclosed, 7 | # reproduced, copied, transmitted, or used in any way for any purpose, 8 | # without the express written permission of Horizon Robotics Inc. 9 | 10 | set -e -v 11 | cd $(dirname $0) 12 | config_file="./yolov7_config.yaml" 13 | model_type="onnx" 14 | # build model 15 | hb_mapper makertbin --config ${config_file} \ 16 | --model-type ${model_type} 17 | -------------------------------------------------------------------------------- /yolov7_horizon/04_inference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2020 Horizon Robotics.All Rights Reserved. 3 | # 4 | # The material in this file is confidential and contains trade secrets 5 | # of Horizon Robotics Inc. This is proprietary information owned by 6 | # Horizon Robotics Inc. No part of this work may be disclosed, 7 | # reproduced, copied, transmitted, or used in any way for any purpose, 8 | # without the express written permission of Horizon Robotics Inc. 9 | 10 | python3 -u inference_image_demo.py 11 | -------------------------------------------------------------------------------- /yolov7_horizon/05_evaluate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2020 Horizon Robotics.All Rights Reserved. 3 | # 4 | # The material in this file is confidential and contains trade secrets 5 | # of Horizon Robotics Inc. This is proprietary information owned by 6 | # Horizon Robotics Inc. No part of this work may be disclosed, 7 | # reproduced, copied, transmitted, or used in any way for any purpose, 8 | # without the express written permission of Horizon Robotics Inc. 9 | 10 | set -v -e 11 | cd $(dirname $0) || exit 12 | 13 | #for converted quanti model evaluation 14 | quanti_model_file="./model_output/yolov5_672x672_nv12_quantized_model.onnx" 15 | quanti_input_layout="NHWC" 16 | 17 | original_model_file="./model_output/yolov5_672x672_nv12_original_float_model.onnx" 18 | original_input_layout="NCHW" 19 | 20 | if [[ $1 =~ "origin" ]]; then 21 | model=$original_model_file 22 | layout=$original_input_layout 23 | input_offset=128 24 | else 25 | model=$quanti_model_file 26 | layout=$quanti_input_layout 27 | input_offset=128 28 | fi 29 | 30 | image_path="../../../01_common/data/coco/coco_val2017/images/" 31 | anno_path="../../../01_common/data/coco/coco_val2017/annotations/instances_val2017.json" 32 | 33 | 34 | if [ -z $2 ]; then 35 | total_image_number=5000 36 | else 37 | total_image_number=$2 38 | fi 39 | 40 | # ------------------------------------------------------------------------------------------------------------- 41 | # shell command "sh 05_evaluate.sh" runs quanti full evaluation by default 42 | # If quanti model eval is intended, please run the shell via command "sh 05_evaluate.sh quanti" 43 | # If float model eval is intended, please run the shell via command "sh 05_evaluate.sh origin"# 44 | # If quanti model quick eval test is intended, please run the shell via command "sh 05_evaluate.sh quanti 20" 45 | # If float model quick eval test is intended, please run the shell via command "sh 05_evaluate.sh origin 20" 46 | # ------------------------------------------------------------------------------------------------------------- 47 | # quanti model eval 48 | python3 -u ../../det_evaluate.py \ 49 | --model=${model} \ 50 | --image_path=${image_path} \ 51 | --annotation_path=${anno_path} \ 52 | --input_layout=${layout} \ 53 | --total_image_number=${total_image_number} \ 54 | --input_offset ${input_offset} 55 | -------------------------------------------------------------------------------- /yolov7_horizon/ReadMe.md: -------------------------------------------------------------------------------- 1 | # 地平线版本 2 | 3 | 测试结果 4 | 5 | ![image](https://github.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn/blob/main/yolov7_horizon/result.jpg) 6 | -------------------------------------------------------------------------------- /yolov7_horizon/cal_data/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_horizon/cal_data/test.jpg -------------------------------------------------------------------------------- /yolov7_horizon/data_preprocess.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Horizon Robotics.All Rights Reserved. 2 | # 3 | # The material in this file is confidential and contains trade secrets 4 | # of Horizon Robotics Inc. This is proprietary information owned by 5 | # Horizon Robotics Inc. No part of this work may be disclosed, 6 | # reproduced, copied, transmitted, or used in any way for any purpose, 7 | # without the express written permission of Horizon Robotics Inc. 8 | 9 | import os 10 | import sys 11 | sys.path.append('.') 12 | 13 | import click 14 | import numpy as np 15 | from preprocess import calibration_transformers 16 | import skimage.io 17 | import cv2 18 | 19 | transformers = calibration_transformers() 20 | 21 | sys.path.append("../../../01_common/python/data/") 22 | from dataloader import DataLoader 23 | from dataset import CifarDataset 24 | 25 | regular_process_list = [ 26 | ".rgb", 27 | ".rgbp", 28 | ".bgr", 29 | ".bgrp", 30 | ".yuv", 31 | ".feature", 32 | ".cali", 33 | ] 34 | 35 | 36 | def read_image(src_file, read_mode): 37 | if read_mode == "skimage": 38 | image = skimage.img_as_float(skimage.io.imread(src_file)).astype( 39 | np.float32) 40 | elif read_mode == "opencv": 41 | image = cv2.imread(src_file) 42 | else: 43 | raise ValueError(f"Invalid read mode {read_mode}") 44 | if image.ndim != 3: # expend gray scale image to three channels 45 | image = image[..., np.newaxis] 46 | image = np.concatenate([image, image, image], axis=-1) 47 | return image 48 | 49 | 50 | def regular_preprocess(src_file, transformers, dst_dir, pic_ext, read_mode): 51 | image = [read_image(src_file, read_mode)] 52 | for trans in transformers: 53 | image = trans(image) 54 | 55 | filename = os.path.basename(src_file) 56 | short_name, ext = os.path.splitext(filename) 57 | pic_name = os.path.join(dst_dir, short_name + pic_ext) 58 | print("write:%s" % pic_name) 59 | dtype = np.float32 if dst_dir.endswith("_f32") else np.uint8 60 | image[0].astype(dtype).tofile(pic_name) 61 | 62 | 63 | def cifar_preprocess(src_file, data_loader, dst_dir, pic_ext, cal_img_num): 64 | for i in range(cal_img_num): 65 | image, label = next(data_loader) 66 | filename = os.path.basename(src_file) 67 | pic_name = os.path.join(dst_dir + '/' + str(i) + pic_ext) 68 | print("write:%s" % pic_name) 69 | image[0].astype(np.uint8).tofile(pic_name) 70 | 71 | 72 | @click.command(help=''' 73 | A Tool used to generate preprocess pics for calibration. 74 | ''') 75 | @click.option('--src_dir', type=str, help='calibration source file') 76 | @click.option('--dst_dir', type=str, help='generated calibration file') 77 | @click.option('--pic_ext', 78 | type=str, 79 | default=".cali", 80 | help='picture extension.') 81 | @click.option('--read_mode', 82 | type=click.Choice(["skimage", "opencv"]), 83 | default="opencv", 84 | help='picture extension.') 85 | @click.option('--cal_img_num', type=int, default=100, help='cali picture num.') 86 | def main(src_dir, dst_dir, pic_ext, read_mode, cal_img_num): 87 | '''A Tool used to generate preprocess pics for calibration.''' 88 | pic_num = 0 89 | os.makedirs(dst_dir, exist_ok=True) 90 | if pic_ext.strip().split('_')[0] in regular_process_list: 91 | print("regular preprocess") 92 | for src_name in sorted(os.listdir(src_dir)): 93 | pic_num += 1 94 | if pic_num > cal_img_num: 95 | break 96 | src_file = os.path.join(src_dir, src_name) 97 | regular_preprocess(src_file, transformers, dst_dir, pic_ext, 98 | read_mode) 99 | elif pic_ext.strip().split('_')[0] == ".cifar": 100 | print("cifar preprocess") 101 | data_loader = DataLoader(CifarDataset(src_dir), transformers, 1) 102 | cifar_preprocess(src_dir, data_loader, dst_dir, pic_ext, cal_img_num) 103 | else: 104 | raise ValueError(f"invalid pic_ext {pic_ext}") 105 | 106 | 107 | if __name__ == '__main__': 108 | main() 109 | -------------------------------------------------------------------------------- /yolov7_horizon/inference_image_demo.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from horizon_tc_ui import HB_ONNXRuntime 3 | from horizon_tc_ui.utils.tool_utils import init_root_logger 4 | from math import exp 5 | import cv2 6 | import numpy as np 7 | 8 | 9 | CLASSES = ['car', 'tail', 'tailB', 'person', 'cyclist'] 10 | 11 | class_num = len(CLASSES) 12 | anchor_num = 3 13 | output_head = 3 14 | 15 | cell_size = [[80, 80], [40, 40], [20, 20]] 16 | 17 | anchor_size = [ 18 | [[17,5], [10,29], [19,16]], 19 | [[45,15], [39,33], [26,93]], 20 | [[75,53], [111,104], [258,203]]] 21 | 22 | stride = [8, 16, 32] 23 | grid_cell = np.zeros(shape=(3, 80, 80, 2)) 24 | 25 | nms_thre = 0.45 26 | obj_thre = [0.45, 0.45, 0.45, 0.45, 0.45] 27 | 28 | input_imgW = 640 29 | input_imgH = 640 30 | 31 | 32 | class DetectBox: 33 | def __init__(self, classId, score, xmin, ymin, xmax, ymax): 34 | self.classId = classId 35 | self.score = score 36 | self.xmin = xmin 37 | self.ymin = ymin 38 | self.xmax = xmax 39 | self.ymax = ymax 40 | 41 | 42 | def grid_cell_init(): 43 | for index in range(output_head): 44 | for w in range(cell_size[index][1]): 45 | for h in range(cell_size[index][0]): 46 | grid_cell[index][h][w][0] = w 47 | grid_cell[index][h][w][1] = h 48 | 49 | 50 | def IOU(xmin1, ymin1, xmax1, ymax1, xmin2, ymin2, xmax2, ymax2): 51 | xmin = max(xmin1, xmin2) 52 | ymin = max(ymin1, ymin2) 53 | xmax = min(xmax1, xmax2) 54 | ymax = min(ymax1, ymax2) 55 | 56 | innerWidth = xmax - xmin 57 | innerHeight = ymax - ymin 58 | 59 | innerWidth = innerWidth if innerWidth > 0 else 0 60 | innerHeight = innerHeight if innerHeight > 0 else 0 61 | 62 | innerArea = innerWidth * innerHeight 63 | 64 | area1 = (xmax1 - xmin1) * (ymax1 - ymin1) 65 | area2 = (xmax2 - xmin2) * (ymax2 - ymin2) 66 | 67 | total = area1 + area2 - innerArea 68 | 69 | return innerArea / total 70 | 71 | 72 | def NMS(detectResult): 73 | predBoxs = [] 74 | 75 | sort_detectboxs = sorted(detectResult, key=lambda x: x.score, reverse=True) 76 | 77 | for i in range(len(sort_detectboxs)): 78 | xmin1 = sort_detectboxs[i].xmin 79 | ymin1 = sort_detectboxs[i].ymin 80 | xmax1 = sort_detectboxs[i].xmax 81 | ymax1 = sort_detectboxs[i].ymax 82 | classId = sort_detectboxs[i].classId 83 | 84 | if sort_detectboxs[i].classId != -1: 85 | predBoxs.append(sort_detectboxs[i]) 86 | for j in range(i + 1, len(sort_detectboxs), 1): 87 | if classId == sort_detectboxs[j].classId: 88 | xmin2 = sort_detectboxs[j].xmin 89 | ymin2 = sort_detectboxs[j].ymin 90 | xmax2 = sort_detectboxs[j].xmax 91 | ymax2 = sort_detectboxs[j].ymax 92 | iou = IOU(xmin1, ymin1, xmax1, ymax1, xmin2, ymin2, xmax2, ymax2) 93 | if iou > nms_thre: 94 | sort_detectboxs[j].classId = -1 95 | return predBoxs 96 | 97 | 98 | def sigmoid(x): 99 | return 1 / (1 + exp(-x)) 100 | 101 | 102 | def postprocess(out, img_h, img_w): 103 | print('postprocess ... ') 104 | 105 | detectResult = [] 106 | 107 | output = [] 108 | for i in range(len(out)): 109 | output.append(out[i].reshape((-1))) 110 | 111 | gs = 4 + 1 + class_num 112 | scale_h = img_h / input_imgH 113 | scale_w = img_w / input_imgW 114 | 115 | for head in range(output_head): 116 | y = output[head] 117 | for h in range(cell_size[head][0]): 118 | 119 | for w in range(cell_size[head][1]): 120 | for a in range(anchor_num): 121 | conf_scale = sigmoid(y[((a * gs + 4) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) 122 | for cl in range(class_num): 123 | conf = sigmoid(y[((a * gs + 5 + cl) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * conf_scale 124 | 125 | if conf > obj_thre[cl]: 126 | bx = (sigmoid(y[((a * gs + 0) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2.0 - 0.5 + grid_cell[head][h][w][0]) * stride[head] 127 | by = (sigmoid(y[((a * gs + 1) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2.0 - 0.5 + grid_cell[head][h][w][1]) * stride[head] 128 | bw = pow((sigmoid(y[((a * gs + 2) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2), 2) * anchor_size[head][a][0] 129 | bh = pow((sigmoid(y[((a * gs + 3) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2), 2) * anchor_size[head][a][1] 130 | 131 | xmin = (bx - bw / 2) * scale_w 132 | ymin = (by - bh / 2) * scale_h 133 | xmax = (bx + bw / 2) * scale_w 134 | ymax = (by + bh / 2) * scale_h 135 | 136 | xmin = xmin if xmin > 0 else 0 137 | ymin = ymin if ymin > 0 else 0 138 | xmax = xmax if xmax < img_w else img_w 139 | ymax = ymax if ymax < img_h else img_h 140 | 141 | if xmin >= 0 and ymin >= 0 and xmax <= img_w and ymax <= img_h: 142 | box = DetectBox(cl, conf, xmin, ymin, xmax, ymax) 143 | detectResult.append(box) 144 | 145 | # NMS 146 | # print('detectResult:', len(detectResult)) 147 | predBox = NMS(detectResult) 148 | return predBox 149 | 150 | 151 | def preprocess(src_image): 152 | src_image = cv2.cvtColor(src_image, cv2.COLOR_BGR2RGB) 153 | img = cv2.resize(src_image, (input_imgW, input_imgH)) 154 | return img 155 | 156 | 157 | def inference(model_path, image_path, input_layout, input_offset): 158 | # init_root_logger("inference.log", console_level=logging.INFO, file_level=logging.DEBUG) 159 | 160 | sess = HB_ONNXRuntime(model_file=model_path) 161 | sess.set_dim_param(0, 0, '?') 162 | 163 | if input_layout is None: 164 | logging.warning(f"input_layout not provided. Using {sess.layout[0]}") 165 | input_layout = sess.layout[0] 166 | 167 | origimg = cv2.imread(image_path) 168 | img_h, img_w = origimg.shape[:2] 169 | image_data = preprocess(origimg) 170 | 171 | # image_data = image_data.transpose((2, 0, 1)) 172 | image_data = np.expand_dims(image_data, axis=0) 173 | 174 | input_name = sess.input_names[0] 175 | output_name = sess.output_names 176 | output = sess.run(output_name, {input_name: image_data}, input_offset=input_offset) 177 | 178 | print('inference finished, output len is:', len(output)) 179 | 180 | out = [] 181 | for i in range(len(output)): 182 | out.append(output[i]) 183 | 184 | predbox = postprocess(out, img_h, img_w) 185 | 186 | print('detect object num is:', len(predbox)) 187 | 188 | for i in range(len(predbox)): 189 | xmin = int(predbox[i].xmin) 190 | ymin = int(predbox[i].ymin) 191 | xmax = int(predbox[i].xmax) 192 | ymax = int(predbox[i].ymax) 193 | classId = predbox[i].classId 194 | score = predbox[i].score 195 | 196 | cv2.rectangle(origimg, (xmin, ymin), (xmax, ymax), (0, 255, 0), 2) 197 | ptext = (xmin, ymin) 198 | title = CLASSES[classId] + "%.2f" % score 199 | cv2.putText(origimg, title, ptext, cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2, cv2.LINE_AA) 200 | 201 | cv2.imwrite('./result.jpg', origimg) 202 | # cv2.imshow("test", origimg) 203 | # cv2.waitKey(0) 204 | 205 | 206 | if __name__ == '__main__': 207 | print('This main ... ') 208 | grid_cell_init() 209 | 210 | model_path = './model_output/yolov7_quantized_model.onnx' 211 | image_path = './test.jpg' 212 | input_layout = 'NHWC' 213 | input_offset = 128 214 | 215 | inference(model_path, image_path, input_layout, input_offset) 216 | 217 | -------------------------------------------------------------------------------- /yolov7_horizon/model/yolov7.onnx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_horizon/model/yolov7.onnx -------------------------------------------------------------------------------- /yolov7_horizon/model_output/torch-jit-export_subgraph_0.json: -------------------------------------------------------------------------------- 1 | { 2 | "summary": { 3 | "BPU OPs per frame (effective)": 6651136000, 4 | "BPU OPs per run (effective)": 6651136000, 5 | "BPU PE number": 1, 6 | "BPU core number": 1, 7 | "BPU march": "BERNOULLI2", 8 | "DDR bytes per frame": 15546912.0, 9 | "DDR bytes per run": 15546912, 10 | "DDR bytes per second": 916697347, 11 | "DDR megabytes per frame": 14.827, 12 | "DDR megabytes per run": 14.827, 13 | "DDR megabytes per second": 874.2, 14 | "FPS": 58.96, 15 | "HBDK version": "3.27.4", 16 | "compiling options": "-f hbir -m /tmp/tmpecxgg1c6/torch-jit-export_subgraph_0.bin -o /tmp/tmpecxgg1c6/torch-jit-export_subgraph_0.hbm --march bernoulli2 --progressbar --fast --O3 --input-layout NHWC --output-layout NCHW --input-source ddr", 17 | "frame per run": 1, 18 | "frame per second": 58.96, 19 | "input features": [ 20 | [ 21 | "input name", 22 | "input size" 23 | ], 24 | [ 25 | "data", 26 | "1x640x640x3" 27 | ] 28 | ], 29 | "interval loading bandwidth (megabytes/s)": [ 30 | 813, 31 | 625, 32 | 659, 33 | 590, 34 | 674, 35 | 404, 36 | 419, 37 | 400, 38 | 184, 39 | 110, 40 | 87, 41 | 284, 42 | 1632, 43 | 531, 44 | 0, 45 | 0, 46 | 278, 47 | 426, 48 | 644, 49 | 0, 50 | 117, 51 | 0, 52 | 1504, 53 | 595, 54 | 532, 55 | 1949, 56 | 640, 57 | 1384, 58 | 190, 59 | 1008, 60 | 420, 61 | 177, 62 | 1070, 63 | 257 64 | ], 65 | "interval number": 34, 66 | "interval storing bandwidth (megabytes/s)": [ 67 | 273, 68 | 312, 69 | 312, 70 | 312, 71 | 351, 72 | 0, 73 | 0, 74 | 0, 75 | 0, 76 | 0, 77 | 683, 78 | 878, 79 | 0, 80 | 156, 81 | 156, 82 | 234, 83 | 234, 84 | 117, 85 | 597, 86 | 117, 87 | 117, 88 | 0, 89 | 17, 90 | 99, 91 | 390, 92 | 878, 93 | 558, 94 | 418, 95 | 0, 96 | 914, 97 | 457, 98 | 386, 99 | 991, 100 | 1066 101 | ], 102 | "interval time (ms)": 0.5, 103 | "latency (ms)": 16.96, 104 | "latency (ms) by segments": [ 105 | 16.96 106 | ], 107 | "latency (us)": 16959.7, 108 | "loaded bytes per frame": 9761568, 109 | "loaded bytes per run": 9761568, 110 | "model json CRC": "e100e719", 111 | "model json file": "/tmp/tmpecxgg1c6/torch-jit-export_subgraph_0.bin", 112 | "model name": "torch-jit-export_subgraph_0", 113 | "model param CRC": "00000000", 114 | "multicore sync time (ms)": 0.0, 115 | "run per second": 58.96, 116 | "runtime version": "3.13.27", 117 | "stored bytes per frame": 5785344, 118 | "stored bytes per run": 5785344, 119 | "worst FPS": 58.96 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /yolov7_horizon/model_output/yolov7.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_horizon/model_output/yolov7.bin -------------------------------------------------------------------------------- /yolov7_horizon/model_output/yolov7_optimized_float_model.onnx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_horizon/model_output/yolov7_optimized_float_model.onnx -------------------------------------------------------------------------------- /yolov7_horizon/model_output/yolov7_original_float_model.onnx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_horizon/model_output/yolov7_original_float_model.onnx -------------------------------------------------------------------------------- /yolov7_horizon/model_output/yolov7_quantized_model.onnx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_horizon/model_output/yolov7_quantized_model.onnx -------------------------------------------------------------------------------- /yolov7_horizon/preprocess.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Horizon Robotics.All Rights Reserved. 2 | # 3 | # The material in this file is confidential and contains trade secrets 4 | # of Horizon Robotics Inc. This is proprietary information owned by 5 | # Horizon Robotics Inc. No part of this work may be disclosed, 6 | # reproduced, copied, transmitted, or used in any way for any purpose, 7 | # without the express written permission of Horizon Robotics Inc. 8 | 9 | import sys 10 | sys.path.append("../../../01_common/python/data/") 11 | from transformer import * 12 | from dataloader import * 13 | 14 | 15 | def calibration_transformers(): 16 | """ 17 | step: 18 | 1、pad resize to 672 * 672 19 | 2、NHWC to NCHW 20 | 3、bgr to rgb 21 | """ 22 | transformers = [ 23 | PadResizeTransformer(target_size=(672, 672)), 24 | HWC2CHWTransformer(), 25 | BGR2RGBTransformer(data_format="CHW"), 26 | ] 27 | return transformers 28 | 29 | 30 | def infer_transformers(input_shape, input_layout="NHWC"): 31 | """ 32 | step: 33 | 1、pad resize to target_size(input_shape) 34 | 2、bgr to rgb 35 | 3、rgb to nv12 36 | 3、nv12 to yuv444 37 | :param input_shape: input shape(target size) 38 | :param input_layout: NCHW / NHWC 39 | """ 40 | transformers = [ 41 | PadResizeTransformer(target_size=input_shape), 42 | BGR2RGBTransformer(data_format="HWC"), 43 | RGB2NV12Transformer(data_format="HWC"), 44 | NV12ToYUV444Transformer(target_size=input_shape, 45 | yuv444_output_layout=input_layout[1:]), 46 | ] 47 | return transformers 48 | 49 | 50 | def infer_image_preprocess(image_file, input_layout, input_shape): 51 | """ 52 | image for single image inference 53 | note: imread_mode [skimage / opencv] 54 | opencv read image as 8-bit unsigned integers BGR in range [0, 255] 55 | skimage read image as float32 RGB in range [0, 1] 56 | make sure to use the same imread_mode as the model training 57 | :param image_file: image file 58 | :param input_layout: NCHW / NHWC 59 | :param input_shape: input shape(target size) 60 | :return: origin image, processed image (uint8, 0-255) 61 | """ 62 | transformers = infer_transformers(input_shape, input_layout) 63 | origin_image, processed_image = SingleImageDataLoaderWithOrigin( 64 | transformers, image_file, imread_mode="opencv") 65 | return origin_image, processed_image 66 | 67 | 68 | def eval_image_preprocess(image_path, annotation_path, input_shape, 69 | input_layout): 70 | """ 71 | image for full scale evaluation 72 | note: imread_mode [skimage / opencv] 73 | opencv read image as 8-bit unsigned integers BGR in range [0, 255] 74 | skimage read image as float32 RGB in range [0, 1] 75 | make sure to use the same imread_mode as the model training 76 | :param image_path: image path 77 | :param annotation_path: annotation path 78 | :param input_shape: input shape(target size) 79 | :param input_layout: input layout 80 | :return: data loader 81 | """ 82 | transformers = infer_transformers(input_shape, input_layout) 83 | data_loader = COCODataLoader(transformers, 84 | image_path, 85 | annotation_path, 86 | imread_mode='opencv') 87 | 88 | return data_loader 89 | -------------------------------------------------------------------------------- /yolov7_horizon/result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_horizon/result.jpg -------------------------------------------------------------------------------- /yolov7_horizon/src_data/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_horizon/src_data/test.jpg -------------------------------------------------------------------------------- /yolov7_horizon/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_horizon/test.jpg -------------------------------------------------------------------------------- /yolov7_horizon/yolov7_config.yaml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Horizon Robotics.All Rights Reserved. 2 | # 3 | # The material in this file is confidential and contains trade secrets 4 | # of Horizon Robotics Inc. This is proprietary information owned by 5 | # Horizon Robotics Inc. No part of this work may be disclosed, 6 | # reproduced, copied, transmitted, or used in any way for any purpose, 7 | # without the express written permission of Horizon Robotics Inc. 8 | 9 | # 模型转化相关的参数 10 | # ------------------------------------ 11 | # model conversion related parameters 12 | model_parameters: 13 | # Onnx浮点网络数据模型文件 14 | # ----------------------------------------------------------- 15 | # the model file of floating-point ONNX neural network data 16 | onnx_model: './model/yolov7.onnx' 17 | 18 | # 适用BPU架构 19 | # -------------------------------- 20 | # the applicable BPU architecture 21 | march: "bernoulli2" 22 | 23 | # 指定模型转换过程中是否输出各层的中间结果,如果为True,则输出所有层的中间输出结果, 24 | # -------------------------------------------------------------------------------------- 25 | # specifies whether or not to dump the intermediate results of all layers in conversion 26 | # if set to True, then the intermediate results of all layers shall be dumped 27 | layer_out_dump: False 28 | 29 | # 日志文件的输出控制参数, 30 | # debug输出模型转换的详细信息 31 | # info只输出关键信息 32 | # warn输出警告和错误级别以上的信息 33 | # ---------------------------------------------------------------------------------------- 34 | # output control parameter of log file(s), 35 | # if set to 'debug', then details of model conversion will be dumped 36 | # if set to 'info', then only important imformation will be dumped 37 | # if set to 'warn', then information ranked higher than 'warn' and 'error' will be dumped 38 | log_level: 'debug' 39 | 40 | # 模型转换输出的结果的存放目录 41 | # ----------------------------------------------------------- 42 | # the directory in which model conversion results are stored 43 | working_dir: 'model_output' 44 | 45 | # 模型转换输出的用于上板执行的模型文件的名称前缀 46 | # ----------------------------------------------------------------------------------------- 47 | # model conversion generated name prefix of those model files used for dev board execution 48 | output_model_file_prefix: 'yolov7' 49 | 50 | # 模型输入相关参数, 若输入多个节点, 则应使用';'进行分隔, 使用默认缺省设置则写None 51 | # -------------------------------------------------------------------------- 52 | # model input related parameters, 53 | # please use ";" to seperate when inputting multiple nodes, 54 | # please use None for default setting 55 | input_parameters: 56 | 57 | # (选填) 模型输入的节点名称, 此名称应与模型文件中的名称一致, 否则会报错, 不填则会使用模型文件中的节点名称 58 | # -------------------------------------------------------------------------------------------------------- 59 | # (Optional) node name of model input, 60 | # it shall be the same as the name of model file, otherwise an error will be reported, 61 | # the node name of model file will be used when left blank 62 | input_name: "" 63 | 64 | # 网络实际执行时,输入给网络的数据格式,包括 nv12/rgb/bgr/yuv444/gray/featuremap, 65 | # ------------------------------------------------------------------------------------------ 66 | # the data formats to be passed into neural network when actually performing neural network 67 | # available options: nv12/rgb/bgr/yuv444/gray/featuremap, 68 | input_type_rt: 'rgb' 69 | 70 | # 网络实际执行时输入的数据排布, 可选值为 NHWC/NCHW 71 | # 若input_type_rt配置为nv12,则此处参数不需要配置 72 | # ------------------------------------------------------------------ 73 | # the data layout formats to be passed into neural network when actually performing neural network, available options: NHWC/NCHW 74 | # If input_type_rt is configured as nv12, then this parameter does not need to be configured 75 | input_layout_rt: 'NCHW' 76 | 77 | # 网络训练时输入的数据格式,可选的值为rgb/bgr/gray/featuremap/yuv444 78 | # -------------------------------------------------------------------- 79 | # the data formats in network training 80 | # available options: rgb/bgr/gray/featuremap/yuv444 81 | input_type_train: 'rgb' 82 | 83 | # 网络训练时输入的数据排布, 可选值为 NHWC/NCHW 84 | # ------------------------------------------------------------------ 85 | # the data layout in network training, available options: NHWC/NCHW 86 | input_layout_train: 'NCHW' 87 | 88 | # (选填) 模型网络的输入大小, 以'x'分隔, 不填则会使用模型文件中的网络输入大小,否则会覆盖模型文件中输入大小 89 | # ------------------------------------------------------------------------------------------- 90 | # (Optional)the input size of model network, seperated by 'x' 91 | # note that the network input size of model file will be used if left blank 92 | # otherwise it will overwrite the input size of model file 93 | input_shape: '' 94 | 95 | # 网络实际执行时,输入给网络的batch_size, 默认值为1 96 | # --------------------------------------------------------------------- 97 | # the data batch_size to be passed into neural network when actually performing neural network, default value: 1 98 | #input_batch: 1 99 | 100 | # 网络输入的预处理方法,主要有以下几种: 101 | # no_preprocess 不做任何操作 102 | # data_mean 减去通道均值mean_value 103 | # data_scale 对图像像素乘以data_scale系数 104 | # data_mean_and_scale 减去通道均值后再乘以scale系数 105 | # ------------------------------------------------------------------------------------------- 106 | # preprocessing methods of network input, available options: 107 | # 'no_preprocess' indicates that no preprocess will be made 108 | # 'data_mean' indicates that to minus the channel mean, i.e. mean_value 109 | # 'data_scale' indicates that image pixels to multiply data_scale ratio 110 | # 'data_mean_and_scale' indicates that to multiply scale ratio after channel mean is minused 111 | norm_type: 'data_scale' 112 | 113 | # 图像减去的均值, 如果是通道均值,value之间必须用空格分隔 114 | # -------------------------------------------------------------------------- 115 | # the mean value minused by image 116 | # note that values must be seperated by space if channel mean value is used 117 | mean_value: '' 118 | 119 | # 图像预处理缩放比例,如果是通道缩放比例,value之间必须用空格分隔 120 | # --------------------------------------------------------------------------- 121 | # scale value of image preprocess 122 | # note that values must be seperated by space if channel scale value is used 123 | scale_value: 0.003921568627451 124 | 125 | # 模型量化相关参数 126 | # ----------------------------- 127 | # model calibration parameters 128 | calibration_parameters: 129 | 130 | # 模型量化的参考图像的存放目录,图片格式支持Jpeg、Bmp等格式,输入的图片 131 | # 应该是使用的典型场景,一般是从测试集中选择20~100张图片,另外输入 132 | # 的图片要覆盖典型场景,不要是偏僻场景,如过曝光、饱和、模糊、纯黑、纯白等图片 133 | # 若有多个输入节点, 则应使用';'进行分隔 134 | # ------------------------------------------------------------------------------------------------- 135 | # the directory where reference images of model quantization are stored 136 | # image formats include JPEG, BMP etc. 137 | # should be classic application scenarios, usually 20~100 images are picked out from test datasets 138 | # in addition, note that input images should cover typical scenarios 139 | # and try to avoid those overexposed, oversaturated, vague, 140 | # pure blank or pure white images 141 | # use ';' to seperate when there are multiple input nodes 142 | cal_data_dir: './cal_data' 143 | 144 | # 如果输入的图片文件尺寸和模型训练的尺寸不一致时,并且preprocess_on为true, 145 | # 则将采用默认预处理方法(skimage resize), 146 | # 将输入图片缩放或者裁减到指定尺寸,否则,需要用户提前把图片处理为训练时的尺寸 147 | # --------------------------------------------------------------------------------- 148 | # In case the size of input image file is different from that of in model training 149 | # and that preprocess_on is set to True, 150 | # shall the default preprocess method(skimage resize) be used 151 | # i.e., to resize or crop input image into specified size 152 | # otherwise user must keep image size as that of in training in advance 153 | preprocess_on: True 154 | 155 | # 模型量化的算法类型,支持kl、max、default、load,通常采用default即可满足要求, 若为QAT导出的模型, 则应选择load 156 | # ---------------------------------------------------------------------------------- 157 | # types of model quantization algorithms, usually default will meet the need 158 | # available options:kl, max, default and load 159 | # if converted model is quanti model exported from QAT , then choose `load` 160 | calibration_type: 'default' 161 | 162 | # 编译器相关参数 163 | # ---------------------------- 164 | # compiler related parameters 165 | compiler_parameters: 166 | 167 | # 编译策略,支持bandwidth和latency两种优化模式; 168 | # bandwidth以优化ddr的访问带宽为目标; 169 | # latency以优化推理时间为目标 170 | # ------------------------------------------------------------------------------------------- 171 | # compilation strategy, there are 2 available optimization modes: 'bandwidth' and 'lantency' 172 | # the 'bandwidth' mode aims to optimize ddr access bandwidth 173 | # while the 'lantency' mode aims to optimize inference duration 174 | compile_mode: 'latency' 175 | 176 | # 设置debug为True将打开编译器的debug模式,能够输出性能仿真的相关信息,如帧率、DDR带宽占用等 177 | # ----------------------------------------------------------------------------------- 178 | # the compiler's debug mode will be enabled by setting to True 179 | # this will dump performance simulation related information 180 | # such as: frame rate, DDR bandwidth usage etc. 181 | debug: False 182 | 183 | # 编译模型指定核数,不指定默认编译单核模型, 若编译双核模型,将下边注释打开即可 184 | # ------------------------------------------------------------------------------------- 185 | # specifies number of cores to be used in model compilation 186 | # as default, single core is used as this value left blank 187 | # please delete the "# " below to enable dual-core mode when compiling dual-core model 188 | # core_num: 2 189 | 190 | # 优化等级可选范围为O0~O3 191 | # O0不做任何优化, 编译速度最快,优化程度最低, 192 | # O1-O3随着优化等级提高,预期编译后的模型的执行速度会更快,但是所需编译时间也会变长。 193 | # 推荐用O2做最快验证 194 | # ---------------------------------------------------------------------------------------------------------- 195 | # optimization level ranges between O0~O3 196 | # O0 indicates that no optimization will be made 197 | # the faster the compilation, the lower optimization level will be 198 | # O1-O3: as optimization levels increase gradually, model execution, after compilation, shall become faster 199 | # while compilation will be prolonged 200 | # it is recommended to use O2 for fastest verification 201 | optimize_level: 'O3' 202 | -------------------------------------------------------------------------------- /yolov7_onnx/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Yolov7_onnx 2 | ![image](https://github.com/cqu20160901/yolov7_caffe_onnx_tensorRT/blob/main/yolov7_onnx/result.jpg) 3 | -------------------------------------------------------------------------------- /yolov7_onnx/result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_onnx/result.jpg -------------------------------------------------------------------------------- /yolov7_onnx/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_onnx/test.jpg -------------------------------------------------------------------------------- /yolov7_onnx/yolov7.onnx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_onnx/yolov7.onnx -------------------------------------------------------------------------------- /yolov7_onnx/yolov7_onnx_demo.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import onnxruntime as ort 3 | from math import exp 4 | import cv2 5 | 6 | 7 | CLASSES = ['car', 'tail', 'tailB', 'person', 'cyclist'] 8 | 9 | class_num = len(CLASSES) 10 | anchor_num = 3 11 | output_head = 3 12 | 13 | cell_size = [[80, 80], [40, 40], [20, 20]] 14 | 15 | anchor_size = [ 16 | [[17,5], [10,29], [19,16]], 17 | [[45,15], [39,33], [26,93]], 18 | [[75,53], [111,104], [258,203]]] 19 | 20 | stride = [8, 16, 32] 21 | grid_cell = np.zeros(shape=(3, 80, 80, 2)) 22 | 23 | nms_thre = 0.45 24 | obj_thre = [0.4, 0.4, 0.4, 0.4, 0.4] 25 | 26 | input_imgW = 640 27 | input_imgH = 640 28 | 29 | 30 | class DetectBox: 31 | def __init__(self, classId, score, xmin, ymin, xmax, ymax): 32 | self.classId = classId 33 | self.score = score 34 | self.xmin = xmin 35 | self.ymin = ymin 36 | self.xmax = xmax 37 | self.ymax = ymax 38 | 39 | 40 | def grid_cell_init(): 41 | for index in range(output_head): 42 | for w in range(cell_size[index][1]): 43 | for h in range(cell_size[index][0]): 44 | grid_cell[index][h][w][0] = w 45 | grid_cell[index][h][w][1] = h 46 | 47 | 48 | def IOU(xmin1, ymin1, xmax1, ymax1, xmin2, ymin2, xmax2, ymax2): 49 | xmin = max(xmin1, xmin2) 50 | ymin = max(ymin1, ymin2) 51 | xmax = min(xmax1, xmax2) 52 | ymax = min(ymax1, ymax2) 53 | 54 | innerWidth = xmax - xmin 55 | innerHeight = ymax - ymin 56 | 57 | innerWidth = innerWidth if innerWidth > 0 else 0 58 | innerHeight = innerHeight if innerHeight > 0 else 0 59 | 60 | innerArea = innerWidth * innerHeight 61 | 62 | area1 = (xmax1 - xmin1) * (ymax1 - ymin1) 63 | area2 = (xmax2 - xmin2) * (ymax2 - ymin2) 64 | 65 | total = area1 + area2 - innerArea 66 | 67 | return innerArea / total 68 | 69 | 70 | def NMS(detectResult): 71 | predBoxs = [] 72 | 73 | sort_detectboxs = sorted(detectResult, key=lambda x: x.score, reverse=True) 74 | 75 | for i in range(len(sort_detectboxs)): 76 | xmin1 = sort_detectboxs[i].xmin 77 | ymin1 = sort_detectboxs[i].ymin 78 | xmax1 = sort_detectboxs[i].xmax 79 | ymax1 = sort_detectboxs[i].ymax 80 | classId = sort_detectboxs[i].classId 81 | 82 | if sort_detectboxs[i].classId != -1: 83 | predBoxs.append(sort_detectboxs[i]) 84 | for j in range(i + 1, len(sort_detectboxs), 1): 85 | if classId == sort_detectboxs[j].classId: 86 | xmin2 = sort_detectboxs[j].xmin 87 | ymin2 = sort_detectboxs[j].ymin 88 | xmax2 = sort_detectboxs[j].xmax 89 | ymax2 = sort_detectboxs[j].ymax 90 | iou = IOU(xmin1, ymin1, xmax1, ymax1, xmin2, ymin2, xmax2, ymax2) 91 | if iou > nms_thre: 92 | sort_detectboxs[j].classId = -1 93 | return predBoxs 94 | 95 | 96 | def sigmoid(x): 97 | return 1 / (1 + exp(-x)) 98 | 99 | 100 | def postprocess(out, img_h, img_w): 101 | print('postprocess ... ') 102 | 103 | detectResult = [] 104 | 105 | output = [] 106 | for i in range(len(out)): 107 | output.append(out[i].reshape((-1))) 108 | 109 | gs = 4 + 1 + class_num 110 | scale_h = img_h / input_imgH 111 | scale_w = img_w / input_imgW 112 | 113 | for head in range(output_head): 114 | y = output[head] 115 | for h in range(cell_size[head][0]): 116 | 117 | for w in range(cell_size[head][1]): 118 | for a in range(anchor_num): 119 | conf_scale = sigmoid(y[((a * gs + 4) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) 120 | for cl in range(class_num): 121 | if class_num > 1: 122 | conf = sigmoid(y[((a * gs + 5 + cl) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * conf_scale 123 | else: 124 | conf = conf_scale 125 | 126 | if conf > obj_thre[cl]: 127 | bx = (sigmoid(y[((a * gs + 0) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2.0 - 0.5 + grid_cell[head][h][w][0]) * stride[head] 128 | by = (sigmoid(y[((a * gs + 1) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2.0 - 0.5 + grid_cell[head][h][w][1]) * stride[head] 129 | bw = pow((sigmoid(y[((a * gs + 2) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2), 2) * anchor_size[head][a][0] 130 | bh = pow((sigmoid(y[((a * gs + 3) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2), 2) * anchor_size[head][a][1] 131 | 132 | xmin = (bx - bw / 2) * scale_w 133 | ymin = (by - bh / 2) * scale_h 134 | xmax = (bx + bw / 2) * scale_w 135 | ymax = (by + bh / 2) * scale_h 136 | 137 | xmin = xmin if xmin > 0 else 0 138 | ymin = ymin if ymin > 0 else 0 139 | xmax = xmax if xmax < img_w else img_w 140 | ymax = ymax if ymax < img_h else img_h 141 | 142 | if xmin >= 0 and ymin >= 0 and xmax <= img_w and ymax <= img_h: 143 | box = DetectBox(cl, conf, xmin, ymin, xmax, ymax) 144 | detectResult.append(box) 145 | 146 | # NMS 过程 147 | print('detectResult:', len(detectResult)) 148 | predBox = NMS(detectResult) 149 | return predBox 150 | 151 | 152 | def preprocess(src): 153 | img = cv2.resize(src, (input_imgW, input_imgH)) 154 | img = img * 0.00392156 155 | return img 156 | 157 | 158 | def detect(imgfile): 159 | origimg = cv2.imread(imgfile) 160 | origimg = cv2.cvtColor(origimg, cv2.COLOR_BGR2RGB) 161 | img_h, img_w = origimg.shape[:2] 162 | img = preprocess(origimg) 163 | 164 | img = img.astype(np.float32) 165 | img = img.transpose((2, 0, 1)) 166 | 167 | img = np.expand_dims(img, axis=0) 168 | 169 | ort_session = ort.InferenceSession('./yolov7.onnx') 170 | res = (ort_session.run(None, {'data': img})) 171 | ''' 172 | img = np.ones((1, 3, 640, 640), dtype = np.float32) 173 | res = (ort_session.run(None, {'data': img})) 174 | for i in range(len(res)): 175 | print(res[i]) 176 | return 0 177 | ''' 178 | 179 | out = [] 180 | for i in range(len(res)): 181 | print(i, res[i].shape) 182 | out.append(res[i]) 183 | 184 | predbox = postprocess(out, img_h, img_w) 185 | 186 | print(len(predbox)) 187 | 188 | for i in range(len(predbox)): 189 | xmin = int(predbox[i].xmin) 190 | ymin = int(predbox[i].ymin) 191 | xmax = int(predbox[i].xmax) 192 | ymax = int(predbox[i].ymax) 193 | classId = predbox[i].classId 194 | score = predbox[i].score 195 | 196 | cv2.rectangle(origimg, (xmin, ymin), (xmax, ymax), (0, 255, 0), 2) 197 | ptext = (xmin, ymin) 198 | title = CLASSES[classId] + "%.2f" % score 199 | cv2.putText(origimg, title, ptext, cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2, cv2.LINE_AA) 200 | 201 | cv2.imwrite('./result.jpg', origimg) 202 | # cv2.imshow("test", origimg) 203 | # cv2.waitKey(0) 204 | 205 | 206 | if __name__ == '__main__': 207 | print('This is main .... ') 208 | grid_cell_init() 209 | detect('./test.jpg') 210 | -------------------------------------------------------------------------------- /yolov7_rknn/ReadMe.md: -------------------------------------------------------------------------------- 1 | # yolov7 的 rknn 版本 2 | 3 | 注意:实际使用过程中 dataset.txt 中的量化图片需要多放一些,由于为了测试方便把量化图片设置为一张 4 | 5 | ![image](https://github.com/cqu20160901/yolov7_caffe_onnx_tensorRT/blob/main/yolov7_rknn/result_rknn.jpg) 6 | -------------------------------------------------------------------------------- /yolov7_rknn/dataset.txt: -------------------------------------------------------------------------------- 1 | ./test.jpg -------------------------------------------------------------------------------- /yolov7_rknn/onnx2rknn_demo.py: -------------------------------------------------------------------------------- 1 | import os 2 | import urllib 3 | import traceback 4 | import time 5 | import sys 6 | import numpy as np 7 | import cv2 8 | from rknn.api import RKNN 9 | from math import exp 10 | 11 | ONNX_MODEL = 'yolov7.onnx' 12 | RKNN_MODEL = 'yolov7.rknn' 13 | DATASET = './dataset.txt' 14 | 15 | QUANTIZE_ON = True 16 | 17 | CLASSES = ['car', 'tail', 'tailB', 'person', 'cyclist'] 18 | 19 | class_num = len(CLASSES) 20 | anchor_num = 3 21 | output_head = 3 22 | 23 | cell_size = [[80, 80], [40, 40], [20, 20]] 24 | 25 | anchor_size = [ 26 | [[17, 5], [10, 29], [19, 16]], 27 | [[45, 15], [39, 33], [26, 93]], 28 | [[75, 53], [111, 104], [258, 203]]] 29 | 30 | stride = [8, 16, 32] 31 | grid_cell = np.zeros(shape=(3, 80, 80, 2)) 32 | 33 | nms_thre = 0.45 34 | obj_thre = [0.4, 0.4, 0.4, 0.4, 0.4] 35 | 36 | input_imgW = 640 37 | input_imgH = 640 38 | 39 | 40 | class DetectBox: 41 | def __init__(self, classId, score, xmin, ymin, xmax, ymax): 42 | self.classId = classId 43 | self.score = score 44 | self.xmin = xmin 45 | self.ymin = ymin 46 | self.xmax = xmax 47 | self.ymax = ymax 48 | 49 | 50 | def grid_cell_init(): 51 | for index in range(output_head): 52 | for w in range(cell_size[index][1]): 53 | for h in range(cell_size[index][0]): 54 | grid_cell[index][h][w][0] = w 55 | grid_cell[index][h][w][1] = h 56 | 57 | 58 | def IOU(xmin1, ymin1, xmax1, ymax1, xmin2, ymin2, xmax2, ymax2): 59 | xmin = max(xmin1, xmin2) 60 | ymin = max(ymin1, ymin2) 61 | xmax = min(xmax1, xmax2) 62 | ymax = min(ymax1, ymax2) 63 | 64 | innerWidth = xmax - xmin 65 | innerHeight = ymax - ymin 66 | 67 | innerWidth = innerWidth if innerWidth > 0 else 0 68 | innerHeight = innerHeight if innerHeight > 0 else 0 69 | 70 | innerArea = innerWidth * innerHeight 71 | 72 | area1 = (xmax1 - xmin1) * (ymax1 - ymin1) 73 | area2 = (xmax2 - xmin2) * (ymax2 - ymin2) 74 | 75 | total = area1 + area2 - innerArea 76 | 77 | return innerArea / total 78 | 79 | 80 | def NMS(detectResult): 81 | predBoxs = [] 82 | 83 | sort_detectboxs = sorted(detectResult, key=lambda x: x.score, reverse=True) 84 | 85 | for i in range(len(sort_detectboxs)): 86 | xmin1 = sort_detectboxs[i].xmin 87 | ymin1 = sort_detectboxs[i].ymin 88 | xmax1 = sort_detectboxs[i].xmax 89 | ymax1 = sort_detectboxs[i].ymax 90 | classId = sort_detectboxs[i].classId 91 | 92 | if sort_detectboxs[i].classId != -1: 93 | predBoxs.append(sort_detectboxs[i]) 94 | for j in range(i + 1, len(sort_detectboxs), 1): 95 | if classId == sort_detectboxs[j].classId: 96 | xmin2 = sort_detectboxs[j].xmin 97 | ymin2 = sort_detectboxs[j].ymin 98 | xmax2 = sort_detectboxs[j].xmax 99 | ymax2 = sort_detectboxs[j].ymax 100 | iou = IOU(xmin1, ymin1, xmax1, ymax1, xmin2, ymin2, xmax2, ymax2) 101 | if iou > nms_thre: 102 | sort_detectboxs[j].classId = -1 103 | return predBoxs 104 | 105 | 106 | def sigmoid(x): 107 | return 1 / (1 + exp(-x)) 108 | 109 | 110 | def postprocess(out, img_h, img_w): 111 | print('postprocess ... ') 112 | 113 | detectResult = [] 114 | 115 | output = [] 116 | for i in range(len(out)): 117 | output.append(out[i].reshape((-1))) 118 | 119 | gs = 4 + 1 + class_num 120 | scale_h = img_h / input_imgH 121 | scale_w = img_w / input_imgW 122 | 123 | for head in range(output_head): 124 | y = output[head] 125 | for h in range(cell_size[head][0]): 126 | 127 | for w in range(cell_size[head][1]): 128 | for a in range(anchor_num): 129 | conf_scale = sigmoid( 130 | y[((a * gs + 4) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) 131 | for cl in range(class_num): 132 | if class_num > 1: 133 | conf = sigmoid(y[((a * gs + 5 + cl) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * conf_scale 134 | else: 135 | conf = conf_scale 136 | 137 | if conf > obj_thre[cl]: 138 | bx = (sigmoid(y[((a * gs + 0) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2.0 - 0.5 + grid_cell[head][h][w][0]) * stride[head] 139 | by = (sigmoid(y[((a * gs + 1) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2.0 - 0.5 + grid_cell[head][h][w][1]) * stride[head] 140 | bw = pow((sigmoid(y[((a * gs + 2) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2), 2) * anchor_size[head][a][0] 141 | bh = pow((sigmoid(y[((a * gs + 3) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2), 2) * anchor_size[head][a][1] 142 | 143 | xmin = (bx - bw / 2) * scale_w 144 | ymin = (by - bh / 2) * scale_h 145 | xmax = (bx + bw / 2) * scale_w 146 | ymax = (by + bh / 2) * scale_h 147 | 148 | xmin = xmin if xmin > 0 else 0 149 | ymin = ymin if ymin > 0 else 0 150 | xmax = xmax if xmax < img_w else img_w 151 | ymax = ymax if ymax < img_h else img_h 152 | 153 | if xmin >= 0 and ymin >= 0 and xmax <= img_w and ymax <= img_h: 154 | box = DetectBox(cl, conf, xmin, ymin, xmax, ymax) 155 | detectResult.append(box) 156 | 157 | # NMS 过程 158 | print('detectResult:', len(detectResult)) 159 | predBox = NMS(detectResult) 160 | return predBox 161 | 162 | 163 | def export_rknn_inference(img): 164 | # Create RKNN object 165 | rknn = RKNN(verbose=True) 166 | 167 | # pre-process config 168 | print('--> Config model') 169 | rknn.config(mean_values=[[0, 0, 0]], std_values=[[255, 255, 255]]) 170 | print('done') 171 | 172 | # Load ONNX model 173 | print('--> Loading model') 174 | ret = rknn.load_onnx(model=ONNX_MODEL, outputs=['output1', 'output2', 'output3']) 175 | if ret != 0: 176 | print('Load model failed!') 177 | exit(ret) 178 | print('done') 179 | 180 | # Build model 181 | print('--> Building model') 182 | ret = rknn.build(do_quantization=QUANTIZE_ON, dataset=DATASET) 183 | if ret != 0: 184 | print('Build model failed!') 185 | exit(ret) 186 | print('done') 187 | 188 | # Export RKNN model 189 | print('--> Export rknn model') 190 | ret = rknn.export_rknn(RKNN_MODEL) 191 | if ret != 0: 192 | print('Export rknn model failed!') 193 | exit(ret) 194 | print('done') 195 | 196 | # Init runtime environment 197 | print('--> Init runtime environment') 198 | ret = rknn.init_runtime() 199 | # ret = rknn.init_runtime('rk3566') 200 | if ret != 0: 201 | print('Init runtime environment failed!') 202 | exit(ret) 203 | print('done') 204 | 205 | # Inference 206 | print('--> Running model') 207 | outputs = rknn.inference(inputs=[img]) 208 | rknn.release() 209 | print('done') 210 | 211 | return outputs 212 | 213 | 214 | if __name__ == '__main__': 215 | print('This is main ...') 216 | grid_cell_init() 217 | 218 | img_path = './test.jpg' 219 | origimg = cv2.imread(img_path) 220 | img_h, img_w = origimg.shape[:2] 221 | 222 | img = cv2.cvtColor(origimg, cv2.COLOR_BGR2RGB) 223 | img = cv2.resize(img, (input_imgW, input_imgH)) 224 | 225 | outputs = export_rknn_inference(img) 226 | 227 | out = [] 228 | for i in range(len(outputs)): 229 | out.append(outputs[i]) 230 | 231 | predbox = postprocess(out, img_h, img_w) 232 | 233 | print(len(predbox)) 234 | 235 | for i in range(len(predbox)): 236 | xmin = int(predbox[i].xmin) 237 | ymin = int(predbox[i].ymin) 238 | xmax = int(predbox[i].xmax) 239 | ymax = int(predbox[i].ymax) 240 | classId = predbox[i].classId 241 | score = predbox[i].score 242 | 243 | cv2.rectangle(origimg, (xmin, ymin), (xmax, ymax), (0, 255, 0), 2) 244 | ptext = (xmin, ymin) 245 | title = CLASSES[classId] + "%.2f" % score 246 | cv2.putText(origimg, title, ptext, cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2, cv2.LINE_AA) 247 | 248 | cv2.imwrite('./result_rknn.jpg', origimg) 249 | # cv2.imshow("test", origimg) 250 | # cv2.waitKey(0) 251 | 252 | -------------------------------------------------------------------------------- /yolov7_rknn/result_rknn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_rknn/result_rknn.jpg -------------------------------------------------------------------------------- /yolov7_rknn/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_rknn/test.jpg -------------------------------------------------------------------------------- /yolov7_rknn/yolov7.onnx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_rknn/yolov7.onnx -------------------------------------------------------------------------------- /yolov7_rknn/yolov7.rknn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_rknn/yolov7.rknn -------------------------------------------------------------------------------- /yolov7_tensorRT/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Yolov7_tensorRT 2 | 3 | ![image](https://github.com/cqu20160901/yolov7_caffe_onnx_tensorRT/blob/main/yolov7_tensorRT/test_result.jpg) 4 | -------------------------------------------------------------------------------- /yolov7_tensorRT/onnx2trt_rt7.py: -------------------------------------------------------------------------------- 1 | import tensorrt as trt 2 | 3 | G_LOGGER = trt.Logger() 4 | 5 | batch_size = 1 6 | imput_h = 640 7 | imput_w = 640 8 | 9 | 10 | def get_engine(onnx_model_name, trt_model_name): 11 | explicit_batch = 1 << (int)(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) 12 | with trt.Builder(G_LOGGER) as builder, builder.create_network(explicit_batch) as network, trt.OnnxParser(network, 13 | G_LOGGER) as parser: 14 | builder.max_batch_size = batch_size 15 | builder.max_workspace_size = 2 << 30 16 | print('Loading ONNX file from path {}...'.format(onnx_model_name)) 17 | with open(onnx_model_name, 'rb') as model: 18 | print('Beginning ONNX file parsing') 19 | if not parser.parse(model.read()): 20 | for error in range(parser.num_errors): 21 | print(parser.get_error(error)) 22 | 23 | print('Completed parsing of ONNX file') 24 | print('Building an engine from file {}; this may take a while...'.format(onnx_model_name)) 25 | 26 | #### 27 | # builder.int8_mode = True 28 | # builder.int8_calibrator = calib 29 | builder.fp16_mode = True 30 | #### 31 | 32 | print("num layers:", network.num_layers) 33 | # last_layer = network.get_layer(network.num_layers - 1) 34 | # if not last_layer.get_output(0): 35 | # network.mark_output(network.get_layer(network.num_layers - 1).get_output(0))//有的模型需要,有的模型在转onnx的之后已经指定了,就不需要这行 36 | 37 | network.get_input(0).shape = [batch_size, 3, imput_h, imput_w] 38 | engine = builder.build_cuda_engine(network) 39 | print("engine:", engine) 40 | print("Completed creating Engine") 41 | with open(trt_model_name, "wb") as f: 42 | f.write(engine.serialize()) 43 | return engine 44 | 45 | 46 | def main(): 47 | onnx_file_path = './yolov7.onnx' 48 | engine_file_path = './yolov7.trt' 49 | 50 | engine = get_engine(onnx_file_path, engine_file_path) 51 | 52 | 53 | if __name__ == '__main__': 54 | print("This is main ...") 55 | main() 56 | -------------------------------------------------------------------------------- /yolov7_tensorRT/tensorRT_inferenc_demo.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import tensorrt as trt 4 | import pycuda.driver as cuda 5 | import pycuda.autoinit 6 | from math import exp 7 | from math import sqrt 8 | 9 | TRT_LOGGER = trt.Logger() 10 | 11 | 12 | CLASSES = ['car', 'tail', 'tailB', 'person', 'cyclist'] 13 | 14 | class_num = len(CLASSES) 15 | anchor_num = 3 16 | output_head = 3 17 | 18 | cell_size = [[80, 80], [40, 40], [20, 20]] 19 | 20 | anchor_size = [ 21 | [[17,5], [10,29], [19,16]], 22 | [[45,15], [39,33], [26,93]], 23 | [[75,53], [111,104], [258,203]]] 24 | 25 | stride = [8, 16, 32] 26 | grid_cell = np.zeros(shape=(3, 80, 80, 2)) 27 | 28 | nms_thre = 0.45 29 | obj_thre = [0.4, 0.4, 0.4, 0.4, 0.4] 30 | 31 | input_imgW = 640 32 | input_imgH = 640 33 | 34 | 35 | # Simple helper data class that's a little nicer to use than a 2-tuple. 36 | class HostDeviceMem(object): 37 | def __init__(self, host_mem, device_mem): 38 | self.host = host_mem 39 | self.device = device_mem 40 | 41 | def __str__(self): 42 | return "Host:\n" + str(self.host) + "\nDevice:\n" + str(self.device) 43 | 44 | def __repr__(self): 45 | return self.__str__() 46 | 47 | 48 | def allocate_buffers(engine): 49 | inputs = [] 50 | outputs = [] 51 | bindings = [] 52 | stream = cuda.Stream() 53 | for binding in engine: 54 | size = trt.volume(engine.get_binding_shape(binding)) * engine.max_batch_size 55 | dtype = trt.nptype(engine.get_binding_dtype(binding)) 56 | # Allocate host and device buffers 57 | host_mem = cuda.pagelocked_empty(size, dtype) 58 | device_mem = cuda.mem_alloc(host_mem.nbytes) 59 | # Append the device buffer to device bindings. 60 | bindings.append(int(device_mem)) 61 | # Append to the appropriate list. 62 | if engine.binding_is_input(binding): 63 | inputs.append(HostDeviceMem(host_mem, device_mem)) 64 | else: 65 | outputs.append(HostDeviceMem(host_mem, device_mem)) 66 | return inputs, outputs, bindings, stream 67 | 68 | 69 | def get_engine_from_bin(engine_file_path): 70 | print('Reading engine from file {}'.format(engine_file_path)) 71 | with open(engine_file_path, 'rb') as f, trt.Runtime(TRT_LOGGER) as runtime: 72 | return runtime.deserialize_cuda_engine(f.read()) 73 | 74 | 75 | # This function is generalized for multiple inputs/outputs. 76 | # inputs and outputs are expected to be lists of HostDeviceMem objects. 77 | def do_inference(context, bindings, inputs, outputs, stream, batch_size=1): 78 | # Transfer input data to the GPU. 79 | [cuda.memcpy_htod_async(inp.device, inp.host, stream) for inp in inputs] 80 | # Run inference. 81 | context.execute_async(batch_size=batch_size, bindings=bindings, stream_handle=stream.handle) 82 | # Transfer predictions back from the GPU. 83 | [cuda.memcpy_dtoh_async(out.host, out.device, stream) for out in outputs] 84 | # Synchronize the stream 85 | stream.synchronize() 86 | # Return only the host outputs. 87 | return [out.host for out in outputs] 88 | 89 | 90 | class DetectBox: 91 | def __init__(self, classId, score, xmin, ymin, xmax, ymax): 92 | self.classId = classId 93 | self.score = score 94 | self.xmin = xmin 95 | self.ymin = ymin 96 | self.xmax = xmax 97 | self.ymax = ymax 98 | 99 | 100 | def grid_cell_init(): 101 | for index in range(output_head): 102 | for w in range(cell_size[index][1]): 103 | for h in range(cell_size[index][0]): 104 | grid_cell[index][h][w][0] = w 105 | grid_cell[index][h][w][1] = h 106 | 107 | 108 | def IOU(xmin1, ymin1, xmax1, ymax1, xmin2, ymin2, xmax2, ymax2): 109 | xmin = max(xmin1, xmin2) 110 | ymin = max(ymin1, ymin2) 111 | xmax = min(xmax1, xmax2) 112 | ymax = min(ymax1, ymax2) 113 | 114 | innerWidth = xmax - xmin 115 | innerHeight = ymax - ymin 116 | 117 | innerWidth = innerWidth if innerWidth > 0 else 0 118 | innerHeight = innerHeight if innerHeight > 0 else 0 119 | 120 | innerArea = innerWidth * innerHeight 121 | 122 | area1 = (xmax1 - xmin1) * (ymax1 - ymin1) 123 | area2 = (xmax2 - xmin2) * (ymax2 - ymin2) 124 | 125 | total = area1 + area2 - innerArea 126 | 127 | return innerArea / total 128 | 129 | 130 | def NMS(detectResult): 131 | predBoxs = [] 132 | 133 | sort_detectboxs = sorted(detectResult, key=lambda x: x.score, reverse=True) 134 | 135 | for i in range(len(sort_detectboxs)): 136 | xmin1 = sort_detectboxs[i].xmin 137 | ymin1 = sort_detectboxs[i].ymin 138 | xmax1 = sort_detectboxs[i].xmax 139 | ymax1 = sort_detectboxs[i].ymax 140 | classId = sort_detectboxs[i].classId 141 | 142 | if sort_detectboxs[i].classId != -1: 143 | predBoxs.append(sort_detectboxs[i]) 144 | for j in range(i + 1, len(sort_detectboxs), 1): 145 | if classId == sort_detectboxs[j].classId: 146 | xmin2 = sort_detectboxs[j].xmin 147 | ymin2 = sort_detectboxs[j].ymin 148 | xmax2 = sort_detectboxs[j].xmax 149 | ymax2 = sort_detectboxs[j].ymax 150 | iou = IOU(xmin1, ymin1, xmax1, ymax1, xmin2, ymin2, xmax2, ymax2) 151 | if iou > nms_thre: 152 | sort_detectboxs[j].classId = -1 153 | return predBoxs 154 | 155 | 156 | def sigmoid(x): 157 | return 1 / (1 + exp(-x)) 158 | 159 | 160 | def postprocess(out, img_h, img_w): 161 | print('postprocess ... ') 162 | 163 | detectResult = [] 164 | 165 | output = [] 166 | for i in range(len(out)): 167 | output.append(out[i].reshape((-1))) 168 | 169 | gs = 4 + 1 + class_num 170 | scale_h = img_h / input_imgH 171 | scale_w = img_w / input_imgW 172 | 173 | for head in range(output_head): 174 | y = output[head] 175 | for h in range(cell_size[head][0]): 176 | 177 | for w in range(cell_size[head][1]): 178 | for a in range(anchor_num): 179 | conf_scale = sigmoid(y[((a * gs + 4) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) 180 | for cl in range(class_num): 181 | if class_num > 1: 182 | conf = sigmoid(y[((a * gs + 5 + cl) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * conf_scale 183 | else: 184 | conf = conf_scale 185 | 186 | if conf > obj_thre[cl]: 187 | bx = (sigmoid(y[((a * gs + 0) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2.0 - 0.5 + grid_cell[head][h][w][0]) * stride[head] 188 | by = (sigmoid(y[((a * gs + 1) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2.0 - 0.5 + grid_cell[head][h][w][1]) * stride[head] 189 | bw = pow((sigmoid(y[((a * gs + 2) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2), 2) * anchor_size[head][a][0] 190 | bh = pow((sigmoid(y[((a * gs + 3) * cell_size[head][0] * cell_size[head][1]) + h * cell_size[head][1] + w]) * 2), 2) * anchor_size[head][a][1] 191 | 192 | xmin = (bx - bw / 2) * scale_w 193 | ymin = (by - bh / 2) * scale_h 194 | xmax = (bx + bw / 2) * scale_w 195 | ymax = (by + bh / 2) * scale_h 196 | 197 | xmin = xmin if xmin > 0 else 0 198 | ymin = ymin if ymin > 0 else 0 199 | xmax = xmax if xmax < img_w else img_w 200 | ymax = ymax if ymax < img_h else img_h 201 | 202 | if xmin >= 0 and ymin >= 0 and xmax <= img_w and ymax <= img_h: 203 | box = DetectBox(cl, conf, xmin, ymin, xmax, ymax) 204 | detectResult.append(box) 205 | 206 | # NMS 过程 207 | print('detectResult:', len(detectResult)) 208 | predBox = NMS(detectResult) 209 | return predBox 210 | 211 | 212 | def preprocess(src): 213 | img = cv2.resize(src, (input_imgW, input_imgH)).astype(np.float32) 214 | img = img * 0.00392156 215 | img = img.transpose(2, 0, 1) 216 | img_input = img.copy() 217 | return img_input 218 | 219 | 220 | 221 | def main(): 222 | engine_file_path = 'yolov7.trt' 223 | input_image_path = 'test.jpg' 224 | 225 | orig = cv2.imread(input_image_path) 226 | orig = cv2.cvtColor(orig, cv2.COLOR_BGR2RGB) 227 | img_h, img_w = orig.shape[:2] 228 | image = preprocess(orig) 229 | 230 | with get_engine_from_bin(engine_file_path) as engine, engine.create_execution_context() as context: 231 | inputs, outputs, bindings, stream = allocate_buffers(engine) 232 | 233 | inputs[0].host = image 234 | trt_outputs = do_inference(context, bindings=bindings, inputs=inputs, outputs=outputs, stream=stream, batch_size=1) 235 | print(len(trt_outputs)) 236 | 237 | out = [] 238 | for i in range(len(trt_outputs)): 239 | out.append(trt_outputs[i]) 240 | 241 | predbox = postprocess(out, img_h, img_w) 242 | 243 | print(len(predbox)) 244 | 245 | for i in range(len(predbox)): 246 | xmin = int(predbox[i].xmin) 247 | ymin = int(predbox[i].ymin) 248 | xmax = int(predbox[i].xmax) 249 | ymax = int(predbox[i].ymax) 250 | classId = predbox[i].classId 251 | score = predbox[i].score 252 | 253 | cv2.rectangle(orig, (xmin, ymin), (xmax, ymax), (0, 255, 0), 2) 254 | ptext = (xmin, ymin) 255 | title = CLASSES[classId] + "%.2f" % score 256 | cv2.putText(orig, title, ptext, cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2, cv2.LINE_AA) 257 | 258 | cv2.imwrite('./test_result.jpg', orig) 259 | # cv2.imshow("test", orig) 260 | # cv2.waitKey(0) 261 | 262 | 263 | if __name__ == '__main__': 264 | print('This is main ...') 265 | grid_cell_init() 266 | main() 267 | -------------------------------------------------------------------------------- /yolov7_tensorRT/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_tensorRT/test.jpg -------------------------------------------------------------------------------- /yolov7_tensorRT/test_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_tensorRT/test_result.jpg -------------------------------------------------------------------------------- /yolov7_tensorRT/yolov7.onnx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_tensorRT/yolov7.onnx -------------------------------------------------------------------------------- /yolov7_tensorRT/yolov7.trt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cqu20160901/yolov7_caffe_onnx_tensorRT_rknn_horizon/58cacb1b9bb79e9bbea6a9d23726acd3f84781c9/yolov7_tensorRT/yolov7.trt --------------------------------------------------------------------------------