{"id":6546,"date":"2022-08-30T21:04:00","date_gmt":"2022-08-30T13:04:00","guid":{"rendered":"http:\/\/139.9.1.231\/?p=6546"},"modified":"2022-08-28T21:06:16","modified_gmt":"2022-08-28T13:06:16","slug":"attention-unet","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/08\/30\/attention-unet\/","title":{"rendered":"Attention UNet"},"content":{"rendered":"\n<p>\u8bba\u6587\uff1a <a href=\"https:\/\/arxiv.org\/abs\/1804.03999\">https:\/\/arxiv.org\/abs\/1804.03999<\/a><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" width=\"453\" height=\"205\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-417.png\" alt=\"\" class=\"wp-image-6548\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-417.png 453w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-417-300x136.png 300w\" sizes=\"(max-width: 453px) 100vw, 453px\" \/><\/figure><\/div>\n\n\n\n<p>        \u4ee5CNN\u4e3a\u57fa\u7840\u7684\u7f16\u89e3\u7801\u7ed3\u6784\u5728\u56fe\u50cf\u5206\u5272\u4e0a\u5c55\u73b0\u51fa\u4e86\u5353\u8d8a\u7684\u6548\u679c\uff0c\u5c24\u5176\u662f\u533b\u5b66\u56fe\u50cf\u7684\u81ea\u52a8\u5206\u5272\u4e0a\u3002\u4f46\u4e00\u4e9b\u7814\u7a76\u8ba4\u4e3a\u4ee5\u5f80\u7684FCN\u548cUNet\u7b49\u5206\u5272\u7f51\u7edc\u5b58\u5728\u8ba1\u7b97\u8d44\u6e90\u548c\u6a21\u578b\u53c2\u6570\u7684\u8fc7\u5ea6\u548c\u91cd\u590d\u4f7f\u7528\uff0c\u4f8b\u5982\u76f8\u4f3c\u7684\u4f4e\u5c42\u6b21\u7279\u5f81\u88ab\u7ea7\u8054\u5185\u7684\u6240\u6709\u7f51\u7edc\u91cd\u590d\u63d0\u53d6\u3002\u9488\u5bf9\u8fd9\u7c7b\u666e\u904d\u6027\u7684\u95ee\u9898\uff0c\u76f8\u5173\u7814\u7a76\u63d0\u51fa\u4e86\u7ed9UNet\u6dfb\u52a0\u6ce8\u610f\u529b\u95e8\u63a7\uff08Attention Gates, AGs\uff09\u7684\u65b9\u6cd5\uff0c\u5f62\u6210\u4e00\u4e2a\u65b0\u7684\u56fe\u50cf\u5206\u5272\u7f51\u7edc\u7ed3\u6784\uff1aAttention UNet\u3002\u63d0\u51faAttention UNet\u7684\u8bba\u6587\u4e3aAttention U-Net: Learning Where to Look for the Pancreas\uff0c\u53d1\u8868\u57282018\u5e74CVPR\u4e0a\u3002\u6ce8\u610f\u529b\u673a\u5236\u539f\u5148\u662f\u5728\u81ea\u7136\u8bed\u8a00\u5904\u7406\u9886\u57df\u88ab\u63d0\u51fa\u5e76\u9010\u6e10\u5f97\u5230\u5e7f\u6cdb\u5e94\u7528\u7684\u4e00\u79cd\u65b0\u578b\u7ed3\u6784\uff0c\u65e8\u5728\u6a21\u4eff\u4eba\u7684\u6ce8\u610f\u529b\u673a\u5236\uff0c\u6709\u9488\u5bf9\u6027\u7684\u805a\u7126\u6570\u636e\u4e2d\u7684\u7a81\u51fa\u7279\u5f81\uff0c\u80fd\u591f\u4f7f\u5f97\u6a21\u578b\u66f4\u52a0\u9ad8\u6548\u3002<\/p>\n\n\n\n<p>       Attention UNet\u7684\u7f51\u7edc\u7ed3\u6784\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8bba\u6587\u4e2d\u7ed9\u51fa\u76843D\u7248\u672c\u7684\u5377\u79ef\u7f51\u7edc\u3002\u5176\u4e2d\u7f16\u7801\u5668\u90e8\u5206\u8ddfUNet\u7f16\u7801\u5668\u57fa\u672c\u4e00\u81f4\uff0c\u4e3b\u8981\u7684\u53d8\u5316\u5728\u4e8e\u89e3\u7801\u5668\u90e8\u5206\u3002\u5176\u7ed3\u6784\u7b80\u8981\u63cf\u8ff0\u5982\u4e0b\uff1a\u7f16\u7801\u5668\u90e8\u5206\uff0c\u8f93\u5165\u56fe\u50cf\u7ecf\u8fc7\u4e24\u7ec43*3*3\u76843D\u5377\u79ef\u548cReLU\u6fc0\u6d3b\uff0c\u7136\u540e\u518d\u8fdb\u884c\u6700\u5927\u6c60\u5316\u4e0b\u91c7\u6837\uff0c\u7ecf\u8fc73\u7ec4\u8fd9\u6837\u7684\u5377\u79ef-\u6c60\u5316\u5757\u4e4b\u540e\uff0c\u7f51\u7edc\u8fdb\u5165\u5230\u89e3\u7801\u5668\u90e8\u5206\u3002\u7f16\u7801\u5668\u6700\u540e\u4e00\u5c42\u7684\u7279\u5f81\u56fe\u9664\u4e86\u76f4\u63a5\u8fdb\u884c\u4e0a\u91c7\u6837\u5916\uff0c\u8fd8\u4e0e\u6765\u81ea\u7f16\u7801\u5668\u7684\u7279\u5f81\u56fe\u8fdb\u884c\u6ce8\u610f\u529b\u95e8\u63a7\u8ba1\u7b97\uff0c\u7136\u540e\u518d\u4e0e\u4e0a\u91c7\u6837\u7684\u7279\u5f81\u56fe\u8fdb\u884c\u5408\u5e76\uff0c\u7ecf\u8fc7\u4e09\u6b21\u8fd9\u6837\u7684\u4e0a\u91c7\u6837\u5757\u4e4b\u540e\u5373\u53ef\u5f97\u5230\u6700\u7ec8\u7684\u5206\u5272\u8f93\u51fa\u56fe\u3002\u76f8\u6bd4\u4e8e\u666e\u901aUNet\u7684\u89e3\u7801\u5668\uff0cAttention UNet\u4f1a\u5c06\u89e3\u7801\u5668\u4e2d\u7684\u7279\u5f81\u4e0e\u7f16\u7801\u5668\u8fde\u63a5\u8fc7\u6765\u7684\u7279\u5f81\u8fdb\u884c\u6ce8\u610f\u529b\u95e8\u63a7\u5904\u7406\uff0c\u7136\u540e\u518d\u4e0e\u4e0a\u91c7\u6837\u8fdb\u884c\u62fc\u63a5\u3002\u7ecf\u8fc7\u6ce8\u610f\u529b\u95e8\u63a7\u5904\u7406\u540e\u5f97\u5230\u7684\u7279\u5f81\u56fe\u4f1a\u5305\u542b\u4e0d\u540c\u7a7a\u95f4\u4f4d\u7f6e\u7684\u91cd\u8981\u6027\u4fe1\u606f\uff0c\u4f7f\u5f97\u6a21\u578b\u80fd\u591f\u91cd\u70b9\u5173\u6ce8\u67d0\u4e9b\u76ee\u6807\u533a\u57df\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"613\" height=\"358\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-418.png\" alt=\"\" class=\"wp-image-6551\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-418.png 613w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-418-300x175.png 300w\" sizes=\"(max-width: 613px) 100vw, 613px\" \/><\/figure>\n\n\n\n<p>      \u6211\u4eec\u5c06Attention UNet\u7684\u6ce8\u610f\u529b\u95e8\u63a7\u5355\u72ec\u62ff\u51fa\u6765\u8fdb\u884c\u5206\u6790\uff0c\u770bAGs\u662f\u5982\u4f55\u8ba9\u6a21\u578b\u80fd\u591f\u805a\u7126\u5230\u76ee\u6807\u533a\u57df\u7684\u3002\u5982\u56fe\u4e2d\u4e0a\u56fe\u6240\u793a\uff0c\u5c06Attention UNet\u7f51\u7edc\u4e2d\u7684\u4e00\u4e2a\u4e0a\u91c7\u6837\u5757\u5355\u72ec\u62ff\u51fa\u6765\uff0c\u5176\u4e2dx_l\u4e3a\u6765\u81ea\u540c\u5c42\u7f16\u7801\u5668\u7684\u8f93\u51fa\u7279\u5f81\u56fe\uff0cg\u8868\u793a\u7531\u89e3\u7801\u5668\u90e8\u5206\u7528\u4e8e\u4e0a\u91c7\u6837\u7684\u7279\u5f81\u56fe\uff0c\u8fd9\u91cc\u540c\u65f6\u4e5f\u4f5c\u4e3a\u6ce8\u610f\u529b\u95e8\u63a7\u7684\u95e8\u63a7\u4fe1\u53f7\u53c2\u6570\u4e0ex_l\u7684\u6ce8\u610f\u529b\u8ba1\u7b97\uff0c\u800cx^hat_l\u5373\u4e3a\u7ecf\u8fc7\u6ce8\u610f\u529b\u95e8\u63a7\u8ba1\u7b97\u540e\u7684\u7279\u5f81\u56fe\uff0c\u6b64\u65f6x^hat_l\u662f\u5305\u542b\u4e86\u7a7a\u95f4\u4f4d\u7f6e\u91cd\u8981\u6027\u4fe1\u606f\u7684\u7279\u5f81\u56fe\uff0c\u518d\u5c06\u5176\u4e0e\u4e0b\u4e00\u5c42\u4e0a\u91c7\u6837\u540e\u7684\u7279\u5f81\u56fe\u8fdb\u884c\u5408\u5e76\u624d\u5f97\u5230\u8be5\u4e0a\u91c7\u6837\u5757\u6700\u7ec8\u7684\u8f93\u51fa\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"884\" height=\"619\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-420.png\" alt=\"\" class=\"wp-image-6554\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-420.png 884w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-420-300x210.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-420-768x538.png 768w\" sizes=\"(max-width: 884px) 100vw, 884px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"863\" height=\"288\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-421.png\" alt=\"\" class=\"wp-image-6556\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-421.png 863w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-421-300x100.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-421-768x256.png 768w\" sizes=\"(max-width: 863px) 100vw, 863px\" \/><\/figure>\n\n\n\n<p>\u5c06x_l\u548cg_i\u8ba1\u7b97\u5f97\u5230\u7684\u6ce8\u610f\u529b\u7cfb\u6570\u518d\u6b21\u4e0ex_l\u76f8\u4e58\u5373\u53ef\u5f97\u5230x^hat_l\uff0c\u8fd9\u79cd\u7ecf\u8fc7\u4e0e\u6ce8\u610f\u529b\u7cfb\u6570\u76f8\u4e58\u540e\u7684\u7279\u5f81\u56fe\u4f1a\u8ba9\u56fe\u50cf\u4e2d\u4e0d\u76f8\u5173\u7684\u533a\u57df\u503c\u53d8\u5c0f\uff0c\u76ee\u6807\u533a\u57df\u7684\u503c\u76f8\u5bf9\u4f1a\u53d8\u5927\uff0c\u63d0\u5347\u7f51\u7edc\u9884\u6d4b\u901f\u5ea6\u540c\u65f6\uff0c\u4e5f\u4f1a\u63d0\u9ad8\u56fe\u50cf\u7684\u5206\u5272\u7cbe\u5ea6\u3002\u8bba\u6587\u4e2d\u7684\u5404\u9879\u5b9e\u9a8c\u7ed3\u679c\u4e5f\u8868\u660e\uff0c\u7ecf\u8fc7\u6ce8\u610f\u529b\u95e8\u63a7\u52a0\u6210\u540e\u540eUNet\uff0c\u6548\u679c\u5747\u8981\u4f18\u4e8e\u539f\u59cb\u7684UNet\u3002\u4e0b\u8ff0\u4ee3\u7801\u7ed9\u51fa\u4e86Attention UNet\u7684\u4e00\u4e2a2D\u53c2\u8003\u5b9e\u73b0\uff0c\u5e76\u4e14\u4e0b\u91c7\u6837\u6b21\u6570\u7531\u8bba\u6587\u4e2d\u76843\u6b21\u6539\u4e3a\u4e864\u6b21\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\r\n### \u5b9a\u4e49Attention UNet\u7c7b\r\nclass Att_UNet(nn.Module):\r\n    def __init__(self,img_ch=3,output_ch=1):\r\n        super(Att_UNet, self).__init__()\r\n        self.Maxpool = nn.MaxPool2d(kernel_size=2, stride=2)\r\n        self.Conv1 = conv_block(ch_in=img_ch, ch_out=64)\r\n        self.Conv2 = conv_block(ch_in=64, ch_out=128)\r\n        self.Conv3 = conv_block(ch_in=128, ch_out=256)\r\n        self.Conv4 = conv_block(ch_in=256, ch_out=512)\r\n        self.Conv5 = conv_block(ch_in=512, ch_out=1024)\r\n\r\n        self.Up5 = up_conv(ch_in=1024, ch_out=512)\r\n        self.Att5 = Attention_block(F_g=512, F_l=512, F_int=256)\r\n        self.Up_conv5 = conv_block(ch_in=1024, ch_out=512)\r\n\r\n        self.Up4 = up_conv(ch_in=512, ch_out=256)\r\n        self.Att4 = Attention_block(F_g=256, F_l=256, F_int=128)\r\n        self.Up_conv4 = conv_block(ch_in=512, ch_out=256)\r\n        \r\n        self.Up3 = up_conv(ch_in=256, ch_out=128)\r\n        self.Att3 = Attention_block(F_g=128, F_l=128, F_int=64)\r\n        self.Up_conv3 = conv_block(ch_in=256, ch_out=128)\r\n        \r\n        self.Up2 = up_conv(ch_in=128, ch_out=64)\r\n        self.Att2 = Attention_block(F_g=64, F_l=64, F_int=32)\r\n        self.Up_conv2 = conv_block(ch_in=128, ch_out=64)\r\n\r\n        self.Conv_1x1 =\r\n       nn.Conv2d(64, output_ch, kernel_size=1, stride=1, padding=0)\r\n    \r\n  ### \u5b9a\u4e49\u524d\u5411\u4f20\u64ad\u6d41\u7a0b\r\n    def forward(self,x):\r\n        # \u7f16\u7801\u5668\u90e8\u5206\r\n        x1 = self.Conv1(x)\r\n        x2 = self.Maxpool(x1)\r\n        x2 = self.Conv2(x2)\r\n        x3 = self.Maxpool(x2)\r\n        x3 = self.Conv3(x3)\r\n        x4 = self.Maxpool(x3)\r\n        x4 = self.Conv4(x4)\r\n        x5 = self.Maxpool(x4)\r\n        x5 = self.Conv5(x5)\r\n\r\n        # \u89e3\u7801\u5668+\u8fde\u63a5\u90e8\u5206\r\n        d5 = self.Up5(x5)\r\n        x4 = self.Att5(g=d5,x=x4)\r\n        d5 = torch.cat((x4,d5),dim=1)        \r\n        d5 = self.Up_conv5(d5)        \r\n        d4 = self.Up4(d5)\r\n        x3 = self.Att4(g=d4,x=x3)\r\n        d4 = torch.cat((x3,d4),dim=1)\r\n        d4 = self.Up_conv4(d4)\r\n\r\n        d3 = self.Up3(d4)\r\n        x2 = self.Att3(g=d3,x=x2)\r\n        d3 = torch.cat((x2,d3),dim=1)\r\n        d3 = self.Up_conv3(d3)\r\n        d2 = self.Up2(d3)\r\n        x1 = self.Att2(g=d2,x=x1)\r\n        d2 = torch.cat((x1,d2),dim=1)\r\n        d2 = self.Up_conv2(d2)\r\n        d1 = self.Conv_1x1(d2)\r\n        return d1\r\n  \r\n  ### \u5b9a\u4e49Attention\u95e8\u63a7\u5757\r\nclass Attention_block(nn.Module):\r\n    def __init__(self, F_g, F_l, F_int):\r\n        super(Attention_block, self).__init__()\r\n    # \u6ce8\u610f\u529b\u95e8\u63a7\u5411\u91cf\r\n        self.W_g = nn.Sequential(\r\n            nn.Conv2d(F_g, F_int,\r\n            kernel_size=1, stride=1, padding=0, bias=True),\r\n            nn.BatchNorm2d(F_int)\r\n            )\r\n        # \u540c\u5c42\u7f16\u7801\u5668\u7279\u5f81\u56fe\u5411\u91cf\r\n        self.W_x = nn.Sequential(\r\n            nn.Conv2d(F_l, F_int,\r\n            kernel_size=1,stride=1,padding=0,bias=True),\r\n            nn.BatchNorm2d(F_int)\r\n        )\r\n    # ReLU\u6fc0\u6d3b\u51fd\u6570\r\n    self.relu = nn.ReLU(inplace=True)\r\n    # \u5377\u79ef+BN+sigmoid\u6fc0\u6d3b\u51fd\u6570\r\n        self.psi = nn.Sequential(\r\n            nn.Conv2d(F_int, 1,\r\n            kernel_size=1, stride=1, padding=0, bias=True),\r\n            nn.BatchNorm2d(1),\r\n            nn.Sigmoid()\r\n        )\r\n        \r\n    ###  Attention\u95e8\u63a7\u7684\u524d\u5411\u8ba1\u7b97\u6d41\u7a0b \r\n    def forward(self,g,x):\r\n        g1 = self.W_g(g)\r\n        x1 = self.W_x(x)\r\n        psi = self.relu(g1+x1)\r\n        psi = self.psi(psi)\r\n        return x*psi\r<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"866\" height=\"255\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-422.png\" alt=\"\" class=\"wp-image-6558\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-422.png 866w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-422-300x88.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-422-768x226.png 768w\" sizes=\"(max-width: 866px) 100vw, 866px\" \/><\/figure>\n\n\n\n<p>\u603b\u7ed3\u6765\u8bf4\uff0cAttention UNet\u63d0\u51fa\u4e86\u5728\u539f\u59cbUNet\u57fa\u7840\u6dfb\u52a0\u6ce8\u610f\u529b\u95e8\u63a7\u5355\u5143\uff0c\u6ce8\u610f\u529b\u5f97\u5206\u80fd\u591f\u4f7f\u5f97\u56fe\u50cf\u5206\u5272\u65f6\u805a\u7126\u5230\u76ee\u6807\u533a\u57df\uff0c\u8be5\u7ed3\u6784\u4f5c\u4e3a\u4e00\u4e2a\u901a\u7528\u7ed3\u6784\u53ef\u4ee5\u6dfb\u52a0\u5230\u4efb\u4f55\u4efb\u52a1\u7c7b\u578b\u7684\u795e\u7ecf\u7f51\u7edc\u7ed3\u6784\u4e2d\uff0c\u5728\u8bed\u4e49\u5206\u5272\u7f51\u7edc\u4e2d\u5bf9\u524d\u666f\u76ee\u6807\u533a\u57df\u7684\u50cf\u7d20\u66f4\u5177\u6709\u654f\u611f\u5ea6\u3002Attention UNet\u58ee\u5927\u4e86UNet\u5bb6\u65cf\u7f51\u7edc\uff0c\u6b64\u540e\u57fa\u4e8e\u5176\u7684\u6539\u8fdb\u7248\u672c\u4e5f\u5c42\u51fa\u4e0d\u7a77\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bba\u6587\uff1a https:\/\/arxiv.org\/abs\/1804.03999 \u4ee5CNN\u4e3a\u57fa\u7840\u7684\u7f16\u89e3\u7801\u7ed3\u6784\u5728\u56fe\u50cf\u5206\u5272 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/08\/30\/attention-unet\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">Attention UNet<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/6546"}],"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=6546"}],"version-history":[{"count":7,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/6546\/revisions"}],"predecessor-version":[{"id":6559,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/6546\/revisions\/6559"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=6546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=6546"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=6546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}