{"id":3216,"date":"2025-07-11T00:35:21","date_gmt":"2025-07-10T16:35:21","guid":{"rendered":"https:\/\/www.gnn.club\/?p=3216"},"modified":"2025-07-18T14:38:44","modified_gmt":"2025-07-18T06:38:44","slug":"canet%ef%bc%9acoordinate-attention-for-efficient-mobile-network-design","status":"publish","type":"post","link":"http:\/\/gnn.club\/?p=3216","title":{"rendered":"CANet\uff1aCoordinate Attention for Efficient Mobile Network Design"},"content":{"rendered":"<h1>\u57fa\u672c\u4fe1\u606f<\/h1>\n<hr \/>\n<ul>\n<li>\ud83d\udcf0\u6807\u9898: Coordinate Attention for Efficient Mobile Network Design<\/li>\n<li>\ud83d\udd8b\ufe0f\u4f5c\u8005: Xiangyu Zhang<\/li>\n<li>\ud83c\udfdb\ufe0f\u673a\u6784: Megvii Technology (\u65f7\u89c6\u79d1\u6280)<\/li>\n<li>\ud83d\udd14\u5173\u952e\u8bcd: Coordinate Attention, Mobile Networks, Efficient Design<\/li>\n<\/ul>\n<h2>\u6458\u8981\u6982\u8ff0<\/h2>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\" style=\"border-collapse: collapse; width: 100%;\">\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u9879\u76ee<\/th>\n<th style=\"text-align: left;\">\u5185\u5bb9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udcd6\u7814\u7a76\u80cc\u666f<\/td>\n<td style=\"text-align: left;\">\u79fb\u52a8\u7f51\u7edc\u8bbe\u8ba1\u9700\u8981\u8f7b\u91cf\u4e14\u9ad8\u6548\u7684\u6ce8\u610f\u529b\u673a\u5236\uff0c\u4f20\u7edf\u65b9\u6cd5\uff08\u5982Squeeze-and-Excitation\uff09\u96be\u4ee5\u540c\u65f6\u6355\u83b7\u7a7a\u95f4\u548c\u901a\u9053\u5173\u7cfb\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83c\udfaf\u7814\u7a76\u76ee\u7684<\/td>\n<td style=\"text-align: left;\">\u63d0\u51fa\u4e00\u79cd\u65b0\u578b\u6ce8\u610f\u529b\u673a\u5236\uff08Coordinate Attention\uff09\uff0c\u901a\u8fc7\u5206\u89e3\u4e8c\u7ef4\u5168\u5c40\u6c60\u5316\u4e3a\u4e24\u4e2a\u4e00\u7ef4\u64cd\u4f5c\uff0c\u9ad8\u6548\u5efa\u6a21\u901a\u9053\u5173\u7cfb\u548c\u957f\u7a0b\u7a7a\u95f4\u4f9d\u8d56\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u270d\ufe0f\u7814\u7a76\u65b9\u6cd5<\/td>\n<td style=\"text-align: left;\">1. \u5c06\u7a7a\u95f4\u5750\u6807\u4fe1\u606f\u5d4c\u5165\u901a\u9053\u6ce8\u610f\u529b\uff1b2. \u4f7f\u7528\u6c34\u5e73\u4e0e\u5782\u76f4\u65b9\u5411\u7684\u5750\u6807\u6ce8\u610f\u529b\uff08Coordinate Attention Blocks\uff09\uff1b3. \u5728MobileNetV2\u7b49\u8f7b\u91cf\u7f51\u7edc\u4e0a\u9a8c\u8bc1\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udd4a\ufe0f\u7814\u7a76\u5bf9\u8c61<\/td>\n<td style=\"text-align: left;\">\u8f7b\u91cf\u7ea7CNN\u67b6\u6784\uff08\u5982MobileNetV2\u3001ShuffleNet\uff09\u53ca\u5176\u5728ImageNet\u5206\u7c7b\u3001\u76ee\u6807\u68c0\u6d4b\u7b49\u4efb\u52a1\u7684\u8868\u73b0\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udd0d\u7814\u7a76\u7ed3\u8bba<\/td>\n<td style=\"text-align: left;\">\u5728\u53c2\u6570\u91cf\u76f8\u8fd1\u7684\u60c5\u51b5\u4e0b\uff0c\u76f8\u6bd4SE\u6a21\u5757\uff0c\u5750\u6807\u6ce8\u610f\u529b\u63d0\u5347MobileNetV2\u5728ImageNet\u4e0a\u7684Top-1\u51c6\u786e\u73871.2%\uff0c\u4e14\u8ba1\u7b97\u5f00\u9500\u4ec5\u589e\u52a00.03ms\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u2b50\u521b\u65b0\u70b9<\/td>\n<td style=\"text-align: left;\">1. \u9996\u6b21\u5c06\u5750\u6807\u4fe1\u606f\u663e\u5f0f\u7f16\u7801\u5230\u6ce8\u610f\u529b\u673a\u5236\uff1b2. \u901a\u8fc7\u5206\u89e3\u6c60\u5316\u64cd\u4f5c\u5b9e\u73b0\u7a7a\u95f4-\u901a\u9053\u8054\u5408\u5efa\u6a21\uff1b3. \u9002\u7528\u4e8e\u79fb\u52a8\u8bbe\u5907\u7684\u5373\u63d2\u5373\u7528\u6a21\u5757\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h1>\u80cc\u666f<\/h1>\n<ul>\n<li>\n<p><strong>\u7814\u7a76\u80cc\u666f<\/strong>\uff1a<br \/>\n\u6ce8\u610f\u529b\u673a\u5236\u901a\u8fc7\u6307\u793a\u6a21\u578b\u201c\u5173\u6ce8\u4ec0\u4e48\u201d\u548c\u201c\u5173\u6ce8\u54ea\u91cc\u201d\uff0c\u5df2\u6210\u4e3a\u63d0\u5347\u6df1\u5ea6\u795e\u7ecf\u7f51\u7edc\u6027\u80fd\u7684\u5173\u952e\u6280\u672f\u3002\u7136\u800c\uff0c\u5176\u5728\u8ba1\u7b97\u8d44\u6e90\u53d7\u9650\u7684\u79fb\u52a8\u7f51\u7edc\uff08Mobile Networks\uff09\u4e2d\u7684\u5e94\u7528\u663e\u8457\u843d\u540e\u4e8e\u5927\u578b\u7f51\u7edc\uff0c\u4e3b\u8981\u56e0\u73b0\u6709\u6ce8\u610f\u529b\u673a\u5236\u7684\u8ba1\u7b97\u5f00\u9500\u96be\u4ee5\u6ee1\u8db3\u79fb\u52a8\u8bbe\u5907\u7684\u8f7b\u91cf\u5316\u9700\u6c42\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u8fc7\u53bb\u65b9\u6848<\/strong>\uff1a<\/p>\n<ol>\n<li>\n<p><strong>Squeeze-and-Excitation (SE)<\/strong>\uff1a\u901a\u8fc72D\u5168\u5c40\u6c60\u5316\u8ba1\u7b97\u901a\u9053\u6ce8\u610f\u529b\uff0c\u8ba1\u7b97\u6210\u672c\u4f4e\u4f46\u5ffd\u7565\u4f4d\u7f6e\u4fe1\u606f\uff0c\u96be\u4ee5\u6355\u6349\u89c6\u89c9\u4efb\u52a1\u4e2d\u7684\u5bf9\u8c61\u7ed3\u6784\u3002<\/p>\n<\/li>\n<li>\n<p><strong>BAM\/CBAM<\/strong>\uff1a\u901a\u8fc7\u964d\u7ef4\u548c\u5377\u79ef\u5f15\u5165\u7a7a\u95f4\u6ce8\u610f\u529b\uff0c\u4f46\u5377\u79ef\u4ec5\u80fd\u5efa\u6a21\u5c40\u90e8\u5173\u7cfb\uff0c\u65e0\u6cd5\u6355\u83b7\u957f\u7a0b\u4f9d\u8d56\uff08long-range dependencies\uff09\u3002<br \/>\n<strong>\u6838\u5fc3\u95ee\u9898<\/strong>\uff1a\u73b0\u6709\u65b9\u6cd5\u65e0\u6cd5\u5e73\u8861\u8ba1\u7b97\u6548\u7387\u4e0e\u7a7a\u95f4-\u901a\u9053\u8054\u5408\u5efa\u6a21\u7684\u9700\u6c42\u3002<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p><strong>\u7814\u7a76\u52a8\u673a<\/strong>\uff1a<br \/>\n\u63d0\u51fa<strong>Coordinate Attention<\/strong>\u673a\u5236\uff0c\u901a\u8fc7\u5206\u89e32D\u6c60\u5316\u4e3a\u4e24\u4e2a1D\u65b9\u5411\u7f16\u7801\uff08\u6c34\u5e73\/\u5782\u76f4\uff09\uff0c\u5c06\u4f4d\u7f6e\u4fe1\u606f\u5d4c\u5165\u901a\u9053\u6ce8\u610f\u529b\uff0c\u5b9e\u73b0\u4ee5\u4e0b\u76ee\u6807\uff1a<br \/>\n\uff081\uff09\u540c\u65f6\u5efa\u6a21\u8de8\u901a\u9053\u4ea4\u4e92\u4e0e\u957f\u7a0b\u7a7a\u95f4\u4f9d\u8d56\uff1b<br \/>\n\uff082\uff09\u4fdd\u6301\u8f7b\u91cf\u5316\u7279\u6027\uff0c\u9002\u914dMobileNetV2\u7b49\u79fb\u52a8\u7f51\u7edc\u67b6\u6784\uff1b<br \/>\n\uff083\uff09\u63d0\u5347\u4e0b\u6e38\u5bc6\u96c6\u9884\u6d4b\u4efb\u52a1\uff08\u5982\u8bed\u4e49\u5206\u5272\uff09\u7684\u6027\u80fd\u3002<\/p>\n<\/li>\n<\/ul>\n<h1>\u65b9\u6cd5<\/h1>\n<ul>\n<li>\n<p><strong>\u7406\u8bba\u80cc\u666f<\/strong>\uff1a<br \/>\n\u672c\u7814\u7a76\u57fa\u4e8e\u6ce8\u610f\u529b\u673a\u5236\u5728\u8f7b\u91cf\u5316\u7f51\u7edc\u4e2d\u7684\u4e24\u5927\u5c40\u9650\uff1a<br \/>\n1) \u4f20\u7edf\u901a\u9053\u6ce8\u610f\u529b\uff08\u5982SE\u6a21\u5757\uff09\u56e0\u5168\u5c40\u6c60\u5316\u4e22\u5931\u7a7a\u95f4\u4f4d\u7f6e\u4fe1\u606f\uff1b<br \/>\n2) \u7a7a\u95f4\u6ce8\u610f\u529b\uff08\u5982CBAM\uff09\u7684\u5377\u79ef\u64cd\u4f5c\u96be\u4ee5\u5efa\u6a21\u957f\u7a0b\u4f9d\u8d56\u3002\u53d7\u4eba\u7c7b\u89c6\u89c9\u7cfb\u7edf\u201c\u5750\u6807-\u901a\u9053\u201d\u534f\u540c\u611f\u77e5\u673a\u5236\u542f\u53d1\uff0c\u63d0\u51fa\u4f4d\u7f6e\u4fe1\u606f\u4e0e\u901a\u9053\u6ce8\u610f\u529b\u8026\u5408\u7684\u7406\u8bba\u6846\u67b6\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u6280\u672f\u8def\u7ebf<\/strong>\uff1a<\/p>\n<\/li>\n<\/ul>\n<p>\u4e0b\u9762\uff0c\u5bf9\u6bd4SENet\u548cCBAM\u6765\u7406\u89e3CANet\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2025\/07\/20250710235847475.png\" width=\"1000\" style=\"display: block; margin: 0 auto;\" \/><\/p>\n<ul>\n<li>\n<p>(a) SE\u901a\u9053\u6ce8\u610f\u529b<br \/>\n\u6d41\u7a0b\uff1a\u901a\u8fc7\u5168\u5c40\u5e73\u5747\u6c60\u5316\uff08GAP\uff09\u538b\u7f29\u7a7a\u95f4\u4fe1\u606f\u2192\u4e24\u4e2a\u5168\u8fde\u63a5\u5c42\uff08\u542b\u964d\u7ef4\uff09\u2192Sigmoid\u751f\u6210\u901a\u9053\u6743\u91cd\u2192\u4e0e\u8f93\u5165\u7279\u5f81\u76f8\u4e58<br \/>\n\u7f3a\u9677\uff1a2D\u5168\u5c40\u6c60\u5316\u5bfc\u81f4\u7a7a\u95f4\u4f4d\u7f6e\u4fe1\u606f\u4e22\u5931\uff0c\u4ec5\u5efa\u6a21\u901a\u9053\u5173\u7cfb.<\/p>\n<\/li>\n<li>\n<p>(b) CBAM\u53cc\u8def\u5f84\u8bbe\u8ba1\uff1a<br \/>\n\u901a\u9053\u6ce8\u610f\u529b\uff1a\u7c7b\u4f3cSE\u4f46\u589e\u52a0GMP\u5206\u652f<br \/>\n\u7a7a\u95f4\u6ce8\u610f\u529b\uff1a\u901a\u8fc7\u901a\u9053\u538b\u7f29+\u5927\u6838\u5377\u79ef\uff087\u00d77\uff09\u751f\u6210\u7a7a\u95f4\u6743\u91cd<br \/>\n\u5c40\u9650\uff1a\u5377\u79ef\u53ea\u80fd\u6355\u83b7\u5c40\u90e8\u5173\u7cfb\uff08\u8bba\u65873.1\u8282\u6307\u51fa\u5176\u96be\u4ee5\u5efa\u6a21\u957f\u7a0b\u4f9d\u8d56\uff09<\/p>\n<\/li>\n<li>\n<p>(c) \u5750\u6807\u6ce8\u610f\u529b\uff08\u672c\u6587\u63d0\u51fa\uff09 \u521b\u65b0\u70b9\uff1a<br \/>\n\u5750\u6807\u4fe1\u606f\u5d4c\u5165\uff1a\u5c062D\u6c60\u5316\u89e3\u8026\u4e3a\u6c34\u5e73\uff08X Avg Pool\uff09\u548c\u5782\u76f4\uff08Y Avg Pool\uff09\u4e24\u4e2a1D\u6c60\u5316\uff0c\u5206\u522b\u4fdd\u7559\u65b9\u5411\u654f\u611f\u7279\u5f81\u3002<br \/>\n\u8054\u5408\u7f16\u7801\uff1a\u62fc\u63a5\u53cc\u65b9\u5411\u7279\u5f81\u2192\u5171\u4eab1\u00d71\u5377\u79ef\u2192\u5206\u89e3\u4e3a\u65b9\u5411\u611f\u77e5\u6ce8\u610f\u529b\u56fe\uff08\u5f3a\u5236\u4e24\u4e2a\u5206\u652f\u5206\u522b\u5b66\u4e60\u6c34\u5e73\/\u5782\u76f4\u65b9\u5411\u7684\u6ce8\u610f\u529b\u6a21\u5f0f\uff0c\u907f\u514d\u7279\u5f81\u6df7\u6dc6\uff09\u21921x1\u5377\u79ef\u2192Sigmoid\u751f\u6210\u901a\u9053\u6743\u91cd\u2192\u4e0e\u5bf9\u5e94\u8f93\u5165\u7279\u5f81\u76f8\u4e58\u3002<br \/>\n\u4f18\u52bf\uff1a \u540c\u65f6\u6355\u83b7\u957f\u7a0b\u4f9d\u8d56\uff08\u5355\u65b9\u5411\uff09\u548c\u7cbe\u786e\u4fdd\u7559\u4f4d\u7f6e\u4fe1\u606f\uff08\u53e6\u4e00\u65b9\u5411\uff09\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5177\u4f53\u6765\u8bf4\uff1a\u4f20\u7edf\u5377\u79ef\uff08\u5982CBAM\u76847\u00d77\u5377\u79ef\uff09\u53d7\u9650\u4e8e\u5c40\u90e8\u611f\u53d7\u91ce\uff0c\u96be\u4ee5\u5efa\u6a21\u56fe\u50cf\u4e2d\u8fdc\u8ddd\u79bb\u50cf\u7d20\u7684\u5173\u8054\uff08\u4f8b\u5982\u5929\u7a7a\u4e0e\u5730\u9762\u7684\u989c\u8272\u6e10\u53d8\u5173\u7cfb\uff09\u3002CANet\u4e2d\u5bf9\u6c34\u5e73\u65b9\u5411\uff08X\u8f74\uff09\u8fdb\u884c1D\u5168\u5c40\u6c60\u5316\uff08X Avg Pool\uff09\uff0c\u5c06\u7279\u5f81\u538b\u7f29\u4e3a C\u00d71\u00d7W \u7684\u5411\u91cf\u3002\u6b64\u65f6\uff0c\u6bcf\u4e2a\u4f4d\u7f6e\u7684\u6743\u91cd\u8ba1\u7b97\u4f1a\u8003\u8651\u8be5\u884c\u6240\u6709\u50cf\u7d20\u7684\u4fe1\u606f\uff08\u5373\u6c34\u5e73\u957f\u7a0b\u4f9d\u8d56\uff09\u3002\u7c7b\u4f3c\u5730\uff0c\u5bf9\u5782\u76f4\u65b9\u5411\uff08Y\u8f74\uff09\u76841D\u6c60\u5316\uff08Y Avg Pool\uff09\u6355\u83b7 C\u00d7H\u00d71 \u7684\u5782\u76f4\u957f\u7a0b\u4f9d\u8d56\u3002\u5355\u65b9\u5411\u76841D\u6c60\u5316\u5929\u7136\u5177\u6709\u5168\u5c40\u89c6\u91ce\uff08\u7c7b\u4f3cNon-local\u7f51\u7edc\u7684\u5168\u5c40\u5173\u7cfb\u5efa\u6a21\uff09\uff0c\u4f46\u8ba1\u7b97\u6210\u672c\u66f4\u4f4e\uff08\u4ec5\u9700O(H)\u6216O(W)\u590d\u6742\u5ea6\uff09\u3002\u53e6\u4e00\u65b9\u9762\uff0cSE\u6a21\u5757\u76842D\u5168\u5c40\u6c60\u5316\u4f1a\u5b8c\u5168\u4e22\u5931\u7a7a\u95f4\u4f4d\u7f6e\u4fe1\u606f\uff08\u4f8b\u5982\u65e0\u6cd5\u533a\u5206\u76ee\u6807\u5728\u56fe\u50cf\u5de6\u4e0a\u89d2\u8fd8\u662f\u53f3\u4e0b\u89d2\uff09\u3002CANet\u901a\u8fc7\u89e3\u8026\u4e3a\u53cc1D\u6c60\u5316\uff0c\u5728\u8ba1\u7b97\u6c34\u5e73\u65b9\u5411\u6ce8\u610f\u529b\u65f6\uff0c\u5782\u76f4\u65b9\u5411\u7684\u5750\u6807\u4fe1\u606f\uff08Y\u8f74\u4f4d\u7f6e\uff09\u88ab\u4fdd\u7559\uff08\u53cd\u4e4b\u4ea6\u7136\uff09\u3002<\/p>\n<h1>\u7ed3\u8bba<\/h1>\n<ul>\n<li>\n<p>\u63d0\u51fa\u9002\u7528\u4e8emobile networks\u7684\u8f7b\u91cf\u7ea7Coordinate Attention\u673a\u5236\uff0c\u89e3\u51b3\u4e86\u4f20\u7edfchannel attention\u65b9\u6cd5\uff08\u5982SE\u6a21\u5757\uff09\u65e0\u6cd5\u540c\u65f6\u5efa\u6a21\u901a\u9053\u5173\u7cfb\u4e0e\u7a7a\u95f4\u4f4d\u7f6e\u4fe1\u606f\u7684\u6838\u5fc3\u95ee\u9898\uff0c\u663e\u8457\u63d0\u5347\u4e86\u8f7b\u91cf\u6a21\u578b\u5728\u89c6\u89c9\u4efb\u52a1\u4e2d\u7684\u6027\u80fd\u8868\u73b0\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u4f18\u70b9<\/strong>\uff1a<br \/>\n1) \u901a\u8fc7\u5206\u89e32D\u6c60\u5316\u4e3a\u53cc1D\u64cd\u4f5c\uff0c\u5728\u4fdd\u6301\u8ba1\u7b97\u6548\u7387\u7684\u540c\u65f6\u6355\u83b7long-range dependencies\uff1b<br \/>\n2) \u5373\u63d2\u5373\u7528\u7279\u6027\u9002\u914d\u591a\u79cd\u8f7b\u91cf\u67b6\u6784\uff08\u5982MobileNetV2\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5c40\u9650<\/strong>\uff1a\u672a\u8ba8\u8bba\u786c\u4ef6\u90e8\u7f72\u65f6\u7684\u5b9e\u9645\u5ef6\u8fdf\u4e0e\u80fd\u8017\u8868\u73b0\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u4e3b\u8981\u7ed3\u8bba<\/strong>\uff1a<\/p>\n<\/li>\n<\/ul>\n<ol>\n<li>Coordinate Attention\u901a\u8fc7\u5750\u6807\u5d4c\u5165\u540c\u65f6\u5efa\u6a21inter-channel relationships\u4e0e\u7cbe\u786e\u4f4d\u7f6e\u4fe1\u606f\uff1b<\/li>\n<li>\u5728ImageNet\u5206\u7c7b\u3001object detection\u548csemantic segmentation\u4efb\u52a1\u4e2d\u5747\u9a8c\u8bc1\u6709\u6548\u6027\uff1b<\/li>\n<li>\u8ba1\u7b97\u5f00\u9500\u4ec5\u8f7b\u5fae\u589e\u52a0\uff08\u5982MobileNetV2\u63a8\u7406\u5ef6\u8fdf+0.03ms\uff09\uff0c\u7b26\u5408\u79fb\u52a8\u7aef\u8f7b\u91cf\u5316\u9700\u6c42\u3002<\/li>\n<\/ol>\n<h1>Pytorch code<\/h1>\n<pre><code class=\"language-python\">import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nclass CoordinateAttention(nn.Module):\n    def __init__(self, in_channels, reduction_ratio=32):\n        &quot;&quot;&quot;\n        Coordinate Attention \u6a21\u5757 (CVPR 2021)\n        Args:\n            in_channels: \u8f93\u5165\u7279\u5f81\u56fe\u7684\u901a\u9053\u6570\n            reduction_ratio: \u4e2d\u95f4\u5c42\u901a\u9053\u538b\u7f29\u6bd4\u4f8b\n        &quot;&quot;&quot;\n        super(CoordinateAttention, self).__init__()\n        self.reduction_ratio = reduction_ratio\n        mid_channels = max(8, in_channels \/\/ reduction_ratio)  # \u786e\u4fdd\u4e2d\u95f4\u901a\u9053\u6570\u22658\n\n        # \u6c34\u5e73\uff08X\u8f74\uff09\u548c\u5782\u76f4\uff08Y\u8f74\uff09\u65b9\u5411\u7684\u6c60\u5316\n        self.x_avg_pool = nn.AdaptiveAvgPool2d((None, 1))      # [b,c,h,w] -&gt; [b,c,h,1]\n        self.y_avg_pool = nn.AdaptiveAvgPool2d((1, None))      # [b,c,h,w] -&gt; [b,c,1,w]\n\n        # \u5171\u4eab\u6743\u91cd\u7684\u4e24\u5c42MLP\uff08\u4e0eSE Block\u4e0d\u540c\uff0c\u8fd9\u91cc\u4e0d\u964d\u7ef4\u5230C\/r\uff09\n        self.conv1 = nn.Conv2d(in_channels, mid_channels, kernel_size=1)\n        self.conv2 = nn.Conv2d(mid_channels, in_channels, kernel_size=1)\n\n        # \u6fc0\u6d3b\u51fd\u6570\n        self.relu = nn.ReLU(inplace=True)\n        self.sigmoid = nn.Sigmoid()\n\n    def forward(self, x):\n        b, c, h, w = x.shape\n\n        # 1. \u5750\u6807\u4fe1\u606f\u5d4c\u5165\uff08Coordinate Information Embedding\uff09\n        # X\u8f74\u65b9\u5411\u6c60\u5316 [b,c,h,w] -&gt; [b,c,h,1]\n        x_avg = self.x_avg_pool(x)\n        # Y\u8f74\u65b9\u5411\u6c60\u5316 [b,c,h,w] -&gt; [b,c,1,w]\n        y_avg = self.y_avg_pool(x)\n\n        # 2. \u8c03\u6574 y_avg \u5f62\u72b6\uff0c\u4f7f\u5176\u80fd\u4e0e x_avg \u5728 dim=2 \u62fc\u63a5\n        y_avg = y_avg.permute(0, 1, 3, 2)  # [b,c,1,w] -&gt; [b,c,w,1]\n\n        # 3. \u62fc\u63a5\u4e24\u4e2a\u65b9\u5411\u7684\u6c60\u5316\u7ed3\u679c [b,c,h,1] + [b,c,w,1] -&gt; [b,c,h+w,1]\n        concat = torch.cat([x_avg, y_avg], dim=2)\n\n        # 4. \u5171\u4eabMLP\u5904\u7406\n        out = self.relu(self.conv1(concat))\n        out = self.sigmoid(self.conv2(out))\n\n        # 5. \u5206\u79bbX\/Y\u8f74\u6ce8\u610f\u529b\u6743\u91cd\n        x_att, y_att = torch.split(out, [h, w], dim=2)  # \u62c6\u5206\u4e3a[b,c,h,1]\u548c[b,c,w,1]\n        y_att = y_att.permute(0, 1, 3, 2)  # [b,c,w,1] -&gt; [b,c,1,w]\uff08\u6062\u590d\u539f\u59cb\u5f62\u72b6\uff09\n\n        # 6. \u7279\u5f81\u56fe\u91cd\u6807\u5b9a\uff08Feature Recalibration\uff09\n        return x * x_att.expand_as(x) * y_att.expand_as(x)\n# ------------------- \u7528\u6cd5\u793a\u4f8b -------------------\nif __name__ == &quot;__main__&quot;:\n    # 1. \u521d\u59cb\u5316\u6a21\u5757\uff08\u8f93\u5165\u901a\u9053=256\uff09\n    ca = CoordinateAttention(in_channels=256)\n\n    # 2. \u6a21\u62df\u8f93\u5165\u6570\u636e\uff08batch_size=4, \u901a\u9053=256, \u5c3a\u5bf8=56x56\uff09\n    dummy_input = torch.randn(4, 256, 56, 56)\n\n    # 3. \u524d\u5411\u4f20\u64ad\n    output = ca(dummy_input)\n\n    print(f&quot;\u8f93\u5165\u5f62\u72b6: {dummy_input.shape}&quot;)\n    print(f&quot;\u8f93\u51fa\u5f62\u72b6: {output.shape}&quot;)  # \u5e94\u4e0e\u8f93\u5165\u5f62\u72b6\u4e00\u81f4<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u4fe1\u606f \ud83d\udcf0\u6807\u9898: Coordinate Attention for Efficient Mobile Net [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3217,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,18],"tags":[],"class_list":["post-3216","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-30","category-18"],"_links":{"self":[{"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/posts\/3216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3216"}],"version-history":[{"count":3,"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/posts\/3216\/revisions"}],"predecessor-version":[{"id":3260,"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/posts\/3216\/revisions\/3260"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/media\/3217"}],"wp:attachment":[{"href":"http:\/\/gnn.club\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3216"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}