{"id":8654,"date":"2022-09-30T09:57:01","date_gmt":"2022-09-30T01:57:01","guid":{"rendered":"http:\/\/139.9.1.231\/?p=8654"},"modified":"2022-09-30T09:57:02","modified_gmt":"2022-09-30T01:57:02","slug":"diated_conv","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/09\/30\/diated_conv\/","title":{"rendered":"\u7a7a\u6d1e\u5377\u79ef"},"content":{"rendered":"\n<p class=\"has-bright-blue-background-color has-background\"><a href=\"https:\/\/arxiv.org\/abs\/1511.07122\" target=\"_blank\" rel=\"noreferrer noopener\">Multi-Scale Context Aggregation by Dilated Convolutions<\/a><\/p>\n\n\n\n<p>\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c[\u52a8\u6001\u56fe\u6765\u6e90\uff1a<a href=\"https:\/\/github.com\/vdumoulin\/conv_arithmetic\" target=\"_blank\" rel=\"noreferrer noopener\">vdumoulin\/conv_arithmetic<\/a>]\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/picx.zhimg.com\/50\/v2-d552433faa8363df84c53b905443a556_720w.webp?source=1940ef5c\" alt=\"\u52a8\u56fe\"\/><figcaption>Standard Convolution with a 3 x 3 kernel (and padding)<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/pica.zhimg.com\/50\/v2-4959201e816888c6648f2e78cccfd253_720w.jpg?source=1940ef5c\" alt=\"\u52a8\u56fe\u5c01\u9762\"\/><figcaption>Dilated Convolution with a 3 x 3 kernel and dilation rate 2<\/figcaption><\/figure>\n\n\n\n<p>\u5bf9\u4e8e dilated convolution\uff0c \u6211\u4eec\u5df2\u7ecf\u53ef\u4ee5\u53d1\u73b0\u4ed6\u7684\u4f18\u70b9\uff0c\u5373\u5185\u90e8\u6570\u636e\u7ed3\u6784\u7684\u4fdd\u7559\u548c\u907f\u514d\u4f7f\u7528 down-sampling \u8fd9\u6837\u7684\u7279\u6027\u3002\u4f46\u662f\u5b8c\u5168\u57fa\u4e8e dilated convolution \u7684\u7ed3\u6784\u5982\u4f55\u8bbe\u8ba1\u5219\u662f\u4e00\u4e2a\u65b0\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p><strong>\u6f5c\u5728\u95ee\u9898 1\uff1aThe Gridding Effect<\/strong><\/p>\n\n\n\n<p>\u5047\u8bbe\u6211\u4eec\u4ec5\u4ec5\u591a\u6b21\u53e0\u52a0 dilation rate 2 \u7684 3 x 3 kernel \u7684\u8bdd\uff0c\u5219\u4f1a\u51fa\u73b0\u8fd9\u4e2a\u95ee\u9898\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/pic1.zhimg.com\/v2-478a6b82e1508a147712af63d6472d9a_r.jpg?source=1940ef5c\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u6211\u4eec\u53d1\u73b0\u6211\u4eec\u7684 kernel \u5e76\u4e0d\u8fde\u7eed\uff0c\u4e5f\u5c31\u662f\u5e76\u4e0d\u662f\u6240\u6709\u7684 pixel \u90fd\u7528\u6765\u8ba1\u7b97\u4e86\uff0c\u56e0\u6b64\u8fd9\u91cc\u5c06\u4fe1\u606f\u770b\u505a checker-board \u7684\u65b9\u5f0f\u4f1a\u635f\u5931\u4fe1\u606f\u7684\u8fde\u7eed\u6027\u3002\u8fd9\u5bf9 pixel-level dense prediction \u7684\u4efb\u52a1\u6765\u8bf4\u662f\u81f4\u547d\u7684\u3002<\/p>\n\n\n\n<p><strong>\u6f5c\u5728\u95ee\u9898 2\uff1aLong-ranged information might be not relevant.<\/strong><\/p>\n\n\n\n<p>\u6211\u4eec\u4ece dilated convolution \u7684\u8bbe\u8ba1\u80cc\u666f\u6765\u770b\u5c31\u80fd\u63a8\u6d4b\u51fa\u8fd9\u6837\u7684\u8bbe\u8ba1\u662f\u7528\u6765\u83b7\u53d6 long-ranged information\u3002\u7136\u800c\u5149\u91c7\u7528\u5927 dilation rate \u7684\u4fe1\u606f\u6216\u8bb8\u53ea\u5bf9\u4e00\u4e9b\u5927\u7269\u4f53\u5206\u5272\u6709\u6548\u679c\uff0c\u800c\u5bf9\u5c0f\u7269\u4f53\u6765\u8bf4\u53ef\u80fd\u5219\u6709\u5f0a\u65e0\u5229\u4e86\u3002\u5982\u4f55\u540c\u65f6\u5904\u7406\u4e0d\u540c\u5927\u5c0f\u7684\u7269\u4f53\u7684\u5173\u7cfb\uff0c\u5219\u662f\u8bbe\u8ba1\u597d dilated convolution \u7f51\u7edc\u7684\u5173\u952e\u3002<\/p>\n\n\n\n<h2>\u901a\u5411\u6807\u51c6\u5316\u8bbe\u8ba1\uff1aHybrid Dilated Convolution (HDC)<\/h2>\n\n\n\n<p>\u5bf9\u4e8e\u4e0a\u4e2a section \u91cc\u63d0\u5230\u7684\u51e0\u4e2a\u95ee\u9898\uff0c\u56fe\u68ee\u7ec4\u7684\u6587\u7ae0\u5bf9\u5176\u63d0\u51fa\u4e86\u8f83\u597d\u7684\u89e3\u51b3\u7684\u65b9\u6cd5\u3002\u4ed6\u4eec\u8bbe\u8ba1\u4e86\u4e00\u4e2a\u79f0\u4e4b\u4e3a HDC \u7684\u8bbe\u8ba1\u7ed3\u6784\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e00\u4e2a\u7279\u6027\u662f\uff0c\u53e0\u52a0\u5377\u79ef\u7684 dilation rate \u4e0d\u80fd\u6709\u5927\u4e8e1\u7684\u516c\u7ea6\u6570\u3002\u6bd4\u5982 [2, 4, 6] \u5219\u4e0d\u662f\u4e00\u4e2a\u597d\u7684\u4e09\u5c42\u5377\u79ef\uff0c\u4f9d\u7136\u4f1a\u51fa\u73b0 gridding effect\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e8c\u4e2a\u7279\u6027\u662f\uff0c\u6211\u4eec\u5c06 dilation rate \u8bbe\u8ba1\u6210 \u952f\u9f7f\u72b6\u7ed3\u6784\uff0c\u4f8b\u5982 [1, 2, 5, 1, 2, 5] \u5faa\u73af\u7ed3\u6784\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e09\u4e2a\u7279\u6027\u662f\uff0c\u6211\u4eec\u9700\u8981\u6ee1\u8db3\u4e00\u4e0b\u8fd9\u4e2a\u5f0f\u5b50\uff1a&nbsp;Mi=max[Mi+1\u22122ri,Mi+1\u22122(Mi+1\u2212ri),ri]<\/p>\n\n\n\n<p>\u5176\u4e2d&nbsp;ri&nbsp;\u662f i \u5c42\u7684 dilation rate \u800c&nbsp;Mi&nbsp;\u662f\u6307\u5728 i \u5c42\u7684\u6700\u5927dilation rate\uff0c\u90a3\u4e48\u5047\u8bbe\u603b\u5171\u6709n\u5c42\u7684\u8bdd\uff0c\u9ed8\u8ba4&nbsp;Mn=rn&nbsp;\u3002\u5047\u8bbe\u6211\u4eec\u5e94\u7528\u4e8e kernel \u4e3a k x k \u7684\u8bdd\uff0c\u6211\u4eec\u7684\u76ee\u6807\u5219\u662f&nbsp;M2\u2264k&nbsp;\uff0c\u8fd9\u6837\u6211\u4eec\u81f3\u5c11\u53ef\u4ee5\u7528 dilation rate 1 \u5373 standard convolution \u7684\u65b9\u5f0f\u6765\u8986\u76d6\u6389\u6240\u6709\u6d1e\u3002<\/p>\n\n\n\n<p>\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50: dilation rate [1, 2, 5] with 3 x 3 kernel (\u53ef\u884c\u7684\u65b9\u6848)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"844\" height=\"309\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-290.png\" alt=\"\" class=\"wp-image-8661\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-290.png 844w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-290-300x110.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-290-768x281.png 768w\" sizes=\"(max-width: 844px) 100vw, 844px\" \/><\/figure>\n\n\n\n<p>\u800c\u8fd9\u6837\u7684\u952f\u9f7f\u72b6\u672c\u8eab\u7684\u6027\u8d28\u5c31\u6bd4\u8f83\u597d\u7684\u6765\u540c\u65f6\u6ee1\u8db3\u5c0f\u7269\u4f53\u5927\u7269\u4f53\u7684\u5206\u5272\u8981\u6c42(\u5c0f dilation rate \u6765\u5173\u5fc3\u8fd1\u8ddd\u79bb\u4fe1\u606f\uff0c\u5927 dilation rate \u6765\u5173\u5fc3\u8fdc\u8ddd\u79bb\u4fe1\u606f)\u3002<\/p>\n\n\n\n<p>\u8fd9\u6837\u6211\u4eec\u7684\u5377\u79ef\u4f9d\u7136\u662f\u8fde\u7eed\u7684\u4e5f\u5c31\u4f9d\u7136\u80fd\u6ee1\u8db3VGG\u7ec4\u89c2\u5bdf\u7684\u7ed3\u8bba\uff0c\u5927\u5377\u79ef\u662f\u7531\u5c0f\u5377\u79ef\u7684 regularisation \u7684 \u53e0\u52a0\u3002<\/p>\n\n\n\n<p>\u4ee3\u7801\uff1a\uff08\u7ed8\u5236\u7a7a\u6d1e\u5377\u79ef\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import numpy as np\r\nimport matplotlib.pyplot as plt\r\nfrom matplotlib.colors import LinearSegmentedColormap\r\n\r\n\r\ndef dilated_conv_one_pixel(center: (int, int),feature_map: np.ndarray,k: int = 3,r: int = 1,v: int = 1):\r\n    \"\"\"\r\n    \u81a8\u80c0\u5377\u79ef\u6838\u4e2d\u5fc3\u5728\u6307\u5b9a\u5750\u6807center\u5904\u65f6\uff0c\u7edf\u8ba1\u54ea\u4e9b\u50cf\u7d20\u88ab\u5229\u7528\u5230\uff0c\r\n    \u5e76\u5728\u5229\u7528\u5230\u7684\u50cf\u7d20\u4f4d\u7f6e\u5904\u52a0\u4e0a\u589e\u91cfv\r\n    Args:\r\n        center: \u81a8\u80c0\u5377\u79ef\u6838\u4e2d\u5fc3\u7684\u5750\u6807\r\n        feature_map: \u8bb0\u5f55\u6bcf\u4e2a\u50cf\u7d20\u4f7f\u7528\u6b21\u6570\u7684\u7279\u5f81\u56fe\r\n        k: \u81a8\u80c0\u5377\u79ef\u6838\u7684kernel\u5927\u5c0f\r\n        r: \u81a8\u80c0\u5377\u79ef\u7684dilation rate\r\n        v: \u4f7f\u7528\u6b21\u6570\u589e\u91cf\r\n    \"\"\"\r\n    assert divmod(3, 2)&#91;1] == 1\r\n\r\n    # left-top: (x, y)\r\n    left_top = (center&#91;0] - ((k - 1) \/\/ 2) * r, center&#91;1] - ((k - 1) \/\/ 2) * r)\r\n    for i in range(k):\r\n        for j in range(k):\r\n            feature_map&#91;left_top&#91;1] + i * r]&#91;left_top&#91;0] + j * r] += v\r\n\r\n\r\ndef dilated_conv_all_map(dilated_map: np.ndarray,\r\n                         k: int = 3,\r\n                         r: int = 1):\r\n    \"\"\"\r\n    \u6839\u636e\u8f93\u51fa\u7279\u5f81\u77e9\u9635\u4e2d\u54ea\u4e9b\u50cf\u7d20\u88ab\u4f7f\u7528\u4ee5\u53ca\u4f7f\u7528\u6b21\u6570\uff0c\r\n    \u914d\u5408\u81a8\u80c0\u5377\u79efk\u548cr\u8ba1\u7b97\u8f93\u5165\u7279\u5f81\u77e9\u9635\u54ea\u4e9b\u50cf\u7d20\u88ab\u4f7f\u7528\u4ee5\u53ca\u4f7f\u7528\u6b21\u6570\r\n    Args:\r\n        dilated_map: \u8bb0\u5f55\u8f93\u51fa\u7279\u5f81\u77e9\u9635\u4e2d\u6bcf\u4e2a\u50cf\u7d20\u88ab\u4f7f\u7528\u6b21\u6570\u7684\u7279\u5f81\u56fe\r\n        k: \u81a8\u80c0\u5377\u79ef\u6838\u7684kernel\u5927\u5c0f\r\n        r: \u81a8\u80c0\u5377\u79ef\u7684dilation rate\r\n    \"\"\"\r\n    new_map = np.zeros_like(dilated_map)\r\n    for i in range(dilated_map.shape&#91;0]):\r\n        for j in range(dilated_map.shape&#91;1]):\r\n            if dilated_map&#91;i]&#91;j] > 0:\r\n                dilated_conv_one_pixel((j, i), new_map, k=k, r=r, v=dilated_map&#91;i]&#91;j])\r\n\r\n    return new_map\r\n\r\n\r\ndef plot_map(matrix: np.ndarray):\r\n    plt.figure()\r\n\r\n    c_list = &#91;'white', 'blue', 'red']\r\n    new_cmp = LinearSegmentedColormap.from_list('chaos', c_list)\r\n    plt.imshow(matrix, cmap=new_cmp)\r\n\r\n    ax = plt.gca()\r\n    ax.set_xticks(np.arange(-0.5, matrix.shape&#91;1], 1), minor=True)\r\n    ax.set_yticks(np.arange(-0.5, matrix.shape&#91;0], 1), minor=True)\r\n\r\n    # \u663e\u793acolor bar\r\n    plt.colorbar()\r\n\r\n    # \u5728\u56fe\u4e2d\u6807\u6ce8\u6570\u91cf\r\n    thresh = 5\r\n    for x in range(matrix.shape&#91;1]):\r\n        for y in range(matrix.shape&#91;0]):\r\n            # \u6ce8\u610f\u8fd9\u91cc\u7684matrix&#91;y, x]\u4e0d\u662fmatrix&#91;x, y]\r\n            info = int(matrix&#91;y, x])\r\n            ax.text(x, y, info,\r\n                    verticalalignment='center',\r\n                    horizontalalignment='center',\r\n                    color=\"white\" if info > thresh else \"black\")\r\n    ax.grid(which='minor', color='black', linestyle='-', linewidth=1.5)\r\n    plt.show()\r\n    plt.close()\r\n\r\n\r\ndef main():\r\n    # bottom to top\r\n    dilated_rates = &#91;1, 2, 3]\r\n    # init feature map\r\n    size = 31\r\n    m = np.zeros(shape=(size, size), dtype=np.int32)\r\n    center = size \/\/ 2\r\n    m&#91;center]&#91;center] = 1\r\n    # print(m)\r\n    # plot_map(m)\r\n\r\n    for index, dilated_r in enumerate(dilated_rates&#91;::-1]):\r\n        new_map = dilated_conv_all_map(m, r=dilated_r)\r\n        m = new_map\r\n    print(m)\r\n    plot_map(m)\r\n\r\n<\/code><\/pre>\n\n\n\n<p>\u7ed8\u5236\u7ed3\u679c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"525\" height=\"462\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-291.png\" alt=\"\" class=\"wp-image-8665\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-291.png 525w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-291-300x264.png 300w\" sizes=\"(max-width: 525px) 100vw, 525px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Multi-Scale Context Aggregation by Dilated Convolutions &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/09\/30\/diated_conv\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u7a7a\u6d1e\u5377\u79ef<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/8654"}],"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=8654"}],"version-history":[{"count":10,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/8654\/revisions"}],"predecessor-version":[{"id":8666,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/8654\/revisions\/8666"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=8654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=8654"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=8654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}