{"id":6794,"date":"2025-09-29T14:16:23","date_gmt":"2025-09-29T06:16:23","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=6794"},"modified":"2025-09-29T14:16:34","modified_gmt":"2025-09-29T06:16:34","slug":"yolo%e5%85%a5%e9%97%a8%e6%95%99%e7%a8%8b%ef%bc%88%e5%9b%9b%ef%bc%89%ef%bc%9a%e6%90%ad%e5%bb%bayolov1%e7%bd%91%e7%bb%9c","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/yolo\/yolo%e5%85%a5%e9%97%a8%e6%95%99%e7%a8%8b%ef%bc%88%e5%9b%9b%ef%bc%89%ef%bc%9a%e6%90%ad%e5%bb%bayolov1%e7%bd%91%e7%bb%9c\/","title":{"rendered":"YOLO\u5165\u95e8\u6559\u7a0b\uff08\u56db\uff09\uff1a\u642d\u5efaYOLOv1\u7f51\u7edc"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li>\u5b66\u4e60\u6559\u6848\uff1ahttps:\/\/zhuanlan.zhihu.com\/p\/365788432<\/li>\n\n\n\n<li>\u4f5c\u8005\uff1aKissrabbit<\/li>\n\n\n\n<li>\u4f5c\u8005\u4e66\u7c4d\uff1a\u300aYOLO\u76ee\u6807\u68c0\u6d4b\u300b<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u80a1\u5e02\u53ef\u4ee5\u505c\u6b62\u6da8\uff0c\u4f46\u662f\u5b66\u4e60\u4e0d\u80fd\u505c\uff01<\/p>\n<\/blockquote>\n\n\n\n<h1 class=\"wp-block-heading\">0\u3001\u5e8f\u8a00<\/h1>\n\n\n\n<p>\u5728\u4e0a\u4e00\u8282\u4e2d\uff0c\u6211\u4eec\u8bb2\u89e3\u4e86\u6211\u4eec\u6240\u8981\u642d\u5efa\u7684YOLOv1\uff0c\u4e0d\u540c\u4e8e\u539f\u7248\u7684YOLOv1\uff0c\u6211\u4eec\u5728\u4e0d\u504f\u79bb\u539f\u7248\u7684\u5927\u90e8\u5206\u6838\u5fc3\u7406\u5ff5\u7684\u524d\u63d0\u4e0b\uff0c\u505a\u4e86\u66f4\u52a0\u7b26\u5408\u5f53\u4e0b\u7684\u8bbe\u8ba1\u7406\u5ff5\u7684\u4fee\u6539\uff0c\u5305\u62ec\u4f7f\u7528\u66f4\u597d\u7684Backbone\u3001\u6dfb\u52a0Neck\u6a21\u5757\u3001\u4fee\u6539\u68c0\u6d4b\u5934\u7b49\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6709\u70b9\u641e\u5fd8\u4e86\u539f\u672c\u7684\u4ec0\u4e48\u6837\u5b50\u4e86\uff0c\u590d\u4e60\u4e00\u4e0b<\/p>\n<\/blockquote>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u66f4\u597d\u7684 Backbone\uff1a<\/strong><ul><li><strong>ResNet (Residual Networks)\uff1a<\/strong>\u00a0\u901a\u8fc7\u5f15\u5165\u6b8b\u5dee\u8fde\u63a5\u89e3\u51b3\u4e86\u6df1\u5c42\u7f51\u7edc\u8bad\u7ec3\u56f0\u96be\u7684\u95ee\u9898\uff0c\u5141\u8bb8\u6784\u5efa\u66f4\u6df1\u3001\u66f4\u5f3a\u5927\u7684\u7f51\u7edc\uff08\u5982 ResNet-18, ResNet-34, ResNet-50 \u7b49\uff09\u3002\u5b83\u80fd\u63d0\u53d6\u66f4\u4e30\u5bcc\u3001\u66f4\u6df1\u5c42\u6b21\u7684\u7279\u5f81\u3002<\/li><li><strong>MobileNet\uff1a<\/strong>\u00a0\u4e13\u95e8\u4e3a\u79fb\u52a8\u548c\u5d4c\u5165\u5f0f\u8bbe\u5907\u8bbe\u8ba1\uff0c\u4f7f\u7528\u6df1\u5ea6\u53ef\u5206\u79bb\u5377\u79ef\u6765\u5927\u5e45\u51cf\u5c11\u8ba1\u7b97\u91cf\u548c\u53c2\u6570\u6570\u91cf\uff0c\u540c\u65f6\u4fdd\u6301\u8f83\u597d\u7684\u7cbe\u5ea6\u3002\u9002\u5408\u8ffd\u6c42\u901f\u5ea6\u7684\u573a\u666f\u3002<\/li><li><strong>EfficientNet\uff1a<\/strong>\u00a0\u901a\u8fc7\u590d\u5408\u7f29\u653e\u65b9\u6cd5\uff08\u540c\u65f6\u7f29\u653e\u7f51\u7edc\u6df1\u5ea6\u3001\u5bbd\u5ea6\u548c\u8f93\u5165\u5206\u8fa8\u7387\uff09\u5728\u8ba1\u7b97\u8d44\u6e90\u53d7\u9650\u7684\u60c5\u51b5\u4e0b\u8fbe\u5230\u6700\u4f18\u7684\u6027\u80fd\u3002<\/li><li><strong>DarkNet (YOLO \u540e\u7eed\u7248\u672c\u4f7f\u7528\u7684)\uff1a<\/strong>\u00a0YOLOv2\/v3 \u4f5c\u8005\u63d0\u51fa\u7684 Backbone\uff0c\u4e5f\u662f\u9ad8\u6548\u4e14\u5f3a\u5927\u7684\u9009\u62e9\u3002<\/li><\/ul>\n<ul class=\"wp-block-list\">\n<li><strong>\u539f\u59cb YOLOv1\uff1a<\/strong>\u00a0\u4f7f\u7528\u7684\u662f\u57fa\u4e8e GoogLeNet (Inception-v1) \u7684\u81ea\u5b9a\u4e49 Backbone\uff0c\u5305\u542b 24 \u4e2a\u5377\u79ef\u5c42\u548c 2 \u4e2a\u5168\u8fde\u63a5\u5c42\u3002\u8fd9\u4e2a\u7f51\u7edc\u5728 2016 \u5e74\u662f\u4e0d\u9519\u7684\uff0c\u4f46\u4ee5\u4eca\u5929\u7684\u6807\u51c6\u6765\u770b\uff0c\u6548\u7387\u8f83\u4f4e\uff0c\u7279\u5f81\u63d0\u53d6\u80fd\u529b\u76f8\u5bf9\u8f83\u5f31\u3002<\/li>\n\n\n\n<li><strong>\u6539\u8fdb\uff1a<\/strong>\u00a0\u7528<strong>\u66f4\u73b0\u4ee3\u3001\u66f4\u5f3a\u5927\u3001\u66f4\u9ad8\u6548<\/strong>\u7684\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u67b6\u6784\u66ff\u6362\u539f\u59cb\u7684 Backbone\u3002\u5e38\u89c1\u7684\u73b0\u4ee3 Backbone \u5305\u62ec\uff1a<\/li>\n\n\n\n<li><strong>\u76ee\u7684\uff1a<\/strong>\u00a0\u63d0\u5347\u7279\u5f81\u63d0\u53d6\u80fd\u529b\uff0c\u4f7f\u7f51\u7edc\u80fd\u4ece\u8f93\u5165\u56fe\u50cf\u4e2d\u5b66\u4e60\u5230\u66f4\u9c81\u68d2\u3001\u66f4\u5177\u5224\u522b\u6027\u7684\u7279\u5f81\uff0c\u4ece\u800c\u63d0\u9ad8\u68c0\u6d4b\u7cbe\u5ea6\u548c\/\u6216\u901f\u5ea6\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u6dfb\u52a0 Neck \u6a21\u5757\uff1a<\/strong><ul><li><strong>FPN (Feature Pyramid Network)\uff1a<\/strong>\u00a0\u8fd9\u662f\u6700\u5e38\u7528\u7684 Neck \u4e4b\u4e00\u3002\u5b83\u901a\u8fc7\u81ea\u9876\u5411\u4e0b\u548c\u6a2a\u5411\u8fde\u63a5\uff0c\u5c06 Backbone \u4e0d\u540c\u5c42\uff08\u4e0d\u540c\u5c3a\u5ea6\uff09\u7684\u7279\u5f81\u56fe\u878d\u5408\u8d77\u6765\uff0c\u6784\u5efa\u4e00\u4e2a<strong>\u7279\u5f81\u91d1\u5b57\u5854<\/strong>\u3002\u8fd9\u4f7f\u5f97\u540e\u7eed\u7684\u68c0\u6d4b\u5934\u80fd\u591f\u5229\u7528\u4e0d\u540c\u5c3a\u5ea6\u7684\u7279\u5f81\u4fe1\u606f\uff1a\u6df1\u5c42\u7279\u5f81\u8bed\u4e49\u4fe1\u606f\u5f3a\u4f46\u5206\u8fa8\u7387\u4f4e\uff08\u9002\u5408\u5927\u76ee\u6807\uff09\uff0c\u6d45\u5c42\u7279\u5f81\u4f4d\u7f6e\u4fe1\u606f\u7cbe\u786e\u4f46\u8bed\u4e49\u4fe1\u606f\u5f31\uff08\u9002\u5408\u5c0f\u76ee\u6807\uff09\u3002\u6dfb\u52a0 FPN \u80fd\u663e\u8457\u63d0\u5347\u6a21\u578b\uff08\u5c24\u5176\u662f\u5c0f\u76ee\u6807\uff09\u7684\u68c0\u6d4b\u6027\u80fd\u3002<\/li><li><strong>PANet (Path Aggregation Network)\uff1a<\/strong>\u00a0\u5728 FPN \u57fa\u7840\u4e0a\u589e\u52a0\u4e86\u81ea\u5e95\u5411\u4e0a\u7684\u8def\u5f84\u589e\u5f3a\uff0c\u8fdb\u4e00\u6b65\u4f18\u5316\u4e86\u7279\u5f81\u878d\u5408\u8fc7\u7a0b\u3002<\/li><li><strong>BiFPN (Bidirectional Feature Pyramid Network)\uff1a<\/strong>\u00a0\u5728 EfficientDet \u4e2d\u63d0\u51fa\uff0c\u901a\u8fc7\u53cc\u5411\uff08\u81ea\u9876\u5411\u4e0b+\u81ea\u5e95\u5411\u4e0a\uff09\u7684\u8de8\u5c3a\u5ea6\u8fde\u63a5\u548c\u52a0\u6743\u7279\u5f81\u878d\u5408\uff0c\u66f4\u9ad8\u6548\u5730\u878d\u5408\u591a\u5c3a\u5ea6\u7279\u5f81\u3002<\/li><\/ul>\n<ul class=\"wp-block-list\">\n<li><strong>\u539f\u59cb YOLOv1\uff1a<\/strong><strong>\u6ca1\u6709<\/strong>\u660e\u786e\u7684 Neck \u6a21\u5757\u3002Backbone \u63d0\u53d6\u7684\u7279\u5f81\u56fe\u76f4\u63a5\u4f20\u9012\u7ed9\u4e86\u68c0\u6d4b\u5934\uff08Head\uff09\u3002<\/li>\n\n\n\n<li><strong>\u6539\u8fdb\uff1a<\/strong>\u00a0\u5728 Backbone \u548c Head \u4e4b\u95f4<strong>\u589e\u52a0\u4e00\u4e2a Neck \u6a21\u5757<\/strong>\u3002Neck \u7684\u4e3b\u8981\u4f5c\u7528\u662f<strong>\u7279\u5f81\u878d\u5408<\/strong>\u548c<strong>\u7279\u5f81\u589e\u5f3a<\/strong>\u3002\u5e38\u89c1\u7684 Neck \u7ed3\u6784\u5305\u62ec\uff1a<\/li>\n\n\n\n<li><strong>\u76ee\u7684\uff1a<\/strong>\u00a0\u878d\u5408\u4e0d\u540c\u5c42\u6b21\u7684\u7279\u5f81\u4fe1\u606f\uff0c\u7279\u522b\u662f\u589e\u5f3a\u5bf9\u5c0f\u76ee\u6807\u7684\u68c0\u6d4b\u80fd\u529b\uff08\u8fd9\u662f\u539f\u59cb YOLOv1 \u7684\u4e00\u4e2a\u4e3b\u8981\u5f31\u70b9\uff09\uff0c\u5e76\u63d0\u5347\u6574\u4f53\u68c0\u6d4b\u7cbe\u5ea6\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u4fee\u6539\u68c0\u6d4b\u5934 (Head)\uff1a<\/strong><ul><li><strong>\u7528\u5377\u79ef\u5c42\u66ff\u4ee3\u5168\u8fde\u63a5\u5c42\uff1a<\/strong>\u00a0\u5168\u8fde\u63a5\u5c42\u4f1a\u7834\u574f\u7a7a\u95f4\u4fe1\u606f\u4e14\u53c2\u6570\u91cf\u5de8\u5927\u3002\u73b0\u4ee3\u68c0\u6d4b\u5668\u666e\u904d\u4f7f\u7528\u5377\u79ef\u5c42\uff08\u901a\u5e38\u662f\u00a0<code>1x1<\/code>\u00a0\u5377\u79ef\uff09\u6765\u6784\u5efa\u68c0\u6d4b\u5934\uff0c\u8fd9\u6837\u80fd\u4fdd\u7559\u7a7a\u95f4\u4fe1\u606f\uff0c\u53c2\u6570\u66f4\u5c11\uff0c\u66f4\u7075\u6d3b\u3002<\/li><li><strong>\u591a\u5c3a\u5ea6\u9884\u6d4b (Multi-scale Prediction)\uff1a<\/strong>\u00a0\u867d\u7136\u539f\u59cb YOLOv1 \u662f\u5355\u5c3a\u5ea6\u9884\u6d4b\uff0c\u4f46\u73b0\u4ee3\u6539\u8fdb\u53ef\u80fd\u4f1a\u5229\u7528 Neck\uff08\u5982 FPN\uff09\u8f93\u51fa\u7684<strong>\u591a\u4e2a\u5c3a\u5ea6\u7684\u7279\u5f81\u56fe<\/strong>\u8fdb\u884c\u9884\u6d4b\u3002\u4e0d\u540c\u5c3a\u5ea6\u7684\u7279\u5f81\u56fe\u8d1f\u8d23\u9884\u6d4b\u4e0d\u540c\u5927\u5c0f\u7684\u76ee\u6807\uff08\u5927\u7279\u5f81\u56fe\u9884\u6d4b\u5c0f\u76ee\u6807\uff0c\u5c0f\u7279\u5f81\u56fe\u9884\u6d4b\u5927\u76ee\u6807\uff09\uff0c\u8fd9\u663e\u8457\u63d0\u5347\u4e86\u68c0\u6d4b\u80fd\u529b\uff0c\u5c24\u5176\u662f\u5bf9\u5c0f\u76ee\u6807\u3002<\/li><li><strong>Anchor Boxes\uff1a<\/strong>\u00a0\u867d\u7136\u539f\u59cb YOLOv1 \u6ca1\u6709\u4f7f\u7528 Anchor Boxes\uff08\u5b83\u76f4\u63a5\u9884\u6d4b\u76f8\u5bf9\u4e8e\u7f51\u683c\u7684\u504f\u79fb\u91cf\uff09\uff0c\u4f46\u540e\u7eed\u7684 YOLO \u7248\u672c\u5f15\u5165\u4e86\u8fd9\u4e2a\u6982\u5ff5\u3002<em>\u53ef\u80fd<\/em>\u4f1a\u5f15\u5165 Anchor Boxes \u5230 Head \u8bbe\u8ba1\u4e2d\uff0c\u8ba9 Head \u9884\u6d4b\u76f8\u5bf9\u4e8e\u9884\u5b9a\u4e49 Anchor \u7684\u504f\u79fb\u91cf\u548c\u7c7b\u522b\u6982\u7387\u3002\u8fd9\u901a\u5e38\u80fd\u63d0\u5347\u5b9a\u4f4d\u7cbe\u5ea6\u3002<strong>\u4f46\u8bf7\u6ce8\u610f\uff0c\u76ee\u6807\u662f\u201c\u4e0d\u504f\u79bb\u539f\u7248\u7684\u5927\u90e8\u5206\u6838\u5fc3\u7406\u5ff5\u201d\uff0c\u800c\u539f\u59cb YOLOv1 \u7684\u6838\u5fc3\u4e4b\u4e00\u662f\u201c\u65e0 Anchor\u201d\u3002\u6240\u4ee5\u4e5f\u53ef\u80fd\u9009\u62e9\u4fdd\u7559\u65e0 Anchor \u7684\u8bbe\u8ba1\uff0c\u800c\u7528\u5176\u4ed6\u65b9\u5f0f\u6539\u8fdb Head\uff08\u5982\u66f4\u597d\u7684\u635f\u5931\u51fd\u6570\u8bbe\u8ba1\u3001\u66f4\u5408\u7406\u7684\u8f93\u51fa\u8868\u793a\u7b49\uff09\u3002<\/strong><\/li><li><strong>\u66f4\u7cbe\u7ec6\u7684\u8f93\u51fa\u8868\u793a\uff1a<\/strong>\u00a0\u53ef\u80fd\u5bf9\u8fb9\u754c\u6846\u5750\u6807 (<code>x, y, w, h<\/code>)\u3001\u7f6e\u4fe1\u5ea6\u6216\u7c7b\u522b\u6982\u7387\u7684\u9884\u6d4b\u65b9\u5f0f\u8fdb\u884c\u4f18\u5316\u3002<\/li><\/ul><ul><li>\u8f93\u5165\u662f Backbone \u8f93\u51fa\u7684\u5355\u4e00\u5c3a\u5ea6\u7684\u7279\u5f81\u56fe\uff08\u4f8b\u5982\u00a0<code>7x7<\/code>\uff09\u3002<\/li><li>\u7ed3\u6784\uff1a\u4e24\u4e2a\u5168\u8fde\u63a5\u5c42\u3002<\/li><li>\u8f93\u51fa\uff1a\u4e00\u4e2a\u00a0<code>S x S x (B * 5 + C)<\/code>\u00a0\u7684\u5f20\u91cf\u3002<\/li><\/ul><ul><li><code>S x S<\/code>\uff1a \u5c06\u56fe\u50cf\u5212\u5206\u4e3a\u00a0<code>S x S<\/code>\u00a0\u4e2a\u7f51\u683c\u3002<\/li><li><code>B<\/code>\uff1a \u6bcf\u4e2a\u7f51\u683c\u9884\u6d4b\u7684\u8fb9\u754c\u6846\u6570\u91cf\uff08\u539f\u59cb YOLOv1 \u4e2d\u00a0<code>B=2<\/code>\uff09\u3002<\/li><li><code>5<\/code>\uff1a \u6bcf\u4e2a\u8fb9\u754c\u6846\u7684\u9884\u6d4b\u503c (<code>x, y, w, h, confidence<\/code>)\u3002<\/li><li><code>C<\/code>\uff1a \u76ee\u6807\u7c7b\u522b\u7684\u6570\u91cf\uff08\u6bcf\u4e2a\u7f51\u683c\u9884\u6d4b\u4e00\u7ec4\u7c7b\u522b\u6982\u7387\uff09\u3002<\/li><\/ul>\n<ul class=\"wp-block-list\">\n<li><strong>\u539f\u59cb YOLOv1 Head\uff1a<\/strong><\/li>\n\n\n\n<li><strong>\u6539\u8fdb\uff1a<\/strong>\u00a0\u5bf9 Head \u8fdb\u884c\u73b0\u4ee3\u5316\u6539\u9020\uff0c\u53ef\u80fd\u5305\u62ec\uff1a<\/li>\n\n\n\n<li><strong>\u76ee\u7684\uff1a<\/strong>\u00a0\u63d0\u9ad8\u5b9a\u4f4d\u7cbe\u5ea6 (<code>x, y, w, h<\/code>)\uff0c\u63d0\u9ad8\u5206\u7c7b\u7cbe\u5ea6\uff0c\u63d0\u5347\u6a21\u578b\u5bf9\u4e0d\u540c\u5c3a\u5ea6\u76ee\u6807\u7684\u9c81\u68d2\u6027\uff0c\u540c\u65f6\u4fdd\u6301\u6216\u63d0\u5347\u6548\u7387\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u603b\u7ed3:<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p>\u5bf9\u539f\u59cb YOLOv1 \u7684\u6539\u8fdb\u662f\u5c06\u5176\u6838\u5fc3\u601d\u60f3\uff08\u5c06\u68c0\u6d4b\u89c6\u4e3a\u56de\u5f52\u95ee\u9898\u3001\u5212\u5206\u7f51\u683c\u9884\u6d4b\uff09\u4e0e<strong>\u73b0\u4ee3\u76ee\u6807\u68c0\u6d4b\u7684\u6700\u4f73\u5b9e\u8df5<\/strong>\u76f8\u7ed3\u5408\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u66f4\u5f3a\u58ee\u7684 Backbone\uff1a<\/strong>\u00a0\u63d0\u4f9b\u66f4\u597d\u7684\u57fa\u7840\u7279\u5f81\u3002<\/li>\n\n\n\n<li><strong>\u6dfb\u52a0 Neck (\u5982 FPN)\uff1a<\/strong>\u00a0\u878d\u5408\u591a\u5c3a\u5ea6\u7279\u5f81\uff0c\u89e3\u51b3\u5c0f\u76ee\u6807\u68c0\u6d4b\u96be\u9898\u3002<\/li>\n\n\n\n<li><strong>\u73b0\u4ee3\u5316\u7684 Head\uff1a<\/strong>\u00a0\u7528\u5377\u79ef\u66ff\u4ee3\u5168\u8fde\u63a5\uff0c\u53ef\u80fd\u5f15\u5165\u591a\u5c3a\u5ea6\u9884\u6d4b\u6216\u4f18\u5316\u8f93\u51fa\u8868\u793a\uff0c\u63d0\u5347\u7cbe\u5ea6\u548c\u9c81\u68d2\u6027\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u8fd9\u4e9b\u4fee\u6539\u65e8\u5728\u514b\u670d\u539f\u59cb YOLOv1 \u7684\u5df2\u77e5\u7f3a\u70b9\uff08\u5982\u5b9a\u4f4d\u4e0d\u51c6\u3001\u5c0f\u76ee\u6807\u68c0\u6d4b\u5dee\u3001\u53ec\u56de\u7387\u76f8\u5bf9\u8f83\u4f4e\uff09\uff0c\u4f7f\u5176\u5728\u4fdd\u6301 YOLO \u7cfb\u5217\u201c\u5feb\u901f\u201d\u7279\u70b9\u7684\u540c\u65f6\uff0c\u8fbe\u5230\u66f4\u63a5\u8fd1\u73b0\u4ee3\u68c0\u6d4b\u5668\u7684\u7cbe\u5ea6\u6c34\u5e73\u3002\u5f53\u9605\u8bfb\u535a\u5ba2\u540e\u7eed\u7684\u4ee3\u7801\u5b9e\u73b0\u90e8\u5206\u65f6\uff0c\u54b1\u4eec\u5f97\u91cd\u70b9\u5173\u6ce8\u89c2\u5bdf\u4f5c\u8005\u5177\u4f53\u9009\u62e9\u4e86\u54ea\u79cd Backbone\u3001\u54ea\u79cd Neck \u4ee5\u53ca\u5982\u4f55\u8bbe\u8ba1 Head \u7ed3\u6784\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5728\u672c\u8282\uff0c\u6211\u4eec\u5c06\u4f7f\u7528python\u8bed\u8a00\u548cpytorch\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u5f00\u59cb\u642d\u5efa\u6211\u4eec\u7684YOLOv1\u7f51\u7edc\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u4e0b\u65b9\u7684\u56fe1\u5c55\u793a\u4e86\u6211\u4eec\u6240\u8981\u642d\u5efa\u7684YOLOv1\u7684\u7f51\u7edc\u7ed3\u6784\u56fe\uff0c\u8fd9\u5c06\u662f\u6211\u4eec\u63a5\u4e0b\u6765\u7684\u5de5\u4f5c\u7684\u201c\u84dd\u56fe\u201d\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"399\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658-1024x399.jpg\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6795 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658-1024x399.jpg 1024w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658-300x117.jpg 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658-768x299.jpg 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658.jpg 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"399\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658-1024x399.jpg\" alt=\"\" class=\"wp-image-6795\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658-1024x399.jpg 1024w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658-300x117.jpg 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658-768x299.jpg 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658.jpg 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/noscript><\/figure>\n\n\n\n<p>\u6839\u636e\u8fd9\u4e00\u84dd\u56fe\uff0c\u6211\u4eec\u53ef\u4ee5\u5148\u642d\u5efa\u8d77\u6765\u4e00\u4e2a\u6574\u4f53\u7684\u6846\u67b6\uff0c\u5982\u4e0b\u65b9\u7684\u4ee3\u7801\u6240\u793a\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u4e00\u6b65\u4e00\u6b65\u5730\u53bb\u5b8c\u5584\u8fd9\u4e00\u4e2a\u6846\u67b6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># ODLab\/models\/detectors\/yolov1\/yolov1.py<br><br>class YOLOv1(nn.Module):<br>&nbsp; &nbsp; def __init__(self,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cfg,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;device,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;img_size=None,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;num_classes=20,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;conf_thresh=0.01,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nms_thresh=0.5,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;trainable=False,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deploy=False,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nms_class_agnostic :bool = False):<br>&nbsp; &nbsp; &nbsp; &nbsp; super(YOLOv1, self).__init__()<br>&nbsp; &nbsp; &nbsp; &nbsp; # ------------------------- \u57fa\u7840\u53c2\u6570 ---------------------------<br>&nbsp; &nbsp; &nbsp; &nbsp; self.cfg = cfg &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u6a21\u578b\u914d\u7f6e\u6587\u4ef6<br>&nbsp; &nbsp; &nbsp; &nbsp; self.img_size = img_size &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u8f93\u5165\u56fe\u50cf\u5927\u5c0f<br>&nbsp; &nbsp; &nbsp; &nbsp; self.device = device &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # cuda\u6216\u8005\u662fcpu<br>&nbsp; &nbsp; &nbsp; &nbsp; self.num_classes = num_classes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u7c7b\u522b\u7684\u6570\u91cf<br>&nbsp; &nbsp; &nbsp; &nbsp; self.trainable = trainable &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u8bad\u7ec3\u7684\u6807\u8bb0<br>&nbsp; &nbsp; &nbsp; &nbsp; self.conf_thresh = conf_thresh &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u5f97\u5206\u9608\u503c<br>&nbsp; &nbsp; &nbsp; &nbsp; self.nms_thresh = nms_thresh &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # NMS\u9608\u503c<br>&nbsp; &nbsp; &nbsp; &nbsp; self.stride = 32 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u7f51\u7edc\u7684\u6700\u5927\u6b65\u957f<br>&nbsp; &nbsp; &nbsp; &nbsp; self.deploy = deploy<br>&nbsp; &nbsp; &nbsp; &nbsp; self.nms_class_agnostic = nms_class_agnostic<br><br>&nbsp; &nbsp; &nbsp; &nbsp; # &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Backbone\u7f51\u7edc &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<br>&nbsp; &nbsp; &nbsp; &nbsp; # To do\uff1a\u6784\u5efa\u6211\u4eec\u7684backbone\u7f51\u7edc<br>&nbsp; &nbsp; &nbsp; &nbsp; # self.backbone<br><br>&nbsp; &nbsp; &nbsp; &nbsp; # &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Neck\u7f51\u7edc &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<br>&nbsp; &nbsp; &nbsp; &nbsp; # To do\uff1a\u6784\u5efa\u6211\u4eec\u7684neck\u7f51\u7edc<br>&nbsp; &nbsp; &nbsp; &nbsp; # self.neck<br><br>&nbsp; &nbsp; &nbsp; &nbsp; # &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Head\u7f51\u7edc &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<br>&nbsp; &nbsp; &nbsp; &nbsp; # To do\uff1a\u6784\u5efa\u6211\u4eec\u7684head\u7f51\u7edc<br>&nbsp; &nbsp; &nbsp; &nbsp; # self.head<br><br>&nbsp; &nbsp; &nbsp; &nbsp; # &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; \u9884\u6d4b\u5c42 &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<br>&nbsp; &nbsp; &nbsp; &nbsp; # To do\uff1a\u6784\u5efa\u6211\u4eec\u7684\u9884\u6d4b\u5c42<br>&nbsp; &nbsp; &nbsp; &nbsp; # self.pred<br><br>&nbsp; &nbsp; def create_grid(self, fmp_size):<br>&nbsp; &nbsp; &nbsp; &nbsp; # To do\uff1a<br>&nbsp; &nbsp; &nbsp; &nbsp; # \u751f\u6210\u4e00\u4e2atensor\uff1agrid_xy\uff0c\u6bcf\u4e2a\u4f4d\u7f6e\u7684\u5143\u7d20\u662f\u7f51\u683c\u7684\u5750\u6807\uff0c<br>&nbsp; &nbsp; &nbsp; &nbsp; # \u8fd9\u4e00tensor\u5c06\u5728\u83b7\u5f97\u8fb9\u754c\u6846\u53c2\u6570\u7684\u65f6\u5019\u4f1a\u7528\u5230\u3002<br><br>&nbsp; &nbsp; def decode_boxes(self, pred, fmp_size):<br>&nbsp; &nbsp; &nbsp; &nbsp; # \u5c06\u7f51\u7edc\u8f93\u51fa\u7684tx,ty,tw,th\u56db\u4e2a\u91cf\u8f6c\u6362\u6210bbox\u7684(x1,y1),(x2,y2)<br><br>&nbsp; &nbsp; def postprocess(self, bboxes, scores):<br>&nbsp; &nbsp; &nbsp; &nbsp; # \u540e\u5904\u7406\u4ee3\u7801\uff0c\u5305\u62ec\u9608\u503c\u7b5b\u9009\u548c\u975e\u6781\u5927\u503c\u6291\u5236<br><br>&nbsp; &nbsp; @torch.no_grad()<br>&nbsp; &nbsp; def inference(self, x):<br>&nbsp; &nbsp; &nbsp; &nbsp; # \u6d4b\u8bd5\u9636\u6bb5\u7684\u524d\u5411\u63a8\u7406\u4ee3\u7801<br><br>&nbsp; &nbsp; def forward(self, x, target=None):<br>&nbsp; &nbsp; &nbsp; &nbsp; # \u8bad\u7ec3\u9636\u6bb5\u7684\u524d\u5411\u63a8\u7406\u4ee3\u7801<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u65e2\u7136\u662f\u5c0f\u767d\uff0c\u6211\u4eec\u641e\u6162\u70b9\uff0c\u5148\u6765\u9010\u90e8\u5206\u8be6\u7ec6\u89e3\u91ca\u8fd9\u6bb5 YOLOv1 \u6a21\u578b\u7c7b\u7684\u4ee3\u7801\u6846\u67b6\u3002<\/p>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5b9a\u4e49\u4e86\u4e00\u4e2a PyTorch \u6a21\u578b\u7c7b&nbsp;<code>YOLOv1<\/code>\uff0c\u5b83\u5305\u542b\u4e86\u6a21\u578b\u6784\u5efa\u548c\u524d\u5411\u4f20\u64ad\u6240\u9700\u7684\u4e3b\u8981\u7ec4\u4ef6\u548c\u65b9\u6cd5\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol class=\"wp-block-list\">\n<li>\u7c7b\u5b9a\u4e49\u4e0e\u521d\u59cb\u5316 (<code>__init__<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>class&nbsp;YOLOv1(nn.Module):<br>&nbsp; &nbsp;&nbsp;def&nbsp;__init__(self,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cfg, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u914d\u7f6e\u6587\u4ef6\u5bf9\u8c61\uff0c\u53ef\u80fd\u5305\u542b\u6a21\u578b\u7ed3\u6784\u3001\u8d85\u53c2\u6570\u7b49<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;device, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em># \u8ba1\u7b97\u8bbe\u5907 ('cuda' \u6216 'cpu')<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;img_size=None, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u8f93\u5165\u56fe\u50cf\u5c3a\u5bf8 (e.g., 416)<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;num_classes=20, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em># \u8981\u68c0\u6d4b\u7684\u7c7b\u522b\u6570 (\u9ed8\u8ba4\u4e3aVOC\u768420\u7c7b)<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;conf_thresh=0.01, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em># \u7f6e\u4fe1\u5ea6\u5206\u6570\u9608\u503c\uff0c\u7528\u4e8e\u8fc7\u6ee4\u4f4e\u7f6e\u4fe1\u5ea6\u9884\u6d4b<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nms_thresh=0.5, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em># \u975e\u6781\u5927\u503c\u6291\u5236 (NMS) \u7684IoU\u9608\u503c<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;trainable=False, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u6a21\u5f0f\u6807\u5fd7\uff1aTrue\u4e3a\u8bad\u7ec3\uff0cFalse\u4e3a\u6d4b\u8bd5\/\u9a8c\u8bc1<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deploy=False, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em># \u90e8\u7f72\u6a21\u5f0f\u6807\u5fd7\uff0c\u53ef\u80fd\u7528\u4e8e\u7b80\u5316\u8f93\u51fa\uff08\u5982ONNX\u5bfc\u51fa\uff09<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nms_class_agnostic :bool = False):&nbsp;<em># NMS\u662f\u5426\u8de8\u7c7b\u522b\u8fdb\u884c\uff08True\u5219\u6240\u6709\u7c7b\u522b\u4e00\u8d77\u505aNMS\uff09<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; super(YOLOv1, self).__init__()<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># ------------------------- \u57fa\u7840\u53c2\u6570 ---------------------------<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; self.cfg = cfg<br>&nbsp; &nbsp; &nbsp; &nbsp; self.img_size = img_size<br>&nbsp; &nbsp; &nbsp; &nbsp; self.device = device<br>&nbsp; &nbsp; &nbsp; &nbsp; self.num_classes = num_classes<br>&nbsp; &nbsp; &nbsp; &nbsp; self.trainable = trainable<br>&nbsp; &nbsp; &nbsp; &nbsp; self.conf_thresh = conf_thresh<br>&nbsp; &nbsp; &nbsp; &nbsp; self.nms_thresh = nms_thresh<br>&nbsp; &nbsp; &nbsp; &nbsp; self.stride =&nbsp;32&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em># \u7f51\u7edc\u7684\u603b\u4e0b\u91c7\u6837\u6b65\u957f\uff08 backbone + neck\uff09<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; self.deploy = deploy<br>&nbsp; &nbsp; &nbsp; &nbsp; self.nms_class_agnostic = nms_class_agnostic<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u76ee\u7684<\/strong>: \u521d\u59cb\u5316\u6a21\u578b\u7684\u8d85\u53c2\u6570\u548c\u7ed3\u6784\u7ec4\u4ef6\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u53c2\u6570<\/strong>:\n<ul class=\"wp-block-list\">\n<li><code>cfg<\/code>: \u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u5bf9\u8c61\uff0c\u901a\u5e38\u6765\u81ea\u00a0<code>yaml<\/code>\u00a0\u6587\u4ef6\uff0c\u5b83\u96c6\u4e2d\u5b9a\u4e49\u4e86 Backbone\u3001Neck\u3001Head \u7684\u5177\u4f53\u7ed3\u6784\uff08\u5982\u5c42\u6570\u3001\u901a\u9053\u6570\u7b49\uff09\uff0c\u4f7f\u5f97\u4ee3\u7801\u66f4\u7075\u6d3b\uff0c\u65e0\u9700\u4fee\u6539\u4ee3\u7801\u5373\u53ef\u6539\u53d8\u6a21\u578b\u7ed3\u6784\u3002<\/li>\n\n\n\n<li><code>device<\/code>: \u6307\u5b9a\u6a21\u578b\u52a0\u8f7d\u5230 GPU \u8fd8\u662f CPU\u3002<\/li>\n\n\n\n<li><code>num_classes<\/code>: \u51b3\u5b9a\u4e86\u5206\u7c7b\u8f93\u51fa\u7684\u7ef4\u5ea6\u3002<\/li>\n\n\n\n<li><code>conf_thresh<\/code>\u00a0&amp;\u00a0<code>nms_thresh<\/code>: \u540e\u5904\u7406\u53c2\u6570\uff0c\u5728\u6d4b\u8bd5\/\u63a8\u7406\u9636\u6bb5\u4f7f\u7528\u3002<\/li>\n\n\n\n<li><code>trainable<\/code>: \u63a7\u5236\u6a21\u578b\u5904\u4e8e\u8bad\u7ec3\u6a21\u5f0f\u8fd8\u662f\u8bc4\u4f30\u6a21\u5f0f\uff08\u5f71\u54cd Batch Normalization \u548c Dropout \u7b49\u5c42\u7684\u884c\u4e3a\uff09\u3002<\/li>\n\n\n\n<li><code>stride=32<\/code>: \u8868\u793a\u4ece\u8f93\u5165\u56fe\u50cf\u5230\u6700\u7ec8\u7279\u5f81\u56fe\u7684\u603b\u4f53\u4e0b\u91c7\u6837\u500d\u6570\u3002\u4f8b\u5982\uff0c\u8f93\u5165\u00a0<code>416x416<\/code>\uff0c\u8f93\u51fa\u7279\u5f81\u56fe\u5c3a\u5bf8\u4e3a\u00a0<code>13x13<\/code>\u00a0(<code>416\/32=13<\/code>)\u3002\u8fd9\u662f\u4e00\u4e2a\u5173\u952e\u53c2\u6570\uff0c\u7528\u4e8e\u5c06\u7279\u5f81\u56fe\u4e0a\u7684\u5750\u6807\u6620\u5c04\u56de\u539f\u56fe\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u7f51\u7edc\u7ec4\u4ef6\u5b9a\u4e49 (Backbone, Neck, Head, Pred)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Backbone\u7f51\u7edc &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># To do\uff1a\u6784\u5efa\u6211\u4eec\u7684backbone\u7f51\u7edc<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># self.backbone<\/em><br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Neck\u7f51\u7edc &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># To do\uff1a\u6784\u5efa\u6211\u4eec\u7684neck\u7f51\u7edc<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># self.neck<\/em><br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Head\u7f51\u7edc &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># To do\uff1a\u6784\u5efa\u6211\u4eec\u7684head\u7f51\u7edc<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># self.head<\/em><br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; \u9884\u6d4b\u5c42 &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># To do\uff1a\u6784\u5efa\u6211\u4eec\u7684\u9884\u6d4b\u5c42<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># self.pred<\/em><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u76ee\u7684<\/strong>: \u58f0\u660e\u6a21\u578b\u7684\u6838\u5fc3\u67b6\u6784\u6a21\u5757\u3002\u8fd9\u4e9b\u90e8\u5206\u662f\u5f85\u5b9e\u73b0\u7684\uff0c\u6839\u636e\u535a\u5ba2\u5185\u5bb9\uff0c\u5b83\u4eec\u5c06\u88ab\u5177\u4f53\u6784\u5efa\uff1a\n<ul class=\"wp-block-list\">\n<li><code>self.backbone<\/code>: \u7279\u5f81\u63d0\u53d6\u4e3b\u5e72\u7f51\u7edc (\u5982 ResNet, CSPDarknet)\u3002<\/li>\n\n\n\n<li><code>self.neck<\/code>: \u7279\u5f81\u91d1\u5b57\u5854\u6216\u878d\u5408\u7f51\u7edc (\u5982 FPN, PAN)\u3002<\/li>\n\n\n\n<li><code>self.head<\/code>: \u68c0\u6d4b\u5934\uff0c\u901a\u5e38\u7531\u51e0\u4e2a\u5377\u79ef\u5c42\u7ec4\u6210\uff0c\u8d1f\u8d23\u8f93\u51fa\u6700\u7ec8\u7684\u9884\u6d4b tensor\u3002<\/li>\n\n\n\n<li><code>self.pred<\/code>: \u53ef\u80fd\u662f\u4e00\u4e2a\u6700\u7ec8\u7684\u5377\u79ef\u5c42\uff0c\u5c06\u00a0<code>head<\/code>\u00a0\u7684\u8f93\u51fa\u901a\u9053\u6570\u8f6c\u6362\u4e3a\u6a21\u578b\u6700\u7ec8\u9700\u8981\u7684\u7ef4\u5ea6\u00a0<code>S x S x (B*5 + C)<\/code>\u3002\u6709\u65f6\u8fd9\u4e2a\u5c42\u4f1a\u88ab\u5408\u5e76\u5230\u00a0<code>head<\/code>\u00a0\u4e2d\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"3\" class=\"wp-block-list\">\n<li>\u7f51\u683c\u751f\u6210 (<code>create_grid<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp; &nbsp;&nbsp;def&nbsp;create_grid(self, fmp_size):<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># To do\uff1a<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u751f\u6210\u4e00\u4e2atensor\uff1agrid_xy\uff0c\u6bcf\u4e2a\u4f4d\u7f6e\u7684\u5143\u7d20\u662f\u7f51\u683c\u7684\u5750\u6807\uff0c<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u8fd9\u4e00tensor\u5c06\u5728\u83b7\u5f97\u8fb9\u754c\u6846\u53c2\u6570\u7684\u65f6\u5019\u4f1a\u7528\u5230\u3002<\/em><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u76ee\u7684<\/strong>: \u4e3a\u7279\u5f81\u56fe\u4e0a\u7684\u6bcf\u4e2a\u5355\u5143\u683c\u751f\u6210\u5176\u5de6\u4e0a\u89d2\u7684\u5750\u6807\u7f51\u683c\u3002<\/li>\n\n\n\n<li><strong>\u5de5\u4f5c\u539f\u7406<\/strong>:\n<ul class=\"wp-block-list\">\n<li>\u8f93\u5165\u00a0<code>fmp_size<\/code>\u00a0\u662f\u7279\u5f81\u56fe\u7684\u9ad8\u5ea6\u00a0<code>H<\/code>\u00a0\u548c\u5bbd\u5ea6\u00a0<code>W<\/code>\u3002<\/li>\n\n\n\n<li>\u5b83\u4f1a\u521b\u5efa\u4e00\u4e2a\u5f62\u72b6\u4e3a\u00a0<code>(H, W, 2)<\/code>\u00a0\u7684\u5f20\u91cf\u3002<\/li>\n\n\n\n<li>\u8fd9\u4e2a\u5f20\u91cf\u5728\u00a0<code>(i, j)<\/code>\u00a0\u4f4d\u7f6e\u7684\u503c\u662f\u00a0<code>(j, i)<\/code>\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u00a0<code>13x13<\/code>\u00a0\u7684\u7279\u5f81\u56fe\uff0c\u4f4d\u7f6e\u00a0<code>(0, 0)<\/code>\u00a0\u7684\u503c\u4e3a\u00a0<code>(0, 0)<\/code>\uff0c\u4f4d\u7f6e\u00a0<code>(0, 1)<\/code>\u00a0\u7684\u503c\u4e3a\u00a0<code>(1, 0)<\/code>\uff0c...\uff0c\u4f4d\u7f6e\u00a0<code>(12, 12)<\/code>\u00a0\u7684\u503c\u4e3a\u00a0<code>(12, 12)<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u4e3a\u4ec0\u4e48\u9700\u8981\u5b83\uff1f<\/strong>\u00a0YOLO \u9884\u6d4b\u7684\u662f\u8fb9\u754c\u6846\u4e2d\u5fc3\u76f8\u5bf9\u4e8e\u5176\u6240\u5728\u7f51\u683c\u5de6\u4e0a\u89d2\u7684\u504f\u79fb\u91cf (<code>tx, ty<\/code>)\u3002\u5728\u89e3\u7801\u65f6\uff0c\u9700\u8981\u52a0\u4e0a\u7f51\u683c\u7684\u5de6\u4e0a\u89d2\u5750\u6807\uff08\u5c31\u662f\u8fd9\u4e2a\u51fd\u6570\u751f\u6210\u7684\uff09\u5e76\u5f52\u4e00\u5316\uff0c\u624d\u80fd\u5f97\u5230\u6846\u5728\u539f\u59cb\u56fe\u50cf\u4e0a\u7684\u7edd\u5bf9\u5750\u6807\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"4\" class=\"wp-block-list\">\n<li>\u8fb9\u754c\u6846\u89e3\u7801 (<code>decode_boxes<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp; &nbsp;&nbsp;def&nbsp;decode_boxes(self, pred, fmp_size):<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u5c06\u7f51\u7edc\u8f93\u51fa\u7684tx,ty,tw,th\u56db\u4e2a\u91cf\u8f6c\u6362\u6210bbox\u7684(x1,y1),(x2,y2)<\/em><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u76ee\u7684<\/strong>: \u5c06\u7f51\u7edc\u8f93\u51fa\u7684\u539f\u59cb\u9884\u6d4b\u503c\u8f6c\u6362\u4e3a\u4eba\u53ef\u8bfb\u7684\u8fb9\u754c\u6846\u5750\u6807\u3002<\/li>\n\n\n\n<li><strong>\u8f93\u5165<\/strong>:\n<ul class=\"wp-block-list\">\n<li><code>pred<\/code>: \u7f51\u7edc\u7684\u539f\u59cb\u8f93\u51fa\u5f20\u91cf\uff0c\u5f62\u72b6\u901a\u5e38\u4e3a\u00a0<code>(B, H, W, B*(5+C))<\/code>\u00a0\u6216\u00a0<code>(B, B*(5+C), H, W)<\/code>\u3002<\/li>\n\n\n\n<li><code>fmp_size<\/code>: \u7279\u5f81\u56fe\u5c3a\u5bf8\u00a0<code>(H, W)<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u5904\u7406\u8fc7\u7a0b<\/strong>\u00a0(\u4ee5 YOLOv1 \u4e3a\u4f8b):\n<ol class=\"wp-block-list\">\n<li>\u4ece\u00a0<code>pred<\/code>\u00a0\u4e2d\u5207\u7247\u51fa\u00a0<code>tx, ty, tw, th<\/code>\u00a0\u548c\u7f6e\u4fe1\u5ea6\u00a0<code>conf<\/code>\u00a0\u4ee5\u53ca\u7c7b\u522b\u6982\u7387\u00a0<code>cls_pred<\/code>\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528\u00a0<code>sigmoid<\/code>\u00a0\u51fd\u6570\u5904\u7406\u00a0<code>tx, ty<\/code>\uff0c\u5c06\u5b83\u4eec\u9650\u5236\u5728\u00a0<code>(0, 1)<\/code>\u00a0\u8303\u56f4\u5185\uff0c\u8868\u793a\u4e2d\u5fc3\u70b9\u5728\u7f51\u683c\u5185\u7684\u504f\u79fb\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528\u00a0<code>create_grid<\/code>\u00a0\u751f\u6210\u7684\u7f51\u683c\u5750\u6807\u3002\u89e3\u7801\u540e\u7684\u4e2d\u5fc3\u70b9\u00a0<code>bx = sigmoid(tx) + grid_x<\/code>\uff0c<code>by = sigmoid(ty) + grid_y<\/code>\u3002<\/li>\n\n\n\n<li>\u5904\u7406\u00a0<code>tw, th<\/code>\u3002\u539f\u59cb YOLOv1 \u662f\u76f4\u63a5\u9884\u6d4b\u5bbd\u9ad8\uff0c\u4f46\u73b0\u4ee3\u5b9e\u73b0\u5e38\u7528\u00a0<code>exp(tw) * anchor_w<\/code>\u00a0\u6216\u7c7b\u4f3c\u65b9\u5f0f\u3002\u8fd9\u91cc\u9700\u8981\u770b\u4f5c\u8005\u5177\u4f53\u5982\u4f55\u5b9e\u73b0\u3002\u6700\u7ec8\u5f97\u5230\u00a0<code>bw<\/code>\u00a0\u548c\u00a0<code>bh<\/code>\u3002<\/li>\n\n\n\n<li>\u5c06\u6240\u6709\u5750\u6807\u00a0<code>(bx, by, bw, bh)<\/code>\u00a0\u4e58\u4ee5\u00a0<code>stride<\/code>\u00a0(\u8fd9\u91cc\u662f 32) \u6765\u5c06\u5b83\u4eec\u4ece\u7279\u5f81\u56fe\u5c3a\u5ea6\u6620\u5c04\u56de\u539f\u56fe\u5c3a\u5ea6\u3002<\/li>\n\n\n\n<li>\u6700\u540e\u8ba1\u7b97\u8fb9\u754c\u6846\u7684\u5de6\u4e0a\u89d2\u00a0<code>(x1, y1)<\/code>\u00a0\u548c\u53f3\u4e0b\u89d2\u00a0<code>(x2, y2)<\/code>\u00a0\u5750\u6807\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"5\" class=\"wp-block-list\">\n<li>\u540e\u5904\u7406 (<code>postprocess<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp; &nbsp;&nbsp;def&nbsp;postprocess(self, bboxes, scores):<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u540e\u5904\u7406\u4ee3\u7801\uff0c\u5305\u62ec\u9608\u503c\u7b5b\u9009\u548c\u975e\u6781\u5927\u503c\u6291\u5236<\/em><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u76ee\u7684<\/strong>: \u5bf9\u6a21\u578b\u8f93\u51fa\u7684\u6240\u6709\u9884\u6d4b\u6846\u8fdb\u884c\u7b5b\u9009\uff0c\u5f97\u5230\u6700\u7ec8\u5e72\u51c0\u3001\u53ef\u9760\u7684\u68c0\u6d4b\u7ed3\u679c\u3002<strong>\u4ec5\u5728\u63a8\u7406\u9636\u6bb5\u4f7f\u7528<\/strong>\u3002<\/li>\n\n\n\n<li><strong>\u5904\u7406\u6b65\u9aa4<\/strong>:<ul><li>\u6309\u7c7b\u522b\u5faa\u73af\uff08\u9664\u975e\u00a0<code>nms_class_agnostic=True<\/code>\uff09\u3002<\/li><li>\u5bf9\u6bcf\u4e2a\u7c7b\u522b\uff0c\u6839\u636e\u7f6e\u4fe1\u5ea6\u5206\u6570\u8fdb\u884c\u6392\u5e8f\u3002<\/li><li>\u904d\u5386\u6392\u5e8f\u540e\u7684\u6846\uff0c\u79fb\u9664\u6240\u6709\u4e0e\u5f53\u524d\u6700\u9ad8\u5206\u6846\u7684 IoU \u8d85\u8fc7\u00a0<code>self.nms_thresh<\/code>\u00a0\u7684\u5176\u4ed6\u6846\u3002<\/li><\/ul>\n<ol class=\"wp-block-list\">\n<li><strong>\u7f6e\u4fe1\u5ea6\u9608\u503c\u8fc7\u6ee4<\/strong>: \u5254\u9664\u7f6e\u4fe1\u5ea6\u00a0<code>conf<\/code>\u00a0\u4f4e\u4e8e\u00a0<code>self.conf_thresh<\/code>\u00a0\u7684\u9884\u6d4b\u6846\u3002<\/li>\n\n\n\n<li><strong>\u975e\u6781\u5927\u503c\u6291\u5236 (NMS)<\/strong>:<\/li>\n\n\n\n<li>\u8fd4\u56de\u7ecf\u8fc7\u7b5b\u9009\u540e\u4fdd\u7559\u7684\u8fb9\u754c\u6846\u3001\u5206\u6570\u548c\u7c7b\u522b\u6807\u7b7e\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"6\" class=\"wp-block-list\">\n<li>\u63a8\u7406\u65b9\u6cd5 (<code>inference<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp; &nbsp; @torch.no_grad()<br>&nbsp; &nbsp;&nbsp;def&nbsp;inference(self, x):<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u6d4b\u8bd5\u9636\u6bb5\u7684\u524d\u5411\u63a8\u7406\u4ee3\u7801<\/em><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u76ee\u7684<\/strong>: \u6a21\u578b\u90e8\u7f72\u6216\u6d4b\u8bd5\u65f6\u4f7f\u7528\u7684\u5b8c\u6574\u524d\u5411\u4f20\u64ad\u6d41\u7a0b\u3002<\/li>\n\n\n\n<li><code>@torch.no_grad()<\/code>: \u88c5\u9970\u5668\uff0c\u5173\u95ed PyTorch \u7684\u68af\u5ea6\u8ba1\u7b97\uff0c\u5927\u5e45\u51cf\u5c11\u5185\u5b58\u6d88\u8017\u5e76\u52a0\u901f\u8ba1\u7b97\u3002<\/li>\n\n\n\n<li><strong>\u6d41\u7a0b<\/strong>:\n<ol class=\"wp-block-list\">\n<li>\u901a\u8fc7\u00a0<code>self.backbone<\/code>\u3001<code>self.neck<\/code>\u3001<code>self.head<\/code>\u00a0\u8fdb\u884c\u524d\u5411\u4f20\u64ad\uff0c\u5f97\u5230\u539f\u59cb\u9884\u6d4b\u00a0<code>pred<\/code>\u3002<\/li>\n\n\n\n<li>\u8c03\u7528\u00a0<code>self.decode_boxes(pred, ...)<\/code>\u00a0\u5f97\u5230\u89e3\u7801\u540e\u7684\u8fb9\u754c\u6846\u5750\u6807\u548c\u5206\u6570\u3002<\/li>\n\n\n\n<li>\u8c03\u7528\u00a0<code>self.postprocess(bboxes, scores)<\/code>\u00a0\u8fdb\u884c\u540e\u5904\u7406\uff0c\u5f97\u5230\u6700\u7ec8\u68c0\u6d4b\u7ed3\u679c\u3002<\/li>\n\n\n\n<li>\u8fd4\u56de\u7ed3\u679c\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"7\" class=\"wp-block-list\">\n<li>\u524d\u5411\u4f20\u64ad\u65b9\u6cd5 (<code>forward<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp; &nbsp;&nbsp;def&nbsp;forward(self, x, target=None):<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u8bad\u7ec3\u9636\u6bb5\u7684\u524d\u5411\u63a8\u7406\u4ee3\u7801<\/em><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u76ee\u7684<\/strong>: \u8bad\u7ec3\u548c\u9a8c\u8bc1\u6a21\u5f0f\u4e0b\u7684\u524d\u5411\u4f20\u64ad\u3002\u8fd9\u662f PyTorch\u00a0<code>nn.Module<\/code>\u00a0\u7684\u6838\u5fc3\u65b9\u6cd5\u3002<\/li>\n\n\n\n<li><strong>\u8f93\u5165<\/strong>:\n<ul class=\"wp-block-list\">\n<li><code>x<\/code>: \u8f93\u5165\u56fe\u50cf\u6279\u6b21\u3002<\/li>\n\n\n\n<li><code>target<\/code>: (\u4ec5\u5728\u8bad\u7ec3\u65f6\u63d0\u4f9b) \u771f\u5b9e\u6807\u7b7e\uff08GT\uff09\uff0c\u7528\u4e8e\u8ba1\u7b97\u635f\u5931\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u884c\u4e3a<\/strong>:<ul><li><strong>\u5982\u679c\u00a0<code>target<\/code>\u00a0\u4e0d\u662f\u00a0<code>None<\/code>\u00a0(\u8bad\u7ec3\u6a21\u5f0f)<\/strong>:<\/li><li><strong>\u5982\u679c\u00a0<code>target<\/code>\u00a0\u662f\u00a0<code>None<\/code>\u00a0(\u9a8c\u8bc1\u6a21\u5f0f\u6216\u7b80\u5355\u63a8\u7406)<\/strong>:<\/li><\/ul><ol><li>\u8fdb\u884c\u524d\u5411\u4f20\u64ad\u5f97\u5230\u00a0<code>pred<\/code>\u3002<\/li><li>\uff08\u53ef\u9009\uff09\u53ef\u80fd\u8fdb\u884c\u89e3\u7801\u548c\u540e\u5904\u7406\uff0c\u6216\u8005\u76f4\u63a5\u8fd4\u56de\u00a0<code>pred<\/code>\u00a0\u4f9b\u5916\u90e8\u8ba1\u7b97\u6307\u6807\uff08\u5982mAP\uff09\u3002<\/li><li>\u8fd4\u56de\u9884\u6d4b\u7ed3\u679c\u3002<\/li><\/ol>\n<ol class=\"wp-block-list\">\n<li>\u8fdb\u884c\u524d\u5411\u4f20\u64ad\u5f97\u5230\u00a0<code>pred<\/code>\u3002<\/li>\n\n\n\n<li>\u8ba1\u7b97\u635f\u5931\u51fd\u6570\uff08\u4f8b\u5982 YOLO \u7684\u5750\u6807\u635f\u5931\u3001\u7f6e\u4fe1\u5ea6\u635f\u5931\u3001\u5206\u7c7b\u635f\u5931\uff09\u3002<\/li>\n\n\n\n<li>\u8fd4\u56de\u635f\u5931\u503c\u00a0<code>loss<\/code>\u00a0\u548c\u4e00\u4e2a\u53ef\u80fd\u5305\u542b\u635f\u5931\u660e\u7ec6\u7684\u5b57\u5178\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u603b\u7ed3<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u662f\u4e00\u4e2a\u9ad8\u5ea6\u6a21\u5757\u5316\u3001\u7ed3\u6784\u6e05\u6670\u7684 YOLOv1 \u5b9e\u73b0\u6846\u67b6\u3002\u5b83\u4e25\u683c\u533a\u5206\u4e86\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6a21\u578b\u6784\u5efa<\/strong>\u00a0(<code>__init__<\/code>\u00a0\u4e2d\u7684\u7ec4\u4ef6\u5b9a\u4e49)<\/li>\n\n\n\n<li><strong>\u6838\u5fc3\u8ba1\u7b97<\/strong>\u00a0(<code>forward<\/code>\u00a0\u548c\u00a0<code>inference<\/code>)<\/li>\n\n\n\n<li><strong>\u89e3\u7801\u903b\u8f91<\/strong>\u00a0(<code>decode_boxes<\/code>,\u00a0<code>create_grid<\/code>)<\/li>\n\n\n\n<li><strong>\u540e\u5904\u7406<\/strong>\u00a0(<code>postprocess<\/code>)<\/li>\n<\/ul>\n\n\n\n<p>\u8fd9\u79cd\u8bbe\u8ba1\u4f7f\u5f97\u4ee3\u7801\u6613\u4e8e\u9605\u8bfb\u3001\u8c03\u8bd5\u548c\u6269\u5c55\u3002\u5f85\u5b9e\u73b0\u7684&nbsp;<code>Backbone<\/code>,&nbsp;<code>Neck<\/code>,&nbsp;<code>Head<\/code>&nbsp;\u90e8\u5206\u5c06\u4f1a\u6839\u636e\u4f20\u5165\u7684&nbsp;<code>cfg<\/code>&nbsp;\u914d\u7f6e\u6587\u4ef6\u6765\u5177\u4f53\u5b9e\u4f8b\u5316\uff0c\u8fd9\u63d0\u4f9b\u4e86\u6781\u5927\u7684\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u8f7b\u677e\u5c1d\u8bd5\u4e0d\u540c\u7684\u7f51\u7edc\u67b6\u6784\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5728\u6df1\u5165\u5c55\u5f00\u7684\u65f6\u5019\uff0c\u5148\u770b\u770b\u8fd9\u4e2a\u90e8\u5206\u662f\u600e\u4e48\u5de5\u4f5c\u7684\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u6211\u4eec\u628a\u8fd9\u4e2a YOLOv1 \u7684\u4ee3\u7801\u60f3\u8c61\u6210\u4e00\u4e2a&nbsp;<strong>\u667a\u80fd\u5de5\u5382\u7684\u6d41\u6c34\u7ebf<\/strong>\uff0c\u7528\u6700\u901a\u4fd7\u6613\u61c2\u7684\u65b9\u5f0f\u89e3\u91ca\u5b83\u7684\u5de5\u4f5c\u6d41\u7a0b\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>YOLOv1 \u6a21\u578b\u5de5\u4f5c\u6d41\u7a0b\uff08\u5de5\u5382\u6d41\u6c34\u7ebf\u7248\uff09<\/p>\n<\/blockquote>\n\n\n\n<p>\u6574\u4e2a\u6a21\u578b\u5c31\u50cf\u4e00\u5bb6\u4e13\u95e8\u4ece\u56fe\u7247\u4e2d<strong>\u627e\u51fa\u7269\u54c1\u5e76\u753b\u6846<\/strong>\u7684\u667a\u80fd\u5de5\u5382\u3002\u5b83\u7684\u5de5\u4f5c\u5206\u4e3a\u4e24\u5927\u6a21\u5f0f\uff1a<strong>\u8bad\u7ec3\u6a21\u5f0f<\/strong>\uff08\u5de5\u5382\u5b66\u4e60\u548c\u81ea\u6211\u6539\u8fdb\uff09\u548c<strong>\u63a8\u7406\u6a21\u5f0f<\/strong>\uff08\u5de5\u5382\u6b63\u5f0f\u5e72\u6d3b\uff09\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u4e00\u3001\u5de5\u5382\u7684\u84dd\u56fe\u4e0e\u7b79\u5907 (<code>__init__<\/code>&nbsp;\u51fd\u6570)<\/p>\n<\/blockquote>\n\n\n\n<p>\u5728\u5de5\u5382\u5f00\u5de5\u524d\uff0c\u9700\u8981\u5148\u8bbe\u8ba1\u597d\u84dd\u56fe\u548c\u51c6\u5907\u597d\u6240\u6709\u8bbe\u5907\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u786e\u5b9a\u5de5\u5382\u53c2\u6570<\/strong>\uff1a\u6536\u5230\u603b\u90e8\u53d1\u6765\u7684<code>cfg<\/code>\u914d\u7f6e\u6587\u4ef6\uff0c\u91cc\u9762\u89c4\u5b9a\u4e86\u8981\u7528\u4ec0\u4e48\u673a\u5668\u3001\u6d41\u6c34\u7ebf\u591a\u5bbd\u7b49\u3002\u540c\u65f6\u786e\u5b9a\u8981\u68c0\u6d4b\u7684\u7269\u54c1\u79cd\u7c7b\u6570(<code>num_classes<\/code>)\u3001\u5408\u683c\u5206\u6570(<code>conf_thresh<\/code>)\u3001\u4ee5\u53ca\u5224\u65ad\u4e24\u4e2a\u6846\u662f\u4e0d\u662f\u540c\u4e00\u4e2a\u7269\u7684\u6807\u51c6(<code>nms_thresh<\/code>)\u7b49\u3002<\/li>\n\n\n\n<li><strong>\u7ec4\u88c5\u4e09\u6761\u6838\u5fc3\u6d41\u6c34\u7ebf<\/strong>\uff1a<ul><li><code>(x, y, w, h)<\/code>\uff1a\u4e00\u4e2a\u8fb9\u754c\u6846\u7684\u521d\u6b65\u4f4d\u7f6e\u548c\u5927\u5c0f\u3002<\/li><li><code>confidence<\/code>\uff1a\u8fd9\u4e2a\u6846\u91cc\u201c\u6709\u7269\u4f53\u201d\u7684\u628a\u63e1\u6709\u591a\u5927\u3002<\/li><li><code>class_scores<\/code>\uff1a\u5982\u679c\u8fd9\u91cc\u6709\u7269\u4f53\uff0c\u5b83\u5206\u522b\u662f\u5404\u4e2a\u7c7b\u522b\u7684\u6982\u7387\u662f\u591a\u5c11\u3002<\/li><\/ul>\n<ul class=\"wp-block-list\">\n<li><strong>Backbone\uff08\u4e3b\u5e72\u7279\u5f81\u63d0\u53d6\u7ebf\uff09<\/strong>\uff1a\u5c31\u50cf\u5de5\u5382\u7684<strong>\u773c\u775b\u548c\u521d\u7ea7\u7b5b\u9009\u90e8\u95e8<\/strong>\u3002\u5b83\u7684\u4efb\u52a1\u662f\u5bf9\u8f93\u5165\u7684\u539f\u6750\u6599\uff08\u56fe\u7247\uff09\u8fdb\u884c\u5feb\u901f\u626b\u63cf\uff0c\u63d0\u53d6\u51fa\u56fe\u7247\u91cc\u6240\u6709\u6709\u7528\u7684\u57fa\u672c\u7279\u5f81\uff08\u5982\u8fb9\u7f18\u3001\u989c\u8272\u5757\u3001\u7eb9\u7406\u7b49\uff09\u3002\u8fd9\u6761\u7ebf\u901a\u5e38\u7531\u4e00\u4e9b\u5f3a\u5927\u7684\u3001\u73b0\u6210\u7684\u7f51\u7edc\uff08\u5982 ResNet\uff09\u62c5\u4efb\u3002<\/li>\n\n\n\n<li><strong>Neck\uff08\u7279\u5f81\u878d\u5408\u7ebf\uff09<\/strong>\uff1a\u5c31\u50cf\u5de5\u5382\u7684<strong>\u4fe1\u606f\u6574\u5408\u90e8\u95e8<\/strong>\u3002\u5b83\u63a5\u6536 Backbone \u9001\u6765\u7684\u4e0d\u540c\u7c97\u7ec6\uff08\u4e0d\u540c\u5c3a\u5ea6\uff09\u7684\u7279\u5f81\u4fe1\u606f\u3002\u5b83\u7684\u4efb\u52a1\u662f\u628a\u8fd9\u4e9b\u4fe1\u606f\u5de7\u5999\u5730\u878d\u5408\u8d77\u6765\uff0c\u786e\u4fdd\u65e0\u8bba\u662f\u5927\u7269\u4f53\uff08\u7528\u7c97\u7565\u7279\u5f81\uff09\u8fd8\u662f\u5c0f\u7269\u4f53\uff08\u7528\u7cbe\u7ec6\u7279\u5f81\uff09\u90fd\u4e0d\u4f1a\u88ab\u9057\u6f0f\u3002<strong>\u8fd9\u662f\u5bf9\u539f\u59cb YOLOv1 \u7684\u4e00\u4e2a\u91cd\u8981\u5347\u7ea7\u3002<\/strong><\/li>\n\n\n\n<li><strong>Head\uff08\u68c0\u6d4b\u5934\uff09<\/strong>\uff1a\u5c31\u50cf\u5de5\u5382\u7684<strong>\u6700\u7ec8\u51b3\u7b56\u5927\u8111<\/strong>\u3002\u5b83\u63a5\u6536 Neck \u9001\u6765\u7684\u878d\u5408\u597d\u7684\u9ad8\u7ea7\u7279\u5f81\u4fe1\u606f\uff0c\u7136\u540e\u76f4\u63a5\u5728\u7279\u5f81\u56fe\u7684\u6bcf\u4e00\u4e2a\u4f4d\u7f6e\u4e0a\uff0c\u9884\u6d4b\u51fa\uff1a<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u4e8c\u3001\u5de5\u5382\u7684\u6b63\u5f0f\u5de5\u4f5c\u6d41\u7a0b<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u573a\u666f\u4e00\uff1a\u8bad\u7ec3\u6a21\u5f0f (<code>forward<\/code>&nbsp;\u51fd\u6570) - \u5de5\u5382\u5b66\u5f92\u671f<\/p>\n<\/blockquote>\n\n\n\n<p><strong>\u76ee\u6807<\/strong>\uff1a\u8ba9\u5de5\u5382\u5b66\u4f1a\u5982\u4f55\u6b63\u786e\u627e\u4e1c\u897f\u3002\u9700\u8981\u5e08\u5085\u63d0\u4f9b\u6807\u51c6\u7b54\u6848\uff08<code>target<\/code>\uff09\u6765\u7ea0\u6b63\u5b83\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6d41\u6c34\u7ebf\u52a0\u5de5<\/strong>\uff1a\u56fe\u7247\u9001\u5165 Backbone -> Neck -> Head\uff0c\u6700\u7ec8\u5f97\u5230\u4e00\u5806\u201c\u539f\u59cb\u9884\u6d4b\u201d\uff08<code>pred<\/code>\uff09\u3002\u4f46\u8fd9\u4e9b\u9884\u6d4b\u4e00\u5f00\u59cb\u5168\u662f\u9519\u7684\u3002<\/li>\n\n\n\n<li><strong>\u5e08\u5085\u7ea0\u9519<\/strong>\uff1a\u5de5\u5382\u7684\u201c\u8001\u5e08\u5085\u201d\uff08\u635f\u5931\u51fd\u6570 Loss Function\uff09\u4f1a\u62ff\u7740\u6807\u51c6\u7b54\u6848\uff08<code>target<\/code>\uff0c\u56fe\u7247\u4e2d\u7269\u4f53\u6846\u7684\u771f\u5b9e\u4f4d\u7f6e\u548c\u7c7b\u522b\uff09\u6765\u5bf9\u6bd4\u5de5\u5382\u7684\u539f\u59cb\u9884\u6d4b\uff08<code>pred<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>\u8ba1\u7b97\u635f\u5931<\/strong>\uff1a\u8001\u5e08\u5085\u4f1a\u4e25\u5389\u5730\u6307\u51fa\uff1a\u201c\u4f60\u8fd9\u4e2a\u6846\u7684\u4f4d\u7f6e\u504f\u4e86 5 \u4e2a\u50cf\u7d20\uff01\u201d\u3001\u201c\u4f60\u628a\u8fd9\u4e2a\u72d7 confidently \u8ba4\u6210\u4e86\u732b\uff0c\u5927\u9519\u7279\u9519\uff01\u201d\u3002\u6240\u6709\u8fd9\u4e9b\u9519\u8bef\u90fd\u88ab\u91cf\u5316\u6210\u4e00\u4e2a\u6570\u503c\uff0c\u53eb<strong>\u635f\u5931\uff08Loss\uff09<\/strong>\u3002<\/li>\n\n\n\n<li><strong>\u81ea\u6211\u6539\u8fdb<\/strong>\uff1a\u5de5\u5382\u6839\u636e\u8fd9\u4e2a\u635f\u5931\u503c\uff0c\u53cd\u5411\u8c03\u6574\u4e09\u6761\u6d41\u6c34\u7ebf\uff08Backbone, Neck, Head\uff09\u4e0a\u6240\u6709\u673a\u5668\u7684\u87ba\u4e1d\uff08\u6a21\u578b\u53c2\u6570\uff09\uff0c\u4e89\u53d6\u4e0b\u6b21\u505a\u5f97\u66f4\u597d\u3002<\/li>\n\n\n\n<li><strong>\u8f93\u51fa<\/strong>\uff1a\u8fd9\u4e2a\u9636\u6bb5\u4e0d\u8f93\u51fa\u5177\u4f53\u7684\u6846\uff0c\u53ea\u8f93\u51fa\u4e00\u4e2a<strong>\u635f\u5931\u503c<\/strong>\uff0c\u544a\u8bc9\u5916\u754c\u201c\u6211\u8fd9\u6b21\u9519\u5f97\u6709\u591a\u79bb\u8c31\u201d\u3002<\/li>\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u573a\u666f\u4e8c\uff1a\u63a8\u7406\/\u68c0\u6d4b\u6a21\u5f0f (<code>inference<\/code>&nbsp;\u51fd\u6570) - \u5de5\u5382\u6b63\u5f0f\u5e72\u6d3b<\/p>\n<\/blockquote>\n\n\n\n<p><strong>\u76ee\u6807<\/strong>\uff1a\u7528\u8bad\u7ec3\u597d\u7684\u5de5\u5382\u5bf9\u65b0\u56fe\u7247\u8fdb\u884c\u68c0\u6d4b\u3002<strong>\u4e0d\u9700\u8981\u6807\u51c6\u7b54\u6848<\/strong>\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5173\u95ed\u5b66\u4e60\u5f00\u5173<\/strong>\uff1a<code>@torch.no_grad()<\/code>\u00a0\u8868\u793a\u5de5\u5382\u6309\u65e2\u5b9a\u6d41\u7a0b\u5de5\u4f5c\uff0c\u4e0d\u518d\u81ea\u6211\u8c03\u6574\u3002<\/li>\n\n\n\n<li><strong>\u6d41\u6c34\u7ebf\u52a0\u5de5<\/strong>\uff1a\u548c\u8bad\u7ec3\u6a21\u5f0f\u4e00\u6837\uff0c\u56fe\u7247\u9001\u5165 Backbone -> Neck -> Head\uff0c\u5f97\u5230\u201c\u539f\u59cb\u9884\u6d4b\u201d\uff08<code>pred<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>\u89e3\u7801 Decode (<code>decode_boxes<\/code>)<\/strong>\uff1a\u539f\u59cb\u9884\u6d4b\u662f\u4e00\u4e9b\u5f88\u96be\u61c2\u7684\u6570\u5b57\u3002\u89e3\u7801\u90e8\u95e8\u7684\u5de5\u4f5c\u5c31\u662f\u628a\u8fd9\u4e9b\u6570\u5b57\u7ffb\u8bd1\u6210\u4eba\u80fd\u770b\u61c2\u7684\u4fe1\u606f\u3002\n<ul class=\"wp-block-list\">\n<li>\u4ed6\u4eec\u6709\u4e00\u4e2a\u201c\u7f51\u683c\u5750\u6807\u7eb8\u201d\uff08<code>create_grid<\/code>\u00a0\u751f\u6210\u7684\u7f51\u683c\uff09\uff0c\u77e5\u9053\u6bcf\u4e2a\u9884\u6d4b\u5bf9\u5e94\u539f\u56fe\u4e0a\u7684\u54ea\u4e2a\u533a\u57df\u3002<\/li>\n\n\n\n<li>\u4ed6\u4eec\u628a\u9884\u6d4b\u7684<strong>\u504f\u79fb\u91cf<\/strong>\u548c<strong>\u7f29\u653e\u6bd4\u4f8b<\/strong>\u6362\u7b97\u6210\u56fe\u7247\u4e0a<strong>\u771f\u5b9e\u7684\u8fb9\u6846\u5750\u6807<\/strong><code>(x1, y1, x2, y2)<\/code>\u00a0\u548c\u771f\u5b9e\u7684<strong>\u7f6e\u4fe1\u5ea6\u5206\u6570<\/strong>\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u540e\u5904\u7406 Postprocess (<code>postprocess<\/code>)<\/strong>\uff1a\u89e3\u7801\u540e\u4f1a\u6709\u6210\u5343\u4e0a\u4e07\u4e2a\u6846\uff0c\u5f88\u591a\u662f\u91cd\u590d\u7684\u6216\u778e\u731c\u7684\u3002\u8d28\u68c0\u90e8\u95e8\u8d1f\u8d23\u7b5b\u9009\u3002\n<ul class=\"wp-block-list\">\n<li><strong>\u7b2c\u4e00\u8f6e\u7b5b\u9009\uff08\u7f6e\u4fe1\u5ea6\u9608\u503c\uff09<\/strong>\uff1a\u4fe1\u5fc3\u4e0d\u8db3\uff08\u5206\u6570\u4f4e\u4e8e\u00a0<code>conf_thresh<\/code>\uff09\u7684\u6846\uff0c\u76f4\u63a5\u6254\u6389\u3002<\/li>\n\n\n\n<li><strong>\u7b2c\u4e8c\u8f6e\u7b5b\u9009\uff08\u975e\u6781\u5927\u503c\u6291\u5236 NMS\uff09<\/strong>\uff1a\u5bf9\u4e8e\u5269\u4e0b\u7684\u6846\uff0c\u540c\u4e00\u4e2a\u7269\u4f53\u53ef\u80fd\u88ab\u597d\u51e0\u4e2a\u6846\u5708\u4e2d\u3002NMS \u4f1a\u627e\u51fa\u5206\u6570\u6700\u9ad8\u7684\u90a3\u4e2a\u6846\u4f5c\u4e3a\u4ee3\u8868\uff0c\u7136\u540e\u628a\u548c\u5b83\u91cd\u53e0\u5ea6\u592a\u9ad8\uff08IoU \u8d85\u8fc7\u00a0<code>nms_thresh<\/code>\uff09\u7684\u5176\u4ed6\u6846\u90fd\u6254\u6389\uff0c\u4fdd\u8bc1\u4e00\u4e2a\u7269\u4f53\u53ea\u7559\u4e00\u4e2a\u6700\u51c6\u7684\u6846\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u51fa\u8d27<\/strong>\uff1a\u7ecf\u8fc7\u4ee5\u4e0a\u6240\u6709\u6b65\u9aa4\uff0c\u5de5\u5382\u6700\u7ec8\u8f93\u51fa\u4e00\u4efd<strong>\u6e05\u6d01\u7684\u68c0\u6d4b\u62a5\u544a<\/strong>\uff1a\u4e00\u7cfb\u5217\u753b\u597d\u7684\u6846\u3001\u6bcf\u4e2a\u6846\u662f\u4ec0\u4e48\u7269\u4f53\u3001\u4ee5\u53ca\u5de5\u5382\u5bf9\u8fd9\u4e2a\u5224\u65ad\u7684\u628a\u63e1\u6709\u591a\u5927\u3002<\/li>\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u603b\u7ed3<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u4e2a\u6d41\u7a0b\u53ef\u4ee5\u7b80\u5355\u5730\u6982\u62ec\u4e3a\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<p><strong>\u8bad\u7ec3\uff1a<\/strong><code>\u56fe\u7247<\/code>&nbsp;-&gt;&nbsp;<code>\u6d41\u6c34\u7ebf(Backbone-Neck-Head)<\/code>&nbsp;-&gt;&nbsp;<code>\u539f\u59cb\u9884\u6d4b<\/code>&nbsp;-&gt;&nbsp;<code>\u4e0e\u6b63\u786e\u7b54\u6848\u5bf9\u6bd4\u7b97\u635f\u5931<\/code>&nbsp;-&gt;&nbsp;<code>\u8c03\u6574\u53c2\u6570<\/code><\/p>\n\n\n\n<p><strong>\u63a8\u7406\uff1a<\/strong><code>\u56fe\u7247<\/code>&nbsp;-&gt;&nbsp;<code>\u6d41\u6c34\u7ebf<\/code>&nbsp;-&gt;&nbsp;<code>\u539f\u59cb\u9884\u6d4b<\/code>&nbsp;-&gt;&nbsp;<code>\u89e3\u7801\u6210\u771f\u5b9e\u6846<\/code>&nbsp;-&gt;&nbsp;<code>\u8fc7\u6ee4\u548c\u53bb\u91cd<\/code>&nbsp;-&gt;&nbsp;<code>\u6700\u7ec8\u68c0\u6d4b\u7ed3\u679c<\/code><\/p>\n\n\n\n<p>\u5e0c\u671b\u8fd9\u4e2a\u201c\u5de5\u5382\u6d41\u6c34\u7ebf\u201d\u7684\u6bd4\u55bb\u80fd\u8ba9\u4f60\u5bf9 YOLOv1 \u7684\u4ee3\u7801\u7ed3\u6784\u548c\u5de5\u4f5c\u539f\u7406\u6709\u4e00\u4e2a\u6e05\u6670\u76f4\u89c2\u7684\u7406\u89e3\uff01<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e00\u3001\u642d\u5efaYOLOv1<\/h1>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u4eec\u6765\u642d\u5efaYOLOv1\u7684\u7f51\u7edc\u7ed3\u6784\uff0c\u5305\u62ecBackbone\u7f51\u7edc\u3001Neck\u7f51\u7edc\u3001Detection head\u7f51\u7edc\u4ee5\u53ca\u6700\u540e\u7684\u9884\u6d4b\u5c42\u3002\u4e3a\u4e86\u80fd\u591f\u987a\u5229\u642d\u5efa\u7f51\u7edc\uff0c\u6211\u4eec\u9884\u5148\u5199\u597d\u4e86\u540e\u7eed\u4f1a\u7528\u5230\u7684YOLOv1\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5176\u5185\u5bb9\u5982\u4e0b\u65b9\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># RT-ODLab\/config\/model_config\/yolov1_config.py<br><br><br>yolov1_cfg = {<br>&nbsp; &nbsp; # input<br>&nbsp; &nbsp; 'trans_type': 'ssd',<br>&nbsp; &nbsp; 'multi_scale': &#91;0.5, 1.5],<br>&nbsp; &nbsp; # model<br>&nbsp; &nbsp; 'backbone': 'resnet18',<br>&nbsp; &nbsp; 'pretrained': True,<br>&nbsp; &nbsp; 'stride': 32, &nbsp;# P5<br>&nbsp; &nbsp; 'max_stride': 32,<br>&nbsp; &nbsp; # neck<br>&nbsp; &nbsp; 'neck': 'sppf',<br>&nbsp; &nbsp; 'expand_ratio': 0.5,<br>&nbsp; &nbsp; 'pooling_size': 5,<br>&nbsp; &nbsp; 'neck_act': 'lrelu',<br>&nbsp; &nbsp; 'neck_norm': 'BN',<br>&nbsp; &nbsp; 'neck_depthwise': False,<br>&nbsp; &nbsp; # head<br>&nbsp; &nbsp; 'head': 'decoupled_head',<br>&nbsp; &nbsp; 'head_act': 'lrelu',<br>&nbsp; &nbsp; 'head_norm': 'BN',<br>&nbsp; &nbsp; 'num_cls_head': 2,<br>&nbsp; &nbsp; 'num_reg_head': 2,<br>&nbsp; &nbsp; 'head_depthwise': False,<br>&nbsp; &nbsp; # loss weight<br>&nbsp; &nbsp; 'loss_obj_weight': 1.0,<br>&nbsp; &nbsp; 'loss_cls_weight': 1.0,<br>&nbsp; &nbsp; 'loss_box_weight': 5.0,<br>&nbsp; &nbsp; # training configuration<br>&nbsp; &nbsp; 'trainer_type': 'yolov8',<br>}<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6765\u5457<\/p>\n<\/blockquote>\n\n\n\n<p>\u6211\u4eec\u628a\u8fd9\u6bb5\u914d\u7f6e\u4ee3\u7801\u60f3\u8c61\u6210\u4e00\u4e2a&nbsp;<strong>\u5efa\u9020\u8d85\u7ea7\u89c6\u89c9AI\u673a\u5668\u4eba\u7684\u201c\u914d\u65b9\u201d\u6216\u201c\u84dd\u56fe\u201d<\/strong>\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u914d\u65b9\u8be6\u7ec6\u8bf4\u660e\u4e86\u8981\u7528\u4ec0\u4e48\u6750\u6599\u3001\u600e\u4e48\u7ec4\u88c5\u3001\u4ee5\u53ca\u5982\u4f55\u8bad\u7ec3\u8fd9\u4e2a\u673a\u5668\u4eba\uff0c\u8ba9\u5b83\u80fd\u5728\u56fe\u7247\u91cc\u53c8\u5feb\u53c8\u51c6\u5730\u627e\u5230\u76ee\u6807\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u914d\u65b9\u8be6\u89e3\uff08YOLOv1\u914d\u7f6e\u7248\uff09<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol class=\"wp-block-list\">\n<li>\u3010\u51c6\u5907\u539f\u6750\u6599\u3011- \u6570\u636e\u9884\u5904\u7406 (<code>trans_type<\/code>\u00a0&amp;\u00a0<code>multi_scale<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>'trans_type': 'ssd'<\/code>\n<ul class=\"wp-block-list\">\n<li><strong>\u901a\u4fd7\u89e3\u91ca<\/strong>\uff1a\u89c4\u5b9a\u7ed9\u56fe\u7247\u201c\u505a\u9884\u5904\u7406\u201d\u7684\u6d41\u6c34\u7ebf\u6807\u51c6\u3002\u8fd9\u91cc\u7528\u7684\u662f\u548c<strong>SSD\u7b97\u6cd5<\/strong>\u4e00\u6837\u7684\u6807\u51c6\u6d41\u7a0b\uff08\u6bd4\u5982\u8c03\u6574\u5927\u5c0f\u3001\u989c\u8272\u5fae\u8c03\u7b49\uff09\uff0c\u8fd9\u662f\u4e45\u7ecf\u8003\u9a8c\u7684\u65b9\u6848\uff0c\u7167\u505a\u5c31\u884c\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>'multi_scale': [0.5, 1.5]<\/code>\n<ul class=\"wp-block-list\">\n<li><strong>\u901a\u4fd7\u89e3\u91ca<\/strong>\uff1a\u7ed9\u673a\u5668\u4eba\u770b<strong>\u4e0d\u540c\u5c3a\u5bf8\u7684\u56fe\u7247<\/strong>\u6765\u8bad\u7ec3\u3002\u5c31\u50cf\u8ba9\u5b66\u751f\u4e0d\u4ec5\u8981\u505a\u6b63\u5e38\u5927\u5c0f\u7684\u8bd5\u5377\uff0c\u8fd8\u8981\u505a\u653e\u5927\u548c\u7f29\u5c0f\u7684\u8bd5\u5377\uff0c\u8fd9\u6837\u4ed6\u8003\u8bd5\u65f6\u4e0d\u7ba1\u9898\u76ee\u5b57\u4f53\u5927\u5c0f\u90fd\u80fd\u9002\u5e94\u3002<code>[0.5, 1.5]<\/code>\u00a0\u8868\u793a\u56fe\u7247\u4f1a\u968f\u673a\u7f29\u653e\u81f3\u539f\u5927\u5c0f\u76840.5\u500d\u52301.5\u500d\uff0c\u6781\u5927\u63d0\u5347\u673a\u5668\u4eba\u68c0\u6d4b\u4e0d\u540c\u5927\u5c0f\u7269\u4f53\u7684\u80fd\u529b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u3010\u642d\u5efa\u6838\u5fc3\u9aa8\u67b6\u3011- Backbone\u4e3b\u5e72\u7f51\u7edc (<code>backbone<\/code>\u00a0&amp;\u00a0<code>pretrained<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>'backbone': 'resnet18'<\/code>\n<ul class=\"wp-block-list\">\n<li><strong>\u901a\u4fd7\u89e3\u91ca<\/strong>\uff1a\u9009\u62e9\u673a\u5668\u4eba\u7684\u201c<strong>\u773c\u775b\u548c\u5927\u8111\u57fa\u7840<\/strong>\u201d\u3002\u8fd9\u91cc\u9009\u7528\u7684\u662f<strong>ResNet18<\/strong>\u8fd9\u4e2a\u6a21\u578b\u3002\u5b83\u662f\u4e00\u4e2a\u975e\u5e38\u9ad8\u6548\u4e14\u5f3a\u5927\u7684\u73b0\u6210\u6a21\u578b\uff0c\u5df2\u7ecf\u5728\u6570\u767e\u4e07\u5f20\u56fe\u7247\u4e0a\u5b66\u4e60\u8fc7\u5982\u4f55\u63d0\u53d6\u7279\u5f81\u3002\u5c31\u50cf\u7ed9\u673a\u5668\u4eba\u88c5\u4e0a\u4e86\u4e00\u4e2a\u7ecf\u9a8c\u4e30\u5bcc\u7684\u201c\u8001\u5175\u201d\u7684\u773c\u775b\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>'pretrained': True<\/code>\n<ul class=\"wp-block-list\">\n<li><strong>\u901a\u4fd7\u89e3\u91ca<\/strong>\uff1a<strong>\u4f7f\u7528\u201c\u9884\u8bad\u7ec3\u201d\u6743\u91cd<\/strong>\u3002\u610f\u601d\u662f\u4e0d\u662f\u4ece\u96f6\u5f00\u59cb\u8bad\u7ec3\u8fd9\u4e2a\u201c\u8001\u5175\u201d\u7684\u773c\u775b\uff0c\u800c\u662f\u76f4\u63a5\u7528\u5b83\u5df2\u7ecf\u5b66\u597d\u7684\u7ecf\u9a8c\u4f5c\u4e3a\u8d77\u70b9\uff0c\u7136\u540e\u9488\u5bf9\u6211\u4eec\u7279\u5b9a\u7684\u627e\u4efb\u52a1\u8fdb\u884c\u5fae\u8c03\u3002\u8fd9\u80fd\u8282\u7701\u5927\u91cf\u8bad\u7ec3\u65f6\u95f4\uff0c\u5e76\u4e14\u6548\u679c\u901a\u5e38\u66f4\u597d\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"3\" class=\"wp-block-list\">\n<li>\u3010\u7ec4\u88c5\u4fe1\u606f\u878d\u5408\u5c42\u3011- Neck\u9888\u90e8\u7f51\u7edc (<code>neck<\/code>\u00a0\u7b49\u4e00\u7cfb\u5217\u53c2\u6570)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/wxa.wxs.qq.com\/tmpl\/oc\/base_tmpl.html\n<\/div><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>'neck': 'sppf'<\/code>\n<ul class=\"wp-block-list\">\n<li><strong>\u901a\u4fd7\u89e3\u91ca<\/strong>\uff1a\u5728\u201c\u773c\u775b\u201d\u548c\u201c\u51b3\u7b56\u5927\u8111\u201d\u4e4b\u95f4\uff0c\u52a0\u4e00\u4e2a**\u201c\u4fe1\u606f\u6574\u5408\u4e2d\u53f0\u201d**\u3002<code>SPPF<\/code>\u662f\u4e00\u4e2a\u5f88\u5f3a\u5927\u7684\u6a21\u5757\uff0c\u5b83\u80fd\u628a\u201c\u773c\u775b\u201d\u770b\u5230\u7684\u4e0d\u540c\u5c3a\u5ea6\u7684\u4fe1\u606f\uff08\u5927\u7269\u4f53\u8f6e\u5ed3\u548c\u5c0f\u7269\u4f53\u7ec6\u8282\uff09\u878d\u5408\u5728\u4e00\u8d77\uff0c\u8fd9\u6837\u65e0\u8bba\u7269\u4f53\u5927\u5c0f\uff0c\u673a\u5668\u4eba\u90fd\u80fd\u770b\u6e05\u695a\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>'expand_ratio': 0.5<\/code>,\u00a0<code>'pooling_size': 5<\/code>...\n<ul class=\"wp-block-list\">\n<li><strong>\u901a\u4fd7\u89e3\u91ca<\/strong>\uff1a\u8fd9\u4e9b\u662f\u8fd9\u4e2a\u201c\u4fe1\u606f\u4e2d\u53f0\u201d\u7684<strong>\u5177\u4f53\u5de5\u7a0b\u8bbe\u8ba1\u53c2\u6570<\/strong>\u3002\u6bd4\u5982<code>pooling_size: 5<\/code>\u8868\u793a\u7528\u4e00\u4e2a5x5\u7684\u7a97\u53e3\u6765\u6c47\u805a\u4fe1\u606f\uff0c\u5c31\u50cf\u7528\u4e0d\u540c\u5927\u5c0f\u7684\u7b5b\u5b50\u6765\u7b5b\u9009\u4e0d\u540c\u9897\u7c92\u7684\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"4\" class=\"wp-block-list\">\n<li>\u3010\u5b89\u88c5\u51b3\u7b56\u5927\u8111\u3011- Head\u5934\u90e8\u7f51\u7edc (<code>head<\/code>\u00a0\u7b49\u4e00\u7cfb\u5217\u53c2\u6570)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>'head': 'decoupled_head'<\/code><ul><li><strong>\u4e00\u4e2a\u5b9a\u4f4d\u4e13\u5bb6\u7ec4<\/strong>\u00a0(<code>num_reg_head: 2<\/code>)\uff1a\u4e13\u95e8\u8d1f\u8d23\u7cbe\u786e\u9884\u6d4b\u7269\u4f53\u7684<strong>\u4f4d\u7f6e\u548c\u6846\u7684\u5927\u5c0f<\/strong>\u3002<\/li><li><strong>\u4e00\u4e2a\u5206\u7c7b\u4e13\u5bb6\u7ec4<\/strong>\u00a0(<code>num_cls_head: 2<\/code>)\uff1a\u4e13\u95e8\u8d1f\u8d23\u5224\u65ad\u7269\u4f53<strong>\u5c5e\u4e8e\u54ea\u4e2a\u7c7b\u522b<\/strong>\u3002<\/li><\/ul>\n<ul class=\"wp-block-list\">\n<li><strong>\u901a\u4fd7\u89e3\u91ca<\/strong>\uff1a\u8fd9\u662f\u5bf9\u539f\u59cbYOLOv1\u7684\u4e00\u4e2a<strong>\u91cd\u5927\u5347\u7ea7<\/strong>\uff01\u539f\u59cb\u6a21\u578b\u7528\u4e00\u4e2a\u8111\u5b50\u540c\u65f6\u601d\u8003\u201c\u6846\u5728\u54ea\u201d\u548c\u201c\u662f\u4ec0\u4e48\u201d\u4e24\u4e2a\u95ee\u9898\u3002\u73b0\u5728\u6211\u4eec\u7528**\u201c\u89e3\u8026\u5934\u201d**\uff0c\u4e5f\u5c31\u662f\u62c6\u6210\u4e24\u4e2a\u4e13\u5bb6\u5c0f\u7ec4\uff1a<\/li>\n\n\n\n<li><strong>\u597d\u5904<\/strong>\uff1a\u5206\u5de5\u660e\u786e\uff0c\u4e13\u4e1a\u7684\u4eba\u505a\u4e13\u4e1a\u7684\u4e8b\uff0c\u8ba9\u5b9a\u4f4d\u548c\u5206\u7c7b\u90fd\u66f4\u51c6\u786e\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"5\" class=\"wp-block-list\">\n<li>\u3010\u8bbe\u5b9a\u8bad\u7ec3\u91cd\u70b9\u3011- \u635f\u5931\u6743\u91cd (<code>loss_*_weight<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>'loss_box_weight': 5.0<\/code><\/li>\n\n\n\n<li><code>'loss_obj_weight': 1.0<\/code><\/li>\n\n\n\n<li><code>'loss_cls_weight': 1.0<\/code><ul><li><strong>\u201c\u6846\u7684\u4f4d\u7f6e\u4e0d\u51c6\u201d<\/strong>\u00a0\u8fd9\u79cd\u9519\u8bef\u975e\u5e38\u4e25\u91cd\uff0c\u8981\u9ad8\u5ea6\u91cd\u89c6\uff01\uff08\u6743\u91cd\u662f5\u500d\uff09<\/li><li><strong>\u201c\u6ca1\u770b\u5230\u7269\u4f53\u201d<\/strong>\u00a0\u548c\u00a0<strong>\u201c\u8ba4\u9519\u4e86\u7c7b\u522b\u201d<\/strong>\u00a0\u7684\u9519\u8bef\u4e5f\u5f88\u91cd\u8981\uff0c\u4f46\u76f8\u5bf9\u6b21\u8981\uff08\u6743\u91cd\u662f1\u500d\uff09\u3002<\/li><\/ul>\n<ul class=\"wp-block-list\">\n<li><strong>\u901a\u4fd7\u89e3\u91ca<\/strong>\uff1a\u544a\u8bc9\u673a\u5668\u4eba\uff0c\u5728\u8bad\u7ec3\u65f6<strong>\u54ea\u65b9\u9762\u7684\u9519\u8bef\u66f4\u91cd\u8981<\/strong>\u3002\u8fd9\u91cc<code>loss_box_weight: 5.0<\/code>\u610f\u5473\u7740\uff1a<\/li>\n\n\n\n<li>\u8fd9\u6837\u673a\u5668\u4eba\u5c31\u4f1a\u82b1\u66f4\u591a\u7cbe\u529b\u53bb\u5b66\u4e60\u5982\u4f55\u628a\u6846\u753b\u5f97\u66f4\u51c6\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"6\" class=\"wp-block-list\">\n<li>\u3010\u9009\u62e9\u6559\u7ec3\u3011- \u8bad\u7ec3\u5668\u7c7b\u578b (<code>trainer_type<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>'trainer_type': 'yolov8'<\/code>\n<ul class=\"wp-block-list\">\n<li><strong>\u901a\u4fd7\u89e3\u91ca<\/strong>\uff1a\u9009\u62e9<strong>\u54ea\u4f4d\u540d\u5e08<\/strong>\u6765\u8bad\u7ec3\u6211\u4eec\u7684\u673a\u5668\u4eba\u3002\u8fd9\u91cc\u6307\u5b9a\u4f7f\u7528<strong>YOLOv8\u5b98\u65b9\u63d0\u4f9b\u7684\u8bad\u7ec3\u65b9\u6cd5<\/strong>\u3002\u8fd9\u5957\u65b9\u6cd5\u5305\u542b\u4e86\u6700\u65b0\u7684\u8bad\u7ec3\u6280\u5de7\u548c\u4f18\u5316\u7b56\u7565\uff0c\u5c31\u50cf\u8bf7\u4e86\u6700\u9876\u5c16\u7684\u6559\u7ec3\u6765\u6307\u5bfc\uff0c\u80fd\u6700\u5927\u7a0b\u5ea6\u6fc0\u53d1\u673a\u5668\u4eba\u7684\u6f5c\u80fd\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u603b\u7ed3<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u4e2a\u201c\u914d\u65b9\u201d<strong>\u8fdc\u4e0d\u6b62\u662f\u539f\u59cb\u7684YOLOv1<\/strong>\uff0c\u800c\u662f\u4e00\u4e2a\u7528<strong>\u73b0\u4ee3\u6280\u672f\u6df1\u5ea6\u5347\u7ea7\u548c\u4f18\u5316<\/strong>\u7684\u5f3a\u529b\u7248\u672c\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u66f4\u5f3a\u7684\u773c\u775b<\/strong>\uff1a\u7528\u4e86\u73b0\u6210\u7684\u5f3a\u5927\u4e3b\u5e72\u7f51\u7edc\u00a0<code>ResNet<\/code>\uff0c\u800c\u4e0d\u662f\u539f\u59cb\u7684\u81ea\u5b9a\u4e49\u7f51\u7edc\u3002<\/li>\n\n\n\n<li><strong>\u66f4\u5f3a\u7684\u4fe1\u606f\u878d\u5408<\/strong>\uff1a\u589e\u52a0\u4e86\u00a0<code>SPPF<\/code>\u00a0\u9888\u90e8\u548c\u00a0<code>FPN\/PAN<\/code>\u00a0\u7ed3\u6784\uff0c\u80fd\u66f4\u597d\u5730\u5904\u7406\u4e0d\u540c\u5927\u5c0f\u7684\u7269\u4f53\u3002<\/li>\n\n\n\n<li><strong>\u66f4\u5f3a\u7684\u51b3\u7b56\u5927\u8111<\/strong>\uff1a\u4f7f\u7528\u4e86\u201c\u89e3\u8026\u5934\u201d\uff0c\u5c06\u5b9a\u4f4d\u548c\u5206\u7c7b\u4efb\u52a1\u5206\u5f00\uff0c\u7cbe\u5ea6\u66f4\u9ad8\u3002<\/li>\n\n\n\n<li><strong>\u66f4\u79d1\u5b66\u7684\u8bad\u7ec3<\/strong>\uff1a\u91c7\u7528\u4e86\u6700\u65b0\u7684\u8bad\u7ec3\u7b56\u7565\u548c\u635f\u5931\u6743\u91cd\u8bbe\u8ba1\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u5c31\u662f\u5efa\u9020\u4e00\u4e2a<strong>\u9ad8\u6027\u80fd\u3001\u9ad8\u7cbe\u5ea6\u3001\u73b0\u4ee3\u5316YOLO\u68c0\u6d4b\u5668<\/strong>\u7684\u5b8c\u6574\u84dd\u56fe\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1.1 \u642d\u5efaBackbone\u7f51\u7edc<\/h2>\n\n\n\n<p>\u8fd9\u4e00\u90e8\u5206\uff0c\u6211\u4eec\u6765\u642d\u5efa\u4e3b\u5e72\u7f51\u7edc\uff1aResNet18\u3002<\/p>\n\n\n\n<p>\u7531\u4e8ePyTorch\u5b98\u7f51\u5df2\u7ecf\u63d0\u4f9b\u4e86ResNet\u7684\u6e90\u7801\u548c\u9884\u8bad\u7ec3\u6a21\u578b\uff0c\u56e0\u6b64\uff0c\u8fd9\u91cc\u6211\u4eec\u76f4\u63a5\u4f7f\u7528PyTorch\u5b98\u65b9\u63d0\u4f9b\u7684\u4ee3\u7801\u3002<\/p>\n\n\n\n<p>\u5728\u4e0b\u65b9\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5c55\u793a\u4e86PyTorch\u5b98\u65b9\u5b9e\u73b0\u7684ResNet\u7f51\u7edc\u7684<strong>\u5fc5\u8981\u90e8\u5206\u7684\u4ee3\u7801\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># RT-ODLab\/models\/detectors\/yolov1\/yolov1_backbone.py<br><br><br># --------------------- ResNet -----------------------<br>class ResNet(nn.Module):<br><br>&nbsp; &nbsp; def __init__(self, block, layers, zero_init_residual=False):<br>&nbsp; &nbsp; &nbsp; &nbsp; super(ResNet, self).__init__()<br>&nbsp; &nbsp; &nbsp; &nbsp; self.inplanes = 64<br>&nbsp; &nbsp; &nbsp; &nbsp; self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, bias=False)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.bn1 = nn.BatchNorm2d(64)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.relu = nn.ReLU(inplace=True)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.layer1 = self._make_layer(block, 64, layers&#91;0])<br>&nbsp; &nbsp; &nbsp; &nbsp; self.layer2 = self._make_layer(block, 128, layers&#91;1], stride=2)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.layer3 = self._make_layer(block, 256, layers&#91;2], stride=2)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.layer4 = self._make_layer(block, 512, layers&#91;3], stride=2)<br>&nbsp; &nbsp; &nbsp; &nbsp; ...<br><br>&nbsp; &nbsp; def forward(self, x):<br>&nbsp; &nbsp; &nbsp; &nbsp; \"\"\"<br>&nbsp; &nbsp; &nbsp; &nbsp; Input:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: (Tensor) -&gt; &#91;B, C, H, W]<br>&nbsp; &nbsp; &nbsp; &nbsp; Output:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c5: (Tensor) -&gt; &#91;B, C, H\/32, W\/32]<br>&nbsp; &nbsp; &nbsp; &nbsp; \"\"\"<br>&nbsp; &nbsp; &nbsp; &nbsp; c1 = self.conv1(x) &nbsp; &nbsp; # &#91;B, C, H\/2, W\/2]<br>&nbsp; &nbsp; &nbsp; &nbsp; c1 = self.bn1(c1) &nbsp; &nbsp; &nbsp;# &#91;B, C, H\/2, W\/2]<br>&nbsp; &nbsp; &nbsp; &nbsp; c1 = self.relu(c1) &nbsp; &nbsp; # &#91;B, C, H\/2, W\/2]<br>&nbsp; &nbsp; &nbsp; &nbsp; c2 = self.maxpool(c1) &nbsp;# &#91;B, C, H\/4, W\/4]<br><br>&nbsp; &nbsp; &nbsp; &nbsp; c2 = self.layer1(c2) &nbsp; # &#91;B, C, H\/4, W\/4]<br>&nbsp; &nbsp; &nbsp; &nbsp; c3 = self.layer2(c2) &nbsp; # &#91;B, C, H\/8, W\/8]<br>&nbsp; &nbsp; &nbsp; &nbsp; c4 = self.layer3(c3) &nbsp; # &#91;B, C, H\/16, W\/16]<br>&nbsp; &nbsp; &nbsp; &nbsp; c5 = self.layer4(c4) &nbsp; # &#91;B, C, H\/32, W\/32]<br><br>&nbsp; &nbsp; &nbsp; &nbsp; return c5<br><br>## build resnet<br>def build_backbone(model_name='resnet18', pretrained=False):<br>&nbsp; &nbsp; if model_name == 'resnet18':<br>&nbsp; &nbsp; &nbsp; &nbsp; model = resnet18(pretrained)<br>&nbsp; &nbsp; &nbsp; &nbsp; feat_dim = 512<br>&nbsp; &nbsp; elif model_name == 'resnet34':<br>&nbsp; &nbsp; &nbsp; &nbsp; model = resnet34(pretrained)<br>&nbsp; &nbsp; &nbsp; &nbsp; feat_dim = 512<br>&nbsp; &nbsp; elif model_name == 'resnet50':<br>&nbsp; &nbsp; &nbsp; &nbsp; model = resnet34(pretrained)<br>&nbsp; &nbsp; &nbsp; &nbsp; feat_dim = 2048<br>&nbsp; &nbsp; elif model_name == 'resnet101':<br>&nbsp; &nbsp; &nbsp; &nbsp; model = resnet34(pretrained)<br>&nbsp; &nbsp; &nbsp; &nbsp; feat_dim = 2048<br><br>&nbsp; &nbsp; return model, feat_dim<\/code><\/pre>\n\n\n\n<p>\u901a\u8fc7\u8c03\u7528build_backbone\u51fd\u6570\u5373\u53ef\u8c03\u7528\u6307\u5b9a\u7684ResNet\u7f51\u7edc\uff0c\u5982ResNet18\u51fd\u6570\u65f6\u3002\u5f53pretrained\u53c2\u6570\u88ab\u8bbe\u7f6e\u4e3aTrue\u65f6\uff0c\u8fd9\u90e8\u5206\u4ee3\u7801\u4f1a\u81ea\u52a8\u4e0b\u8f7d\u7531PyTorch\u5b98\u65b9\u5df2\u63d0\u4f9b\u7684ImageNet\u9884\u8bad\u7ec3\u6743\u91cd\u3002<\/p>\n\n\n\n<p>\u5728YOLOv1\u7684\u4e3b\u4f53\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5199\u4e0a\u4e0b\u9762\u7684\u4ee3\u7801\u5373\u53ef\u642d\u5efaBackbone\u7f51\u7edc\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Backbone\u7f51\u7edc<br>self.backbone, feat_dim = build_backbone(cfg&#91;'backbone'], trainable&amp;cfg&#91;'pretrained'])<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7ee7\u7eed\u6765\u770b\u770b\u5457<\/p>\n<\/blockquote>\n\n\n\n<p>\u6211\u4eec\u8981\u6559\u4e00\u4e2a\u673a\u5668\u4eba\u5982\u4f55\u201c\u770b\u201d\u56fe\u7247\u5e76\u627e\u5230\u91cc\u9762\u7684\u7269\u4f53\uff0c\u800c ResNet \u5c31\u662f\u5b83\u7684\u201c\u773c\u775b\u548c\u89c6\u89c9\u5927\u8111\u201d\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6545\u4e8b\uff1aResNet \u2014\u2014 \u4e00\u4e2a\u7cbe\u660e\u7684\u56fe\u7247\u201c\u538b\u7f29\u4e0e\u7406\u89e3\u201d\u6d41\u6c34\u7ebf<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u4e2a\u6d41\u6c34\u7ebf\uff08ResNet\uff09\u7684\u4efb\u52a1\u4e0d\u662f\u76f4\u63a5\u627e\u7269\u4f53\uff0c\u800c\u662f\u628a\u4e00\u5f20\u9ad8\u6e05\u5927\u56fe\uff0c<strong>\u538b\u7f29\u5e76\u63d0\u70bc<\/strong>\u6210\u4e00\u5f20\u5c0f\u5c0f\u7684\u3001\u4f46\u4fe1\u606f\u6781\u5ea6\u6d53\u7f29\u7684\u201c\u7279\u5f81\u5730\u56fe\u201d\u3002\u540e\u7eed\u7684 Neck \u548c Head \u90e8\u95e8\uff08\u4e0b\u4e00\u9053\u5de5\u5e8f\uff09\u4f1a\u62ff\u7740\u8fd9\u5f20\u5c0f\u5730\u56fe\u53bb\u7cbe\u786e\u5730\u5b9a\u4f4d\u7269\u4f53\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e00\u90e8\u5206\uff1a\u6d41\u6c34\u7ebf\u7684\u8bbe\u8ba1\u84dd\u56fe\uff08<code>class ResNet<\/code>\uff09<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol class=\"wp-block-list\">\n<li>\u521d\u59cb\u51c6\u5907\u533a\uff08<code>__init__<\/code>\u00a0\u65b9\u6cd5\uff09 \u8fd9\u91cc\u89c4\u5b9a\u4e86\u6d41\u6c34\u7ebf\u7684\u6240\u6709\u5de5\u4f5c\u7ad9\uff1a<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>self.conv1<\/code>:\u00a0<strong>\u7b2c\u4e00\u9053\u7c97\u52a0\u5de5\u7ad9<\/strong>\u3002\u7528\u4e00\u4e2a\u5de8\u5927\u7684 7x7 \u7b5b\u5b50\uff08\u5377\u79ef\u6838\uff09\uff0c\u5927\u6b65\u6d41\u661f\uff08<code>stride=2<\/code>\uff09\u5730\u628a\u56fe\u7247\u5feb\u901f\u8fc7\u4e00\u904d\u3002\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165<\/strong>\uff1a\u539f\u59cb\u56fe\u7247\u00a0<code>[3, H, W]<\/code>\u00a0(3\u8868\u793a\u989c\u8272\u901a\u9053)<\/li>\n\n\n\n<li><strong>\u8f93\u51fa<\/strong>\uff1a\u521d\u6b65\u7279\u5f81\u00a0<code>[64, H\/2, W\/2]<\/code>\u3002\u56fe\u7247\u5c3a\u5bf8\u7f29\u4e00\u534a\uff0c\u4f46\u7279\u5f81\u901a\u9053\u6570\u53d8\u4e3a64\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>self.bn1<\/code>\u00a0\u548c\u00a0<code>self.relu<\/code>:\u00a0<strong>\u6807\u51c6\u5316\u548c\u6fc0\u6d3b\u7ad9<\/strong>\u3002\u628a\u7c97\u52a0\u5de5\u540e\u7684\u6750\u6599\u6807\u51c6\u5316\u4e00\u4e0b\uff0c\u7136\u540e\u901a\u8fc7\u4e00\u4e2a\u201c\u6fc0\u6d3b\u51fd\u6570\u201d\u8ba9\u91cd\u8981\u4fe1\u606f\u51f8\u663e\u51fa\u6765\uff0c\u65e0\u5173\u4fe1\u606f\u88ab\u6291\u5236\u3002<\/li>\n\n\n\n<li><code>self.maxpool<\/code>:\u00a0<strong>\u6700\u5927\u6c60\u5316\u7ad9<\/strong>\u3002\u8fdb\u4e00\u6b65\u538b\u7f29\u56fe\u7247\u5c3a\u5bf8\u3002<code>stride=2<\/code>\u00a0\u610f\u5473\u7740\u5c3a\u5bf8\u518d\u7f29\u4e00\u534a\u3002\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165<\/strong>\uff1a<code>[64, H\/2, W\/2]<\/code><\/li>\n\n\n\n<li><strong>\u8f93\u51fa<\/strong>\uff1a<code>[64, H\/4, W\/4]<\/code>\u3002\u81f3\u6b64\uff0c\u56fe\u7247\u5c3a\u5bf8\u5df2\u7ecf\u53d8\u4e3a\u539f\u6765\u7684 1\/4\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u6838\u5fc3\u7cbe\u52a0\u5de5\u533a\uff08<code>self.layer1<\/code>\u00a0~\u00a0<code>self.layer4<\/code>\uff09 \u8fd9\u662f ResNet \u7684\u7cbe\u534e\u6240\u5728\uff01\u5b83\u7531\u00a0<strong>4 \u4e2a\u6838\u5fc3\u8f66\u95f4<\/strong>\u7ec4\u6210\uff0c\u6bcf\u4e2a\u8f66\u95f4\u90fd\u7531\u82e5\u5e72\u53f0\u76f8\u540c\u7684\u201c\u6b8b\u5dee\u673a\u5668\u201d\uff08<code>block<\/code>\uff0c\u5982 BasicBlock\uff09\u6784\u6210\u3002<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>self.layer1<\/code><\/strong>\uff1a<strong>\u4e00\u7ea7\u7cbe\u52a0\u5de5\u8f66\u95f4<\/strong>\u3002\n<ul class=\"wp-block-list\">\n<li>\u4efb\u52a1\uff1a\u5bf9\u8f93\u5165\u8fdb\u884c\u6df1\u5ea6\u7279\u5f81\u63d0\u53d6\uff0c<strong>\u4e0d\u6539\u53d8\u5c3a\u5bf8<\/strong>\uff08<code>stride=1<\/code>\uff09\u3002<\/li>\n\n\n\n<li>\u8f93\u5165\u8f93\u51fa\uff1a<code>[64, H\/4, W\/4]<\/code>\u00a0->\u00a0<code>[64, H\/4, W\/4]<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong><code>self.layer2<\/code><\/strong>\uff1a<strong>\u4e8c\u7ea7\u7cbe\u52a0\u5de5\u8f66\u95f4<\/strong>\u3002\n<ul class=\"wp-block-list\">\n<li>\u4efb\u52a1\uff1a\u7ee7\u7eed\u63d0\u53d6\u66f4\u590d\u6742\u7684\u7279\u5f81\uff0c\u5e76\u4e14<strong>\u628a\u5c3a\u5bf8\u7f29\u5c0f\u4e00\u500d<\/strong>\uff08<code>stride=2<\/code>\uff09\uff01<\/li>\n\n\n\n<li>\u8f93\u5165\u8f93\u51fa\uff1a<code>[64, H\/4, W\/4]<\/code>\u00a0->\u00a0<code>[128, H\/8, W\/8]<\/code>\u00a0(\u901a\u9053\u6570\u7ffb\u500d\uff0c\u5c3a\u5bf8\u51cf\u534a)<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong><code>self.layer3<\/code><\/strong>\uff1a<strong>\u4e09\u7ea7\u7cbe\u52a0\u5de5\u8f66\u95f4<\/strong>\u3002\n<ul class=\"wp-block-list\">\n<li>\u4efb\u52a1\uff1a\u540c\u4e0a\uff0c\u7ee7\u7eed\u63d0\u53d6\u548c\u7f29\u5c0f\u3002<\/li>\n\n\n\n<li>\u8f93\u5165\u8f93\u51fa\uff1a<code>[128, H\/8, W\/8]<\/code>\u00a0->\u00a0<code>[256, H\/16, W\/16]<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong><code>self.layer4<\/code><\/strong>\uff1a<strong>\u56db\u7ea7\u7cbe\u52a0\u5de5\u8f66\u95f4<\/strong>\u3002\n<ul class=\"wp-block-list\">\n<li>\u4efb\u52a1\uff1a\u6700\u540e\u4e00\u7ea7\u52a0\u5de5\uff0c\u5f97\u5230\u6700\u62bd\u8c61\u3001\u6700\u7cbe\u534e\u7684\u7279\u5f81\u3002<\/li>\n\n\n\n<li>\u8f93\u5165\u8f93\u51fa\uff1a<code>[256, H\/16, W\/16]<\/code>\u00a0->\u00a0<code>[512, H\/32, W\/32]<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>\u4e3a\u4ec0\u4e48\u53eb\u201c\u6b8b\u5dee\u201d\u673a\u5668\uff1f<\/strong>\u60f3\u8c61\u4e00\u4e0b\u5b66\u4e60\u65b0\u77e5\u8bc6\u3002\u6700\u597d\u7684\u65b9\u5f0f\u4e0d\u662f\u628a\u65e7\u77e5\u8bc6\u5168\u4e22\u6389\uff0c\u800c\u662f\u5728\u65e7\u77e5\u8bc6\u7684\u57fa\u7840\u4e0a\uff0c\u53ea\u5b66\u4e60\u201c\u65b0\u77e5\u8bc6\u201d\u548c\u201c\u65e7\u77e5\u8bc6\u201d\u7684<strong>\u5dee\u522b\uff08\u6b8b\u5dee\uff09<\/strong>\u3002\u8fd9\u6837\u5b66\u4e60\u8d77\u6765\u66f4\u8f7b\u677e\u3001\u66f4\u9ad8\u6548\uff0c\u4e5f\u4e0d\u5bb9\u6613\u9057\u5fd8\u3002ResNet \u7684\u6bcf\u4e2a&nbsp;<code>block<\/code>&nbsp;\u5c31\u662f\u8fd9\u4e48\u5de5\u4f5c\u7684\uff0c\u8fd9\u4e5f\u662f\u5b83\u4e3a\u4ec0\u4e48\u80fd\u505a\u5f97\u90a3\u4e48\u6df1\uff08\u5c42\u6570\u591a\uff09\u8fd8\u4e0d\u5931\u6548\u7684\u79d8\u8bc0\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"3\" class=\"wp-block-list\">\n<li>\u6d41\u6c34\u7ebf\u5de5\u4f5c\u6d41\u7a0b\uff08<code>forward<\/code>\u00a0\u65b9\u6cd5\uff09 \u8fd9\u5c31\u662f\u628a\u4e00\u5f20\u56fe\u7247\u00a0<code>x<\/code>\u00a0\u9001\u5165\u6d41\u6c34\u7ebf\u7684\u5168\u8fc7\u7a0b\uff0c\u6211\u4eec\u6e05\u6670\u5730\u770b\u5230\u6570\u636e\u662f\u5982\u4f55\u4e00\u6b65\u6b65\u88ab\u52a0\u5de5\u548c\u538b\u7f29\u7684\uff1a<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>def&nbsp;forward(self, x):<br>&nbsp; &nbsp; c1 = self.conv1(x) &nbsp; &nbsp;&nbsp;<em># \u7c97\u52a0\u5de5: &#91;B, 3, H, W] -&gt; &#91;B, 64, H\/2, W\/2]<\/em><br>&nbsp; &nbsp; c1 = self.bn1(c1) &nbsp; &nbsp; &nbsp;<em># \u6807\u51c6\u5316<\/em><br>&nbsp; &nbsp; c1 = self.relu(c1) &nbsp; &nbsp;&nbsp;<em># \u6fc0\u6d3b<\/em><br>&nbsp; &nbsp; c2 = self.maxpool(c1) &nbsp;<em># \u6c60\u5316: &#91;B, 64, H\/2, W\/2] -&gt; &#91;B, 64, H\/4, W\/4]<\/em><br><br>&nbsp; &nbsp; c2 = self.layer1(c2) &nbsp;&nbsp;<em># \u4e00\u7ea7\u52a0\u5de5: \u5c3a\u5bf8\u4e0d\u53d8 &#91;B, 64, H\/4, W\/4]<\/em><br>&nbsp; &nbsp; c3 = self.layer2(c2) &nbsp;&nbsp;<em># \u4e8c\u7ea7\u52a0\u5de5: &#91;B, 64, H\/4, W\/4] -&gt; &#91;B, 128, H\/8, W\/8]<\/em><br>&nbsp; &nbsp; c4 = self.layer3(c3) &nbsp;&nbsp;<em># \u4e09\u7ea7\u52a0\u5de5: &#91;B, 128, H\/8, W\/8] -&gt; &#91;B, 256, H\/16, W\/16]<\/em><br>&nbsp; &nbsp; c5 = self.layer4(c4) &nbsp;&nbsp;<em># \u56db\u7ea7\u52a0\u5de5: &#91;B, 256, H\/16, W\/16] -&gt; &#91;B, 512, H\/32, W\/32]<\/em><br><br>&nbsp; &nbsp;&nbsp;return&nbsp;c5&nbsp;<em># \u8fd4\u56de\u6700\u7ec8\u63d0\u70bc\u51fa\u7684\u201c\u7279\u5f81\u5c0f\u5730\u56fe\u201d<\/em><\/code><\/pre>\n\n\n\n<p><strong>\u6700\u7ec8\u6210\u679c<\/strong>\uff1a\u4e00\u5f20\u5c3a\u5bf8\u4e3a\u539f\u56fe&nbsp;<strong>1\/32<\/strong>&nbsp;\u7684\u201c\u7279\u5f81\u5c0f\u5730\u56fe\u201d\uff08<code>c5<\/code>\uff09\u3002\u4f8b\u5982\uff0c\u8f93\u5165&nbsp;<code>416x416<\/code>&nbsp;\u7684\u56fe\u7247\uff0c\u4f1a\u5f97\u5230&nbsp;<code>13x13<\/code>&nbsp;\u7684\u7279\u5f81\u56fe\u3002\u8fd9\u5f20\u56fe\u91cc\u6bcf\u4e00\u4e2a\u5c0f\u683c\u5b50\uff08\u6bd4\u5982<code>13x13<\/code>\u91cc\u7684\u67d0\u4e00\u4e2a\uff09\uff0c\u90fd\u5bf9\u5e94\u7740\u539f\u56fe\u4e0a\u4e00\u5927\u7247\u533a\u57df\uff08<code>32x32<\/code>\u50cf\u7d20\uff09\u7684\u7cbe\u534e\u4fe1\u606f\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e8c\u90e8\u5206\uff1a\u9009\u62e9\u5e76\u88c5\u5907\u6d41\u6c34\u7ebf\uff08<code>build_backbone<\/code>&nbsp;\u51fd\u6570\uff09<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u90e8\u5206\u5c31\u50cf\u5de5\u5382\u7684<strong>\u91c7\u8d2d\u90e8<\/strong>\uff0c\u6839\u636e\u4f60\u7684\u8ba2\u5355\uff08\u914d\u7f6e\u53c2\u6570\uff09\u53bb\u83b7\u53d6\u6307\u5b9a\u7684\u6d41\u6c34\u7ebf\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>if model_name == 'resnet18'<\/code>:\u00a0<strong>\u8ba2\u5355\u662f ResNet18 \u53f7\u6d41\u6c34\u7ebf<\/strong>\u3002\n<ul class=\"wp-block-list\">\n<li>\u5b83\u5c31\u5e2e\u4f60\u8054\u7cfb PyTorch \u5b98\u65b9\u5de5\u5382\uff0c\u8c03\u6765\u4e00\u6761 ResNet18 \u6d41\u6c34\u7ebf (<code>model = resnet18(pretrained)<\/code>)\u3002<\/li>\n\n\n\n<li>\u540c\u65f6\u544a\u8bc9\u4f60\uff0c\u8fd9\u6761\u6d41\u6c34\u7ebf\u6700\u7ec8\u4ea7\u51fa\u7684\u201c\u7279\u5f81\u5c0f\u5730\u56fe\u201d\u7684<strong>\u539a\u5ea6\uff08\u901a\u9053\u6570\uff09<\/strong>\u00a0\u662f 512 (<code>feat_dim = 512<\/code>)\u3002\u8fd9\u4e2a\u6570\u5b57\u5bf9\u540e\u7eed\u642d\u5efa Neck \u548c Head \u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u4eec\u9700\u8981\u77e5\u9053\u8f93\u5165\u6570\u636e\u7684\u5f62\u72b6\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>pretrained=True<\/code>:\u00a0<strong>\u91c7\u8d2d\u201c\u9884\u8bad\u7ec3\u201d\u597d\u7684\u6d41\u6c34\u7ebf<\/strong>\u3002\n<ul class=\"wp-block-list\">\n<li>\u8fd9\u610f\u5473\u7740\u8fd9\u6761\u6d41\u6c34\u7ebf\u5df2\u7ecf\u5728\u51e0\u767e\u4e07\u5f20\u56fe\u7247\uff08ImageNet \u6570\u636e\u96c6\uff09\u4e0a\u201c\u7ec3\u4e60\u201d\u8fc7\u4e86\uff0c\u5df2\u7ecf\u5b66\u4f1a\u4e86\u5982\u4f55\u9ad8\u6548\u5730\u63d0\u53d6\u901a\u7528\u7279\u5f81\u3002\u6211\u4eec\u76f4\u63a5\u62ff\u6765\u7528\uff0c\u53ea\u9700\u8981\u7a0d\u5fae\u5fae\u8c03\u4e00\u4e0b\uff0c\u5b83\u5c31\u80fd\u5728\u6211\u4eec\u7684\u7279\u5b9a\u4efb\u52a1\uff08\u68c0\u6d4b\u7269\u4f53\uff09\u4e0a\u8868\u73b0\u5f97\u975e\u5e38\u51fa\u8272\uff0c\u8fd9\u6bd4\u4ece\u96f6\u8bad\u7ec3\u4e00\u6761\u65b0\u6d41\u6c34\u7ebf\u8981\u5feb\u5f97\u591a\u3001\u597d\u5f97\u591a\uff01<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e09\u90e8\u5206\uff1a\u5728YOLO\u5de5\u5382\u4e2d\u5b89\u88c5\u6d41\u6c34\u7ebf<\/p>\n<\/blockquote>\n\n\n\n<p>\u6700\u540e\uff0c\u5728\u4f60\u7684 YOLOv1 \u4e3b\u5de5\u5382\u91cc\uff0c\u53ea\u7528\u4e00\u884c\u4ee3\u7801\u5c31\u80fd\u5b8c\u6210Backbone\u7684\u642d\u5efa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>self.backbone, feat_dim = build_backbone(cfg&#91;'backbone'], trainable&amp;cfg&#91;'pretrained'])<\/code><\/pre>\n\n\n\n<p>\u8fd9\u884c\u4ee3\u7801\u7684\u610f\u601d\u662f\uff1a \u201c\u6839\u636e\u914d\u7f6e\u6587\u4ef6&nbsp;<code>cfg<\/code>&nbsp;\u91cc\u7684\u6307\u4ee4\uff0c\u53bb\u5efa\u9020 (<code>build_backbone<\/code>) \u6211\u7684\u4e3b\u5e72\u7f51\u7edc\u3002\u6211\u8981\u7684\u578b\u53f7\u662f&nbsp;<code>cfg['backbone']<\/code>\uff08\u6bd4\u5982 'resnet18'\uff09\uff0c\u5e76\u4e14\u5982\u679c\u5f53\u524d\u662f\u8bad\u7ec3\u6a21\u5f0f\u4e14\u914d\u7f6e\u8981\u6c42\u7528\u9884\u8bad\u7ec3\u6a21\u578b\uff0c\u5c31\u7ed9\u6211\u642c\u90a3\u6761\u9884\u8bad\u7ec3\u8fc7\u7684\u6d41\u6c34\u7ebf\u8fc7\u6765\u3002\u201d<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u603b\u7ed3<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a<strong>\u9ad8\u6548\u7684\u7279\u5f81\u63d0\u53d6\u6d41\u6c34\u7ebf\uff08Backbone\uff09<\/strong>\uff0c\u5b83\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u9010\u6b65\u538b\u7f29\u56fe\u7247\u5c3a\u5bf8<\/strong>\uff08\u4ece H\/W \u5230 H\/32, W\/32\uff09\u3002<\/li>\n\n\n\n<li><strong>\u9010\u6b65\u589e\u52a0\u4fe1\u606f\u6d53\u5ea6<\/strong>\uff08\u901a\u9053\u6570\u4ece3\u589e\u52a0\u5230512\uff09\u3002<\/li>\n\n\n\n<li><strong>\u5229\u7528\u201c\u6b8b\u5dee\u5b66\u4e60\u201d<\/strong>\uff0c\u4f7f\u5f97\u7f51\u7edc\u53ef\u4ee5\u975e\u5e38\u6df1\uff0c\u4ece\u800c\u63d0\u53d6\u5230\u975e\u5e38\u590d\u6742\u548c\u62bd\u8c61\u7684\u7279\u5f81\u3002<\/li>\n\n\n\n<li><strong>\u901a\u8fc7\u9884\u8bad\u7ec3<\/strong>\uff0c\u83b7\u5f97\u4e86\u5f3a\u5927\u7684\u901a\u7528\u56fe\u50cf\u7279\u5f81\u63d0\u53d6\u80fd\u529b\u3002<\/li>\n\n\n\n<li>\u6700\u7ec8\u8f93\u51fa\u4e00\u5f20<strong>\u5c0f\u800c\u7cbe\u7684\u201c\u7279\u5f81\u5730\u56fe\u201d<\/strong>\uff0c\u4e3a\u540e\u7eed\u7684\u7269\u4f53\u68c0\u6d4b\u4efb\u52a1\u5960\u5b9a\u4e86\u575a\u5b9e\u7684\u57fa\u7840\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u6211\u4eec\u4e0d\u4f7f\u7528\u539f\u59cbYOLOv1\u7684Backbone\uff0c\u800c\u8981\u7528ResNet\u2014\u2014\u56e0\u4e3a\u5b83\u66f4\u5f3a\u5927\u3001\u66f4\u9ad8\u6548\u3001\u66f4\u73b0\u4ee3\uff01<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6f02\u4eae<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1.2 \u642d\u5efaNeck\u7f51\u7edc<\/h2>\n\n\n\n<p>\u6309\u7167\u4e0a\u4e00\u8282\u6240\u8bb2\u7684\uff0cNeck\u90e8\u5206\u6211\u4eec\u9009\u62e9SPP\u7f51\u7edc\uff0c\u5176\u7ed3\u6784\u975e\u5e38\u7b80\u5355\uff0c\u4ec5\u4ec5\u662f\u82e5\u5e72\u4e0d\u540c\u5927\u5c0f\u7684maxpooling\u5c42\u5806\u53e0\u800c\u6210\uff0c\u76f8\u5173\u7684\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff0c\u8fd9\u91cc\uff0c\u6211\u4eec\u53c2\u8003\u4e86YOLOv5\u4e2d\u7684Fast\u7248\u672c\u7684SPP\u5b9e\u73b0\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># RT-ODLab\/models\/detectors\/yolov1\/yolov1_neck.py<br><br><br># Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher<br>class SPPF(nn.Module):<br>&nbsp; &nbsp; \"\"\"<br>&nbsp; &nbsp; &nbsp; &nbsp; This code referenced to https:\/\/github.com\/ultralytics\/yolov5<br>&nbsp; &nbsp; \"\"\"<br>&nbsp; &nbsp; def __init__(self, in_dim, out_dim, expand_ratio=0.5, pooling_size=5, act_type='lrelu', norm_type='BN'):<br>&nbsp; &nbsp; &nbsp; &nbsp; super().__init__()<br>&nbsp; &nbsp; &nbsp; &nbsp; inter_dim = int(in_dim * expand_ratio)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.out_dim = out_dim<br>&nbsp; &nbsp; &nbsp; &nbsp; self.cv1 = Conv(in_dim, inter_dim, k=1, act_type=act_type, norm_type=norm_type)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.cv2 = Conv(inter_dim * 4, out_dim, k=1, act_type=act_type, norm_type=norm_type)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.m = nn.MaxPool2d(kernel_size=pooling_size, stride=1, padding=pooling_size \/\/ 2)<br><br>&nbsp; &nbsp; def forward(self, x):<br>&nbsp; &nbsp; &nbsp; &nbsp; x = self.cv1(x)<br>&nbsp; &nbsp; &nbsp; &nbsp; y1 = self.m(x)<br>&nbsp; &nbsp; &nbsp; &nbsp; y2 = self.m(y1)<br><br>&nbsp; &nbsp; &nbsp; &nbsp; return self.cv2(torch.cat((x, y1, y2, self.m(y2)), 1))<br><br>def build_neck(cfg, in_dim, out_dim):<br>&nbsp; &nbsp; model = cfg&#91;'neck']<br>&nbsp; &nbsp; print('==============================')<br>&nbsp; &nbsp; print('Neck: {}'.format(model))<br>&nbsp; &nbsp; # build neck<br>&nbsp; &nbsp; if model == 'sppf':<br>&nbsp; &nbsp; &nbsp; &nbsp; neck = SPPF(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; in_dim=in_dim,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; out_dim=out_dim,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; expand_ratio=cfg&#91;'expand_ratio'],&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pooling_size=cfg&#91;'pooling_size'],<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; act_type=cfg&#91;'neck_act'],<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; norm_type=cfg&#91;'neck_norm']<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )<br><br>&nbsp; &nbsp; return neck<\/code><\/pre>\n\n\n\n<p>\u5728\u6211\u4eec\u7684YOLOv1\u4e3b\u4f53\u4ee3\u7801\u6846\u67b6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528build_neck\u51fd\u6570\u6765\u642d\u5efaSPP\u6a21\u5757\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>## \u9888\u90e8\u7f51\u7edc<br>self.neck = build_neck(cfg, feat_dim, out_dim=512)<br>head_dim = self.neck.out_dim<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6545\u4e8b\uff1aSPP\u6a21\u5757 \u2014\u2014 \u4e00\u4e2a\u201c\u591a\u5b54\u5f84\u4fe1\u606f\u7b5b\u201d\u5de5\u4f5c\u7ad9<\/p>\n<\/blockquote>\n\n\n\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0cBackbone\uff08ResNet\uff09\u90e8\u95e8\u9001\u6765\u7684\u201c\u7279\u5f81\u5730\u56fe\u201d\u662f\u4e00\u5806<strong>\u6df7\u5408\u4e86\u4e0d\u540c\u5927\u5c0f\u5173\u952e\u4fe1\u606f<\/strong>\u7684\u539f\u6599\u3002\u6709\u7684\u4fe1\u606f\u5f88\u5927\uff08\u6bd4\u5982\u5927\u8c61\u7684\u8f6e\u5ed3\uff09\uff0c\u6709\u7684\u4fe1\u606f\u5f88\u5c0f\uff08\u6bd4\u5982\u8fdc\u5904\u7684\u4e00\u53ea\u732b\uff09\u3002\u6211\u4eec\u7684\u4efb\u52a1\u662f\u4e0d\u6539\u53d8\u8fd9\u5f20\u5730\u56fe\u7684\u5c3a\u5bf8\uff0c\u4f46\u8ba9\u5b83\u5305\u542b\u7684\u4fe1\u606f\u66f4\u4e30\u5bcc\u3001\u66f4\u9c81\u68d2\u3002<\/p>\n\n\n\n<p>SPP\u6a21\u5757\u5c31\u662f\u4e00\u4e2a\u975e\u5e38\u806a\u660e\u7684**\u201c\u591a\u5b54\u5f84\u4fe1\u606f\u7b5b\u201d\u5de5\u4f5c\u7ad9**\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e00\u90e8\u5206\uff1a\u5de5\u4f5c\u7ad9\u7684\u8bbe\u8ba1\uff08<code>class SPPF<\/code>\uff09<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u4e2a\u5de5\u4f5c\u7ad9\u7684\u8bbe\u8ba1\u975e\u5e38\u5de7\u5999\uff0c\u5b83\u53ea\u505a\u4e09\u4ef6\u4e8b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol class=\"wp-block-list\">\n<li>\u521d\u6b65\u538b\u7f29\uff08<code>self.cv1<\/code>\uff09<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>self.cv1 = Conv(...)<\/code><\/strong>\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u8fd9\u662f\u4e00\u4e2a<strong>\u521d\u6b65\u538b\u7f29\u5668<\/strong>\u3002\u8fdb\u6765\u7684\u539f\u6599\uff08<code>in_dim<\/code>\u7ef4\u7279\u5f81\uff09\u6709\u70b9\u591a\uff0c\u5148\u7528\u4e00\u4e2a\u00a0<code>1x1<\/code>\u00a0\u7684\u5377\u79ef\u6838\u628a\u5b83\u538b\u7f29\u4e00\u4e0b\uff0c\u51cf\u5c11\u901a\u9053\u6570\uff08<code>inter_dim = int(in_dim * expand_ratio)<\/code>\uff09\u3002\u8fd9\u5c31\u50cf\u628a\u4e00\u5806\u6742\u4e71\u7684\u6587\u4ef6\u5148\u7c97\u7565\u5206\u7c7b\uff0c\u653e\u8fdb\u66f4\u5c11\u7684\u6587\u4ef6\u5939\u91cc\uff0c\u65b9\u4fbf\u540e\u7eed\u5904\u7406\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u6838\u5fc3\u64cd\u4f5c\uff1a\u591a\u5b54\u5f84\u7b5b\u9009\uff08<code>self.m<\/code>\u00a0\u548c\u00a0<code>forward<\/code>\u00a0\u4e2d\u7684\u64cd\u4f5c\uff09 \u8fd9\u662f\u6574\u4e2a\u5de5\u4f5c\u7ad9\u7684\u7cbe\u534e\uff01<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>self.m = nn.MaxPool2d(...)<\/code><\/strong>\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u8fd9\u662f\u4e00\u4e2a<strong>\u56fa\u5b9a\u5b54\u5f84\u7684\u201c\u6700\u5927\u4fe1\u606f\u7b5b\u201d<\/strong>\u3002\u5b83\u7684\u5b54\u5f84\u5927\u5c0f\u7531\u00a0<code>pooling_size=5<\/code>\u00a0\u51b3\u5b9a\u3002<\/li>\n\n\n\n<li><strong>\u5de5\u4f5c\u539f\u7406<\/strong>\uff1a\u8fd9\u4e2a\u7b5b\u5b50\u4f1a\u5728\u7279\u5f81\u56fe\u7684\u6bcf\u4e00\u4e2a\u5c0f\u533a\u57df\uff08<code>5x5<\/code>\u00a0\u7684\u7a97\u53e3\uff09\u91cc\uff0c\u53ea\u7559\u4e0b<strong>\u6700\u663e\u8457\u3001\u6700\u4eae<\/strong>\u7684\u90a3\u4e2a\u7279\u5f81\u70b9\uff08\u8fd9\u5c31\u662fMaxPooling\u7684\u201c\u53d6\u6700\u5927\u503c\u201d\u64cd\u4f5c\uff09\uff0c\u5ffd\u7565\u5176\u4ed6\u6b21\u8981\u4fe1\u606f\u3002<\/li>\n\n\n\n<li><strong>\u795e\u5947\u4e4b\u5904<\/strong>\uff1a\u5b83<strong>\u4e0d\u6539\u53d8\u7279\u5f81\u56fe\u5c3a\u5bf8<\/strong>\uff08\u56e0\u4e3a<code>stride=1<\/code>\u4e14\u505a\u4e86<code>padding<\/code>\uff09\uff0c\u53ea\u505a\u4fe1\u606f\u63d0\u70bc\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong><code>forward<\/code>\u00a0\u51fd\u6570\u91cc\u7684\u8fde\u73af\u7b5b<\/strong>\uff1a<code>y1 = self.m(x) \u00a0\u00a0<em># \u7528\u7b5b\u5b50\u7b5b\u7b2c\u4e00\u904d<\/em><br>y2 = self.m(y1) \u00a0<em># \u628a\u7b2c\u4e00\u904d\u7b5b\u8fc7\u7684\u7ed3\u679c\uff0c\u518d\u7b5b\u7b2c\u4e8c\u904d\uff01<\/em><br>return\u00a0self.cv2(torch.cat((x, y1, y2, self.m(y2)),\u00a01))<\/code><ul><li><code>x<\/code>: \u539f\u59cb\u6750\u6599\uff08\u5305\u542b\u6240\u6709\u6700\u7cbe\u7ec6\u7684\u7ec6\u8282\uff09<\/li><li><code>y1<\/code>: \u4e2d\u7b49\u5c3a\u5ea6\u4fe1\u606f<\/li><li><code>y2<\/code>: \u5927\u5c3a\u5ea6\u4fe1\u606f<\/li><li><code>self.m(y2)<\/code>: \u8d85\u5927\u5c3a\u5ea6\u4fe1\u606f<\/li><\/ul><ul><li><strong>\u6bd4\u55bb<\/strong>\uff1a\u6211\u4eec\u6765\u73a9\u4e00\u4e2a\u201c<strong>\u8fde\u73af\u7b5b<\/strong>\u201d\u7684\u6e38\u620f\uff01<\/li><li><strong>\u6700\u7ec8<\/strong>\uff0c\u6211\u4eec\u628a\u56db\u79cd\u6750\u6599\u653e\u5230\u4e00\u8d77\uff1a<\/li><li>\u7528\u00a0<code>torch.cat<\/code>\u00a0\u628a\u5b83\u4eec<strong>\u5168\u90e8\u62fc\u63a5\u8d77\u6765<\/strong>\u3002\u73b0\u5728\uff0c\u6211\u4eec\u7684\u7279\u5f81\u56fe\u539a\u5ea6\uff08\u901a\u9053\u6570\uff09\u53d8\u6210\u4e86\u539f\u6765\u76844\u500d\uff08<code>inter_dim * 4<\/code>\uff09\uff0c\u56e0\u4e3a\u5b83\u540c\u65f6\u5305\u542b\u4e86\u4ece\u201c\u7ec6\u8282\u201d\u5230\u201c\u5168\u5c40\u201d\u7684<strong>\u6240\u6709\u5c3a\u5ea6\u7684\u7cbe\u534e\u4fe1\u606f<\/strong>\uff01<\/li><\/ul>\n<ol class=\"wp-block-list\">\n<li><strong>\u7b2c\u4e00\u7b5b (<code>y1<\/code>)<\/strong>\uff1a\u5bf9\u539f\u59cb\u8f93\u5165\u00a0<code>x<\/code>\u00a0\u7b5b\u4e00\u904d\u3002\u8fd9\u4e2a\u7ed3\u679c\u4ee3\u8868\u4e86\u539f\u56fe\u4e2d<strong>\u4e2d\u7b49\u5c3a\u5ea6<\/strong>\uff08\u53d7\u00a0<code>5x5<\/code>\u00a0\u5b54\u5f84\u5f71\u54cd\uff09\u7684\u663e\u8457\u4fe1\u606f\u3002<\/li>\n\n\n\n<li><strong>\u7b2c\u4e8c\u7b5b (<code>y2<\/code>)<\/strong>\uff1a\u628a\u00a0<code>y1<\/code>\u00a0\u518d\u7b5b\u4e00\u904d\u3002\u8fd9\u76f8\u5f53\u4e8e\u5728\u4e00\u4e2a\u66f4\u5927\u7684\u611f\u53d7\u91ce\uff08\u53ef\u4ee5\u60f3\u8c61\u6210\u00a0<code>9x9<\/code>\u00a0\u7684\u533a\u57df\uff09\u91cc\u627e\u6700\u5927\u503c\uff0c\u5b83\u6355\u6349\u7684\u662f<strong>\u66f4\u5927\u5c3a\u5ea6<\/strong>\u7684\u663e\u8457\u4fe1\u606f\u3002<\/li>\n\n\n\n<li><strong>\u7b2c\u4e09\u7b5b (<code>self.m(y2)<\/code>)<\/strong>\uff1a\u518d\u628a\u00a0<code>y2<\/code>\u00a0\u7b5b\u4e00\u904d\uff01\u8fd9\u76f8\u5f53\u4e8e\u5728\u4e00\u4e2a\u5de8\u5927\u7684\uff08<code>13x13<\/code>\uff09\u611f\u53d7\u91ce\u91cc\u627e\u6700\u5927\u503c\uff0c\u6355\u6349<strong>\u8d85\u5927\u5c3a\u5ea6<\/strong>\u7684\u5168\u5c40\u663e\u8457\u4fe1\u606f\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"3\" class=\"wp-block-list\">\n<li>\u6700\u7ec8\u6574\u5408\uff08<code>self.cv2<\/code>\uff09<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>self.cv2 = Conv(...)<\/code><\/strong>\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u73b0\u5728\u6211\u4eec\u6709\u4e86\u4e00\u645e\u4e0d\u540c\u5c3a\u5ea6\u7684\u4fe1\u606f\u62a5\u544a\uff0c\u592a\u591a\u4e86\uff0c\u9700\u8981\u4e00\u4f4d<strong>\u6700\u7ec8\u6574\u5408\u5458<\/strong>\u3002<\/li>\n\n\n\n<li>\u8fd9\u4f4d\u6574\u5408\u5458\uff08\u53c8\u4e00\u4e2a\u00a0<code>1x1<\/code>\u00a0\u5377\u79ef\uff09\u7684\u5de5\u4f5c\u662f\u628a\u8fd9\u645e\u539a\u539a\u7684\u62a5\u544a\uff08<code>inter_dim * 4<\/code>\u00a0\u901a\u9053\uff09\u538b\u7f29\u3001\u6574\u5408\u6210\u4e00\u4efd\u683c\u5f0f\u7edf\u4e00\u3001\u7cbe\u70bc\u7684\u6700\u7ec8\u62a5\u544a\uff08<code>out_dim<\/code>\u00a0\u901a\u9053\uff09\uff0c\u9001\u7ed9\u4e0b\u4e00\u4e2a\u90e8\u95e8\uff08Head\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>SPP\u7684\u6838\u5fc3\u601d\u60f3<\/strong>\uff1a****\u201c\u4e0d\u7ba1\u4f60\u5173\u5fc3\u7684\u4fe1\u606f\u662f\u5927\u662f\u5c0f\uff0c\u6211\u540c\u65f6\u7ed9\u4f60\u770b\u4e00\u904d\uff0c\u4fdd\u8bc1\u4e00\u4e2a\u90fd\u6f0f\u4e0d\u6389\uff01\u201d** \u8fd9\u6781\u5927\u5730\u589e\u5f3a\u4e86\u6a21\u578b\u5bf9\u4e0d\u540c\u5927\u5c0f\u7269\u4f53\u7684\u68c0\u6d4b\u80fd\u529b\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e8c\u90e8\u5206\uff1a\u5de5\u4f5c\u7ad9\u91c7\u8d2d\u90e8\uff08<code>build_neck<\/code>&nbsp;\u51fd\u6570\uff09<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u90e8\u5206\u4ee3\u7801\u5c31\u662f\u6839\u636e\u603b\u516c\u53f8\u7684\u84dd\u56fe\uff08<code>cfg<\/code>\u914d\u7f6e\u5b57\u5178\uff09\u6765\u8ba2\u8d2d\u548c\u7ec4\u88c5\u4e0a\u9762\u90a3\u4e2aSPP\u5de5\u4f5c\u7ad9\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>neck = SPPF(<br>&nbsp; &nbsp; in_dim=in_dim, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u544a\u8bc9\u5de5\u5382\uff1a\u8fdb\u6765\u7684\u539f\u6599\u539a\u5ea6\u662ffeat_dim\uff08\u6765\u81eaBackbone\uff09<\/em><br>&nbsp; &nbsp; out_dim=out_dim, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u6211\u6700\u7ec8\u8981\u7684\u6210\u54c1\u539a\u5ea6\u662f512<\/em><br>&nbsp; &nbsp; expand_ratio=cfg&#91;'expand_ratio'], &nbsp; &nbsp;&nbsp;<em># \u4e2d\u95f4\u538b\u7f29\u7387\u75280.5<\/em><br>&nbsp; &nbsp; pooling_size=cfg&#91;'pooling_size'], &nbsp; &nbsp;&nbsp;<em># \u7ed9\u6211\u914d\u4e00\u4e2a\u5b54\u5f84\u4e3a5\u7684\u7b5b\u5b50<\/em><br>&nbsp; &nbsp; act_type=cfg&#91;'neck_act'], &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u6fc0\u6d3b\u51fd\u6570\u7528LeakyReLU<\/em><br>&nbsp; &nbsp; norm_type=cfg&#91;'neck_norm'] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em># \u6807\u51c6\u5316\u7528BatchNorm<\/em><br>)<\/code><\/pre>\n\n\n\n<p>\u5b83\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u91cc\u7684\u53c2\u6570\uff0c\u50cf\u586b\u8ba2\u5355\u4e00\u6837\uff0c\u5b9a\u5236\u4e86\u4e00\u4e2a\u7b26\u5408\u6211\u4eec\u8981\u6c42\u7684SPPF\u5de5\u4f5c\u7ad9\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e09\u90e8\u5206\uff1a\u5728YOLO\u5de5\u5382\u4e2d\u5b89\u88c5\u5de5\u4f5c\u7ad9<\/p>\n<\/blockquote>\n\n\n\n<p>\u6700\u540e\uff0c\u5728\u4f60\u7684YOLO\u4e3b\u5de5\u5382\u91cc\uff0c\u7528\u4e24\u884c\u4ee3\u7801\u5c31\u5b8c\u6210\u4e86Neck\u7684\u642d\u5efa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>self.neck = build_neck(cfg, feat_dim, out_dim=512)<br>head_dim = self.neck.out_dim<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7b2c\u4e00\u884c<\/strong>\uff1a\u8c03\u7528\u91c7\u8d2d\u90e8\uff08<code>build_neck<\/code>\u51fd\u6570\uff09\uff0c\u547d\u4ee4\u662f\uff1a\u201c\u6839\u636e\u00a0<code>cfg<\/code>\u00a0\u7684\u914d\u7f6e\uff0c\u5efa\u9020\u4e00\u4e2aNeck\u3002\u5b83\u8f93\u5165\u7684\u901a\u9053\u6570\u662f\u00a0<code>feat_dim<\/code>\uff08\u8fd9\u662fBackbone\u544a\u8bc9\u6211\u7684\uff09\uff0c\u8f93\u51fa\u7684\u901a\u9053\u6570\u4f60\u7ed9\u6211\u505a\u6210512\u3002\u201d<\/li>\n\n\n\n<li><strong>\u7b2c\u4e8c\u884c<\/strong>\uff1a\u8bb0\u4e0b\u8fd9\u4e2a\u65b0\u5de5\u4f5c\u7ad9\u6700\u7ec8\u4ea7\u51fa\u7684\u7ef4\u5ea6\u00a0<code>head_dim<\/code>\uff08\u5176\u5b9e\u5c31\u662f512\uff09\uff0c\u56e0\u4e3a\u4e0b\u4e00\u4e2a\u90e8\u95e8\uff08Head\uff09\u9700\u8981\u77e5\u9053\u5b83\u8981\u63a5\u6536\u7684\u6570\u636e\u6709\u591a\u201c\u539a\u201d\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u603b\u7ed3<\/p>\n<\/blockquote>\n\n\n\n<p>SPP\u6a21\u5757\u662f\u4e00\u4e2a\u6781\u5176\u5de7\u5999\u800c\u6709\u6548\u7684\u8bbe\u8ba1\uff0c\u5b83\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4e0d\u6539\u53d8\u8f93\u5165\u7279\u5f81\u7684\u5bbd\u9ad8<\/strong>\uff0c\u53ea\u6539\u53d8\u5176\u901a\u9053\u6570\u3002<\/li>\n\n\n\n<li>\u901a\u8fc7<strong>\u540c\u4e00\u4e2a\u6c60\u5316\u5c42\u7684\u91cd\u590d\u5e94\u7528<\/strong>\uff0c\u4f4e\u6210\u672c\u5730\u5b9e\u73b0\u4e86<strong>\u591a\u5c3a\u5ea6\u7279\u5f81\u878d\u5408<\/strong>\u3002<\/li>\n\n\n\n<li>\u8ba9\u540e\u7eed\u7684\u68c0\u6d4b\u5934\uff08Head\uff09<strong>\u540c\u65f6\u62e5\u6709<\/strong>\u7ec6\u8282\u7279\u5f81\u548c\u5168\u5c40\u8bed\u4e49\u7279\u5f81\uff0c\u4ece\u800c\u65e0\u8bba\u662f\u5927\u76ee\u6807\u8fd8\u662f\u5c0f\u76ee\u6807\uff0c\u90fd\u80fd\u83b7\u5f97\u66f4\u597d\u7684\u68c0\u6d4b\u6548\u679c\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u8fd9\u5c31\u662fYOLOv1\u914d\u7f6e\u4e2d\u201c\u6dfb\u52a0Neck\u6a21\u5757\u201d\u7684\u5177\u4f53\u5b9e\u73b0\uff0c\u4e5f\u662f\u5b83\u6027\u80fd\u8fdc\u8d85\u539f\u7248\u7684\u5173\u952e\u5347\u7ea7\u4e4b\u4e00\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.3 \u642d\u5efaDetection head\u7f51\u7edc<\/h2>\n\n\n\n<p>\u8fd9\u4e00\u90e8\u5206\u5c31\u76f8\u5bf9\u7b80\u5355\u4e86\uff0c\u53ea\u9700\u8981\u642d\u5efa\u4e24\u6761\u5206\u652f\uff0c\u6bcf\u6761\u5206\u652f\u653e\u7f6e\u82e5\u5e72\u5c42\u5377\u79ef\u5c42\u5373\u53ef\uff0c\u5982\u4e0b\u65b9\u7684\u4ee3\u7801\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># RT-ODLab\/models\/detectors\/yolov1\/yolov1_head.py<br><br><br>class DecoupledHead(nn.Module):<br>&nbsp; &nbsp; def __init__(self, cfg, in_dim, out_dim, num_classes=80):<br>&nbsp; &nbsp; &nbsp; &nbsp; super().__init__()<br>&nbsp; &nbsp; &nbsp; &nbsp; print('==============================')<br>&nbsp; &nbsp; &nbsp; &nbsp; print('Head: Decoupled Head')<br>&nbsp; &nbsp; &nbsp; &nbsp; self.in_dim = in_dim<br>&nbsp; &nbsp; &nbsp; &nbsp; self.num_cls_head=cfg&#91;'num_cls_head']<br>&nbsp; &nbsp; &nbsp; &nbsp; self.num_reg_head=cfg&#91;'num_reg_head']<br>&nbsp; &nbsp; &nbsp; &nbsp; self.act_type=cfg&#91;'head_act']<br>&nbsp; &nbsp; &nbsp; &nbsp; self.norm_type=cfg&#91;'head_norm']<br><br>&nbsp; &nbsp; &nbsp; &nbsp; # cls head<br>&nbsp; &nbsp; &nbsp; &nbsp; cls_feats = &#91;]<br>&nbsp; &nbsp; &nbsp; &nbsp; self.cls_out_dim = max(out_dim, num_classes)<br>&nbsp; &nbsp; &nbsp; &nbsp; for i in range(cfg&#91;'num_cls_head']):<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if i == 0:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cls_feats.append(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Conv(in_dim, self.cls_out_dim, k=3, p=1, s=1,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; act_type=self.act_type,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; norm_type=self.norm_type,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; depthwise=cfg&#91;'head_depthwise'])<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cls_feats.append(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Conv(self.cls_out_dim, self.cls_out_dim, k=3, p=1, s=1,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; act_type=self.act_type,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; norm_type=self.norm_type,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; depthwise=cfg&#91;'head_depthwise'])<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )<br>&nbsp; &nbsp; &nbsp; &nbsp; # reg head<br>&nbsp; &nbsp; &nbsp; &nbsp; reg_feats = &#91;]<br>&nbsp; &nbsp; &nbsp; &nbsp; self.reg_out_dim = max(out_dim, 64)<br>&nbsp; &nbsp; &nbsp; &nbsp; for i in range(cfg&#91;'num_reg_head']):<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if i == 0:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reg_feats.append(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Conv(in_dim, self.reg_out_dim, k=3, p=1, s=1,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; act_type=self.act_type,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; norm_type=self.norm_type,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; depthwise=cfg&#91;'head_depthwise'])<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reg_feats.append(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Conv(self.reg_out_dim, self.reg_out_dim, k=3, p=1, s=1,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; act_type=self.act_type,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; norm_type=self.norm_type,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; depthwise=cfg&#91;'head_depthwise'])<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )<br>&nbsp; &nbsp; &nbsp; &nbsp; self.cls_feats = nn.Sequential(*cls_feats)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.reg_feats = nn.Sequential(*reg_feats)<br><br>&nbsp; &nbsp; def forward(self, x):<br>&nbsp; &nbsp; &nbsp; &nbsp; \"\"\"<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; in_feats: (Tensor) &#91;B, C, H, W]<br>&nbsp; &nbsp; &nbsp; &nbsp; \"\"\"<br>&nbsp; &nbsp; &nbsp; &nbsp; cls_feats = self.cls_feats(x)<br>&nbsp; &nbsp; &nbsp; &nbsp; reg_feats = self.reg_feats(x)<br><br>&nbsp; &nbsp; &nbsp; &nbsp; return cls_feats, reg_feats<br><br># build detection head<br>def build_head(cfg, in_dim, out_dim, num_classes=80):<br>&nbsp; &nbsp; head = DecoupledHead(cfg, in_dim, out_dim, num_classes)&nbsp;<br><br>&nbsp; &nbsp; return head<\/code><\/pre>\n\n\n\n<p>\u5728\u6211\u4eec\u7684YOLOv1\u4e3b\u4f53\u4ee3\u7801\u6846\u67b6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528build_head\u51fd\u6570\u6765\u642d\u5efaDecoupled head\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>## \u68c0\u6d4b\u5934<br>self.head = build_head(cfg, head_dim, head_dim, num_classes)<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7ee7\u7eed\u7785\u7785<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6545\u4e8b\uff1aDecoupled Head \u2014\u2014 \u201c\u5206\u5de5\u660e\u786e\u7684\u4e13\u5bb6\u56e2\u961f\u201d<\/p>\n<\/blockquote>\n\n\n\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0cNeck\uff08SPP\u6a21\u5757\uff09\u9001\u6765\u7684\u662f\u4e00\u4efd<strong>\u4fe1\u606f\u975e\u5e38\u4e30\u5bcc\u7684\u201c\u7efc\u5408\u60c5\u62a5\u62a5\u544a\u201d<\/strong>\u3002\u8fd9\u4efd\u62a5\u544a\u91cc\u65e2\u6709\u5173\u4e8e\u201c\u662f\u4ec0\u4e48\u201d\uff08\u5206\u7c7b\uff09\u7684\u7ebf\u7d22\uff0c\u4e5f\u6709\u5173\u4e8e\u201c\u5728\u54ea\u91cc\u201d\uff08\u5b9a\u4f4d\uff09\u7684\u7ebf\u7d22\uff0c\u5b83\u4eec\u6df7\u5728\u4e00\u8d77\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u7684\u4efb\u52a1\u662f\u8981\u4ece\u8fd9\u4efd\u62a5\u544a\u91cc\u5f97\u51fa\u4e24\u4e2a\u660e\u786e\u7684\u7ed3\u8bba\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u7269\u4f53\u662f\u4ec0\u4e48\uff1f<\/strong>\u00a0\uff08\u5206\u7c7b\u4efb\u52a1\uff09<\/li>\n\n\n\n<li><strong>\u7269\u4f53\u7684\u7cbe\u786e\u4f4d\u7f6e\u5728\u54ea\uff1f<\/strong>\u00a0\uff08\u56de\u5f52\u4efb\u52a1\uff09<\/li>\n<\/ol>\n\n\n\n<p>\u539f\u59cbYOLOv1\u7684\u505a\u6cd5\u662f\uff1a\u8ba9<strong>\u4e00\u4e2a\u56e2\u961f<\/strong>\u540c\u65f6\u5904\u7406\u8fd9\u4e24\u4e2a\u95ee\u9898\u3002\u8fd9\u5c31\u50cf\u8ba9\u4e00\u4e2a\u533b\u751f\u65e2\u8d1f\u8d23\u770bX\u5149\u7247\uff08\u5206\u7c7b\uff1a\u6709\u6ca1\u6709\u75c5\u7076\uff1f\uff09\uff0c\u53c8\u8d1f\u8d23\u62ff\u624b\u672f\u5200\u505a\u624b\u672f\uff08\u56de\u5f52\uff1a\u75c5\u7076\u7684\u7cbe\u786e\u4f4d\u7f6e\u548c\u5927\u5c0f\uff1f\uff09\u3002\u867d\u7136\u4e5f\u80fd\u505a\uff0c\u4f46\u6548\u7387\u548c\u7cbe\u5ea6\u53ef\u80fd\u4e0d\u662f\u6700\u4f18\u3002<\/p>\n\n\n\n<p>\u800c\u201c\u89e3\u8026\u5934\u201d\u7684\u505a\u6cd5\u662f\uff1a\u6210\u7acb<strong>\u4e24\u4e2a\u4e13\u4e1a\u7684\u4e13\u5bb6\u56e2\u961f<\/strong>\uff0c\u4e00\u4e2a\u4e13\u95e8\u8d1f\u8d23\u201c\u5206\u7c7b\u201d\uff0c\u4e00\u4e2a\u4e13\u95e8\u8d1f\u8d23\u201c\u5b9a\u4f4d\u201d\u3002\u5b83\u4eec\u5404\u81ea\u7814\u7a76\u540c\u4e00\u4efd\u60c5\u62a5\uff0c\u4f46\u53ea\u4e13\u6ce8\u4e8e\u89e3\u51b3\u81ea\u5df1\u6700\u64c5\u957f\u7684\u95ee\u9898\u3002\u8fd9\u5c31\u662f\u201c\u89e3\u8026\u201d\uff08Decoupled\uff09\u7684\u542b\u4e49\u2014\u2014\u5c06\u8026\u5408\u5728\u4e00\u8d77\u7684\u4efb\u52a1\u5206\u79bb\u5f00\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e00\u90e8\u5206\uff1a\u7ec4\u5efa\u4e13\u5bb6\u56e2\u961f\uff08<code>class DecoupledHead<\/code>\uff09<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u4e2a\u7c7b\u5c31\u662f\u5728\u7ec4\u5efa\u8fd9\u4e24\u4e2a\u4e13\u5bb6\u56e2\u961f\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol class=\"wp-block-list\">\n<li>\u56e2\u961f\u914d\u7f6e\uff08<code>__init__<\/code>\u00a0\u65b9\u6cd5\u4e2d\u7684\u53c2\u6570\uff09<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>num_cls_head<\/code>\u00a0\u548c\u00a0<code>num_reg_head<\/code>\uff1a\u8fd9\u51b3\u5b9a\u4e86\u6bcf\u4e2a\u4e13\u5bb6\u56e2\u961f\u6709\u591a\u5c11<strong>\u5c42<\/strong>\uff08\u5373\uff0c\u6709\u591a\u5c11\u4f4d\u4e13\u5bb6\u8fdb\u884c\u63a5\u529b\u5206\u6790\uff09\u3002\u6bd4\u5982\u00a0<code>num_cls_head=2<\/code>\u00a0\u8868\u793a\u5206\u7c7b\u4e13\u5bb6\u7ec4\u67092\u5c42\u5377\u79ef\u5c42\u3002<\/li>\n\n\n\n<li><code>act_type<\/code>\u00a0\u548c\u00a0<code>norm_type<\/code>\uff1a\u8fd9\u662f\u7ed9\u6bcf\u4f4d\u4e13\u5bb6\u914d\u5907\u7684<strong>\u6807\u51c6\u5de5\u4f5c\u88c5\u5907<\/strong>\uff08\u6fc0\u6d3b\u51fd\u6570\u548c\u6807\u51c6\u5316\u5c42\uff09\uff0c\u786e\u4fdd\u4ed6\u4eec\u7684\u5de5\u4f5c\u6d41\u7a0b\u9ad8\u6548\u7a33\u5b9a\u3002<\/li>\n\n\n\n<li><code>depthwise<\/code>\uff1a\u8fd9\u662f\u4e00\u79cd\u66f4\u9ad8\u6548\u3001\u66f4\u8f7b\u91cf\u5316\u7684\u201c\u4e13\u5bb6\u5de5\u4f5c\u6a21\u5f0f\u201d\uff08\u6df1\u5ea6\u53ef\u5206\u79bb\u5377\u79ef\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u7ec4\u5efa\u5206\u7c7b\u4e13\u5bb6\u7ec4 (<code>cls_feats<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/wxa.wxs.qq.com\/tmpl\/oc\/base_tmpl.html\n<\/div><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>cls_feats = &#91;]<br>for&nbsp;i&nbsp;in&nbsp;range(cfg&#91;'num_cls_head']):<br>&nbsp; &nbsp;&nbsp;if&nbsp;i ==&nbsp;0:<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u7b2c\u4e00\u4f4d\u4e13\u5bb6\uff1a\u76f4\u63a5\u63a5\u89e6\u539f\u59cb\u60c5\u62a5<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; cls_feats.append(Conv(in_dim, self.cls_out_dim, k=3, p=1, s=1, ...))<br>&nbsp; &nbsp;&nbsp;else:<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u540e\u7eed\u4e13\u5bb6\uff1a\u57fa\u4e8e\u524d\u4e00\u4f4d\u4e13\u5bb6\u7684\u5206\u6790\u7ed3\u679c\u8fdb\u884c\u6df1\u5316<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; cls_feats.append(Conv(self.cls_out_dim, self.cls_out_dim, k=3, p=1, s=1, ...))<br>self.cls_feats = nn.Sequential(*cls_feats)&nbsp;<em># \u5c06\u4e13\u5bb6\u4eec\u4e32\u8054\u6210\u4e00\u4e2a\u6d41\u6c34\u7ebf<\/em><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u5206\u7c7b\u4e13\u5bb6\u7ec4\u662f\u4e00\u4e2a<strong>\u5206\u6790\u6d41\u6c34\u7ebf<\/strong>\u3002\n<ul class=\"wp-block-list\">\n<li><strong>\u7b2c\u4e00\u4f4d\u4e13\u5bb6<\/strong>\uff1a\u4ed6\u4ece\u603b\u60c5\u62a5 (<code>in_dim<\/code>) \u4e2d\u63a5\u624b\uff0c\u5f00\u59cb\u521d\u6b65\u5206\u6790\uff0c\u5e76\u628a\u4ed6\u7684\u53d1\u73b0\u6574\u7406\u6210\u4e00\u4efd\u6807\u51c6\u7684\u5206\u7c7b\u62a5\u544a\u683c\u5f0f (<code>cls_out_dim<\/code>)\u3002<\/li>\n\n\n\n<li><strong>\u7b2c\u4e8c\u4f4d\u4e13\u5bb6<\/strong>\uff1a\u4ed6\u62ff\u5230\u524d\u4e00\u4f4d\u7684\u62a5\u544a\uff0c\u5e76\u4e0d\u53bb\u770b\u539f\u59cb\u60c5\u62a5\u4e86\u3002\u4ed6\u7684\u4efb\u52a1\u662f<strong>\u8fdb\u4e00\u6b65\u63d0\u70bc\u548c\u786e\u8ba4<\/strong>\u8fd9\u4efd\u62a5\u544a\uff0c\u8ba9\u7ed3\u8bba\u66f4\u52a0\u53ef\u9760\u3002\u4ed6\u8f93\u51fa\u7684\u8fd8\u662f\u540c\u6837\u683c\u5f0f\u7684\u62a5\u544a\u3002<\/li>\n\n\n\n<li><code>nn.Sequential<\/code>\u00a0\u5c31\u50cf\u628a\u8fd9\u4e24\u4f4d\u4e13\u5bb6\u5b89\u6392\u5728\u4e00\u4e2a\u623f\u95f4\u91cc\uff0c\u60c5\u62a5\u4ece\u7b2c\u4e00\u4f4d\u4f20\u5230\u6700\u540e\u4e00\u4f4d\uff0c\u5b8c\u6210\u6574\u4e2a\u5206\u7c7b\u5206\u6790\u6d41\u7a0b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"3\" class=\"wp-block-list\">\n<li>\u7ec4\u5efa\u5b9a\u4f4d\u4e13\u5bb6\u7ec4 (<code>reg_feats<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>reg_feats = &#91;]<br>for&nbsp;i&nbsp;in&nbsp;range(cfg&#91;'num_reg_head']):<br>&nbsp; &nbsp;&nbsp;if&nbsp;i ==&nbsp;0:<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u7b2c\u4e00\u4f4d\u4e13\u5bb6\uff1a\u76f4\u63a5\u63a5\u89e6\u539f\u59cb\u60c5\u62a5<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; reg_feats.append(Conv(in_dim, self.reg_out_dim, k=3, p=1, s=1, ...))<br>&nbsp; &nbsp;&nbsp;else:<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em># \u540e\u7eed\u4e13\u5bb6\uff1a\u57fa\u4e8e\u524d\u4e00\u4f4d\u4e13\u5bb6\u7684\u5206\u6790\u7ed3\u679c\u8fdb\u884c\u6df1\u5316<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; reg_feats.append(Conv(self.reg_out_dim, self.reg_out_dim, k=3, p=1, s=1, ...))<br>self.reg_feats = nn.Sequential(*reg_feats)&nbsp;<em># \u5c06\u4e13\u5bb6\u4eec\u4e32\u8054\u6210\u4e00\u4e2a\u6d41\u6c34\u7ebf<\/em><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u5b9a\u4f4d\u4e13\u5bb6\u7ec4\u7684\u7684\u5de5\u4f5c\u6a21\u5f0f\u548c\u5206\u7c7b\u7ec4<strong>\u5b8c\u5168\u4e00\u6837<\/strong>\uff0c\u4f46\u4ed6\u4eec\u662f\u53e6\u4e00\u6279\u4e13\u5bb6\uff0c\u4ed6\u4eec\u7684\u5de5\u4f5c\u76ee\u6807\u4e0d\u540c\uff1a\n<ul class=\"wp-block-list\">\n<li>\u4ed6\u4eec\u7684\u4efb\u52a1\u662f\u5206\u6790\u7269\u4f53\u7684<strong>\u7cbe\u786e\u5750\u6807<\/strong>\u00a0(<code>x, y, w, h<\/code>)\u3002<\/li>\n\n\n\n<li>\u4ed6\u4eec\u8f93\u51fa\u7684\u62a5\u544a\u683c\u5f0f (<code>reg_out_dim<\/code>) \u4e5f\u662f\u4e3a\u4e86\u540e\u7eed\u8ba1\u7b97\u5750\u6807\u800c\u8bbe\u8ba1\u7684\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>\u5173\u952e\u70b9<\/strong>\uff1a\u4e24\u4e2a\u56e2\u961f<strong>\u72ec\u7acb\u5de5\u4f5c\uff0c\u4e92\u4e0d\u5e72\u6270<\/strong>\u3002\u5b83\u4eec\u90fd\u4ece\u540c\u4e00\u4efd\u539f\u59cb\u60c5\u62a5 (<code>x<\/code>) \u5f00\u59cb\uff0c\u4f46\u5404\u81ea\u53d1\u5c55\u51fa\u81ea\u5df1\u7684\u4e13\u4e1a\u5206\u6790\u7ed3\u679c\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e8c\u90e8\u5206\uff1a\u56e2\u961f\u5de5\u4f5c\u6d41\u7a0b\uff08<code>forward<\/code>&nbsp;\u65b9\u6cd5\uff09<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>def&nbsp;forward(self, x):<br>&nbsp; &nbsp; cls_feats = self.cls_feats(x)&nbsp;<em># \u628a\u60c5\u62a5\u4ea4\u7ed9\u5206\u7c7b\u4e13\u5bb6\u7ec4\uff0c\u5f97\u5230\u5206\u7c7b\u7ed3\u8bba<\/em><br>&nbsp; &nbsp; reg_feats = self.reg_feats(x)&nbsp;<em># \u628a\u540c\u4e00\u4efd\u60c5\u62a5\u4ea4\u7ed9\u5b9a\u4f4d\u4e13\u5bb6\u7ec4\uff0c\u5f97\u5230\u5b9a\u4f4d\u7ed3\u8bba<\/em><br>&nbsp; &nbsp;&nbsp;return&nbsp;cls_feats, reg_feats &nbsp;&nbsp;<em># \u8fd4\u56de\u4e24\u4efd\u4e13\u5bb6\u62a5\u544a<\/em><\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u8fc7\u7a0b\u975e\u5e38\u7b80\u5355\u6e05\u6670\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u8f93\u5165\uff1a\u6765\u81eaNeck\u7684\u201c\u7efc\u5408\u60c5\u62a5\u201d\u00a0<code>x<\/code>\u3002<\/li>\n\n\n\n<li>\u8fc7\u7a0b\uff1a\u5c06\u00a0<code>x<\/code><strong>\u540c\u65f6<\/strong>\u9001\u5165\u4e24\u4e2a\u4e13\u5bb6\u56e2\u961f\u3002<\/li>\n\n\n\n<li>\u8f93\u51fa\uff1a\u5f97\u5230\u4e24\u4efd\u4e13\u5bb6\u62a5\u544a\uff1a\n<ul class=\"wp-block-list\">\n<li><code>cls_feats<\/code>\uff1a\u8fd9\u662f\u4e00\u5f20\u201c<strong>\u662f\u4ec0\u4e48<\/strong>\u201d\u7684\u70ed\u529b\u56fe\uff0c\u6bcf\u4e2a\u4f4d\u7f6e\u7684\u503c\u4ee3\u8868\u4e86\u8be5\u5904\u662f\u67d0\u4e2a\u7c7b\u522b\u7684\u6982\u7387\u3002<\/li>\n\n\n\n<li><code>reg_feats<\/code>\uff1a\u8fd9\u662f\u4e00\u5f20\u201c<strong>\u5728\u54ea\u91cc<\/strong>\u201d\u7684\u504f\u79fb\u91cf\u8868\uff0c\u6bcf\u4e2a\u4f4d\u7f6e\u7684\u503c\u7528\u4e8e\u8ba1\u7b97\u6700\u7ec8\u8fb9\u754c\u6846\u7684\u7cbe\u786e\u5750\u6807\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e09\u90e8\u5206\uff1a\u56e2\u961f\u8c03\u5ea6\u4e2d\u5fc3\uff08<code>build_head<\/code>&nbsp;\u51fd\u6570\uff09<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u4e2a\u51fd\u6570\u5c31\u662fYOLO\u5de5\u5382\u7684<strong>\u4eba\u529b\u8d44\u6e90\u90e8<\/strong>\uff0c\u5b83\u6839\u636e\u603b\u516c\u53f8\u7684\u8981\u6c42\uff08<code>cfg<\/code>\u914d\u7f6e\uff09\u6765\u62db\u52df\u548c\u7ec4\u5efa\u4e0a\u9762\u90a3\u4e24\u4e2a\u4e13\u5bb6\u56e2\u961f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def&nbsp;build_head(cfg, in_dim, out_dim, num_classes=80):<br>&nbsp; &nbsp; head = DecoupledHead(cfg, in_dim, out_dim, num_classes)<br>&nbsp; &nbsp;&nbsp;return&nbsp;head<\/code><\/pre>\n\n\n\n<p>\u5b83\u544a\u8bc9&nbsp;<code>DecoupledHead<\/code>&nbsp;\u7c7b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>in_dim<\/code>\uff1a\u4e13\u5bb6\u4eec\u8981\u5206\u6790\u7684\u60c5\u62a5\u6709\u591a\u201c\u539a\u201d\uff08\u8f93\u5165\u901a\u9053\u6570\uff09\u3002<\/li>\n\n\n\n<li><code>out_dim<\/code>\uff1a\u6211\u4eec\u5e0c\u671b\u4e13\u5bb6\u4eec\u8f93\u51fa\u7684\u62a5\u544a\u6709\u591a\u201c\u539a\u201d\uff08\u8f93\u51fa\u901a\u9053\u6570\uff09\u3002<\/li>\n\n\n\n<li><code>num_classes<\/code>\uff1a\u5206\u7c7b\u4e13\u5bb6\u9700\u8981\u77e5\u9053\u4e00\u5171\u6709\u591a\u5c11\u79cd\u7269\u4f53\u8981\u533a\u5206\u3002<\/li>\n\n\n\n<li><code>cfg<\/code>\uff1a\u5176\u4ed6\u6240\u6709\u4eba\u5458\u914d\u7f6e\u7ec6\u8282\uff0c\u6bd4\u5982\u8981\u62db\u51e0\u4f4d\u4e13\u5bb6\u3001\u7528\u4ec0\u4e48\u88c5\u5907\u7b49\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u56db\u90e8\u5206\uff1a\u5728YOLO\u5de5\u5382\u4e2d\u542f\u7528\u56e2\u961f<\/p>\n<\/blockquote>\n\n\n\n<p>\u6700\u540e\uff0c\u5728\u4e3b\u4ee3\u7801\u91cc\uff0c\u7528\u4e00\u884c\u4ee3\u7801\u5c31\u5b8c\u6210\u4e86\u4e24\u4e2a\u4e13\u5bb6\u56e2\u961f\u7684\u7ec4\u5efa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>self.head = build_head(cfg, head_dim, head_dim, num_classes)<\/code><\/pre>\n\n\n\n<p>\u8fd9\u884c\u4ee3\u7801\u7684\u610f\u601d\u662f\uff1a\u201c\u4eba\u529b\u8d44\u6e90\u90e8\uff0c\u8bf7\u6309\u7167&nbsp;<code>cfg<\/code>&nbsp;\u91cc\u7684\u914d\u7f6e\uff0c\u5e2e\u6211\u7ec4\u5efa\u4e00\u4e2a\u68c0\u6d4b\u5934\u3002\u8f93\u5165\u8f93\u51fa\u7684\u60c5\u62a5\u539a\u5ea6\u90fd\u662f&nbsp;<code>head_dim<\/code>\uff08512\uff09\uff0c\u8981\u68c0\u6d4b\u7684\u7c7b\u522b\u6570\u662f&nbsp;<code>num_classes<\/code>\u3002\u201d<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u603b\u7ed3<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u201c<strong>\u5206\u5de5\u660e\u786e<\/strong>\u201d\u7684\u68c0\u6d4b\u5934\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4e13\u4e1a\u5316<\/strong>\uff1a\u5c06\u201c\u5206\u7c7b\u201d\u548c\u201c\u5b9a\u4f4d\u201d\u8fd9\u4e24\u4e2a\u4e0d\u540c\u6027\u8d28\u7684\u4efb\u52a1\u4ea4\u7ed9\u4e24\u4e2a\u72ec\u7acb\u7684\u4e13\u5bb6\u56e2\u961f\uff08\u5206\u652f\uff09\u5904\u7406\uff0c\u6bd4\u4e00\u4e2a\u56e2\u961f\u540c\u65f6\u5904\u7406\u4e24\u4e2a\u4efb\u52a1\u6548\u679c\u66f4\u597d\u3002<\/li>\n\n\n\n<li><strong>\u6df1\u5ea6\u5316<\/strong>\uff1a\u6bcf\u4e2a\u56e2\u961f\u90fd\u7531\u591a\u5c42\uff08<code>num_*_head<\/code>\uff09\u4e13\u5bb6\uff08\u5377\u79ef\u5c42\uff09\u6784\u6210\uff0c\u5141\u8bb8\u5bf9\u7279\u5f81\u8fdb\u884c\u66f4\u6df1\u5ea6\u7684\u5904\u7406\uff0c\u4ece\u800c\u505a\u51fa\u66f4\u51c6\u786e\u7684\u5224\u65ad\u3002<\/li>\n\n\n\n<li><strong>\u5e76\u884c\u5904\u7406<\/strong>\uff1a\u4e24\u4e2a\u56e2\u961f\u540c\u65f6\u5de5\u4f5c\uff0c\u6548\u7387\u6781\u9ad8\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u8fd9\u5c31\u662f\u201c\u89e3\u8026\u5934\u201d\uff08Decoupled Head\uff09\u7684\u6838\u5fc3\u601d\u60f3\uff0c\u4e5f\u662f\u73b0\u4ee3\u76ee\u6807\u68c0\u6d4b\u5668\u76f8\u6bd4YOLOv1\u7b49\u65e9\u671f\u6a21\u578b\u7684\u4e00\u4e2a\u91cd\u8981\u6f14\u8fdb\uff0c\u5b83\u663e\u8457\u63d0\u5347\u4e86\u68c0\u6d4b\u7cbe\u5ea6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.4 \u642d\u5efa\u9884\u6d4b\u5c42<\/h2>\n\n\n\n<p>\u6700\u540e\uff0c\u6211\u4eec\u53ea\u9700\u8981\u653e\u7f6e\u4e09\u5c421x1\u5377\u79ef\uff0c\u5206\u522b\u53bb\u5b8c\u6210objectness\u9884\u6d4b\u3001classification\u9884\u6d4b\u4ee5\u53cabbox\u9884\u6d4b\u5373\u53ef\uff0c\u5982\u4e0b\u65b9\u7684\u4ee3\u7801\u6240\u793a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>## \u9884\u6d4b\u5c42<br>self.obj_pred = nn.Conv2d(head_dim, 1, kernel_size=1)<br>self.cls_pred = nn.Conv2d(head_dim, num_classes, kernel_size=1)<br>self.reg_pred = nn.Conv2d(head_dim, 4, kernel_size=1)<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6545\u4e8b\uff1a\u9884\u6d4b\u5c42 \u2014\u2014 \u201c\u4e09\u4f4d\u4e13\u4e1a\u88c1\u5224\u201d<\/p>\n<\/blockquote>\n\n\n\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0c<code>Decoupled Head<\/code>\uff08\u89e3\u8026\u5934\uff09\u91cc\u7684\u4e24\u4e2a\u4e13\u5bb6\u56e2\u961f\u5df2\u7ecf\u5b8c\u6210\u4e86\u4ed6\u4eec\u7684\u5de5\u4f5c\uff0c\u8f93\u51fa\u4e86\u4e24\u4efd\u9ad8\u5ea6\u63d0\u70bc\u7684\u62a5\u544a\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5206\u7c7b\u4e13\u5bb6\u7ec4<\/strong>\u7684\u62a5\u544a (<code>cls_feats<\/code>)\uff1a\u4e00\u5f20\u56fe\uff0c\u4e0a\u9762\u6807\u8bb0\u4e86\u6bcf\u4e2a\u4f4d\u7f6e\u201c\u53ef\u80fd\u662f\u4ec0\u4e48\u201d\u7684\u4e30\u5bcc\u7279\u5f81\u3002<\/li>\n\n\n\n<li><strong>\u5b9a\u4f4d\u4e13\u5bb6\u7ec4<\/strong>\u7684\u62a5\u544a (<code>reg_feats<\/code>)\uff1a\u4e00\u5f20\u56fe\uff0c\u4e0a\u9762\u6807\u8bb0\u4e86\u6bcf\u4e2a\u4f4d\u7f6e\u201c\u53ef\u80fd\u5728\u54ea\u201d\u7684\u4e30\u5bcc\u7279\u5f81\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u9700\u8981\u4ece\u8fd9\u4e24\u4efd\u62a5\u544a\u4e2d\u8bfb\u51fa\u6700\u7ec8\u7684\u3001\u660e\u786e\u7684\u9884\u6d4b\u6570\u503c\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u5c31\u50cf\u8bf7\u6765<strong>\u4e09\u4f4d\u4e13\u4e1a\u88c1\u5224<\/strong>\uff0c\u4ed6\u4eec\u5404\u81ea\u8d1f\u8d23\u4e00\u9879\u8bc4\u5206\uff0c\u5e76\u4e14\u4ed6\u4eec\u7684\u5de5\u4f5c\u6781\u5176\u7b80\u5355\u9ad8\u6548\uff1a<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u4e09\u4f4d\u88c1\u5224\u7684\u5de5\u4f5c\uff08\u4e09\u884c\u4ee3\u7801\uff09<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u4e09\u4f4d\u88c1\u5224\u7684\u5de5\u4f5c\u65b9\u5f0f\u4e00\u6a21\u4e00\u6837\uff0c\u4ed6\u4eec\u90fd\u662f\u201c<strong>1x1\u5377\u79ef\u88c1\u5224<\/strong>\u201d\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol class=\"wp-block-list\">\n<li>\u7269\u4f53\u88c1\u5224 (<code>self.obj_pred<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>self.obj_pred = nn.Conv2d(head_dim,&nbsp;1, kernel_size=1)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4efb\u52a1<\/strong>\uff1a\u5224\u65ad<strong>\u4e00\u4e2a\u683c\u5b50\u91cc\u5230\u5e95\u6709\u6ca1\u6709\u7269\u4f53<\/strong>\u3002<\/li>\n\n\n\n<li><strong>\u5de5\u4f5c\u65b9\u5f0f<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u4ed6\u53ea\u770b\u5b9a\u4f4d\u4e13\u5bb6\u7ec4\u7684\u62a5\u544a (<code>reg_feats<\/code>\u00a0\u7684\u901a\u9053\u6570\u00a0<code>head_dim<\/code>)\u3002<\/li>\n\n\n\n<li>\u4ed6\u7528\u4e00\u4e2a\u795e\u5947\u7684\u201c1x1\u6807\u51c6\u7b54\u6848\u677f\u201d\uff08<code>1x1<\/code>\u5377\u79ef\u6838\uff09\u5728\u6574\u4e2a\u62a5\u544a\u4e0a\u626b\u63cf\u3002<\/li>\n\n\n\n<li><strong>\u8f93\u51fa<\/strong>\uff1a\u5bf9\u4e8e\u62a5\u544a\u4e0a\u7684\u6bcf\u4e00\u4e2a\u70b9\uff0c\u4ed6\u53ea\u7ed9\u51fa<strong>\u4e00\u4e2a\u5206\u6570<\/strong>\uff08\u8f93\u51fa\u901a\u9053\u4e3a\u00a0<code>1<\/code>\uff09\u3002\u8fd9\u4e2a\u5206\u6570\u5c31\u662f\u201c\u7269\u4f53\u7f6e\u4fe1\u5ea6\u201d\uff0c\u8d8a\u63a5\u8fd11\u8868\u793a\u4ed6\u8d8a\u786e\u4fe1\u8fd9\u4e2a\u4f4d\u7f6e\u6709\u4e00\u4e2a\u7269\u4f53\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u5206\u7c7b\u88c1\u5224 (<code>self.cls_pred<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>self.cls_pred = nn.Conv2d(head_dim, num_classes, kernel_size=1)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4efb\u52a1<\/strong>\uff1a\u5224\u65ad<strong>\u8fd9\u4e2a\u7269\u4f53\u5177\u4f53\u662f\u4ec0\u4e48\u7c7b\u522b<\/strong>\u3002<\/li>\n\n\n\n<li><strong>\u5de5\u4f5c\u65b9\u5f0f<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u4ed6\u53ea\u770b\u5206\u7c7b\u4e13\u5bb6\u7ec4\u7684\u62a5\u544a (<code>cls_feats<\/code>\u00a0\u7684\u901a\u9053\u6570\u00a0<code>head_dim<\/code>)\u3002<\/li>\n\n\n\n<li>\u4ed6\u4e5f\u7528\u4e00\u4e2a\u201c1x1\u6807\u51c6\u7b54\u6848\u677f\u201d\u626b\u63cf\u62a5\u544a\u3002<\/li>\n\n\n\n<li><strong>\u8f93\u51fa<\/strong>\uff1a\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u70b9\uff0c\u4ed6\u7ed9\u51fa\u4e00\u4e2a<strong>\u957f\u5ea6\u4e3a\u00a0<code>num_classes<\/code>\u00a0\u7684\u5206\u6570\u5217\u8868<\/strong>\uff08\u8f93\u51fa\u901a\u9053\u4e3a\u00a0<code>num_classes<\/code>\uff09\u3002\u6bd4\u5982\u670920\u4e2a\u7c7b\u522b\uff0c\u4ed6\u5c31\u8f93\u51fa20\u4e2a\u5206\u6570\u3002\u5206\u6570\u6700\u9ad8\u7684\u90a3\u4e2a\u7c7b\u522b\uff0c\u5c31\u662f\u4ed6\u6700\u7ec8\u5224\u65ad\u7684\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol start=\"3\" class=\"wp-block-list\">\n<li>\u5b9a\u4f4d\u88c1\u5224 (<code>self.reg_pred<\/code>)<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>self.reg_pred = nn.Conv2d(head_dim,&nbsp;4, kernel_size=1)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4efb\u52a1<\/strong>\uff1a\u5224\u65ad<strong>\u8fd9\u4e2a\u7269\u4f53\u6846\u7684\u786e\u5207\u4f4d\u7f6e\u548c\u5927\u5c0f<\/strong>\u3002<\/li>\n\n\n\n<li><strong>\u5de5\u4f5c\u65b9\u5f0f<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u4ed6\u4e5f\u662f\u770b\u5b9a\u4f4d\u4e13\u5bb6\u7ec4\u7684\u62a5\u544a (<code>reg_feats<\/code>)\u3002<\/li>\n\n\n\n<li>\u4ed6\u540c\u6837\u7528\u201c1x1\u6807\u51c6\u7b54\u6848\u677f\u201d\u626b\u63cf\u3002<\/li>\n\n\n\n<li><strong>\u8f93\u51fa<\/strong>\uff1a\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u70b9\uff0c\u4ed6\u7ed9\u51fa<strong>4\u4e2a\u6570\u503c<\/strong>\uff08\u8f93\u51fa\u901a\u9053\u4e3a\u00a0<code>4<\/code>\uff09\u3002\u8fd94\u4e2a\u6570\u503c\u901a\u5e38\u5bf9\u5e94\u8fb9\u754c\u6846\u7684\u4e2d\u5fc3\u70b9\u5750\u6807\u504f\u79fb\u91cf (<code>tx, ty<\/code>) \u548c\u5bbd\u9ad8\u7684\u7f29\u653e\u91cf (<code>tw, th<\/code>)\u3002<strong>\u6ce8\u610f\uff1a\u8fd9\u4e9b\u662f\u539f\u59cb\u504f\u79fb\u91cf\uff0c\u9700\u8981\u540e\u7eed\u7528\u00a0<code>decode_boxes<\/code>\u00a0\u51fd\u6570\u89e3\u7801\u6210\u771f\u5b9e\u7684\u5750\u6807\u3002<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u4e3a\u4ec0\u4e48\u7528\u201c1x1\u5377\u79ef\u201d\u5f53\u88c1\u5224\uff1f<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u4f53\u73b0\u4e86\u6781\u81f4\u7684\u7b80\u6d01\u548c\u9ad8\u6548\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4e0d\u6539\u53d8\u7a7a\u95f4\u7ed3\u6784<\/strong>\uff1a\u88c1\u5224\u53ea\u662f\u5728\u6bcf\u4e2a\u4f4d\u7f6e\uff08<code>H, W<\/code>\u00a0\u4fdd\u6301\u4e0d\u53d8\uff09\u4e0a\u5bf9\u5df2\u6709\u7684\u6df1\u5ea6\u7279\u5f81\uff08<code>head_dim<\/code>\u00a0\u7ef4\uff09\u505a\u4e00\u6b21\u201c\u603b\u7ed3\u9648\u8bcd\u201d\uff0c\u4e0d\u4f1a\u6539\u53d8\u7279\u5f81\u56fe\u7684\u9ad8\u548c\u5bbd\u3002<\/li>\n\n\n\n<li><strong>\u4e13\u804c\u4e13\u7528<\/strong>\uff1a\u4ed6\u4eec\u7684\u4efb\u52a1\u4ec5\u4ec5\u662f\u5c06\u6df1\u5ea6\u7279\u5f81\u901a\u9053\u6570\u6620\u5c04\u5230\u6211\u4eec\u9700\u8981\u7684\u7279\u5b9a\u7ef4\u6570\uff081\u3001<code>num_classes<\/code>\u00a0\u6216 4\uff09\u30021x1\u5377\u79ef\u662f\u5b9e\u73b0\u8fd9\u4e00\u76ee\u7684\u6700\u76f4\u63a5\u3001\u53c2\u6570\u6700\u5c11\u7684\u64cd\u4f5c\u3002<\/li>\n\n\n\n<li><strong>\u6df1\u5ea6\u878d\u5408<\/strong>\uff1a\u867d\u7136\u6bcf\u4e2a\u88c1\u5224\u53ea\u8f93\u51fa\u5f88\u5c11\u7684\u503c\uff0c\u4f46\u4ed6\u4eec\u505a\u51fa\u5224\u65ad\u65f6\uff0c\u662f\u7efc\u5408\u4e86\u8f93\u5165\u7279\u5f81\u6240\u6709\u901a\u9053\u7684\u4fe1\u606f\uff08\u56e0\u4e3a1x1\u5377\u79ef\u4f1a\u8fdb\u884c\u8de8\u901a\u9053\u7684\u4fe1\u606f\u878d\u5408\uff09\u3002<\/li>\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5de5\u4f5c\u6d41\u7a0b\u4e32\u8054<\/p>\n<\/blockquote>\n\n\n\n<p>\u6574\u4e2a\u6d41\u7a0b\u5728\u63a8\u7406\u65f6\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Backbone<\/strong>\uff1a\u201c\u773c\u775b\u201d\u770b\u5230\u56fe\u7247\uff0c\u8f93\u51fa\u521d\u6b65\u7279\u5f81\u3002<\/li>\n\n\n\n<li><strong>Neck (SPPF)<\/strong>\uff1a\u201c\u4fe1\u606f\u6574\u5408\u4e2d\u53f0\u201d\u5bf9\u7279\u5f81\u8fdb\u884c\u591a\u5c3a\u5ea6\u878d\u5408\uff0c\u8f93\u51fa richer \u7684\u7279\u5f81\u3002<\/li>\n\n\n\n<li><strong>Head (Decoupled)<\/strong>\uff1a\u4e24\u4e2a\u201c\u4e13\u5bb6\u56e2\u961f\u201d\u5206\u522b\u5904\u7406\u5206\u7c7b\u548c\u5b9a\u4f4d\u4fe1\u606f\u3002<\/li>\n\n\n\n<li><strong>Prediction Layer (\u88c1\u5224)<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u5b9a\u4f4d\u88c1\u5224\u548c\u7269\u4f53\u88c1\u5224\u67e5\u770b<strong>\u5b9a\u4f4d\u4e13\u5bb6<\/strong>\u7684\u62a5\u544a (<code>reg_feats<\/code>)\uff0c\u5206\u522b\u7ed9\u51fa\u00a0<code>[B, 4, H, W]<\/code>\u00a0\u7684\u504f\u79fb\u91cf\u548c\u00a0<code>[B, 1, H, W]<\/code>\u00a0\u7684\u7f6e\u4fe1\u5ea6\u3002<\/li>\n\n\n\n<li>\u5206\u7c7b\u88c1\u5224\u67e5\u770b<strong>\u5206\u7c7b\u4e13\u5bb6<\/strong>\u7684\u62a5\u544a (<code>cls_feats<\/code>)\uff0c\u7ed9\u51fa\u00a0<code>[B, num_classes, H, W]<\/code>\u00a0\u7684\u7c7b\u522b\u5206\u6570\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u540e\u5904\u7406<\/strong>\uff1a\u5c06\u4e09\u4f4d\u88c1\u5224\u7684\u8f93\u51fa\u5408\u5e76\uff0c\u7ecf\u8fc7\u89e3\u7801\u3001\u9608\u503c\u8fc7\u6ee4\u3001NMS\u7b49\u64cd\u4f5c\uff0c\u5f97\u5230\u6700\u7ec8\u7684\u68c0\u6d4b\u6846\u00a0<code>[x1, y1, x2, y2]<\/code>\u3001\u7f6e\u4fe1\u5ea6\u3001\u7c7b\u522b\u6807\u7b7e\u3002<\/li>\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u603b\u7ed3<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u4e09\u884c\u4ee3\u7801\u5b9a\u4e49\u7684\u9884\u6d4b\u5c42\uff0c\u662f\u6574\u4e2aYOLO\u6a21\u578b\u7684<strong>\u8f93\u51fa\u63a5\u53e3<\/strong>\u3002\u5b83\u4eec\u7684\u4f5c\u7528\u662f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>obj_pred<\/code><\/strong>\uff1a\u5c06\u7279\u5f81\u8f6c\u6362\u4e3a\u201c\u662f\u5426\u6709\u7269\u201d\u7684\u7f6e\u4fe1\u5ea6\u3002<\/li>\n\n\n\n<li><strong><code>cls_pred<\/code><\/strong>\uff1a\u5c06\u7279\u5f81\u8f6c\u6362\u4e3a\u201c\u662f\u4f55\u79cd\u7c7b\u201d\u7684\u6982\u7387\u5206\u5e03\u3002<\/li>\n\n\n\n<li><strong><code>reg_pred<\/code><\/strong>\uff1a\u5c06\u7279\u5f81\u8f6c\u6362\u4e3a\u201c\u6846\u5728\u4f55\u5904\u201d\u7684\u539f\u59cb\u504f\u79fb\u91cf\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5b83\u4eec\u4ee5\u6700\u8f7b\u91cf\u3001\u6700\u9ad8\u6548\u7684\u65b9\u5f0f\uff0c\u5b8c\u6210\u4e86\u4ece\u62bd\u8c61\u7279\u5f81\u5230\u5177\u4f53\u9884\u6d4b\u503c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.5 \u6d4b\u8bd5\u9636\u6bb5\u7684\u524d\u5411\u63a8\u7406<\/h2>\n\n\n\n<p>\u5728\u5b8c\u6210\u4e86\u7f51\u7edc\u7ed3\u6784\u7684\u642d\u5efa\u540e\uff0c\u6211\u4eec\u53c2\u8003\u6700\u5f00\u59cb\u7ed9\u51fa\u7684\u56fe1\uff0c\u4f9d\u846b\u82a6\u753b\u74e2\u5730\u5199\u51fa\u524d\u5411\u63a8\u7406\u90e8\u5206\u7684\u4ee3\u7801\uff0c\u8fd9\u90e8\u5206\u7684\u4ee3\u7801\u903b\u8f91\u6bd4\u8f83\u7b80\u5355\uff0c\u8bfb\u8005\u76f4\u63a5\u9605\u8bfb\u4ee3\u7801\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@torch.no_grad()<br>def inference(self, x):<br>&nbsp; &nbsp; # \u4e3b\u5e72\u7f51\u7edc<br>&nbsp; &nbsp; feat = self.backbone(x)<br><br>&nbsp; &nbsp; # \u9888\u90e8\u7f51\u7edc<br>&nbsp; &nbsp; feat = self.neck(feat)<br><br>&nbsp; &nbsp; # \u68c0\u6d4b\u5934<br>&nbsp; &nbsp; cls_feat, reg_feat = self.head(feat)<br><br>&nbsp; &nbsp; # \u9884\u6d4b\u5c42<br>&nbsp; &nbsp; obj_pred = self.obj_pred(cls_feat)<br>&nbsp; &nbsp; cls_pred = self.cls_pred(cls_feat)<br>&nbsp; &nbsp; reg_pred = self.reg_pred(reg_feat)<br>&nbsp; &nbsp; fmp_size = obj_pred.shape&#91;-2:]<br><br>&nbsp; &nbsp; # \u5bf9 pred \u7684size\u505a\u4e00\u4e9bview\u8c03\u6574\uff0c\u4fbf\u4e8e\u540e\u7eed\u7684\u5904\u7406<br>&nbsp; &nbsp; # &#91;B, C, H, W] -&gt; &#91;B, H, W, C] -&gt; &#91;B, H*W, C]<br>&nbsp; &nbsp; obj_pred = obj_pred.permute(0, 2, 3, 1).contiguous().flatten(1, 2)<br>&nbsp; &nbsp; cls_pred = cls_pred.permute(0, 2, 3, 1).contiguous().flatten(1, 2)<br>&nbsp; &nbsp; reg_pred = reg_pred.permute(0, 2, 3, 1).contiguous().flatten(1, 2)<br><br>&nbsp; &nbsp; # \u6d4b\u8bd5\u65f6\uff0c\u7b14\u8005\u9ed8\u8ba4batch\u662f1\uff0c<br>&nbsp; &nbsp; # \u56e0\u6b64\uff0c\u6211\u4eec\u4e0d\u9700\u8981\u7528batch\u8fd9\u4e2a\u7ef4\u5ea6\uff0c\u7528&#91;0]\u5c06\u5176\u53d6\u8d70\u3002<br>&nbsp; &nbsp; obj_pred = obj_pred&#91;0] &nbsp; &nbsp; &nbsp; # &#91;H*W, 1]<br>&nbsp; &nbsp; cls_pred = cls_pred&#91;0] &nbsp; &nbsp; &nbsp; # &#91;H*W, NC]<br>&nbsp; &nbsp; reg_pred = reg_pred&#91;0] &nbsp; &nbsp; &nbsp; # &#91;H*W, 4]<br><br>&nbsp; &nbsp; # \u6bcf\u4e2a\u8fb9\u754c\u6846\u7684\u5f97\u5206<br>&nbsp; &nbsp; scores = torch.sqrt(obj_pred.sigmoid() * cls_pred.sigmoid())<br><br>&nbsp; &nbsp; # \u89e3\u7b97\u8fb9\u754c\u6846, \u5e76\u5f52\u4e00\u5316\u8fb9\u754c\u6846: &#91;H*W, 4]<br>&nbsp; &nbsp; bboxes = self.decode_boxes(reg_pred, fmp_size)<br><br>&nbsp; &nbsp; if self.deploy:<br>&nbsp; &nbsp; &nbsp; &nbsp; # &#91;n_anchors_all, 4 + C]<br>&nbsp; &nbsp; &nbsp; &nbsp; outputs = torch.cat(&#91;bboxes, scores], dim=-1)<br><br>&nbsp; &nbsp; &nbsp; &nbsp; return outputs<br>&nbsp; &nbsp; else:<br>&nbsp; &nbsp; &nbsp; &nbsp; # \u5c06\u9884\u6d4b\u653e\u5728cpu\u5904\u7406\u4e0a\uff0c\u4ee5\u4fbf\u8fdb\u884c\u540e\u5904\u7406<br>&nbsp; &nbsp; &nbsp; &nbsp; scores = scores.cpu().numpy()<br>&nbsp; &nbsp; &nbsp; &nbsp; bboxes = bboxes.cpu().numpy()<br><br>&nbsp; &nbsp; &nbsp; &nbsp; # \u540e\u5904\u7406<br>&nbsp; &nbsp; &nbsp; &nbsp; bboxes, scores, labels = self.postprocess(bboxes, scores)<br><br>&nbsp; &nbsp; return bboxes, scores, labels<\/code><\/pre>\n\n\n\n<p>\u5bf9\u4e8e\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u505a\u4e00\u4e9b\u5fc5\u8981\u7684\u8bf4\u660e\u3002\u5728\u4e0a\u65b9\u7684\u4ee3\u7801\u4e2d\uff0c\u5206\u522b\u5bf9\u5e94\u4e8eobjectness\u9884\u6d4b\u3001classification\u9884\u6d4b\u548cbbox\u9884\u6d4b\u7684\u4e09\u4e2a\u53d8\u91cfobj_pred\u3001cls_pred\u3001reg_pred\u7684shape\u90fd\u662f[B, C, H, W]\uff0c\u5176\u4e2d\uff0cB\u662fbatch size\uff0cC\u662fchannel\uff0cH\u662f\u7279\u5f81\u56fe\u7684\u9ad8\uff0cW \u662f\u7279\u5f81\u56fe\u7684\u5bbd\u3002\u4e3a\u4e86\u65b9\u4fbf\u540e\u7eed\u7684\u5904\u7406\uff0c\u6211\u4eec\u5c06shape[B, C, H, W]\u8c03\u6574\u6210\u4e86[B,N,C]\u7684\u683c\u5f0f\uff0c\u5176\u4e2dN=H*W\uff0c\u8fd9\u6837\u7684\u64cd\u4f5c\u53ef\u4ee5\u7406\u89e3\u4e3a\u6211\u4eec\u5c06\u6240\u6709\u7f51\u683c\u7684\u9884\u6d4b\u6846\u90fd\u6c47\u603b\u5230\u4e86\u4e00\u8d77\uff0c \u540e\u7eed\u53bb\u8ba1\u7b97\u635f\u5931\u7684\u65f6\u5019\u4e5f\u4f1a\u65b9\u4fbf\u4e00\u4e9b\u3002\u5f53\u7136\uff0c\u8fd9\u4e00\u6b65\u6ca1\u6709\u4efb\u4f55\u7684\u7269\u7406\u610f\u4e49\uff0c\u4ec5\u4ec5\u662f\u4e3a\u4e86\u65b9\u4fbf\u540e\u7eed\u7684\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>\u5728\u5b8c\u6210\u4e86\u4e0a\u8ff0\u7684reshape\u64cd\u4f5c\u540e\uff0c\u6211\u4eec\u5373\u53ef\u53bb\u8ba1\u7b97\u6bcf\u4e00\u4e2a\u8fb9\u754c\u6846\u7684\u5f97\u5206\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u6bcf\u4e2a\u8fb9\u754c\u6846\u7684\u5f97\u5206<br>scores = torch.sqrt(obj_pred.sigmoid() * cls_pred.sigmoid())<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\uff0c\u6211\u4eec\u4f7f\u7528\u5230\u4e86\u5f00\u5e73\u65b9sqrt\u64cd\u4f5c\uff0c\u8fd9\u662f\u8003\u8651\u5230\u8fb9\u754c\u6846\u7684\u7f6e\u4fe1\u5ea6obj_pred.sigmoid()\u548c\u7c7b\u522b\u7684\u7f6e\u4fe1\u5ea6cls_pred.sigmoid()\u90fd\u662f0\uff5e1\u8303\u56f4\u5185\u7684\u6570\uff0c\u4e24\u4e2a\u5c0f\u4e8e1\u7684\u6570\u4e58\u5728\u4e00\u8d77\u53ea\u4f1a\u66f4\u5c0f\uff0c\u56e0\u6b64\u91c7\u7528\u5f00\u6839\u53f7\u7684\u65b9\u5f0f\u6765\u6821\u6b63\u6570\u91cf\u7ea7\uff0c\u8fd9\u4e00\u64cd\u4f5c\u4e5f\u662f\u501f\u9274\u4e0eFCOS\uff08Fully Convolutional One-Stage\uff09\u5de5\u4f5c \u3002<\/p>\n\n\n\n<p>\u968f\u540e\uff0c\u6211\u4eec\u518d\u4f7f\u7528\u9884\u6d4b\u51fa\u6765\u7684\u8fb9\u754c\u6846\u504f\u79fb\u91cfreg_pred \u53bb\u89e3\u8026\u51fa\u6765\u6700\u7ec8\u7684\u8fb9\u754c\u6846\u5750\u6807\uff0c\u5bf9\u4e8e\u8fd9\u4e00\u90e8\u5206\u7684\u539f\u7406\uff0c\u6211\u4eec\u5c06\u4f1a\u518d\u4e0b\u4e00\u63a5\u505a\u8be6\u7ec6\u7684\u539f\u7406\u8bb2\u89e3\uff0c\u8fd9\u91cc\u6682\u4e14\u5356\u4e00\u4e2a\u5173\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u89e3\u7b97\u8fb9\u754c\u6846, \u5e76\u5f52\u4e00\u5316\u8fb9\u754c\u6846: &#91;H*W, 4]<br>bboxes = self.decode_boxes(reg_pred, fmp_size)<br><\/code><\/pre>\n\n\n\n<p>\u6700\u7ec8\uff0c\u6211\u4eec\u5c06\u6240\u6709\u7684\u9884\u6d4b\u7ed3\u679c\u7edf\u7edf\u4e22\u8fdb\u540e\u5904\u7406\u7684\u51fd\u6570\u4e2d\uff0c\u53bb\u5b8c\u6210\u9608\u503c\u7b5b\u9009\u548c\u975e\u6781\u5927\u503c\u6291\u5236\uff0c\u5f53\u8fd9\u4e00\u6b65\u9aa4\u4e5f\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u6700\u7ec8\u7684YOLOv1\u7684\u68c0\u6d4b\u7ed3\u679c\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e00\u90e8\u5206\u7684\u524d\u5411\u63a8\u7406\u5e38\u7528\u5728\u6d4b\u8bd5\u9636\u6bb5\uff0c\u6bd4\u5982\u6211\u4eec\u8bad\u7ec3\u597d\u4e86\u6a21\u578b\u540e\uff0c\u9700\u8981\u53bb\u8ba1\u7b97\u6a21\u578b\u5728\u6d4b\u8bd5\u96c6\u4e0a\u7684\u6027\u80fd\uff0c\u90a3\u4e48\u5c31\u9700\u8981\u6211\u4eec\u7684\u6a21\u578b\u5bf9\u8f93\u5165\u7684\u56fe\u7247\u8fdb\u884c\u63a8\u7406\uff0c\u8f93\u51fa\u68c0\u6d4b\u7ed3\u679c\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u5728\u5b9e\u9645\u573a\u666f\u8fd0\u884c\u65f6\uff0c\u6211\u4eec\u7684\u6a21\u578b\u4e5f\u9700\u8981\u4f7f\u7528\u8fd9\u90e8\u5206\u7684\u63a8\u7406\u53bb\u5904\u7406\u6bcf\u4e00\u5f20\u8f93\u5165\u7684\u56fe\u7247\uff0c\u7ed9\u51fa\u68c0\u6d4b\u7ed3\u679c\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5c0f\u767d\u7b14\u8bb0\u6765\u5566\uff01\uff01\uff01<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6545\u4e8b\uff1aYOLO\u5de5\u5382\u7684\u201c\u6b63\u5f0f\u751f\u4ea7\u6d41\u6c34\u7ebf\u201d<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u63cf\u8ff0\u4e86\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u5982\u4f55\u5bf9\u4e00\u5f20\u65b0\u56fe\u7247\u8fdb\u884c\u68c0\u6d4b\u7684\u5b8c\u6574\u6d41\u7a0b\u3002\u6211\u4eec\u7ee7\u7eed\u6cbf\u7528\u4e4b\u524d\u7684\u6bd4\u55bb\uff0c\u8fd9\u5c31\u50cf\u662f\u5de5\u5382\u63a5\u5230\u4e00\u4e2a\u8ba2\u5355\uff08\u4e00\u5f20\u65b0\u56fe\u7247\uff09\uff0c\u7136\u540e\u542f\u52a8\u5168\u81ea\u52a8\u5316\u6d41\u6c34\u7ebf\uff0c\u6700\u7ec8\u8f93\u51fa\u4ea7\u54c1\uff08\u68c0\u6d4b\u7ed3\u679c\uff09\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6d41\u6c34\u7ebf\u542f\u52a8 (<code>@torch.no_grad()<\/code>)<\/p>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>@torch.no_grad()<\/code><\/strong>\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u8fd9\u662f<strong>\u5173\u95ed\u5b66\u4e60\u6a21\u5f0f\uff0c\u8fdb\u5165\u751f\u4ea7\u6a21\u5f0f<\/strong>\u7684\u5f00\u5173\u3002\u5728\u8fd9\u4e2a\u6a21\u5f0f\u4e0b\uff0c\u5de5\u5382\u7684\u673a\u5668\u4e0d\u4f1a\u8bb0\u5f55\u4efb\u4f55\u751f\u4ea7\u6570\u636e\u7528\u4e8e\u81ea\u6211\u6539\u8fdb\uff08\u4e0d\u8ba1\u7b97\u68af\u5ea6\uff09\uff0c\u53ea\u662f\u5355\u7eaf\u5730\u6267\u884c\u65e2\u5b9a\u6d41\u7a0b\u3002\u8fd9\u80fd\u5927\u5e45\u63d0\u9ad8\u751f\u4ea7\u901f\u5ea6\u5e76\u51cf\u5c11\u8d44\u6e90\u5360\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e00\u6b65\uff1a\u4e09\u7ea7\u52a0\u5de5 (<code>feat = self.backbone(x)<\/code>&nbsp;-&gt;&nbsp;<code>feat = self.neck(feat)<\/code>&nbsp;-&gt;&nbsp;<code>cls_feat, reg_feat = self.head(feat)<\/code>) \u8fd9\u4e09\u6b65\u6211\u4eec\u5df2\u7ecf\u5f88\u719f\u6089\u4e86\uff0c\u5c31\u662f\u539f\u6750\u6599\u7684\u4e09\u7ea7\u52a0\u5de5\uff1a<\/p>\n<\/blockquote>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Backbone\uff08\u521d\u7ea7\u52a0\u5de5\uff09<\/strong>\uff1a\u7528\u201cResNet\u773c\u775b\u201d\u5feb\u901f\u626b\u63cf\u56fe\u7247\uff0c\u63d0\u53d6\u57fa\u7840\u7279\u5f81 (<code>feat<\/code>)\u3002<\/li>\n\n\n\n<li><strong>Neck\uff08\u7cbe\u7ec6\u52a0\u5de5\uff09<\/strong>\uff1a\u7528\u201cSPPF\u4fe1\u606f\u4e2d\u53f0\u201d\u5bf9\u7279\u5f81\u8fdb\u884c\u591a\u5c3a\u5ea6\u878d\u5408\uff0c\u8ba9\u7279\u5f81\u66f4\u4e30\u5bcc (<code>feat<\/code>)\u3002<\/li>\n\n\n\n<li><strong>Head\uff08\u4e13\u4e1a\u5206\u5de5\uff09<\/strong>\uff1a\u5c06\u878d\u5408\u540e\u7684\u7279\u5f81\u9001\u5165\u201c\u4e24\u4e2a\u4e13\u5bb6\u56e2\u961f\u201d\uff0c\u5206\u522b\u4ea7\u51fa\u7528\u4e8e\u5206\u7c7b (<code>cls_feat<\/code>) \u548c\u5b9a\u4f4d (<code>reg_feat<\/code>) \u7684\u4e13\u9879\u62a5\u544a\u3002<\/li>\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e8c\u6b65\uff1a\u4e13\u5bb6\u8bc4\u5224 (<code>obj_pred = self.obj_pred(cls_feat)<\/code>&nbsp;...) \u8fd9\u6b65\u662f\u4e09\u4f4d\u88c1\u5224\u4e0a\u573a\uff0c\u5bf9\u4e13\u5bb6\u62a5\u544a\u8fdb\u884c\u6700\u7ec8\u6253\u5206\uff1a<\/p>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>obj_pred<\/code>\uff1a<strong>\u7269\u4f53\u88c1\u5224<\/strong>\u5ba1\u89c6\u5206\u7c7b\u4e13\u5bb6\u7684\u62a5\u544a\uff0c\u7ed9\u51fa\u6bcf\u4e2a\u4f4d\u7f6e\u201c\u6709\u7269\u4f53\u201d\u7684\u7f6e\u4fe1\u5206\u3002<\/li>\n\n\n\n<li><code>cls_pred<\/code>\uff1a<strong>\u5206\u7c7b\u88c1\u5224<\/strong>\u5ba1\u89c6\u5206\u7c7b\u4e13\u5bb6\u7684\u62a5\u544a\uff0c\u7ed9\u51fa\u6bcf\u4e2a\u4f4d\u7f6e\u201c\u662f\u67d0\u7c7b\u201d\u7684\u5404\u7c7b\u522b\u5206\u6570\u3002<\/li>\n\n\n\n<li><code>reg_pred<\/code>\uff1a<strong>\u5b9a\u4f4d\u88c1\u5224<\/strong>\u5ba1\u89c6\u5b9a\u4f4d\u4e13\u5bb6\u7684\u62a5\u544a\uff0c\u7ed9\u51fa\u6bcf\u4e2a\u4f4d\u7f6e\u6846\u76844\u4e2a\u539f\u59cb\u504f\u79fb\u91cf\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u6b64\u65f6\uff0c\u4e09\u4f4d\u88c1\u5224\u7684\u8f93\u51fa\u683c\u5f0f\u90fd\u662f&nbsp;<code>[B, C, H, W]<\/code>\uff08\u6bd4\u5982&nbsp;<code>[1, 80, 13, 13]<\/code>\uff09\uff0c\u8fd9\u5c31\u50cf\u6709<code>13x13<\/code>\u4e2a\u683c\u5b50\uff0c\u6bcf\u4e2a\u683c\u5b50\u91cc\u90fd\u6709\u4e00\u645e\u6253\u5206\u5361\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e09\u6b65\uff1a\u6574\u7406\u62a5\u544a\uff08<code>permute<\/code>&nbsp;\u548c&nbsp;<code>flatten<\/code>&nbsp;\u64cd\u4f5c\uff09<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>obj_pred = obj_pred.permute(0,&nbsp;2,&nbsp;3,&nbsp;1).contiguous().flatten(1,&nbsp;2)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u73b0\u5728\u6211\u4eec\u7684\u62a5\u544a\u662f\u6309<strong>\u7f51\u683c\u65b9\u5f0f<\/strong>\u5b58\u653e\u7684\uff08<code>13x13<\/code>\u683c\uff0c\u6bcf\u683c\u4e00\u645e\u5206\u6570\uff09\uff0c\u4e0d\u65b9\u4fbf\u540e\u7eed\u7684\u201c\u8d28\u68c0\u90e8\u95e8\u201d\uff08\u540e\u5904\u7406\uff09\u5de5\u4f5c\u3002\u6211\u4eec\u9700\u8981\u628a\u5b83\u91cd\u65b0\u6574\u7406\u4e00\u4e0b\u3002<\/li>\n\n\n\n<li><strong><code>permute(0, 2, 3, 1)<\/code><\/strong>\uff1a\u6539\u53d8\u7ef4\u5ea6\u987a\u5e8f\u3002\u8fd9\u5c31\u50cf\u628a\u201c\u6bcf\u683c\u4e00\u645e\u5206\u6570\u201d\u7684\u6446\u653e\u65b9\u5f0f\uff0c\u6539\u6210\u201c\u628a\u6240\u6709\u683c\u5b50\u7684\u5206\u6570\u645e\u5206\u522b\u4e00\u5f20\u5f20\u644a\u5f00\u5e73\u94fa\u201d\u3002\u4ece\u00a0<code>[Batch, Channel, Height, Width]<\/code>\u00a0\u53d8\u6210\u00a0<code>[Batch, Height, Width, Channel]<\/code>\u3002<\/li>\n\n\n\n<li><strong><code>flatten(1, 2)<\/code><\/strong>\uff1a\u5c06\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u7ef4\u5ea6\u5408\u5e76\u3002\u8fd9\u5c31\u50cf\u628a\u00a0<code>13x13<\/code>\u00a0\u7684\u7f51\u683c\u56fe<strong>\u6495\u4e0b\u6765\uff0c\u628a\u6240\u6709\u683c\u5b50\u6309\u987a\u5e8f\u7c98\u6210\u4e00\u6761\u957f\u957f\u7684\u6e05\u5355<\/strong>\u3002\u683c\u5f0f\u53d8\u6210\u4e86\u00a0<code>[Batch, Height*Width, Channel]<\/code>\uff08\u4f8b\u5982\u00a0<code>[1, 169, 80]<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>\u76ee\u7684<\/strong>\uff1a\u8fd9\u4e2a\u64cd\u4f5c\u6ca1\u6709\u6570\u5b66\u610f\u4e49\uff0c\u7eaf\u7cb9\u662f\u4e3a\u4e86<strong>\u7f16\u7a0b\u65b9\u4fbf<\/strong>\u3002\u8fd9\u6837\uff0c\u6240\u6709\u7684\u9884\u6d4b\u6846\u5c31\u90fd\u6392\u5217\u5728\u4e00\u4e2a\u7ef4\u5ea6\u4e0a\uff0c\u540e\u7eed\u7684\u9608\u503c\u8fc7\u6ee4\u3001\u6392\u5e8f\u3001NMS\u7b49\u64cd\u4f5c\u5b9e\u73b0\u8d77\u6765\u5c31\u975e\u5e38\u7b80\u5355\u76f4\u89c2\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u56db\u6b65\uff1a\u8ba1\u7b97\u6700\u7ec8\u5f97\u5206 (<code>scores = torch.sqrt(...)<\/code>)<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>scores = torch.sqrt(obj_pred.sigmoid() * cls_pred.sigmoid())<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u8fd9\u662f<strong>\u8d28\u91cf\u7efc\u5408\u5f97\u5206<\/strong>\u7684\u8ba1\u7b97\u516c\u5f0f\u3002<\/li>\n\n\n\n<li><strong><code>obj_pred.sigmoid()<\/code><\/strong>\uff1a\u7269\u4f53\u88c1\u5224\u6253\u7684\u5206\uff0c\u901a\u8fc7<code>sigmoid<\/code>\u51fd\u6570\u8f6c\u6362\u62100-1\u4e4b\u95f4\u7684\u201c\u6709\u7269\u6982\u7387\u201d\u3002<\/li>\n\n\n\n<li><strong><code>cls_pred.sigmoid()<\/code><\/strong>\uff1a\u5206\u7c7b\u88c1\u5224\u6253\u7684\u5206\uff0c\u8f6c\u6362\u62100-1\u4e4b\u95f4\u7684\u201c\u7c7b\u522b\u6982\u7387\u201d\uff08\u53d6\u5206\u6570\u6700\u9ad8\u7684\u90a3\u4e2a\u7c7b\u522b\u7684\u6982\u7387\uff09\u3002<\/li>\n\n\n\n<li><strong>\u76f8\u4e58 (<code>*<\/code>)<\/strong>\uff1a\u4e00\u4e2a\u683c\u5b50\u7684\u6700\u7ec8\u5f97\u5206\uff0c\u65e2\u8981\u76f8\u4fe1\u201c\u8fd9\u91cc\u6709\u4e2a\u4e1c\u897f\u201d\uff0c\u4e5f\u8981\u76f8\u4fe1\u201c\u8fd9\u4e2a\u4e1c\u897f\u662f\u67d0\u4e2a\u7c7b\u522b\u201d\u3002\u4e24\u8005\u662f<strong>\u540c\u65f6\u6210\u7acb<\/strong>\u7684\u5173\u7cfb\uff0c\u6240\u4ee5\u7528\u4e58\u6cd5\u7efc\u5408\u3002\u4f46\u4e24\u4e2a\u5c0f\u4e8e1\u7684\u6570\u76f8\u4e58\uff0c\u7ed3\u679c\u4f1a\u53d8\u5f97\u66f4\u5c0f\uff08\u4f8b\u5982\u00a0<code>0.9 * 0.9 = 0.81<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>\u5f00\u6839\u53f7 (<code>sqrt<\/code>)<\/strong>\uff1a\u4e3a\u4e86<strong>\u6821\u6b63\u6570\u503c\u5c3a\u5ea6<\/strong>\u3002\u53d6\u5e73\u65b9\u6839\u540e\uff0c\u6570\u503c\u4f1a\u76f8\u5bf9\u53d8\u5927\u4e00\u4e9b\uff08<code>sqrt(0.81) \u2248 0.9<\/code>\uff09\uff0c\u66f4\u63a5\u8fd1\u539f\u59cb\u7f6e\u4fe1\u5ea6\u7684\u6c34\u5e73\uff0c\u4f7f\u5f97\u5206\u6570\u5206\u5e03\u66f4\u5408\u7406\uff0c\u4fbf\u4e8e\u540e\u7eed\u8bbe\u7f6e\u9608\u503c\u3002\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u5b9e\u7528\u7684\u5de5\u7a0b\u6280\u5de7\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e94\u6b65\uff1a\u89e3\u7801\u5750\u6807 (<code>bboxes = self.decode_boxes(reg_pred, fmp_size)<\/code>)<\/p>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u5b9a\u4f4d\u88c1\u5224\u7ed9\u51fa\u7684 (<code>tx, ty, tw, th<\/code>) \u662f**\u201c\u56fe\u7eb8\u4e0a\u7684\u76f8\u5bf9\u5750\u6807\u201d<strong>\u3002\u73b0\u5728\u9700\u8981\u4e00\u4f4d<\/strong>\u89e3\u7801\u5458**\uff0c\u6839\u636e\u8fd9\u5f20\u56fe\u7eb8\u7684\u5c3a\u5bf8 (<code>fmp_size<\/code>)\uff0c\u628a\u8fd9\u4e9b\u76f8\u5bf9\u5750\u6807\u6362\u7b97\u6210**\u201c\u771f\u5b9e\u4e16\u754c\u4e2d\u7684\u7edd\u5bf9\u5750\u6807\u201d**\u00a0<code>(x1, y1, x2, y2)<\/code>\u3002<\/li>\n\n\n\n<li>\u8fd9\u4e2a\u89e3\u7801\u8fc7\u7a0b\u6d89\u53ca\u5c06\u504f\u79fb\u91cf\u52a0\u4e0a\u7f51\u683c\u5750\u6807\u3001\u7528\u6307\u6570\u51fd\u6570\u5904\u7406\u5bbd\u9ad8\u3001\u5e76\u6620\u5c04\u56de\u539f\u56fe\u5c3a\u5bf8\u7b49\u6b65\u9aa4\u3002\u8fd9\u662f\u6838\u5fc3\u7b97\u6cd5\uff0c\u6240\u4ee5\u4f5c\u8005\u8bf4\u4f1a\u5728\u4e0b\u4e00\u8282\u8be6\u8ff0\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u516d\u6b65\uff1a\u8d28\u68c0\u4e0e\u5305\u88c5\uff08\u540e\u5904\u7406&nbsp;<code>postprocess<\/code>\uff09<\/p>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u9608\u503c\u7b5b\u9009<\/strong>\uff1a\u8d28\u68c0\u5458\u8bf4\uff1a\u201c\u7efc\u5408\u5f97\u5206\u4f4e\u4e8e\u00a0<code>conf_thresh<\/code>\u00a0(\u6bd4\u59820.5) \u7684\u4ea7\u54c1\u90fd\u662f\u6b21\u54c1\uff0c\u6254\u6389\uff01\u201d\u3002<\/li>\n\n\n\n<li><strong>\u975e\u6781\u5927\u503c\u6291\u5236 (NMS)<\/strong>\uff1a\u8d28\u68c0\u5458\u53c8\u8bf4\uff1a\u201c\u597d\u51e0\u4e2a\u6846\u6846\u7684\u90fd\u662f\u540c\u4e00\u4e2a\u7269\u4f53\uff0c\u6211\u53ea\u7559\u5f97\u5206\u6700\u9ad8\u7684\u90a3\u4e00\u4e2a\uff0c\u5176\u4ed6\u7684\u90fd\u6254\u6389\uff01\u201d\u3002\u8fd9\u786e\u4fdd\u4e86\u6bcf\u4e2a\u7269\u4f53\u53ea\u88ab\u68c0\u6d4b\u4e00\u6b21\u3002<\/li>\n\n\n\n<li><strong>\u6700\u7ec8\u51fa\u54c1<\/strong>\uff1a\u7ecf\u8fc7\u5c42\u5c42\u7b5b\u9009\uff0c\u6700\u7ec8\u5f97\u5230\u5e72\u51c0\u3001\u51c6\u786e\u7684\u68c0\u6d4b\u7ed3\u679c\uff1a<code>bboxes<\/code>\uff08\u6846\u5750\u6807\uff09,\u00a0<code>scores<\/code>\uff08\u7f6e\u4fe1\u5ea6\uff09,\u00a0<code>labels<\/code>\uff08\u7c7b\u522b\u6807\u7b7e\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u4e24\u4e2a\u8f93\u51fa\u5206\u652f (<code>if self.deploy<\/code>)<\/p>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>else<\/code>\u00a0\u5206\u652f\uff08\u5e38\u89c4\u6d4b\u8bd5\uff09<\/strong>\uff1a\u5c06\u7ed3\u679c\u79fb\u5230CPU\u5e76\u8f6c\u4e3aNumPy\u683c\u5f0f\uff0c\u8fdb\u884c\u540e\u5904\u7406\uff0c\u8fd4\u56de\u7ed9\u4eba\u770b\u7684\u6700\u7ec8\u7ed3\u679c\u3002<\/li>\n\n\n\n<li><strong><code>if self.deploy<\/code>\u00a0\u5206\u652f\uff08\u90e8\u7f72\u6a21\u5f0f\uff09<\/strong>\uff1a\u76f4\u63a5\u8fd4\u56de\u62fc\u63a5\u597d\u7684Tensor\u3002\u8fd9\u4e2a\u6a21\u5f0f\u662f\u4e3a\u4e86<strong>\u7b80\u5316\u8f93\u51fa\uff0c\u4fbf\u4e8e\u5c06\u6a21\u578b\u90e8\u7f72\u5230\u624b\u673a\u3001\u6444\u50cf\u5934\u7b49\u7ec8\u7aef\u8bbe\u5907<\/strong>\uff08\u4f8b\u5982\u8f6c\u6362\u6210ONNX\u683c\u5f0f\u65f6\uff09\uff0c\u8fd9\u4e9b\u8bbe\u5907\u4e0a\u7684\u540e\u5904\u7406\u4ee3\u7801\u53ef\u80fd\u7528C++\u7b49\u8bed\u8a00\u7f16\u5199\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u603b\u7ed3<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u6bb5&nbsp;<code>inference<\/code>&nbsp;\u4ee3\u7801\u662f\u6574\u4e2aYOLO\u6a21\u578b\u7684<strong>\u603b\u88c5\u6d41\u6c34\u7ebf<\/strong>\uff0c\u5b83\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4e32\u8054\u6240\u6709\u7ec4\u4ef6<\/strong>\uff1a\u6307\u6325Backbone\u3001Neck\u3001Head\u3001Prediction\u5c42\u6709\u5e8f\u5de5\u4f5c\u3002<\/li>\n\n\n\n<li><strong>\u8f6c\u6362\u6570\u636e\u683c\u5f0f<\/strong>\uff1a\u5c06\u7f51\u7edc\u8f93\u51fa\u8f6c\u6362\u6210\u4fbf\u4e8e\u540e\u5904\u7406\u7684\u5f62\u5f0f\u3002<\/li>\n\n\n\n<li><strong>\u6267\u884c\u6838\u5fc3\u7b97\u6cd5<\/strong>\uff1a\u8ba1\u7b97\u7efc\u5408\u5f97\u5206\u3001\u89e3\u7801\u8fb9\u754c\u6846\u5750\u6807\u3002<\/li>\n\n\n\n<li><strong>\u8fdb\u884c\u6700\u7ec8\u8d28\u68c0<\/strong>\uff1a\u901a\u8fc7\u9608\u503c\u548cNMS\u8f93\u51fa\u6700\u53ef\u9760\u7684\u68c0\u6d4b\u7ed3\u679c\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u8fd9\u5c31\u662f\u6a21\u578b\u5728<strong>\u5b9e\u9645\u5e94\u7528<\/strong>\u65f6\u6240\u505a\u7684\u6bcf\u4e00\u6b65\uff0c\u7406\u89e3\u4e86\u8fd9\u4e2a\u6d41\u7a0b\uff0c\u4f60\u5c31\u5b8c\u5168\u7406\u89e3\u4e86YOLOv1\u662f\u5982\u4f55\u4ece\u8f93\u5165\u4e00\u5f20\u56fe\u7247\uff0c\u5230\u6700\u540e\u8f93\u51fa\u68c0\u6d4b\u6846\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.6 \u8bad\u7ec3\u9636\u6bb5\u7684\u524d\u5411\u63a8\u7406<\/h2>\n\n\n\n<p>\u6700\u540e\uff0c\u6211\u4eec\u518d\u4ecb\u7ecd\u4e00\u4e0b\u8bad\u7ec3\u9636\u6bb5\u4f1a\u4f7f\u7528\u5230\u7684\u63a8\u7406\u51fd\u6570\u3002\u76f8\u8f83\u4e8e\u6d4b\u8bd5\u9636\u6bb5\u7684\u63a8\u7406\uff0c\u8bad\u7ec3\u9636\u6bb5\u7684\u63a8\u7406\u5f80\u5f80\u4e0d\u5305\u542b\u540e\u5904\u7406\u7684\uff0c\u800c\u662f\u76f4\u63a5\u5c06\u7f51\u7edc\u7684\u9884\u6d4b\u7ed3\u679c\u505a\u4e00\u4e9b\u5fc5\u8981\u7684\u8c03\u6574\u540e\u5c31\u8f93\u51fa\uff0c\u4ee5\u4fbf\u53bb\u5b8c\u6210\u540e\u7eed\u7684\u6807\u7b7e\u5206\u914d\u548c\u635f\u5931\u51fd\u6570\u7684\u8ba1\u7b97\u7b49\u3002\u5bf9\u4e8e\u8fd9\u4e00\u90e8\u5206\u7684\u4ee3\u7801\uff0c\u5b9e\u73b0\u8d77\u6765\u4e5f\u8f83\u4e3a\u7b80\u5355\uff0c\u8bfb\u8005\u53ef\u4ee5\u76f4\u63a5\u9605\u8bfb\u4e0b\u65b9\u7684\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def forward(self, x):<br>&nbsp; &nbsp; if not self.trainable:<br>&nbsp; &nbsp; &nbsp; &nbsp; return self.inference(x)<br>&nbsp; &nbsp; else:<br>&nbsp; &nbsp; &nbsp; &nbsp; # \u4e3b\u5e72\u7f51\u7edc<br>&nbsp; &nbsp; &nbsp; &nbsp; feat = self.backbone(x)<br><br>&nbsp; &nbsp; &nbsp; &nbsp; # \u9888\u90e8\u7f51\u7edc<br>&nbsp; &nbsp; &nbsp; &nbsp; feat = self.neck(feat)<br><br>&nbsp; &nbsp; &nbsp; &nbsp; # \u68c0\u6d4b\u5934<br>&nbsp; &nbsp; &nbsp; &nbsp; cls_feat, reg_feat = self.head(feat)<br><br>&nbsp; &nbsp; &nbsp; &nbsp; # \u9884\u6d4b\u5c42<br>&nbsp; &nbsp; &nbsp; &nbsp; obj_pred = self.obj_pred(cls_feat)<br>&nbsp; &nbsp; &nbsp; &nbsp; cls_pred = self.cls_pred(cls_feat)<br>&nbsp; &nbsp; &nbsp; &nbsp; reg_pred = self.reg_pred(reg_feat)<br>&nbsp; &nbsp; &nbsp; &nbsp; fmp_size = obj_pred.shape&#91;-2:]<br><br>&nbsp; &nbsp; &nbsp; &nbsp; # \u5bf9 pred \u7684size\u505a\u4e00\u4e9bview\u8c03\u6574\uff0c\u4fbf\u4e8e\u540e\u7eed\u7684\u5904\u7406<br>&nbsp; &nbsp; &nbsp; &nbsp; # &#91;B, C, H, W] -&gt; &#91;B, H, W, C] -&gt; &#91;B, H*W, C]<br>&nbsp; &nbsp; &nbsp; &nbsp; obj_pred = obj_pred.permute(0, 2, 3, 1).contiguous().flatten(1, 2)<br>&nbsp; &nbsp; &nbsp; &nbsp; cls_pred = cls_pred.permute(0, 2, 3, 1).contiguous().flatten(1, 2)<br>&nbsp; &nbsp; &nbsp; &nbsp; reg_pred = reg_pred.permute(0, 2, 3, 1).contiguous().flatten(1, 2)<br><br>&nbsp; &nbsp; &nbsp; &nbsp; # decode bbox<br>&nbsp; &nbsp; &nbsp; &nbsp; box_pred = self.decode_boxes(reg_pred, fmp_size)<br><br>&nbsp; &nbsp; &nbsp; &nbsp; # \u7f51\u7edc\u8f93\u51fa<br>&nbsp; &nbsp; &nbsp; &nbsp; outputs = {\"pred_obj\": obj_pred, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# (Tensor) &#91;B, M, 1]<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \"pred_cls\": cls_pred, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # (Tensor) &#91;B, M, C]<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \"pred_box\": box_pred, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # (Tensor) &#91;B, M, 4]<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \"stride\": self.stride, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# (Int)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \"fmp_size\": fmp_size &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# (List) &#91;fmp_h, fmp_w]<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; return outputs<\/code><\/pre>\n\n\n\n<p>\u518d\u5b8c\u6210\u4e86\u5fc5\u8981\u7684reshape\u64cd\u4f5c\u540e\uff08\u5bf9\u5e94torch\u4e2d\u7684view\u64cd\u4f5c\uff09\uff0c\u6211\u4eec\u518d\u4f7f\u7528\u504f\u79fb\u91cf\u9884\u6d4breg_pred \u7ed3\u7b97\u51fabox_pred\uff0c\u5373\u9884\u6d4b\u7684\u8fb9\u754c\u6846\u7684\u5750\u6807\uff0c\u540e\u7eed\u6211\u4eec\u5728\u8ba1\u7b97\u635f\u5931\u65f6\u4f1a\u7528\u5230\u8fd9\u4e00\u53d8\u91cf\u3002\u6700\u540e\uff0c\u6211\u4eec\u5c06\u6240\u6709\u7684\u9884\u6d4b\u7ed3\u679c\u4ee5\u53ca\u5176\u4ed6\u7684\u5fc5\u8981\u7684\u53c2\u6570\u7edf\u4e00\u653e\u5230outputs\u53d8\u91cf\u4e2d\uff0c\u53bb\u53c2\u4e0e\u540e\u7eed\u7684\u5904\u7406\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u9a6c\u4e0a\u8981\u7ed3\u675f\u672c\u7bc7\u4e86\uff01<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u6bb5\u8bad\u7ec3\u9636\u6bb5\u7684\u524d\u5411\u4f20\u64ad\u4ee3\u7801\u662f\u6a21\u578b\u5b66\u4e60\u7684\u6838\u5fc3\uff0c\u5b83\u7684\u76ee\u7684\u548c\u6d4b\u8bd5\u9636\u6bb5\u5b8c\u5168\u4e0d\u540c\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6545\u4e8b\uff1aYOLO\u5de5\u5382\u7684\u201c\u5185\u90e8\u8d28\u68c0\u4e0e\u5b66\u4e60\u201d\u6d41\u7a0b<\/p>\n<\/blockquote>\n\n\n\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0c\u6d4b\u8bd5\u9636\u6bb5\u7684\u63a8\u7406 (<code>inference<\/code>) \u662f\u5de5\u5382\u7684<strong>\u6b63\u5f0f\u751f\u4ea7\u7ebf<\/strong>\uff0c\u76ee\u7684\u662f\u4e3a\u5ba2\u6237\u63d0\u4f9b\u5b8c\u7f8e\u6210\u54c1\u3002\u800c\u8bad\u7ec3\u9636\u6bb5\u7684\u8fd9\u4e2a&nbsp;<code>forward<\/code>&nbsp;\u51fd\u6570\uff0c\u5219\u662f\u5de5\u5382\u7684<strong>\u5185\u90e8\u8d28\u68c0\u548c\u5b66\u4e60\u4f1a<\/strong>\u3002\u5b83\u7684\u76ee\u7684\u4e0d\u662f\u51fa\u8d27\uff0c\u800c\u662f<strong>\u627e\u51fa\u5f53\u524d\u751f\u4ea7\u6d41\u7a0b\u4e2d\u7684\u9519\u8bef\uff0c\u4ece\u800c\u6539\u8fdb\u5de5\u827a<\/strong>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6838\u5fc3\u533a\u522b\uff1a\u76ee\u7684\u4e0d\u540c<\/p>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6d4b\u8bd5\/\u63a8\u7406 (<code>inference<\/code>)<\/strong>\uff1a\u8f93\u5165\u56fe\u7247 ->\u00a0<strong>\u8f93\u51fa\u68c0\u6d4b\u7ed3\u679c<\/strong>\u00a0(\u7ed9\u7528\u6237\u770b)<\/li>\n\n\n\n<li><strong>\u8bad\u7ec3 (<code>forward<\/code>)<\/strong>\uff1a\u8f93\u5165\u56fe\u7247 ->\u00a0<strong>\u8f93\u51fa\u201c\u672a\u7ecf\u52a0\u5de5\u7684\u539f\u59cb\u9884\u6d4b\u6570\u636e\u201d<\/strong>\u00a0(\u7ed9\u201c\u635f\u5931\u51fd\u6570\u201d\u548c\u201c\u6807\u7b7e\u5206\u914d\u201d\u6a21\u5757\u4f7f\u7528\uff0c\u7528\u4e8e\u8ba1\u7b97\u9519\u8bef\u5e76\u6307\u5bfc\u6a21\u578b\u66f4\u65b0)<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6d41\u7a0b\u89e3\u6790<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e00\u6b65\uff1a\u6a21\u5f0f\u5224\u65ad (<code>if not self.trainable<\/code>)<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>if&nbsp;not&nbsp;self.trainable:<br>&nbsp; &nbsp;&nbsp;return&nbsp;self.inference(x)&nbsp;<em># \u5982\u679c\u662f\u6d4b\u8bd5\u6a21\u5f0f\uff0c\u76f4\u63a5\u8c03\u7528\u6b63\u5f0f\u7684\u63a8\u7406\u6d41\u7a0b<\/em><br>else:<br>&nbsp; &nbsp; ...&nbsp;<em># \u5426\u5219\uff0c\u8fdb\u5165\u4e0b\u9762\u7684\u8bad\u7ec3\u6d41\u7a0b<\/em><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u5de5\u5382\u5927\u95e8\u6709\u4e2a\u6253\u5361\u673a\u3002\u5982\u679c\u4eca\u5929\u662f\u201c\u751f\u4ea7\u65e5\u201d\uff08\u975e\u8bad\u7ec3\u6a21\u5f0f\uff09\uff0c\u5de5\u4eba\u76f4\u63a5\u53bb\u6d41\u6c34\u7ebf\u5e72\u6d3b\u3002\u5982\u679c\u662f\u201c\u5b66\u4e60\u65e5\u201d\uff08\u8bad\u7ec3\u6a21\u5f0f\uff09\uff0c\u5de5\u4eba\u4eec\u5219\u524d\u5f80\u4f1a\u8bae\u5ba4\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e8c\u6b65\uff1a\u7279\u5f81\u63d0\u53d6\u4e0e\u9884\u6d4b\uff08\u4e0e\u63a8\u7406\u9636\u6bb5\u76f8\u540c\uff09<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>feat = self.backbone(x)<br>feat = self.neck(feat)<br>cls_feat, reg_feat = self.head(feat)<br>obj_pred = self.obj_pred(cls_feat)<br>cls_pred = self.cls_pred(cls_feat)<br>reg_pred = self.reg_pred(reg_feat)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8fc7\u7a0b<\/strong>\uff1a\u8fd9\u4e00\u6b65\u548c\u63a8\u7406\u6d41\u7a0b<strong>\u5b8c\u5168\u4e00\u6837<\/strong>\u3002\u56e0\u4e3a\u65e0\u8bba\u662f\u5b66\u4e60\u8fd8\u662f\u751f\u4ea7\uff0c\u52a0\u5de5\u539f\u6599\u7684\u6d41\u7a0b\u662f\u4e0d\u53d8\u7684\u3002Backbone\u3001Neck\u3001Head\u3001Prediction\u5c42\u90fd\u4f1a\u6b63\u5e38\u5de5\u4f5c\uff0c\u4ea7\u51fa\u539f\u59cb\u7684\u9884\u6d4b\u503c\u00a0<code>obj_pred<\/code>,\u00a0<code>cls_pred<\/code>,\u00a0<code>reg_pred<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e09\u6b65\uff1a\u6574\u7406\u6570\u636e\uff08\u4e0e\u63a8\u7406\u9636\u6bb5\u76f8\u540c\uff09<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>obj_pred = obj_pred.permute(0,&nbsp;2,&nbsp;3,&nbsp;1).contiguous().flatten(1,&nbsp;2)<br>...<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u76ee\u7684<\/strong>\uff1a\u540c\u6837\u662f\u4e3a\u4e86\u540e\u7eed\u5904\u7406\u65b9\u4fbf\uff0c\u5c06\u6570\u636e\u4ece\u00a0<code>[B, C, H, W]<\/code>\u00a0\u7684\u7f51\u683c\u683c\u5f0f\u8f6c\u6362\u4e3a\u00a0<code>[B, H*W, C]<\/code>\u00a0\u7684\u6e05\u5355\u683c\u5f0f\u3002\u8fd9\u6837\uff0c\u6bcf\u4e2a\u9884\u6d4b\u6846\u90fd\u6210\u4e86\u6e05\u5355\u4e0a\u72ec\u7acb\u7684\u4e00\u884c\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u56db\u6b65\uff1a\u89e3\u7801\u8fb9\u754c\u6846\uff08\u5173\u952e\u6b65\u9aa4\uff09<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>box_pred = self.decode_boxes(reg_pred, fmp_size)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u5728\u5185\u90e8\u5b66\u4e60\u4f1a\u4e0a\uff0c\u6211\u4eec\u4e0d\u80fd\u53ea\u770b\u201c\u56fe\u7eb8\u4e0a\u7684\u76f8\u5bf9\u5750\u6807\u201d\uff08<code>reg_pred<\/code>\uff09\uff0c\u6211\u4eec\u9700\u8981\u77e5\u9053\u6839\u636e\u5f53\u524d\u5de5\u827a\uff0c\u5b9e\u9645\u751f\u4ea7\u51fa\u7684\u201c\u6837\u54c1\u6846\u201d\u7684<strong>\u7cbe\u786e\u5c3a\u5bf8<\/strong>\u00a0(<code>box_pred<\/code>) \u662f\u591a\u5c11\u3002<\/li>\n\n\n\n<li><strong>\u4e3a\u4ec0\u4e48\u8bad\u7ec3\u9700\u8981\u89e3\u7801\uff1f<\/strong>\uff1a\u56e0\u4e3a\u635f\u5931\u51fd\u6570\uff08Loss Function\uff09\u9700\u8981\u8ba1\u7b97\u9884\u6d4b\u6846 (<code>box_pred<\/code>) \u548c\u771f\u5b9e\u6846\uff08Ground Truth\uff09\u4e4b\u95f4\u7684<strong>\u76f4\u63a5\u5dee\u8ddd<\/strong>\uff0c\u6bd4\u5982IoU\uff08\u4ea4\u5e76\u6bd4\uff09\u6216\u5750\u6807\u8bef\u5dee\u3002\u6211\u4eec\u5fc5\u987b\u628a\u7f51\u7edc\u8f93\u51fa\u7684\u504f\u79fb\u91cf\u89e3\u7801\u6210\u771f\u5b9e\u7684\u5750\u6807\uff0c\u624d\u80fd\u8fdb\u884c\u8fd9\u79cd\u6bd4\u8f83\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b2c\u4e94\u6b65\uff1a\u6253\u5305\u5b66\u4e60\u6750\u6599\uff08\u4e0e\u63a8\u7406\u9636\u6bb5<strong>\u6839\u672c\u4e0d\u540c<\/strong>\uff09<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>outputs = {<br>&nbsp; &nbsp;&nbsp;\"pred_obj\": obj_pred, &nbsp;&nbsp;<em># \u6a21\u578b\u9884\u6d4b\u7684\u201c\u6709\u65e0\u7269\u4f53\u201d\u7684\u539f\u59cb\u5206\u6570<\/em><br>&nbsp; &nbsp;&nbsp;\"pred_cls\": cls_pred, &nbsp;&nbsp;<em># \u6a21\u578b\u9884\u6d4b\u7684\u201c\u7269\u4f53\u7c7b\u522b\u201d\u7684\u539f\u59cb\u5206\u6570<\/em><br>&nbsp; &nbsp;&nbsp;\"pred_box\": box_pred, &nbsp;&nbsp;<em># \u6a21\u578b\u9884\u6d4b\u7684\u201c\u8fb9\u754c\u6846\u201d\u7684\u771f\u5b9e\u5750\u6807<\/em><br>&nbsp; &nbsp;&nbsp;\"stride\": self.stride, &nbsp;&nbsp;<em># \u603b\u6b65\u957f\uff0832\uff09\uff0c\u7528\u4e8e\u6620\u5c04\u7f51\u683c<\/em><br>&nbsp; &nbsp;&nbsp;\"fmp_size\": fmp_size &nbsp; &nbsp;&nbsp;<em># \u7279\u5f81\u56fe\u5c3a\u5bf8\uff0c\u7528\u4e8e\u6620\u5c04\u7f51\u683c<\/em><br>}<br>return&nbsp;outputs<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u5b66\u4e60\u4f1a\u5f00\u59cb\u4e86\u3002\u6211\u4eec\u4e0d\u4f1a\u628a\u201c\u6210\u54c1\u201d\uff08\u7ecf\u8fc7\u540e\u5904\u7406\u7684\u7ed3\u679c\uff09\u4ea4\u7ed9\u8001\u5e08\u5085\uff0c\u800c\u662f\u628a<strong>\u6240\u6709\u539f\u59cb\u7684\u5b66\u4e60\u6750\u6599<\/strong>\u6253\u5305\u597d\u9001\u8fc7\u53bb\u3002\u8fd9\u4e2a\u5305\u88f9\u91cc\u5305\u542b\uff1a\n<ul class=\"wp-block-list\">\n<li><code>pred_obj<\/code>\uff1a\u6240\u6709\u7f51\u683c\u7684\u201c\u6709\u6ca1\u6709\u7269\u4f53\u201d\u7684<strong>\u539f\u59cb\u8003\u8bd5\u7b54\u6848<\/strong>\uff08\u8fd8\u6ca1\u7528Sigmoid\u6253\u5206\uff09\u3002<\/li>\n\n\n\n<li><code>pred_cls<\/code>\uff1a\u6240\u6709\u7f51\u683c\u7684\u201c\u5c5e\u4e8e\u54ea\u4e2a\u7c7b\u522b\u201d\u7684<strong>\u539f\u59cb\u8003\u8bd5\u7b54\u6848<\/strong>\u3002<\/li>\n\n\n\n<li><code>pred_box<\/code>\uff1a\u6240\u6709\u7f51\u683c\u7684\u201c\u6846\u5728\u54ea\u91cc\u201d\u7684<strong>\u539f\u59cb\u8003\u8bd5\u7b54\u6848<\/strong>\uff08\u5df2\u89e3\u7801\u6210\u771f\u5b9e\u5750\u6807\uff09\u3002<\/li>\n\n\n\n<li><code>stride<\/code>\u00a0\u548c\u00a0<code>fmp_size<\/code>\uff1a<strong>\u8003\u8bd5\u7b54\u6848\u7684\u7d22\u5f15\u548c\u8bc4\u5206\u6807\u51c6<\/strong>\u3002\u8001\u5e08\u5085\u9700\u8981\u77e5\u9053\u54ea\u4e2a\u7b54\u6848\u5bf9\u5e94\u539f\u56fe\u7684\u54ea\u4e2a\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u540e\u7eed\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f\uff08\u4e3a\u4e0b\u4e00\u7ae0\u94fa\u57ab\uff09<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u4e2a&nbsp;<code>outputs<\/code>&nbsp;\u5b57\u5178\u4e0d\u4f1a\u88ab\u76f4\u63a5\u7528\u4e8e\u663e\u793a\uff0c\u800c\u662f\u4f1a\u7acb\u5373\u9001\u7ed9\u4e24\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u6a21\u5757\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6807\u7b7e\u5206\u914d (Label Assignment)<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u4e00\u4f4d\u201c\u6807\u51c6\u7b54\u6848\u5206\u53d1\u5458\u201d\u3002\u4ed6\u4f1a\u62ff\u7740\u201c\u771f\u5b9e\u6807\u7b7e\u201d\uff08\u4e00\u5f20\u56fe\u91cc\u6240\u6709\u7269\u4f53\u7684\u771f\u5b9e\u4f4d\u7f6e\u548c\u7c7b\u522b\uff09\uff0c\u548c\u6a21\u578b\u9884\u6d4b\u7684\u00a0<code>pred_box<\/code>\u00a0\u8fdb\u884c\u5bf9\u6bd4\u3002<\/li>\n\n\n\n<li><strong>\u4efb\u52a1<\/strong>\uff1a\u51b3\u5b9a\u00a0<code>outputs<\/code>\u00a0\u6e05\u5355\u91cc\u7684<strong>\u54ea\u4e00\u884c\u9884\u6d4b<\/strong>\u5e94\u8be5\u8d1f\u8d23\u68c0\u6d4b<strong>\u54ea\u4e00\u4e2a\u771f\u5b9e\u7269\u4f53<\/strong>\u3002\u4ed6\u4f1a\u7ed9\u6e05\u5355\u91cc\u7684\u67d0\u4e9b\u884c\u8d34\u4e0a\u201c\u6b63\u6837\u672c\u201d\u7684\u6807\u7b7e\uff08\u8868\u793a\u8fd9\u4e9b\u9884\u6d4b\u662f\u597d\u7684\u3001\u5e94\u8be5\u88ab\u9f13\u52b1\u7684\uff09\uff0c\u7ed9\u5176\u4ed6\u884c\u8d34\u4e0a\u201c\u8d1f\u6837\u672c\u201d\u7684\u6807\u7b7e\uff08\u8868\u793a\u8fd9\u4e9b\u9884\u6d4b\u662f\u5dee\u7684\u3001\u5e94\u8be5\u88ab\u6291\u5236\u7684\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u635f\u5931\u51fd\u6570 (Loss Function)<\/strong>\uff1a<ul><li><code>pred_obj<\/code>\u00a0\u548c\u201c\u6b63\u8d1f\u6837\u672c\u6807\u7b7e\u201d\u4e4b\u95f4\u7684\u8bef\u5dee\u3002<\/li><li><code>pred_cls<\/code>\u00a0\u548c\u201c\u771f\u5b9e\u7c7b\u522b\u201d\u4e4b\u95f4\u7684\u8bef\u5dee\u3002<\/li><li><code>pred_box<\/code>\u00a0\u548c\u201c\u771f\u5b9e\u6846\u5750\u6807\u201d\u4e4b\u95f4\u7684\u8bef\u5dee\u3002<\/li><\/ul>\n<ul class=\"wp-block-list\">\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u4e00\u4f4d\u201c\u4e25\u5389\u7684\u8001\u5e08\u5085\u201d\u3002<\/li>\n\n\n\n<li><strong>\u4efb\u52a1<\/strong>\uff1a\u4ed6\u62ff\u5230\u00a0<code>outputs<\/code>\uff08\u6a21\u578b\u7684\u539f\u59cb\u7b54\u6848\uff09\u548c\u201c\u6807\u7b7e\u5206\u914d\u201d\u7684\u7ed3\u679c\uff08\u54ea\u4e9b\u7b54\u6848\u5bf9\u5e94\u54ea\u4e9b\u6807\u51c6\u7b54\u6848\uff09\u3002<\/li>\n\n\n\n<li><strong>\u5de5\u4f5c<\/strong>\uff1a\u4ed6\u5f00\u59cb\u9010\u9879\u6279\u6539\u8bd5\u5377\uff0c\u8ba1\u7b97\uff1a<\/li>\n\n\n\n<li><strong>\u8f93\u51fa<\/strong>\uff1a\u6240\u6709\u8fd9\u4e9b\u8bef\u5dee\u6c47\u603b\u6210\u4e00\u4e2a<strong>\u603b\u5206<\/strong>\u2014\u2014<strong>\u635f\u5931\u503c (Loss)<\/strong>\u3002\u8fd9\u4e2a\u5206\u6570\u76f4\u63a5\u53cd\u6620\u4e86\u6a21\u578b\u5f53\u524d\u201c\u9519\u5f97\u6709\u591a\u79bb\u8c31\u201d\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>\u8fd9\u4e2a\u635f\u5931\u503c\u4f1a\u53cd\u5411\u4f20\u64ad\u56de\u53bb\uff0c\u6307\u5bfcBackbone\u3001Neck\u3001Head\u7b49\u6240\u6709\u90e8\u95e8\u7684\u5de5\u4eba\uff08\u6a21\u578b\u53c2\u6570\uff09\u5982\u4f55\u8c03\u6574\u81ea\u5df1\u7684\u5de5\u4f5c\u65b9\u5f0f\uff0c\u4ee5\u4fbf\u5728\u4e0b\u4e00\u6b21\u201c\u5b66\u4e60\u4f1a\u201d\u4e0a\u80fd\u62ff\u5230\u66f4\u9ad8\u7684\u5206\u6570\uff08\u66f4\u4f4e\u7684\u635f\u5931\uff09\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u603b\u7ed3<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u6bb5\u8bad\u7ec3\u7528\u7684&nbsp;<code>forward<\/code>&nbsp;\u4ee3\u7801\u662f\u6a21\u578b<strong>\u81ea\u6211\u5b66\u4e60\u548c\u6539\u8fdb\u7684\u6838\u5fc3<\/strong>\u3002\u5b83\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e0d\u8fdb\u884c\u4efb\u4f55\u540e\u5904\u7406<\/strong>\uff08\u65e0\u9608\u503c\u8fc7\u6ee4\uff0c\u65e0NMS\uff09\u3002<\/li>\n\n\n\n<li>\u8f93\u51fa<strong>\u539f\u59cb\u3001\u672a\u52a0\u5de5\u7684\u9884\u6d4b\u6570\u636e<\/strong>\u3002<\/li>\n\n\n\n<li>\u6838\u5fc3\u6b65\u9aa4\u662f<strong>\u89e3\u7801\u8fb9\u754c\u6846<\/strong>\uff0c\u4e3a\u8ba1\u7b97\u635f\u5931\u505a\u51c6\u5907\u3002<\/li>\n\n\n\n<li>\u6700\u7ec8\u76ee\u7684\u662f\u4e3a<strong>\u6807\u7b7e\u5206\u914d<\/strong>\u548c<strong>\u635f\u5931\u8ba1\u7b97<\/strong>\u63d0\u4f9b\u6240\u9700\u7684\u5168\u90e8\u8f93\u5165\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u7406\u89e3\u4e86\u8fd9\u4e2a\u6d41\u7a0b\uff0c\u4f60\u5c31\u660e\u767d\u4e86YOLO\u662f\u5982\u4f55\u901a\u8fc7\u6bd4\u8f83\u201c\u9884\u6d4b\u201d\u548c\u201c\u771f\u5b9e\u201d\u4e4b\u95f4\u7684\u5dee\u8ddd\u6765\u5b9e\u73b0\u81ea\u6211\u4f18\u5316\u7684\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e8c\u3001\u7ed3\u675f\u8bed<\/h1>\n\n\n\n<p>\u5230\u6b64\uff0c\u6211\u4eec\u83b7\u5f97\u4e86YOLOv1\u7f51\u7edc\u7684\u642d\u5efa\uff0c\u5e76\u4e14\u5b9e\u73b0\u4e86\u524d\u5411\u63a8\u7406\u3002\u4f46\u662f\uff0c\u5728\u63a8\u7406\u7684\u4ee3\u7801\u4e2d\u8fd8\u9057\u7559\u4e86\u51e0\u4e2a\u91cd\u8981\u7684\u95ee\u9898\u5c1a\u5f85\u5904\u7406\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u4f55\u4ece\u8fb9\u754c\u6846\u504f\u79fb\u91cfreg_pred\u89e3\u8026\u51fa\u8fb9\u754c\u6846\u5750\u6807box_pred\uff1f<\/li>\n\n\n\n<li>\u5982\u4f55\u5b9e\u73b0\u540e\u5904\u7406\u64cd\u4f5c\uff1f<\/li>\n\n\n\n<li>\u5982\u4f55\u8ba1\u7b97\u8bad\u7ec3\u9636\u6bb5\u7684\u635f\u5931\uff1f<\/li>\n<\/ul>\n\n\n\n<p>\u53d7\u7bc7\u5e45\u9650\u5236\uff0c\u6211\u4eec\u5c06\u8fd9\u4e09\u4e2a\u95ee\u9898\u7559\u5230\u540e\u7eed\u7684\u7ae0\u8282\u4e2d\u53bb\u4e00\u4e00\u89e3\u51b3\u3002\u5728\u672c\u7ae0\uff0c\u8bfb\u8005\u53ea\u9700\u8981\u5b66\u4f1a\u642d\u5efa\u6211\u4eec\u7684YOLOv1\u7f51\u7edc\u3001\u7406\u6e05\u63a8\u7406\u7684\u4ee3\u7801\u903b\u8f91\u5373\u53ef\uff0c\u5728\u8111\u6d77\u91cc\uff0c\u6700\u597d\u80fd\u6784\u5efa\u51fa\u5bf9\u4e8eYOLOv1\u7684\u6574\u4f53\u67b6\u6784\u7684\u201c\u56fe\u50cf\u201d\u8bb0\u5fc6\u3002\u4ece\u4e0b\u4e00\u8282\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u4e00\u4e00\u89e3\u51b3\u8fd9\u9057\u7559\u7684\u4e09\u4e2a\u95ee\u9898\u3002<\/p>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u80a1\u5e02\u53ef\u4ee5\u505c\u6b62\u6da8\uff0c\u4f46\u662f\u5b66\u4e60\u4e0d\u80fd\u505c\uff01 0\u3001\u5e8f\u8a00 \u5728\u4e0a\u4e00\u8282\u4e2d\uff0c\u6211\u4eec\u8bb2\u89e3\u4e86\u6211\u4eec\u6240\u8981\u642d\u5efa\u7684YOLOv1\uff0c\u4e0d\u540c\u4e8e\u539f\u7248\u7684YOLOv1\uff0c\u6211\u4eec\u5728\u4e0d\u504f &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[46],"tags":[],"class_list":["post-6794","post","type-post","status-publish","format-standard","hentry","category-yolo"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658.jpg","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658.jpg","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658.jpg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658.jpg","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658.jpg","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658.jpg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658.jpg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658.jpg","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658-1024x399.jpg","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929061617658-1024x399.jpg","id":"image1"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"YOLO","post_date":"2025-09-29","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":441,"next_post_id":6797,"next_post_title":"YOLO\u5165\u95e8\u6559\u7a0b\uff08\u756a\u5916\uff09\uff1a\u4e00\u6587\u641e\u5b9aOpenCV","previous_post_id":6787,"previous_post_title":"YOLO\u5165\u95e8\u6559\u7a0b\uff08\u4e09\uff09\uff1a\u6539\u8fdbYOLOv1","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6794","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=6794"}],"version-history":[{"count":1,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6794\/revisions"}],"predecessor-version":[{"id":6796,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6794\/revisions\/6796"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=6794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=6794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=6794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}