{"id":4692,"date":"2022-07-20T20:03:31","date_gmt":"2022-07-20T12:03:31","guid":{"rendered":"http:\/\/139.9.1.231\/?p=4692"},"modified":"2022-07-20T20:03:33","modified_gmt":"2022-07-20T12:03:33","slug":"a-convnet-for-the-2020s","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/07\/20\/a-convnet-for-the-2020s\/","title":{"rendered":"A ConvNet for the 2020s"},"content":{"rendered":"\n<p>\u8bba\u6587\u5730\u5740\uff1ahttps:\/\/arxiv.org\/abs\/2201.03545<\/p>\n\n\n\n<p>github\uff1a https:\/\/github.com\/facebookresearch\/ConvNeXt<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Block(nn.Module):\r\n    r\"\"\" ConvNeXt Block. There are two equivalent implementations:\r\n    (1) DwConv -> LayerNorm (channels_first) -> 1x1 Conv -> GELU -> 1x1 Conv; all in (N, C, H, W)\r\n    (2) DwConv -> Permute to (N, H, W, C); LayerNorm (channels_last) -> Linear -> GELU -> Linear; Permute back\r\n    We use (2) as we find it slightly faster in PyTorch\r\n    \r\n    Args:\r\n        dim (int): Number of input channels.\r\n        drop_path (float): Stochastic depth rate. Default: 0.0\r\n        layer_scale_init_value (float): Init value for Layer Scale. Default: 1e-6.\r\n    \"\"\"\r\n    def __init__(self, dim, drop_path=0., layer_scale_init_value=1e-6):\r\n        super().__init__()\r\n        self.dwconv = nn.Conv2d(dim, dim, kernel_size=7, padding=3, groups=dim) # depthwise conv\r\n        self.norm = LayerNorm(dim, eps=1e-6)\r\n        self.pwconv1 = nn.Linear(dim, 4 * dim) # pointwise\/1x1 convs, implemented with linear layers\r\n        self.act = nn.GELU()\r\n        self.pwconv2 = nn.Linear(4 * dim, dim)\r\n        self.gamma = nn.Parameter(layer_scale_init_value * torch.ones((dim)), \r\n                                    requires_grad=True) if layer_scale_init_value > 0 else None\r\n        self.drop_path = DropPath(drop_path) if drop_path > 0. else nn.Identity()\r\n\r\n    def forward(self, x):\r\n        input = x\r\n        x = self.dwconv(x)\r\n        x = x.permute(0, 2, 3, 1) # (N, C, H, W) -> (N, H, W, C)\r\n        x = self.norm(x)\r\n        x = self.pwconv1(x)\r\n        x = self.act(x)\r\n        x = self.pwconv2(x)\r\n        if self.gamma is not None:\r\n            x = self.gamma * x\r\n        x = x.permute(0, 3, 1, 2) # (N, H, W, C) -> (N, C, H, W)\r\n\r\n        x = input + self.drop_path(x)\r\n        return x\r\n\r\n<\/code><\/pre>\n\n\n\n<p>2020\u5e74\u4ee5\u6765\uff0cViT\u4e00\u76f4\u662f\u7814\u7a76\u70ed\u70b9\u3002ViT\u5728\u56fe\u7247\u5206\u7c7b\u4e0a\u7684\u6027\u80fd\u8d85\u8fc7\u5377\u79ef\u7f51\u7edc\u7684\u6027\u80fd\uff0c\u540e\u7eed\u53d1\u5c55\u800c\u6765\u7684\u5404\u79cd\u53d8\u4f53\u5c06ViT\u53d1\u626c\u5149\u5927\uff08\u5982Swin-T\uff0cCSwin-T\u7b49\uff09\uff0c\u503c\u5f97\u4e00\u63d0\u7684\u662fSwin-T\u4e2d\u7684\u6ed1\u7a97\u64cd\u4f5c\u7c7b\u4f3c\u4e8e\u5377\u79ef\u64cd\u4f5c\uff0c\u964d\u4f4e\u4e86\u8fd0\u7b97\u590d\u6742\u5ea6\uff0c\u4f7f\u5f97ViT\u53ef\u4ee5\u88ab\u7528\u505a\u5176\u4ed6\u89c6\u89c9\u4efb\u52a1\u7684\u9aa8\u5e72\u7f51\u7edc\uff0cViT\u53d8\u5f97\u66f4\u706b\u4e86\u3002\u672c\u6587\u63a2\u7a76\u5377\u79ef\u7f51\u7edc\u5230\u5e95\u8f93\u5728\u4e86\u54ea\u91cc\uff0c\u5377\u79ef\u7f51\u7edc\u7684\u6781\u9650\u5728\u54ea\u91cc\u3002\u5728\u672c\u6587\u4e2d\uff0c\u4f5c\u8005\u9010\u6e10\u5411ResNet\u4e2d\u589e\u52a0\u7ed3\u6784\uff08\u6216\u4f7f\u7528trick\uff09\u6765\u63d0\u5347\u5377\u79ef\u6a21\u578b\u6027\u80fd\uff0c\u6700\u7ec8\u5c06ImageNet top-1\u5237\u5230\u4e8687.8%\u3002\u4f5c\u8005\u8ba4\u4e3a\u672c\u6587\u6240\u63d0\u51fa\u7684\u7f51\u7edc\u7ed3\u6784\u662f\u65b0\u4e00\u4ee3\uff082020\u5e74\u4ee3\uff09\u7684\u5377\u79ef\u7f51\u7edc\uff08ConvNeXt\uff09\uff0c\u56e0\u6b64\u5c06\u6587\u7ae0\u547d\u540d\u4e3a\u201c2020\u5e74\u4ee3\u7684\u5377\u79ef\u7f51\u7edc\u201d\u3002<\/p>\n\n\n\n<h2>\u65b9\u6cd5<\/h2>\n\n\n\n<h3>\u8bad\u7ec3\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u4f5c\u8005\u9996\u5148\u5c06ViT\u7684\u8bad\u7ec3\u6280\u5de7\uff0c\u5305\u62eclr scheduler\u3001\u6570\u636e\u589e\u5f3a\u65b9\u6cd5\u3001\u4f18\u5316\u5668\u8d85\u53c2\u7b49\u5e94\u7528\u4e8eResNet-50\uff0c\u5e76\u5c06\u8bad\u7ec3\u8f6e\u6570\u753190\u6269\u5927\u5230300\uff0c\u7ed3\u679c\u5206\u7c7b\u51c6\u786e\u7387\u753176.1%\u4e0a\u5347\u523078.8%\u3002\u5177\u4f53\u8bad\u7ec3config\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"486\" height=\"525\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/07\/image-50.png\" alt=\"\" class=\"wp-image-4917\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/07\/image-50.png 486w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/07\/image-50-278x300.png 278w\" sizes=\"(max-width: 486px) 100vw, 486px\" \/><\/figure>\n\n\n\n<h3>\u5b8f\u89c2\u8bbe\u8ba1<\/h3>\n\n\n\n<p>\u4f5c\u8005\u501f\u9274\u4e86Swin-T\u7684\u4e24\u4e2a\u8bbe\u8ba1:<\/p>\n\n\n\n<ol><li>\u6bcf\u9636\u6bb5\u7684\u8ba1\u7b97\u91cf<\/li><li>\u5bf9\u8f93\u5165\u56fe\u7247\u4e0b\u91c7\u6837\u65b9\u6cd5<\/li><\/ol>\n\n\n\n<p>\u5bf9\u4e8e\u7b2c\u4e00\u70b9\u7c7b\u4f3cSwin-T\u56db\u4e2a\u9636\u6bb51:1:9:1\u7684\u8ba1\u7b97\u91cf\uff0c\u4f5c\u8005<strong><em>\u5c06ResNet-50\u6bcf\u4e2a\u9636\u6bb5block\u6570\u8c03\u6574\u4e3a3\uff0c3\uff0c9\uff0c3<\/em><\/strong>\uff08\u539f\u6765\u4e3a3\uff0c4\uff0c6\uff0c3\uff09\uff0c\u589e\u52a0\u7b2c\u4e09\u9636\u6bb5\u8ba1\u7b97\u91cf\uff0c\u51c6\u786e\u7387\u753178.8%\u63d0\u5347\u81f379.4%\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u7b2c\u4e8c\u70b9Swin-T\u878d\u5408\u538b\u7f292&nbsp;<img src=\"https:\/\/www.zhihu.com\/equation?tex=%5Ctimes\" alt=\"[\u516c\u5f0f]\">&nbsp;2\u7684\u533a\u57df\uff0c\u4f5c\u8005\u5219<strong><em>\u4f7f\u75284&nbsp;&nbsp;4\u6b65\u957f\u4e3a4\u7684\u5377\u79ef\u5bf9\u8f93\u5165\u56fe\u7247\u8fdb\u884c\u4e0b\u91c7\u6837<\/em><\/strong>\uff0c\u8fd9\u6837\u6bcf\u6b21\u5377\u79ef\u64cd\u4f5c\u7684\u611f\u53d7\u91ce\u4e0d\u91cd\u53e0\uff0c\u51c6\u786e\u7387\u753179.4%\u63d0\u5347\u81f379.5%\u3002<\/p>\n\n\n\n<h3>\u7c7bResNeXt\u8bbe\u8ba1<\/h3>\n\n\n\n<p>depthwise conv\u4e2d\u7684\u9010channel\u5377\u79ef\u64cd\u4f5c\u548cself-attention\u4e2d\u7684\u52a0\u6743\u6c42\u548c\u5f88\u7c7b\u4f3c\uff0c\u56e0\u6b64\u4f5c\u8005<em><strong>\u91c7\u7528depthwise conv\u66ff\u6362\u666e\u901a\u5377\u79ef<\/strong><\/em>\u3002\u53c2\u7167ResNeXt\uff0c\u4f5c\u8005\u5c06\u901a\u9053\u6570\u589e\u52a0\u523096\uff0c\u51c6\u786e\u7387\u63d0\u5347\u81f380.5%\uff0cFLOPs\u76f8\u5e94\u589e\u5927\u5230\u4e865.3G\u3002\u76f8\u6bd4\u4e4b\u4e0b\u539f\u59cb\u7684ResNet-50 FLOPs\u4e3a4G\uff0c\u8fd0\u7b97\u91cf\u589e\u5927\u5f88\u591a\u3002<\/p>\n\n\n\n<h3>Inverted Bottleneck<\/h3>\n\n\n\n<p>\u5728depthwise conv\u7684\u57fa\u7840\u4e0a<strong><em>\u501f\u9274MobileNet\u7684inverted bottleneck\u8bbe\u8ba1<\/em><\/strong>\uff0c\u5c06block\u7531\u4e0b\u56fe(a)\u53d8\u4e3a(b)\u3002\u56e0\u4e3adepthwise\u4e0d\u4f1a\u4f7fchannel\u4e4b\u95f4\u7684\u4fe1\u606f\u4ea4\u4e92\uff0c\u56e0\u6b64\u4e00\u822cdepthwise conv\u4e4b\u540e\u90fd\u4f1a\u63a51\u00a0<img src=\"https:\/\/www.zhihu.com\/equation?tex=%5Ctimes+\" alt=\"[\u516c\u5f0f]\">\u00a01\u00a0<img src=\"https:\/\/www.zhihu.com\/equation?tex=%5Ctimes\" alt=\"[\u516c\u5f0f]\">\u00a0C\u7684pointwise conv\u3002\u8fd9\u4e00\u987f\u64cd\u4f5c\u4e0b\u6765\u51c6\u786e\u7387\u53ea\u6da8\u4e860.1%\u523080.6%\u3002\u5728\u540e\u6587\u8bf4\u660e\u7684\u5927\u6a21\u578b\u4e0a\u6da8\u70b9\u591a\u4e00\u70b9\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" width=\"452\" height=\"238\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/07\/image-51.png\" alt=\"\" class=\"wp-image-4918\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/07\/image-51.png 452w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/07\/image-51-300x158.png 300w\" sizes=\"(max-width: 452px) 100vw, 452px\" \/><\/figure><\/div>\n\n\n\n<h3>\u589e\u5927\u5377\u79efkernel<\/h3>\n\n\n\n<p>\u4f5c\u8005\u8ba4\u4e3a\u66f4\u5927\u7684\u611f\u53d7\u91ce\u662fViT\u6027\u80fd\u66f4\u597d\u7684\u53ef\u80fd\u539f\u56e0\u4e4b\u4e00\uff0c\u4f5c\u8005\u5c1d\u8bd5\u589e\u5927\u5377\u79ef\u7684kernel\uff0c\u4f7f\u6a21\u578b\u83b7\u5f97\u66f4\u5927\u7684\u611f\u53d7\u91ce\u3002\u9996\u5148\u5728pointwise conv\u7684\u4f7f\u7528\u4e0a\uff0c\u4f5c\u8005\u4e3a\u4e86\u83b7\u5f97\u66f4\u5927\u7684\u611f\u53d7\u91ce\uff0c<strong><em>\u5c06depthwise conv\u63d0\u524d\u52301&nbsp;&nbsp;1 conv\u4e4b\u524d\uff0c\u4e4b\u540e\u7528384\u4e2a1&nbsp;&nbsp;1&nbsp;&nbsp;96\u7684conv\u5c06\u6a21\u578b\u5bbd\u5ea6\u63d0\u53474\u500d\uff0c\u5728\u752896\u4e2a1&nbsp;&nbsp;1&nbsp;&nbsp;96\u7684conv\u6062\u590d\u6a21\u578b\u5bbd\u5ea6<\/em><\/strong>\u3002\u53cd\u6620\u5728\u4e0a\u56fe\u4e2d\u5c31\u662f\u7531(b)\u53d8\u4e3a(c)\u3002\u7531\u4e8e3<img src=\"https:\/\/www.zhihu.com\/equation?tex=%5Ctimes+\" alt=\"[\u516c\u5f0f]\">3\u7684conv\u6570\u91cf\u51cf\u5c11\uff0c\u6a21\u578bFLOPs\u75315.3G\u51cf\u5c11\u52304G\uff0c\u76f8\u5e94\u5730\u6027\u80fd\u6682\u65f6\u4e0b\u964d\u523079.9%\u3002<\/p>\n\n\n\n<p>\u7136\u540e\u4f5c\u8005\u5c1d\u8bd5<strong><em>\u589e\u5927depthwise conv\u7684\u5377\u79ef\u6838\u5927\u5c0f\uff0c\u8bc1\u660e77\u5927\u5c0f\u7684\u5377\u79ef\u6838\u6548\u679c\u8fbe\u5230\u6700\u4f73<\/em><\/strong>\u3002<\/p>\n\n\n\n<h3>\u5176\u4ed6\u4e71\u4e03\u516b\u7cdf\u7684\u5c1d\u8bd5<\/h3>\n\n\n\n<p>\u501f\u9274\u6700\u521d\u7684Transformer\u8bbe\u8ba1\uff0c\u4f5c\u8005\u5c06ReLU\u66ff\u6362\u4e3aGELU\uff1bViT\u7684K\/Q\/V\u8ba1\u7b97\u4e2d\u90fd\u6ca1\u6709\u7528\u5230\u6fc0\u6d3b\u51fd\u6570\u548c\u5f52\u4e00\u5316\u5c42\uff0c\u4e8e\u662f\u4f5c\u8005\u4e5f<strong><em>\u5220\u9664\u4e86\u5927\u91cf\u7684\u6fc0\u6d3b\u51fd\u6570\u548c\u5f52\u4e00\u5316\u5c42\uff0c\u4ec5\u57281\u00a0\u00a01\u5377\u79ef\u4e4b\u95f4\u4f7f\u7528\u6fc0\u6d3b\u51fd\u6570\uff0c\u4ec5\u57287\u00a0\u00a07\u5377\u79ef\u548c1\u00a0\u00a01 \u5377\u79ef\u4e4b\u95f4\u4f7f\u7528\u5f52\u4e00\u5316\u5c42<\/em><\/strong>\uff0c\u540c\u65f6<strong><em>\u5c06BN\u5347\u7ea7\u4e3aLN<\/em><\/strong>\u3002\u6700\u7ec8block\u7ed3\u6784\u786e\u5b9a\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/07\/image-52.png\" alt=\"\" class=\"wp-image-4919\" width=\"496\" height=\"592\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/07\/image-52.png 496w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/07\/image-52-251x300.png 251w\" sizes=\"(max-width: 496px) 100vw, 496px\" \/><\/figure><\/div>\n\n\n\n<p>\u6700\u540e\u4eff\u7167Swin-T\uff0c\u4f5c\u8005\u5c06\u4e0b\u91c7\u6837\u5c42\u5355\u72ec\u5206\u79bb\u51fa\u6765\uff0c\u5355\u72ec\u4f7f\u75282&nbsp;<img src=\"https:\/\/www.zhihu.com\/equation?tex=%5Ctimes+\" alt=\"[\u516c\u5f0f]\">&nbsp;2\u5377\u79ef\u5c42\u8fdb\u884c\u4e0b\u91c7\u6837\u3002\u4e3a\u4fdd\u8bc1\u6536\u655b\uff0c\u5728\u4e0b\u91c7\u6837\u540e\u52a0\u4e0aLayer Norm\u5f52\u4e00\u5316\u3002\u6700\u7ec8\u52a0\u5f3a\u7248ResNet-50\u51c6\u786e\u738782.0%\uff08FLOPs 4.5G\uff09\u3002<\/p>\n\n\n\n<p>\u603b\u7684\u6765\u8bf4ResNet-50\u3001\u672c\u6587\u6a21\u578b\u548cSwin-T\u7ed3\u6784\u5dee\u522b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"694\" height=\"521\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/07\/image-53.png\" alt=\"\" class=\"wp-image-4920\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/07\/image-53.png 694w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/07\/image-53-300x225.png 300w\" sizes=\"(max-width: 694px) 100vw, 694px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bba\u6587\u5730\u5740\uff1ahttps:\/\/arxiv.org\/abs\/2201.03545 github\uff1a https:\/\/g &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/07\/20\/a-convnet-for-the-2020s\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">A ConvNet for the 2020s<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/4692"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=4692"}],"version-history":[{"count":2,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/4692\/revisions"}],"predecessor-version":[{"id":4921,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/4692\/revisions\/4921"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=4692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=4692"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=4692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}