{"id":531,"date":"2022-07-20T13:06:25","date_gmt":"2022-07-20T13:06:25","guid":{"rendered":"https:\/\/blog.liguanxin.cn\/?p=531"},"modified":"2022-07-20T13:06:25","modified_gmt":"2022-07-20T13:06:25","slug":"%e8%ae%ba%e6%96%87%e7%ac%94%e8%ae%b0-aaai-2022less-is-more-pay-less-attention-in-vision-transformers","status":"publish","type":"post","link":"https:\/\/blog.liguanxin.cn\/index.php\/2022\/07\/20\/%e8%ae%ba%e6%96%87%e7%ac%94%e8%ae%b0-aaai-2022less-is-more-pay-less-attention-in-vision-transformers\/","title":{"rendered":"\u8bba\u6587\u7b14\u8bb0\u2014\u2014[AAAI 2022]Less is More: Pay Less Attention in Vision Transformers"},"content":{"rendered":"<p><strong>\u521b\u65b0\u70b9\uff1a<br \/>\n\u2460\u5728\u6d45\u5c42\u7528MLP\u7f16\u7801\u5c40\u90e8\u7279\u5f81<br \/>\n\u2461\u5728\u6df1\u5c42\u7528\u81ea\u6ce8\u610f\u529b\u6355\u83b7\u957f\u8ddd\u79bb\u4f9d\u8d56<br \/>\n\u2462\u53ef\u53d8\u5f62\u7684token\u878d\u5408\u6a21\u5757\uff0c\u4ee5\u975e\u5747\u5300\u7684\u65b9\u5f0f\u81ea\u9002\u5e94\u5730\u878d\u5408patch\u3002<\/strong><\/p>\n<p><strong>\u7279\u70b9\uff1a\u51cf\u5c11\u8ba1\u7b97\u6210\u672c<\/strong><\/p>\n<p><strong>\u52a8\u673a\uff1a<\/strong><\/p>\n<ul>\n<li>\u5148\u524d\u5728CNNs\u548cTransformers\u4e0a\u7684\u7814\u7a76\u8868\u660e\uff0c\u6d45\u5c42\u5173\u6ce8\u5c40\u90e8\u7279\u5f81\uff0c\u800c\u66f4\u6df1\u5c42\u5219\u503e\u5411\u4e8e\u6355\u83b7\u9ad8\u7ea7\u8bed\u4e49\u6216\u5168\u5c40\u5173\u7cfb\u3002\u56e0\u6b64\u4f5c\u8005\u8ba4\u4e3a\u5728\u65e9\u671f\u4e0d\u5fc5\u8981\u91c7\u7528Transformers\u3002<\/li>\n<li>\u8d8a\u5c11\u7684\u5934\u8868\u8fbe\u80fd\u529b\u8d8a\u5f31\uff08\u7c7b\u4f3c1\u00d71\u5377\u79ef\uff09\uff08\u5177\u6709\u4e00\u4e2a\u5934\u7684MSA\u53ea\u80fd\u8fd1\u4f3c\u4e8e\u4e00\u4e2aFC\u5c42\uff09<\/li>\n<li>\u91c7\u7528\u7279\u5f81\u91d1\u5b57\u5854\u7684\u65b9\u5f0f\uff0c\u5728\u65e9\u671f\u91c7\u7528MLP\uff0c\u540e\u671f\u91c7\u7528\u81ea\u6ce8\u610f\u529b\uff0c\u53ef\u4ee5\u907f\u514d\u65e9\u671f\u9ad8\u5206\u8fa8\u7387\u56fe\u50cf\u5e26\u6765\u7684\u5de8\u5927\u8ba1\u7b97\u6210\u672c\u548c\u5185\u5b58\u5360\u7528\u3002<\/li>\n<\/ul>\n<h1>\u6574\u4f53\u7ed3\u6784<\/h1>\n<p><img src=\"https:\/\/blog.liguanxin.cn\/wp-content\/uploads\/2022\/07\/\u5fae\u4fe1\u622a\u56fe_20220720201734.png\" alt=\"\" \/><br \/>\nLIT\u7684\u6574\u4f53\u67b6\u6784\u3002\u8be5\u6a21\u578b\u5206\u4e3a\u56db\u4e2astages\uff0c\u6211\u4eec\u5728\u524d\u4e24\u4e2astages\u5e94\u7528MLP\u5757\uff0c\u5728\u540e\u4e24\u4e2astages\u91c7\u7528\u6807\u51c6Transformer\u5757\u3002<strong>DTM<\/strong>\u8868\u793a\u6240\u63d0\u51fa\u7684\u53ef\u53d8\u5f62\u7684token\u878d\u5408\u6a21\u5757\u3002<\/p>\n<hr \/>\n<h2>\u53ef\u53d8\u5f62\u7684token\u878d\u5408\u6a21\u5757Deformable Token Merging(DTM)<\/h2>\n<p>\u7075\u611f\u6765\u81ea\u53ef\u53d8\u5f62\u5377\u79ef\uff0c\u539f\u59cb\u7684\u53ef\u53d8\u5f62\u5377\u79ef\u53ef\u4ee5\u901a\u8fc7\u516c\u5f0f\u8868\u793a\u4e3a\uff1a<\/p>\n<p><center><span class=\"katex-eq\" data-katex-display=\"false\"> DC(\\textbf{X}_{p,:}) = \\sum_{k\\in [K \\times K]}\\textbf{X}_{p+g(k)+\\Delta g(k),:}\\textbf{W}_{g(k),:,:} <\/span><\/center><\/p>\n<p>\u4e0e\u666e\u901a\u5377\u79ef\u76f8\u6bd4\u53ef\u53d8\u5f62\u5377\u79ef\u5b66\u4e60\u4e86\u4e00\u4e2a<span class=\"katex-eq\" data-katex-display=\"false\">\\Delta g(k)<\/span>\u504f\u79fb\u91cf\uff0c\u8fd9\u540c\u6837\u53ef\u4ee5\u5e94\u7528\u4e8e\u7279\u5f81\u56fe\u7684\u751f\u6210\u3002\u4e3a\u4e86\u5408\u5e76patches\uff0c\u91c7\u7528\u53ef\u53d8\u5f62\u5377\u79ef\u65b9\u5f0f\uff1a<\/p>\n<p><center><span class=\"katex-eq\" data-katex-display=\"false\"> DTM(\\textbf{X}=GELU(BN(DC(\\textbf(X))))) <\/span><\/center><\/p>\n<h2>\u5b9e\u9a8c\u7ed3\u679c<\/h2>\n<p><img src=\"https:\/\/blog.liguanxin.cn\/wp-content\/uploads\/2022\/07\/\u5fae\u4fe1\u622a\u56fe_20220720204913.png\" alt=\"\" \/><br \/>\n\u5728\u53c2\u6570\u5dee\u4e0d\u591a\u7684\u60c5\u51b5\u4e0b\u51c6\u786e\u7387\u76f8\u6bd4swin\u63d0\u4e860.\u51e0<\/p>\n<h2>\u53ef\u53d8\u5f62\u5377\u79eftoken\u6a21\u5757\u7684\u6709\u6548\u6027<\/h2>\n<p><img src=\"https:\/\/blog.liguanxin.cn\/wp-content\/uploads\/2022\/07\/\u5fae\u4fe1\u622a\u56fe_20220720205226.png\" alt=\"\" \/><br \/>\n\u7eff\u6846\u4e3a\u539f\u672c\u5377\u79ef\u7a97\u53e3\uff0c\u7ea2\u8272\u4ee3\u8868\u53d8\u5f62\u540e\u7684\u5377\u79ef\u7a97\u53e3\u4f4d\u7f6e<\/p>\n<h2>CODE<\/h2>\n<p><strong>\u53ef\u53d8\u5f62\u7684token\u878d\u5408\u6a21\u5757\uff08\u8c03\u7528\u53ef\u53d8\u5f62\u5377\u79ef\u7684\u7b97\u5b50\uff09<\/strong><\/p>\n<pre><code class=\"language-python\">class DeformablePatchMerging(nn.Module):\n    r&quot;&quot;&quot; Patch Merging Layer.\n    Args:\n        input_resolution (tuple[int]): Resolution of input feature.\n        dim (int): Number of input channels.\n        norm_layer (nn.Module, optional): Normalization layer.  Default: nn.LayerNorm\n    &quot;&quot;&quot;\n\n    def __init__(self, input_resolution, dim, norm_layer=nn.LayerNorm):\n        super().__init__()\n        self.input_resolution = input_resolution\n        self.dim = dim\n        self.kernel_size = 2\n        self.stride = 2\n        self.padding = 0\n        self.c_in = dim\n        self.c_out = dim*2\n        self.dconv = DeformConv2dPack(dim, dim*2, kernel_size=2, stride=2, padding=0)\n        self.norm_layer = nn.BatchNorm2d(dim*2)\n        self.act_layer = nn.GELU()\n\n    def forward(self, x, return_offset=False):\n        &quot;&quot;&quot;\n        x: B, H*W, C\n        &quot;&quot;&quot;\n        H, W = self.input_resolution\n        B, L, C = x.shape\n        assert L == H * W, &quot;input feature has wrong size&quot;\n        assert H % 2 == 0 and W % 2 == 0, f&quot;x size ({H}*{W}) are not even.&quot;\n\n        x = x.reshape(B, H, W, C).permute(0, 3, 1, 2).contiguous()\n        x, offset = self.dconv(x, return_offset=False)\n        x = self.act_layer(self.norm_layer(x)).flatten(2).transpose(1, 2)\n        if return_offset:\n            return x, offset\n        else:\n            return x<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u521b\u65b0\u70b9\uff1a \u2460\u5728\u6d45\u5c42\u7528MLP\u7f16\u7801\u5c40\u90e8\u7279\u5f81 \u2461\u5728\u6df1\u5c42\u7528\u81ea\u6ce8\u610f\u529b\u6355\u83b7\u957f\u8ddd\u79bb\u4f9d\u8d56 \u2462\u53ef\u53d8\u5f62\u7684token\u878d\u5408\u6a21\u5757\uff0c\u4ee5\u975e\u5747 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[14,13,19,17,11],"_links":{"self":[{"href":"https:\/\/blog.liguanxin.cn\/index.php\/wp-json\/wp\/v2\/posts\/531"}],"collection":[{"href":"https:\/\/blog.liguanxin.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.liguanxin.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.liguanxin.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.liguanxin.cn\/index.php\/wp-json\/wp\/v2\/comments?post=531"}],"version-history":[{"count":0,"href":"https:\/\/blog.liguanxin.cn\/index.php\/wp-json\/wp\/v2\/posts\/531\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.liguanxin.cn\/index.php\/wp-json\/wp\/v2\/media?parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.liguanxin.cn\/index.php\/wp-json\/wp\/v2\/categories?post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.liguanxin.cn\/index.php\/wp-json\/wp\/v2\/tags?post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}