{"id":1994,"date":"2018-12-03T16:59:38","date_gmt":"2018-12-03T08:59:38","guid":{"rendered":"https:\/\/yanjingang.com\/blog\/?p=1994"},"modified":"2019-08-02T16:03:18","modified_gmt":"2019-08-02T08:03:18","slug":"%e5%b0%8f%e7%8c%aa%e5%ad%a6paddle-cnn%e4%b9%8b%e6%89%8b%e5%86%99%e6%95%b0%e5%ad%97%e5%9b%be%e5%83%8f%e8%af%86%e5%88%ab","status":"publish","type":"post","link":"https:\/\/yanjingang.com\/blog\/?p=1994","title":{"rendered":"\u5c0f\u732a\u5b66AI\u2014CNN\u56fe\u50cf\u8bc6\u522b\u4e4b\u624b\u5199\u6570\u5b57"},"content":{"rendered":"<p>\u524d\u6bb5\u65f6\u95f4\u5fd9\u4e86\u597d\u4e00\u9635\uff0c\u7ec8\u4e8e\u6709\u65f6\u95f4\u7ee7\u7eed\u5b66\u4e60\u4e86\uff0c\u4eca\u5929\u5f00\u59cb\u901a\u8fc7paddlepaddle\u7684\u624b\u5199\u6570\u5b57\u8bc6\u522b\u770b\u4e00\u4e0b\u7b80\u5355\u7684cnn\u56fe\u50cf\u8bc6\u522b\u6a21\u578b\u662f\u600e\u4e48\u8bad\u7ec3\u51fa\u6765\u7684\u3002<\/p>\n<h1><strong>\u6982\u8ff0<\/strong><\/h1>\n<p>\u624b\u5199\u8bc6\u522b\u5c5e\u4e8e\u5178\u578b\u7684\u56fe\u50cf\u5206\u7c7b\u95ee\u9898\uff0c\u6bd4\u8f83\u7b80\u5355\uff0c\u793a\u4f8b\u4f7f\u7528MNIST\u6570\u636e\u96c6\uff0c\u5b83\u5305\u542b7w\u4e2a\u5982\u4e0b\u56fe\u6240\u793a\u7684\u624b\u5199\u6570\u5b57\u56fe\u7247\u548c\u5bf9\u5e94\u7684\u4eba\u5de5\u6807\u6ce8\u6570\u503c\u3002\u56fe\u7247\u662f28&#215;28\u7684\u50cf\u7d20\u77e9\u9635\uff0c\u6807\u7b7e\u5219\u5bf9\u5e94\u77400~9\u768410\u4e2a\u6570\u5b57\u3002\u6bcf\u5f20\u56fe\u7247\u90fd\u7ecf\u8fc7\u4e86\u5927\u5c0f\u5f52\u4e00\u5316\u548c\u5c45\u4e2d\u5904\u7406\u3002<\/p>\n<p><a href=\"https:\/\/yanjingang.com\/blog\/?attachment_id=1995\" rel=\"attachment wp-att-1995\"><img loading=\"lazy\" class=\"alignnone size-medium wp-image-1995 aligncenter\" src=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/mnist_example_image-300x41.png\" alt=\"\" width=\"300\" height=\"41\" srcset=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/mnist_example_image-300x41.png 300w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/mnist_example_image-768x104.png 768w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/mnist_example_image.png 800w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: center;\">MNIST\u56fe\u7247\u793a\u4f8b<\/p>\n<p><a href=\"https:\/\/yanjingang.com\/blog\/?attachment_id=2003\" rel=\"attachment wp-att-2003\"><img loading=\"lazy\" class=\"size-medium wp-image-2003 aligncenter\" src=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/mnist-300x174.png\" alt=\"\" width=\"300\" height=\"174\" srcset=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/mnist-300x174.png 300w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/mnist.png 767w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: center;\">MNIST\u6570\u636e\u96c6\u683c\u5f0f\u8bf4\u660e<\/p>\n<p>\u6807\u7b7e\u96c6\u524d8\u4e2a\u5b57\u8282\u662fmagic\u548c\u6570\u76ee\uff0c\u540e\u9762\u6bcf\u4e2a\u5b57\u8282\u4ee3\u8868\u6570\u5b570-9\u7684\u6807\u7b7e\uff1b<\/p>\n<p>\u56fe\u50cf\u96c6\u524d16\u5b57\u8282\u662f\u4e00\u4e9b\u6570\u636e\u96c6\u4fe1\u606f\uff0c\u5305\u62ecmagic\u3001\u56fe\u50cf\u6570\u76ee\u3001\u884c\u6570\u548c\u5217\u6570\uff0c\u540e\u9762\u6bcf\u4e2a\u5b57\u8282\u4ee3\u8868\u6bcf\u4e2a\u50cf\u7d20\u70b9\uff0c\u8fde\u7eed\u53d6\u51fa28*28\u4e2a\u5b57\u8282\u6309\u987a\u5e8f\u5c31\u53ef\u4ee5\u7ec4\u621028*28\u7684\u56fe\u7247\u3002<\/p>\n<h1>\u6a21\u578b\u4ecb\u7ecd<\/h1>\n<h3>\u5b9a\u4e49\uff1a<\/h3>\n<p><strong> X\u662f\u8f93\u5165<\/strong>\uff1aMNIST\u56fe\u7247\u662f28\u00d728 \u7684\u4e8c\u7ef4\u56fe\u50cf\uff0c\u4e3a\u4e86\u8fdb\u884c\u8ba1\u7b97\uff0c\u6211\u4eec\u5c06\u5176\u8f6c\u5316\u4e3a784\u7ef4\u5411\u91cf\uff0c\u5373X=(x0,x1,\u2026,x783)\u3002<br \/>\n<strong>Y\u662f\u8f93\u51fa<\/strong>\uff1a\u5206\u7c7b\u5668\u7684\u8f93\u51fa\u662f10\u7c7b\u6570\u5b57\uff080-9\uff09\uff0c\u5373Y=(y0,y1,\u2026,y9)\uff0c\u6bcf\u4e00\u7ef4yi\u4ee3\u8868\u56fe\u7247\u5206\u7c7b\u4e3a\u7b2ci\u7c7b\u6570\u5b57\u7684\u6982\u7387\u3002<br \/>\n<strong>L\u662f\u56fe\u7247\u7684\u771f\u5b9e\u6807\u7b7e<\/strong>\uff1aL=(l0,l1,\u2026,l9)\u4e5f\u662f10\u7ef4\uff0c\u4f46\u53ea\u6709\u4e00\u7ef4\u4e3a1\uff0c\u5176\u4ed6\u90fd\u4e3a0\u3002<\/p>\n<h3 id=\"permalink-3-softmax-softmax-regression-\">Softmax\u56de\u5f52(Softmax Regression)<\/h3>\n<p>\u6700\u7b80\u5355\u7684Softmax\u56de\u5f52\u6a21\u578b\u662f\u5148\u5c06\u8f93\u5165\u5c42\u7ecf\u8fc7\u4e00\u4e2a\u5168\u8fde\u63a5\u5c42\u5f97\u5230\u7684\u7279\u5f81\uff0c\u7136\u540e\u76f4\u63a5\u901a\u8fc7softmax \u51fd\u6570\u8fdb\u884c\u591a\u5206\u7c7b[<a href=\"http:\/\/www.paddlepaddle.org\/documentation\/book\/zh\/develop\/02.recognize_digits\/index.cn.html#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE\">9<\/a>]\u3002<\/p>\n<p>\u8f93\u5165\u5c42\u7684\u6570\u636e<span id=\"equation-0\" class=\"markdown-equation\"><span id=\"MathJax-Element-11-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;X&lt;\/mi&gt;&lt;\/math&gt; &lt;p&gt;\"><span id=\"MathJax-Span-91\" class=\"math\"><span id=\"MathJax-Span-92\" class=\"mrow\"><span id=\"MathJax-Span-93\" class=\"mi\">X<\/span><\/span><\/span><\/span><\/span>\u4f20\u5230\u8f93\u51fa\u5c42\uff0c\u5728\u6fc0\u6d3b\u64cd\u4f5c\u4e4b\u524d\uff0c\u4f1a\u4e58\u4ee5\u76f8\u5e94\u7684\u6743\u91cd\u00a0<span id=\"equation-11\" class=\"markdown-equation\"><span id=\"MathJax-Element-12-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;W&lt;\/mi&gt;&lt;\/math&gt; &lt;p&gt;\"><span class=\"MJX_Assistive_MathML\" role=\"presentation\">W<\/span><\/span><\/span>\u00a0\uff0c\u5e76\u52a0\u4e0a\u504f\u7f6e\u53d8\u91cf\u00a0<span id=\"equation-12\" class=\"markdown-equation\"><span id=\"MathJax-Element-13-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;b&lt;\/mi&gt;&lt;\/math&gt; &lt;p&gt;\"><span class=\"MJX_Assistive_MathML\" role=\"presentation\">b<\/span><\/span><\/span>\u00a0\u3002<\/p>\n<p>\u5bf9\u4e8e\u6709\u00a0<span id=\"equation-15\" class=\"markdown-equation\"><span id=\"MathJax-Element-16-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;N&lt;\/mi&gt;&lt;\/math&gt; &lt;p&gt;\"><span id=\"MathJax-Span-154\" class=\"math\"><span id=\"MathJax-Span-155\" class=\"mrow\"><span id=\"MathJax-Span-156\" class=\"mi\">N<\/span><\/span><\/span><\/span><\/span>\u4e2a\u7c7b\u522b\u7684\u591a\u5206\u7c7b\u95ee\u9898\uff0c\u6307\u5b9a\u00a0<span id=\"equation-15\" class=\"markdown-equation\"><span id=\"MathJax-Element-17-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;N&lt;\/mi&gt;&lt;\/math&gt; &lt;p&gt;\"><span id=\"MathJax-Span-157\" class=\"math\"><span id=\"MathJax-Span-158\" class=\"mrow\"><span id=\"MathJax-Span-159\" class=\"mi\">N<\/span><\/span><\/span><\/span><\/span>\u00a0\u4e2a\u8f93\u51fa\u8282\u70b9\uff0c<span id=\"equation-15\" class=\"markdown-equation\"><span id=\"MathJax-Element-18-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;N&lt;\/mi&gt;&lt;\/math&gt; &lt;p&gt;\"><span id=\"MathJax-Span-160\" class=\"math\"><span id=\"MathJax-Span-161\" class=\"mrow\"><span id=\"MathJax-Span-162\" class=\"mi\">N<\/span><\/span><\/span><\/span><\/span>\u00a0\u7ef4\u7ed3\u679c\u5411\u91cf\u7ecf\u8fc7softmax\u5c06\u5f52\u4e00\u5316\u4e3a\u00a0<span id=\"equation-15\" class=\"markdown-equation\"><span id=\"MathJax-Element-19-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;N&lt;\/mi&gt;&lt;\/math&gt; &lt;p&gt;\"><span id=\"MathJax-Span-163\" class=\"math\"><span id=\"MathJax-Span-164\" class=\"mrow\"><span id=\"MathJax-Span-165\" class=\"mi\">N<\/span><\/span><\/span><\/span><\/span>\u00a0\u4e2a[0,1]\u8303\u56f4\u5185\u7684\u5b9e\u6570\u503c\uff0c\u5206\u522b\u8868\u793a\u8be5\u6837\u672c\u5c5e\u4e8e\u8fd9\u00a0<span id=\"equation-15\" class=\"markdown-equation\"><span id=\"MathJax-Element-20-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;N&lt;\/mi&gt;&lt;\/math&gt; &lt;p&gt;\"><span class=\"MJX_Assistive_MathML\" role=\"presentation\">N<\/span><\/span><\/span>\u00a0\u4e2a\u7c7b\u522b\u7684\u6982\u7387\u3002\u6b64\u5904\u7684\u00a0<span id=\"equation-6\" class=\"markdown-equation\"><span id=\"MathJax-Element-21-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;msub&gt;&lt;mi&gt;y&lt;\/mi&gt;&lt;mi&gt;i&lt;\/mi&gt;&lt;\/msub&gt;&lt;\/math&gt; &lt;p&gt;\"><span class=\"MJX_Assistive_MathML\" role=\"presentation\">yi<\/span><\/span><\/span>\u00a0\u5373\u5bf9\u5e94\u8be5\u56fe\u7247\u4e3a\u6570\u5b57\u00a0<span id=\"equation-7\" class=\"markdown-equation\"><span id=\"MathJax-Element-22-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;i&lt;\/mi&gt;&lt;\/math&gt; &lt;p&gt;\"><span id=\"MathJax-Span-174\" class=\"math\"><span id=\"MathJax-Span-175\" class=\"mrow\"><span id=\"MathJax-Span-176\" class=\"mi\">i\u00a0<\/span><\/span><\/span><\/span><\/span>\u7684\u9884\u6d4b\u6982\u7387\u3002<\/p>\n<p>\u8be6\u7ec6\u4ecb\u7ecd\u8bf7\u53c2\u8003<a href=\"https:\/\/en.wikipedia.org\/wiki\/Activation_function\">\u7ef4\u57fa\u767e\u79d1\u6fc0\u6d3b\u51fd\u6570<\/a>\u3002<\/p>\n<p>\u4e0b\u56fe\u4e3asoftmax\u56de\u5f52\u7684\u7f51\u7edc\u56fe\uff0c\u56fe\u4e2d\u6743\u91cd\u7528\u84dd\u7ebf\u8868\u793a\u3001\u504f\u7f6e\u7528\u7ea2\u7ebf\u8868\u793a\u3001+1\u4ee3\u8868\u504f\u7f6e\u53c2\u6570\u7684\u7cfb\u6570\u4e3a1\u3002<\/p>\n<p><a href=\"https:\/\/yanjingang.com\/blog\/?attachment_id=1996\" rel=\"attachment wp-att-1996\"><img loading=\"lazy\" class=\"aligncenter wp-image-1996 size-large\" src=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/softmax_regression-956x1024.png\" alt=\"\" width=\"660\" height=\"707\" srcset=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/softmax_regression-956x1024.png 956w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/softmax_regression-280x300.png 280w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/softmax_regression-768x823.png 768w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><\/p>\n<p align=\"center\">softmax\u56de\u5f52\u7f51\u7edc\u7ed3\u6784\u56fe<\/p>\n<h3 id=\"permalink-4--multilayer-perceptron-mlp-\">\u591a\u5c42\u611f\u77e5\u5668(Multilayer Perceptron, MLP)<\/h3>\n<p>Softmax\u56de\u5f52\u6a21\u578b\u91c7\u7528\u4e86\u6700\u7b80\u5355\u7684\u4e24\u5c42\u795e\u7ecf\u7f51\u7edc\uff0c\u5373\u53ea\u6709\u8f93\u5165\u5c42\u548c\u8f93\u51fa\u5c42\uff0c\u56e0\u6b64\u5176\u62df\u5408\u80fd\u529b\u6709\u9650\u3002\u4e3a\u4e86\u8fbe\u5230\u66f4\u597d\u7684\u8bc6\u522b\u6548\u679c\uff0c\u6211\u4eec\u8003\u8651\u5728\u8f93\u5165\u5c42\u548c\u8f93\u51fa\u5c42\u4e2d\u95f4\u52a0\u4e0a\u82e5\u5e72\u4e2a\u9690\u85cf\u5c42[<a href=\"http:\/\/www.paddlepaddle.org\/documentation\/book\/zh\/develop\/02.recognize_digits\/index.cn.html#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE\">10<\/a>]\u3002<\/p>\n<p>\u7ecf\u8fc7\u7b2c\u4e00\u4e2a\u9690\u85cf\u5c42\uff0c\u53ef\u4ee5\u5f97\u5230\u00a0<span id=\"equation-23\" class=\"markdown-equation\"><span id=\"MathJax-Element-24-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;msub&gt;&lt;mi&gt;H&lt;\/mi&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;\/msub&gt;&lt;mo&gt;=&lt;\/mo&gt;&lt;mi&gt;&amp;#x03D5;&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;\/mo&gt;&lt;msub&gt;&lt;mi&gt;W&lt;\/mi&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;\/msub&gt;&lt;mi&gt;X&lt;\/mi&gt;&lt;mo&gt;+&lt;\/mo&gt;&lt;msub&gt;&lt;mi&gt;b&lt;\/mi&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;\/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;\/mo&gt;&lt;\/math&gt; &lt;p&gt;\"><span id=\"MathJax-Span-225\" class=\"math\"><span id=\"MathJax-Span-226\" class=\"mrow\"><span id=\"MathJax-Span-227\" class=\"msubsup\"><span id=\"MathJax-Span-228\" class=\"mi\">H<\/span><span id=\"MathJax-Span-229\" class=\"mn\">1<\/span><\/span><span id=\"MathJax-Span-230\" class=\"mo\">=<\/span><span id=\"MathJax-Span-231\" class=\"mi\">\u03d5<\/span><span id=\"MathJax-Span-232\" class=\"mo\">(<\/span><span id=\"MathJax-Span-233\" class=\"msubsup\"><span id=\"MathJax-Span-234\" class=\"mi\">W<\/span><span id=\"MathJax-Span-235\" class=\"mn\">1<\/span><\/span><span id=\"MathJax-Span-236\" class=\"mi\">X<\/span><span id=\"MathJax-Span-237\" class=\"mo\">+<\/span><span id=\"MathJax-Span-238\" class=\"msubsup\"><span id=\"MathJax-Span-239\" class=\"mi\">b<\/span><span id=\"MathJax-Span-240\" class=\"mn\">1<\/span><\/span><span id=\"MathJax-Span-241\" class=\"mo\">)<\/span><\/span><\/span><\/span><\/span>\uff0c\u5176\u4e2d<span id=\"equation-24\" class=\"markdown-equation\"><span id=\"MathJax-Element-25-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;&amp;#x03D5;&lt;\/mi&gt;&lt;\/math&gt; &lt;p&gt;\"><span id=\"MathJax-Span-242\" class=\"math\"><span id=\"MathJax-Span-243\" class=\"mrow\"><span id=\"MathJax-Span-244\" class=\"mi\">\u03d5<\/span><\/span><\/span><\/span><\/span>\u4ee3\u8868\u6fc0\u6d3b\u51fd\u6570\uff0c\u5e38\u89c1\u7684\u6709sigmoid\u3001tanh\u6216ReLU\u7b49\u51fd\u6570\u3002<\/p>\n<p>\u7ecf\u8fc7\u7b2c\u4e8c\u4e2a\u9690\u85cf\u5c42\uff0c\u53ef\u4ee5\u5f97\u5230\u00a0<span id=\"equation-25\" class=\"markdown-equation\"><span id=\"MathJax-Element-26-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;msub&gt;&lt;mi&gt;H&lt;\/mi&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/msub&gt;&lt;mo&gt;=&lt;\/mo&gt;&lt;mi&gt;&amp;#x03D5;&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;\/mo&gt;&lt;msub&gt;&lt;mi&gt;W&lt;\/mi&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/msub&gt;&lt;msub&gt;&lt;mi&gt;H&lt;\/mi&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;\/msub&gt;&lt;mo&gt;+&lt;\/mo&gt;&lt;msub&gt;&lt;mi&gt;b&lt;\/mi&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;\/mo&gt;&lt;\/math&gt; &lt;p&gt;\"><span id=\"MathJax-Span-245\" class=\"math\"><span id=\"MathJax-Span-246\" class=\"mrow\"><span id=\"MathJax-Span-247\" class=\"msubsup\"><span id=\"MathJax-Span-248\" class=\"mi\">H<\/span><span id=\"MathJax-Span-249\" class=\"mn\">2<\/span><\/span><span id=\"MathJax-Span-250\" class=\"mo\">=<\/span><span id=\"MathJax-Span-251\" class=\"mi\">\u03d5<\/span><span id=\"MathJax-Span-252\" class=\"mo\">(<\/span><span id=\"MathJax-Span-253\" class=\"msubsup\"><span id=\"MathJax-Span-254\" class=\"mi\">W<\/span><span id=\"MathJax-Span-255\" class=\"mn\">2<\/span><\/span><span id=\"MathJax-Span-256\" class=\"msubsup\"><span id=\"MathJax-Span-257\" class=\"mi\">H<\/span><span id=\"MathJax-Span-258\" class=\"mn\">1<\/span><\/span><span id=\"MathJax-Span-259\" class=\"mo\">+<\/span><span id=\"MathJax-Span-260\" class=\"msubsup\"><span id=\"MathJax-Span-261\" class=\"mi\">b<\/span><span id=\"MathJax-Span-262\" class=\"mn\">2<\/span><\/span><span id=\"MathJax-Span-263\" class=\"mo\">)<\/span><\/span><\/span><\/span><\/span>\u3002<\/p>\n<p>\u6700\u540e\uff0c\u518d\u7ecf\u8fc7\u8f93\u51fa\u5c42\uff0c\u5f97\u5230\u7684<span id=\"equation-26\" class=\"markdown-equation\"><span id=\"MathJax-Element-27-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;Y&lt;\/mi&gt;&lt;mo&gt;=&lt;\/mo&gt;&lt;mtext&gt;softmax&lt;\/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;\/mo&gt;&lt;msub&gt;&lt;mi&gt;W&lt;\/mi&gt;&lt;mn&gt;3&lt;\/mn&gt;&lt;\/msub&gt;&lt;msub&gt;&lt;mi&gt;H&lt;\/mi&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/msub&gt;&lt;mo&gt;+&lt;\/mo&gt;&lt;msub&gt;&lt;mi&gt;b&lt;\/mi&gt;&lt;mn&gt;3&lt;\/mn&gt;&lt;\/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;\/mo&gt;&lt;\/math&gt; &lt;p&gt;\"><span id=\"MathJax-Span-264\" class=\"math\"><span id=\"MathJax-Span-265\" class=\"mrow\"><span id=\"MathJax-Span-266\" class=\"mi\">Y<\/span><span id=\"MathJax-Span-267\" class=\"mo\">=<\/span><span id=\"MathJax-Span-268\" class=\"mtext\">softmax<\/span><span id=\"MathJax-Span-269\" class=\"mo\">(<\/span><span id=\"MathJax-Span-270\" class=\"msubsup\"><span id=\"MathJax-Span-271\" class=\"mi\">W<\/span><span id=\"MathJax-Span-272\" class=\"mn\">3<\/span><\/span><span id=\"MathJax-Span-273\" class=\"msubsup\"><span id=\"MathJax-Span-274\" class=\"mi\">H<\/span><span id=\"MathJax-Span-275\" class=\"mn\">2<\/span><\/span><span id=\"MathJax-Span-276\" class=\"mo\">+<\/span><span id=\"MathJax-Span-277\" class=\"msubsup\"><span id=\"MathJax-Span-278\" class=\"mi\">b<\/span><span id=\"MathJax-Span-279\" class=\"mn\">3<\/span><\/span><span id=\"MathJax-Span-280\" class=\"mo\">)<\/span><\/span><\/span><\/span><\/span>\uff0c\u5373\u4e3a\u6700\u540e\u7684\u5206\u7c7b\u7ed3\u679c\u5411\u91cf\u3002<\/p>\n<p>\u4e0b\u56fe\u4e3a\u591a\u5c42\u611f\u77e5\u5668\u7684\u7f51\u7edc\u7ed3\u6784\u56fe\uff0c\u56fe\u4e2d\u6743\u91cd\u7528\u84dd\u7ebf\u8868\u793a\u3001\u504f\u7f6e\u7528\u7ea2\u7ebf\u8868\u793a\u3001+1\u4ee3\u8868\u504f\u7f6e\u53c2\u6570\u7684\u7cfb\u6570\u4e3a1\u3002<\/p>\n<p><a href=\"https:\/\/yanjingang.com\/blog\/?attachment_id=1997\" rel=\"attachment wp-att-1997\"><img loading=\"lazy\" class=\"wp-image-1997 size-large aligncenter\" src=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/mlp-1024x788.png\" alt=\"\" width=\"660\" height=\"508\" srcset=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/mlp-1024x788.png 1024w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/mlp-300x231.png 300w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/mlp-768x591.png 768w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/mlp.png 1274w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><\/p>\n<p align=\"center\">\u591a\u5c42\u611f\u77e5\u5668\u7f51\u7edc\u7ed3\u6784\u56fe<\/p>\n<h3 id=\"permalink-5--convolutional-neural-network-cnn-\">\u5377\u79ef\u795e\u7ecf\u7f51\u7edc(Convolutional Neural Network, CNN)<\/h3>\n<p>\u5728\u591a\u5c42\u611f\u77e5\u5668\u6a21\u578b\u4e2d\uff0c\u5c06\u56fe\u50cf\u5c55\u5f00\u6210\u4e00\u7ef4\u5411\u91cf\u8f93\u5165\u5230\u7f51\u7edc\u4e2d\uff0c\u5ffd\u7565\u4e86\u56fe\u50cf\u7684\u4f4d\u7f6e\u548c\u7ed3\u6784\u4fe1\u606f\uff0c\u800c\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u80fd\u591f\u66f4\u597d\u7684\u5229\u7528\u56fe\u50cf\u7684\u7ed3\u6784\u4fe1\u606f\u3002<a href=\"http:\/\/yann.lecun.com\/exdb\/lenet\/\">LeNet-5<\/a>\u662f\u4e00\u4e2a\u8f83\u7b80\u5355\u7684\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u3002\u56fe4\u663e\u793a\u4e86\u5176\u7ed3\u6784\uff1a\u8f93\u5165\u7684\u4e8c\u7ef4\u56fe\u50cf\uff0c\u5148\u7ecf\u8fc7\u4e24\u6b21\u5377\u79ef\u5c42\u5230\u6c60\u5316\u5c42\uff0c\u518d\u7ecf\u8fc7\u5168\u8fde\u63a5\u5c42\uff0c\u6700\u540e\u4f7f\u7528softmax\u5206\u7c7b\u4f5c\u4e3a\u8f93\u51fa\u5c42\u3002\u4e0b\u9762\u6211\u4eec\u4e3b\u8981\u4ecb\u7ecd\u5377\u79ef\u5c42\u548c\u6c60\u5316\u5c42\u3002<\/p>\n<p><a href=\"https:\/\/yanjingang.com\/blog\/?attachment_id=1998\" rel=\"attachment wp-att-1998\"><img loading=\"lazy\" class=\"alignnone wp-image-1998 size-large\" src=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/cnn-1024x328.png\" alt=\"\" width=\"660\" height=\"211\" srcset=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/cnn-1024x328.png 1024w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/cnn-300x96.png 300w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/cnn-768x246.png 768w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/cnn.png 1207w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><\/p>\n<p style=\"text-align: center;\">LeNet-5\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7ed3\u6784<\/p>\n<h4>\u5377\u79ef\u5c42<\/h4>\n<p>\u5377\u79ef\u5c42\u662f\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7684\u6838\u5fc3\u57fa\u77f3\u3002\u5728\u56fe\u50cf\u8bc6\u522b\u91cc\u6211\u4eec\u63d0\u5230\u7684\u5377\u79ef\u662f\u4e8c\u7ef4\u5377\u79ef\uff0c\u5373\u79bb\u6563\u4e8c\u7ef4\u6ee4\u6ce2\u5668\uff08\u4e5f\u79f0\u4f5c\u5377\u79ef\u6838\uff09\u4e0e\u4e8c\u7ef4\u56fe\u50cf\u505a\u5377\u79ef\u64cd\u4f5c\uff0c\u7b80\u5355\u7684\u8bb2\u662f\u4e8c\u7ef4\u6ee4\u6ce2\u5668\u6ed1\u52a8\u5230\u4e8c\u7ef4\u56fe\u50cf\u4e0a\u6240\u6709\u4f4d\u7f6e\uff0c\u5e76\u5728\u6bcf\u4e2a\u4f4d\u7f6e\u4e0a\u4e0e\u8be5\u50cf\u7d20\u70b9\u53ca\u5176\u9886\u57df\u50cf\u7d20\u70b9\u505a\u5185\u79ef\u3002\u5377\u79ef\u64cd\u4f5c\u88ab\u5e7f\u6cdb\u5e94\u7528\u4e0e\u56fe\u50cf\u5904\u7406\u9886\u57df\uff0c\u4e0d\u540c\u5377\u79ef\u6838\u53ef\u4ee5\u63d0\u53d6\u4e0d\u540c\u7684\u7279\u5f81\uff0c\u4f8b\u5982\u8fb9\u6cbf\u3001\u7ebf\u6027\u3001\u89d2\u7b49\u7279\u5f81\u3002\u5728\u6df1\u5c42\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u4e2d\uff0c\u901a\u8fc7\u5377\u79ef\u64cd\u4f5c\u53ef\u4ee5\u63d0\u53d6\u51fa\u56fe\u50cf\u4f4e\u7ea7\u5230\u590d\u6742\u7684\u7279\u5f81\u3002<\/p>\n<p><a href=\"https:\/\/yanjingang.com\/blog\/?attachment_id=1999\" rel=\"attachment wp-att-1999\"><img loading=\"lazy\" class=\"alignnone wp-image-1999 size-large aligncenter\" src=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/conv_layer-1024x883.png\" alt=\"\" width=\"660\" height=\"569\" srcset=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/conv_layer-1024x883.png 1024w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/conv_layer-300x259.png 300w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/conv_layer-768x662.png 768w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/conv_layer.png 1509w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><\/p>\n<p style=\"text-align: center;\">\u5377\u79ef\u5c42<\/p>\n<p><a href=\"https:\/\/yanjingang.com\/blog\/?attachment_id=2030\" rel=\"attachment wp-att-2030\"><img loading=\"lazy\" class=\"alignnone size-medium wp-image-2030 aligncenter\" src=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/cnn-conv-300x219.gif\" alt=\"\" width=\"300\" height=\"219\" \/><\/a><\/p>\n<p style=\"text-align: center;\">\u5377\u79ef\u8fc7\u7a0b\u52a8\u753b<\/p>\n<p>\u4e0a\u56fe\u662f\u4e00\u4e2a\u5377\u79ef\u8ba1\u7b97\u8fc7\u7a0b\u7684\u793a\u4f8b\u56fe\uff0c\u8f93\u5165\u56fe\u50cf\u5927\u5c0f\u4e3aH=5,W=5,D=3\uff0c\u53735\u00d75\u5927\u5c0f\u76843\u901a\u9053\uff08RGB\uff0c\u4e5f\u79f0\u4f5c\u6df1\u5ea6\uff09\u5f69\u8272\u56fe\u50cf\u3002\u8fd9\u4e2a\u793a\u4f8b\u56fe\u4e2d\u5305\u542b\u4e24\uff08\u7528K\u8868\u793a\uff09\u7ec4\u5377\u79ef\u6838\uff0c\u5373\u56fe\u4e2d\u6ee4\u6ce2\u5668W0\u548cW1\u3002\u5728\u5377\u79ef\u8ba1\u7b97\u4e2d\uff0c\u901a\u5e38\u5bf9\u4e0d\u540c\u7684\u8f93\u5165\u901a\u9053\u91c7\u7528\u4e0d\u540c\u7684\u5377\u79ef\u6838\uff0c\u5982\u56fe\u793a\u4f8b\u4e2d\u6bcf\u7ec4\u5377\u79ef\u6838\u5305\u542b\uff08D=3\uff09\u4e2a3\u00d73\uff08\u7528F\u00d7F\u8868\u793a\uff09\u5927\u5c0f\u7684\u5377\u79ef\u6838\u3002\u53e6\u5916\uff0c\u8fd9\u4e2a\u793a\u4f8b\u4e2d\u5377\u79ef\u6838\u5728\u56fe\u50cf\u7684\u6c34\u5e73\u65b9\u5411\uff08W\u65b9\u5411\uff09\u548c\u5782\u76f4\u65b9\u5411\uff08H\u65b9\u5411\uff09\u7684\u6ed1\u52a8\u6b65\u957f\u4e3a2\uff08\u7528S\u8868\u793a\uff09\uff1b\u5bf9\u8f93\u5165\u56fe\u50cf\u5468\u56f4\u5404\u586b\u51451\uff08\u7528P\u8868\u793a\uff09\u4e2a0\uff0c\u5373\u56fe\u4e2d\u8f93\u5165\u5c42\u539f\u59cb\u6570\u636e\u4e3a\u84dd\u8272\u90e8\u5206\uff0c\u7070\u8272\u90e8\u5206\u662f\u8fdb\u884c\u4e86\u5927\u5c0f\u4e3a1\u7684\u6269\u5c55\uff0c\u75280\u6765\u8fdb\u884c\u6269\u5c55\u3002\u7ecf\u8fc7\u5377\u79ef\u64cd\u4f5c\u5f97\u5230\u8f93\u51fa\u4e3a3\u00d73\u00d72\uff08\u7528Ho\u00d7Wo\u00d7K\u8868\u793a\uff09\u5927\u5c0f\u7684\u7279\u5f81\u56fe\uff0c\u53733\u00d73\u5927\u5c0f\u76842\u901a\u9053\u7279\u5f81\u56fe\uff0c\u5176\u4e2dHo\u8ba1\u7b97\u516c\u5f0f\u4e3a\uff1aHo=(H\u2212F+2\u00d7P)\/S+1\uff0cWo\u540c\u7406\u3002 \u800c\u8f93\u51fa\u7279\u5f81\u56fe\u4e2d\u7684\u6bcf\u4e2a\u50cf\u7d20\uff0c\u662f\u6bcf\u7ec4\u6ee4\u6ce2\u5668\u4e0e\u8f93\u5165\u56fe\u50cf\u6bcf\u4e2a\u7279\u5f81\u56fe\u7684\u5185\u79ef\u518d\u6c42\u548c\uff0c\u518d\u52a0\u4e0a\u504f\u7f6ebo\uff0c\u504f\u7f6e\u901a\u5e38\u5bf9\u4e8e\u6bcf\u4e2a\u8f93\u51fa\u7279\u5f81\u56fe\u662f\u5171\u4eab\u7684\u3002\u8f93\u51fa\u7279\u5f81\u56feo[:,:,0]\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u22122\u8ba1\u7b97\u5982\u4e0a\u56fe\u53f3\u4e0b\u89d2\u516c\u5f0f\u6240\u793a\u3002<\/p>\n<p>\u5728\u5377\u79ef\u64cd\u4f5c\u4e2d\u5377\u79ef\u6838\u662f\u53ef\u5b66\u4e60\u7684\u53c2\u6570\uff0c\u7ecf\u8fc7\u4e0a\u9762\u793a\u4f8b\u4ecb\u7ecd\uff0c\u6bcf\u5c42\u5377\u79ef\u7684\u53c2\u6570\u5927\u5c0f\u4e3a<span id=\"equation-48\" class=\"markdown-equation\"><span id=\"MathJax-Element-49-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;D&lt;\/mi&gt;&lt;mo&gt;&amp;#x00D7;&lt;\/mo&gt;&lt;mi&gt;F&lt;\/mi&gt;&lt;mo&gt;&amp;#x00D7;&lt;\/mo&gt;&lt;mi&gt;F&lt;\/mi&gt;&lt;mo&gt;&amp;#x00D7;&lt;\/mo&gt;&lt;mi&gt;K&lt;\/mi&gt;&lt;\/math&gt; &lt;p&gt;\"><span id=\"MathJax-Span-419\" class=\"math\"><span id=\"MathJax-Span-420\" class=\"mrow\"><span id=\"MathJax-Span-421\" class=\"mi\">D<\/span><span id=\"MathJax-Span-422\" class=\"mo\">\u00d7<\/span><span id=\"MathJax-Span-423\" class=\"mi\">F<\/span><span id=\"MathJax-Span-424\" class=\"mo\">\u00d7<\/span><span id=\"MathJax-Span-425\" class=\"mi\">F<\/span><span id=\"MathJax-Span-426\" class=\"mo\">\u00d7<\/span><span id=\"MathJax-Span-427\" class=\"mi\">K<\/span><\/span><\/span><\/span><\/span>\u3002\u5728\u591a\u5c42\u611f\u77e5\u5668\u6a21\u578b\u4e2d\uff0c\u795e\u7ecf\u5143\u901a\u5e38\u662f\u5168\u90e8\u8fde\u63a5\uff0c\u53c2\u6570\u8f83\u591a\u3002\u800c\u5377\u79ef\u5c42\u7684\u53c2\u6570\u8f83\u5c11\uff0c\u8fd9\u4e5f\u662f\u7531\u5377\u79ef\u5c42\u7684\u4e3b\u8981\u7279\u6027\u5373\u5c40\u90e8\u8fde\u63a5\u548c\u5171\u4eab\u6743\u91cd\u6240\u51b3\u5b9a\u3002<\/p>\n<p>\u5c40\u90e8\u8fde\u63a5\uff1a\u6bcf\u4e2a\u795e\u7ecf\u5143\u4ec5\u4e0e\u8f93\u5165\u795e\u7ecf\u5143\u7684\u4e00\u5757\u533a\u57df\u8fde\u63a5\uff0c\u8fd9\u5757\u5c40\u90e8\u533a\u57df\u79f0\u4f5c\u611f\u53d7\u91ce\uff08receptive field\uff09\u3002\u5728\u56fe\u50cf\u5377\u79ef\u64cd\u4f5c\u4e2d\uff0c\u5373\u795e\u7ecf\u5143\u5728\u7a7a\u95f4\u7ef4\u5ea6\uff08spatial dimension\uff0c\u5373\u4e0a\u56fe\u793a\u4f8bH\u548cW\u6240\u5728\u7684\u5e73\u9762\uff09\u662f\u5c40\u90e8\u8fde\u63a5\uff0c\u4f46\u5728\u6df1\u5ea6\u4e0a\u662f\u5168\u90e8\u8fde\u63a5\u3002\u5bf9\u4e8e\u4e8c\u7ef4\u56fe\u50cf\u672c\u8eab\u800c\u8a00\uff0c\u4e5f\u662f\u5c40\u90e8\u50cf\u7d20\u5173\u8054\u8f83\u5f3a\u3002\u8fd9\u79cd\u5c40\u90e8\u8fde\u63a5\u4fdd\u8bc1\u4e86\u5b66\u4e60\u540e\u7684\u8fc7\u6ee4\u5668\u80fd\u591f\u5bf9\u4e8e\u5c40\u90e8\u7684\u8f93\u5165\u7279\u5f81\u6709\u6700\u5f3a\u7684\u54cd\u5e94\u3002\u5c40\u90e8\u8fde\u63a5\u7684\u601d\u60f3\uff0c\u4e5f\u662f\u53d7\u542f\u53d1\u4e8e\u751f\u7269\u5b66\u91cc\u9762\u7684\u89c6\u89c9\u7cfb\u7edf\u7ed3\u6784\uff0c\u89c6\u89c9\u76ae\u5c42\u7684\u795e\u7ecf\u5143\u5c31\u662f\u5c40\u90e8\u63a5\u53d7\u4fe1\u606f\u7684\u3002<\/p>\n<p>\u6743\u91cd\u5171\u4eab\uff1a\u8ba1\u7b97\u540c\u4e00\u4e2a\u6df1\u5ea6\u5207\u7247\u7684\u795e\u7ecf\u5143\u65f6\u91c7\u7528\u7684\u6ee4\u6ce2\u5668\u662f\u5171\u4eab\u7684\u3002\u4f8b\u5982\u56fe4\u4e2d\u8ba1\u7b97<span id=\"equation-46\" class=\"markdown-equation\"><span id=\"MathJax-Element-50-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;o&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;[&lt;\/mo&gt;&lt;mo&gt;:&lt;\/mo&gt;&lt;mo&gt;,&lt;\/mo&gt;&lt;mo&gt;:&lt;\/mo&gt;&lt;mo&gt;,&lt;\/mo&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;]&lt;\/mo&gt;&lt;\/math&gt; &lt;p&gt;\"><span id=\"MathJax-Span-428\" class=\"math\"><span id=\"MathJax-Span-429\" class=\"mrow\"><span id=\"MathJax-Span-430\" class=\"mi\">o<\/span><span id=\"MathJax-Span-431\" class=\"mo\">[<\/span><span id=\"MathJax-Span-432\" class=\"mo\">:<\/span><span id=\"MathJax-Span-433\" class=\"mo\">,<\/span><span id=\"MathJax-Span-434\" class=\"mo\">:<\/span><span id=\"MathJax-Span-435\" class=\"mo\">,<\/span><span id=\"MathJax-Span-436\" class=\"mn\">0<\/span><span id=\"MathJax-Span-437\" class=\"mo\">]<\/span><\/span><\/span><\/span><\/span>\u7684\u6bcf\u4e2a\u6bcf\u4e2a\u795e\u7ecf\u5143\u7684\u6ee4\u6ce2\u5668\u5747\u76f8\u540c\uff0c\u90fd\u4e3a<span id=\"equation-30\" class=\"markdown-equation\"><span id=\"MathJax-Element-51-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; font-size: 16px; line-height: normal; font-family: inherit; vertical-align: baseline; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;\/p&gt; &lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;msub&gt;&lt;mi&gt;W&lt;\/mi&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;\/msub&gt;&lt;\/math&gt; &lt;p&gt;\"><span id=\"MathJax-Span-438\" class=\"math\"><span id=\"MathJax-Span-439\" class=\"mrow\"><span id=\"MathJax-Span-440\" class=\"msubsup\"><span id=\"MathJax-Span-441\" class=\"mi\">W<\/span><span id=\"MathJax-Span-442\" class=\"mn\">0<\/span><\/span><\/span><\/span><\/span><\/span>\uff0c\u8fd9\u6837\u53ef\u4ee5\u5f88\u5927\u7a0b\u5ea6\u4e0a\u51cf\u5c11\u53c2\u6570\u3002\u5171\u4eab\u6743\u91cd\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u8bb2\u662f\u6709\u610f\u4e49\u7684\uff0c\u4f8b\u5982\u56fe\u7247\u7684\u5e95\u5c42\u8fb9\u7f18\u7279\u5f81\u4e0e\u7279\u5f81\u5728\u56fe\u4e2d\u7684\u5177\u4f53\u4f4d\u7f6e\u65e0\u5173\u3002\u4f46\u662f\u5728\u4e00\u4e9b\u573a\u666f\u4e2d\u662f\u65e0\u610f\u7684\uff0c\u6bd4\u5982\u8f93\u5165\u7684\u56fe\u7247\u662f\u4eba\u8138\uff0c\u773c\u775b\u548c\u5934\u53d1\u4f4d\u4e8e\u4e0d\u540c\u7684\u4f4d\u7f6e\uff0c\u5e0c\u671b\u5728\u4e0d\u540c\u7684\u4f4d\u7f6e\u5b66\u5230\u4e0d\u540c\u7684\u7279\u5f81 (\u53c2\u8003<a href=\"http:\/\/cs231n.github.io\/convolutional-networks\/\">\u65af\u5766\u798f\u5927\u5b66\u516c\u5f00\u8bfe<\/a>)\u3002\u8bf7\u6ce8\u610f\u6743\u91cd\u53ea\u662f\u5bf9\u4e8e\u540c\u4e00\u6df1\u5ea6\u5207\u7247\u7684\u795e\u7ecf\u5143\u662f\u5171\u4eab\u7684\uff0c\u5728\u5377\u79ef\u5c42\uff0c\u901a\u5e38\u91c7\u7528\u591a\u7ec4\u5377\u79ef\u6838\u63d0\u53d6\u4e0d\u540c\u7279\u5f81\uff0c\u5373\u5bf9\u5e94\u4e0d\u540c\u6df1\u5ea6\u5207\u7247\u7684\u7279\u5f81\uff0c\u4e0d\u540c\u6df1\u5ea6\u5207\u7247\u7684\u795e\u7ecf\u5143\u6743\u91cd\u662f\u4e0d\u5171\u4eab\u3002\u53e6\u5916\uff0c\u504f\u91cd\u5bf9\u540c\u4e00\u6df1\u5ea6\u5207\u7247\u7684\u6240\u6709\u795e\u7ecf\u5143\u90fd\u662f\u5171\u4eab\u7684\u3002<\/p>\n<p>\u901a\u8fc7\u4ecb\u7ecd\u5377\u79ef\u8ba1\u7b97\u8fc7\u7a0b\u53ca\u5176\u7279\u6027\uff0c\u53ef\u4ee5\u770b\u51fa\u5377\u79ef\u662f\u7ebf\u6027\u64cd\u4f5c\uff0c\u5e76\u5177\u6709\u5e73\u79fb\u4e0d\u53d8\u6027\uff08shift-invariant\uff09\uff0c\u5e73\u79fb\u4e0d\u53d8\u6027\u5373\u5728\u56fe\u50cf\u6bcf\u4e2a\u4f4d\u7f6e\u6267\u884c\u76f8\u540c\u7684\u64cd\u4f5c\u3002\u5377\u79ef\u5c42\u7684\u5c40\u90e8\u8fde\u63a5\u548c\u6743\u91cd\u5171\u4eab\u4f7f\u5f97\u9700\u8981\u5b66\u4e60\u7684\u53c2\u6570\u5927\u5927\u51cf\u5c0f\uff0c\u8fd9\u6837\u4e5f\u6709\u5229\u4e8e\u8bad\u7ec3\u8f83\u5927\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u3002<\/p>\n<h4>\u6c60\u5316\u5c42<\/h4>\n<p><a href=\"https:\/\/yanjingang.com\/blog\/?attachment_id=2000\" rel=\"attachment wp-att-2000\"><img loading=\"lazy\" class=\"alignnone wp-image-2000 size-medium aligncenter\" src=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/max_pooling-300x174.png\" alt=\"\" width=\"300\" height=\"174\" srcset=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/max_pooling-300x174.png 300w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/max_pooling-768x444.png 768w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/max_pooling.png 1020w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: center;\">\u6c60\u5316\u5c42<\/p>\n<p>\u6c60\u5316\u662f\u975e\u7ebf\u6027\u4e0b\u91c7\u6837\u7684\u4e00\u79cd\u5f62\u5f0f\uff0c\u4e3b\u8981\u4f5c\u7528\u662f\u901a\u8fc7\u51cf\u5c11\u7f51\u7edc\u7684\u53c2\u6570\u6765\u51cf\u5c0f\u8ba1\u7b97\u91cf\uff0c\u5e76\u4e14\u80fd\u591f\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u63a7\u5236\u8fc7\u62df\u5408\u3002\u901a\u5e38\u5728\u5377\u79ef\u5c42\u7684\u540e\u9762\u4f1a\u52a0\u4e0a\u4e00\u4e2a\u6c60\u5316\u5c42\u3002\u6c60\u5316\u5305\u62ec\u6700\u5927\u6c60\u5316\u3001\u5e73\u5747\u6c60\u5316\u7b49\u3002\u5176\u4e2d\u6700\u5927\u6c60\u5316\u662f\u7528\u4e0d\u91cd\u53e0\u7684\u77e9\u5f62\u6846\u5c06\u8f93\u5165\u5c42\u5206\u6210\u4e0d\u540c\u7684\u533a\u57df\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u77e9\u5f62\u6846\u7684\u6570\u53d6\u6700\u5927\u503c\u4f5c\u4e3a\u8f93\u51fa\u5c42\uff0c\u5982\u4e0a\u56fe\u6240\u793a\u3002<\/p>\n<p>\u66f4\u8be6\u7ec6\u7684\u5173\u4e8e\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7684\u5177\u4f53\u77e5\u8bc6\u53ef\u4ee5\u53c2\u8003<a href=\"http:\/\/cs231n.github.io\/convolutional-networks\/\">\u65af\u5766\u798f\u5927\u5b66\u516c\u5f00\u8bfe<\/a>\u548c<a href=\"https:\/\/github.com\/PaddlePaddle\/book\/tree\/develop\/03.image_classification\">\u56fe\u50cf\u5206\u7c7b<\/a>\u6559\u7a0b\u3002<\/p>\n<h1><strong>\u8bad\u7ec3<\/strong><\/h1>\n<p>\u6ce8\uff1a\u672c\u6b21\u5b66\u4e60\u4ee3\u7801\u4f7f\u7528Fluid API\uff0c\u4e00\u79cd\u63a5\u8fd1Pytorch\u548cTensorflow\u7684\u5f00\u53d1\u4e60\u60ef\u3002\u4f7f\u7528\u524d\u9700\u8981\u5148\u5347\u7ea7\u81ea\u5df1\u7684paddlepaddle\u3002<\/p>\n<p>\u4e0b\u8fb9\u662f\u8bad\u7ec3\u8fc7\u7a0b\u7684\u4ee3\u7801\u548c\u81ea\u5df1\u7684\u7406\u89e3\uff0c\u6709\u9519\u8bef\u6b22\u8fce\u6307\u6b63\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">vim train.py\r\n#!\/usr\/bin\/env python\r\n# -*- coding: utf-8 -*-\r\n# \u4f7f\u7528fluid\u5b66\u4e60cnn\u56fe\u50cf\u8bc6\u522b\u624b\u5199\u6570\u5b57\r\nfrom __future__ import print_function\r\nimport os\r\nimport platform\r\nimport subprocess\r\nfrom PIL import Image\r\nimport numpy\r\nimport paddle\r\nimport paddle.fluid as fluid\r\ntry:\r\n    from paddle.fluid.contrib.trainer import *\r\n    from paddle.fluid.contrib.inferencer import *\r\nexcept ImportError:\r\n    print(\r\n        \"In the fluid 1.0, the trainer and inferencer are moving to paddle.fluid.contrib\",\r\n        file=sys.stderr)\r\n    from paddle.fluid.trainer import *\r\n    from paddle.fluid.inferencer import *\r\nimport utils\r\n\r\n\r\ndef main():\r\n    # \u5b9a\u4e49\u8bad\u7ec3\u548c\u6d4b\u8bd5\u6570\u636ebatch reader\r\n    mnist_path = '\/home\/work\/.cache\/paddle\/dataset\/mnist\/'\r\n    train_image   = mnist_path + 'train-images-idx3-ubyte.gz'\r\n    train_label   = mnist_path + 'train-labels-idx1-ubyte.gz'\r\n    test_image    = mnist_path + 't10k-images-idx3-ubyte.gz'\r\n    test_label    = mnist_path + 't10k-labels-idx1-ubyte.gz'\r\n    img_path = '\/home\/work\/paddle\/sample\/recognize_digits\/train\/data\/'\r\n    train_reader = paddle.batch(paddle.reader.shuffle(\r\n\t#paddle.dataset.mnist.train(), \r\n\tutils.mnist_reader_creator(train_image,train_label,buffer_size=100), #\u81ea\u5df1\u8bfb\u53d6mnist\u8bad\u7ec3\u96c6 \r\n\t#utils.image_reader_creator(img_path+'train\/',28,28), #\u81ea\u5df1\u8bfb\u53d6images \r\n\tbuf_size=500),\r\n        batch_size=64)\r\n    test_reader = paddle.batch(\r\n\t#paddle.dataset.mnist.test(),\r\n\tutils.mnist_reader_creator(test_image,test_label,buffer_size=100), #\u81ea\u5df1\u8bfb\u53d6mnist\u6d4b\u8bd5\u96c6 \r\n\t#utils.image_reader_creator(img_path+'test\/',28,28), #\u81ea\u5df1\u8bfb\u53d6images \r\n\tbatch_size=64)\r\n\r\n    # \u662f\u5426\u4f7f\u7528GPU\r\n    use_cuda = False  # set to True if training with GPU\r\n    place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()\r\n\r\n    # \u521b\u5efa\u8bad\u7ec3\u5668(train_func\u635f\u5931\u51fd\u6570; place\u662f\u5426\u4f7f\u7528gpu; optimizer_func\u4f18\u5316\u5668)\r\n    trainer = Trainer(\r\n        train_func=utils.train_program, place=place, optimizer_func=utils.optimizer_program)\r\n\r\n    # \u6a21\u578b\u53c2\u6570\u4fdd\u5b58\u76ee\u5f55\r\n    params_dirname = \"model\/\"\r\n    # \u5b9a\u4e49event_handler\uff0c\u8f93\u51fa\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u7684\u7ed3\u679c\r\n    lists = []\r\n    def event_handler(event):\r\n        if isinstance(event, EndStepEvent):  # \u6bcf\u6b65\u89e6\u53d1\u4e8b\u4ef6\r\n            if event.step % 100 == 0:\r\n                # event.metrics maps with train program return arguments.\r\n                # event.metrics[0] will yeild avg_cost and event.metrics[1] will yeild acc in this example.\r\n                print(\"Pass %d, Batch %d, Cost %f\" % (event.step, event.epoch,\r\n                                                      event.metrics[0]))\r\n        if isinstance(event, EndEpochEvent): # \u6bcf\u6b21\u8fed\u4ee3\u89e6\u53d1\u4e8b\u4ef6\r\n            # test\u7684\u8fd4\u56de\u503c\u5c31\u662ftrain_func\u7684\u8fd4\u56de\u503c\r\n            avg_cost, acc = trainer.test(\r\n                reader=test_reader, feed_order=['img', 'label'])\r\n            print(\"Test with Epoch %d, avg_cost: %s, acc: %s\" %\r\n                  (event.epoch, avg_cost, acc))\r\n            # \u4fdd\u5b58\u6a21\u578b\u53c2\u6570\r\n            trainer.save_params(params_dirname)\r\n            # \u4fdd\u5b58\u8bad\u7ec3\u7ed3\u679c\u635f\u5931\u60c5\u51b5\r\n            lists.append((event.epoch, avg_cost, acc))\r\n\r\n    # \u5f00\u59cb\u8bad\u7ec3\u6a21\u578b\r\n    trainer.train(\r\n        num_epochs=5,\r\n        event_handler=event_handler,\r\n        reader=train_reader,\r\n        feed_order=['img', 'label'])\r\n\r\n    # \u627e\u5230\u8bad\u7ec3\u8bef\u5dee\u6700\u5c0f\u7684\u4e00\u6b21\u7ed3\u679c(\u627e\u5b8c\u6ca1\u7528\uff1ftrainer.save_params()\u81ea\u52a8\u505a\u4e86\u6700\u4f18\u9009\u62e9\uff1f)\r\n    best = sorted(lists, key=lambda list: float(list[1]))[0]\r\n    print('Best pass is %s, testing Avgcost is %s' % (best[0], best[1]))\r\n    print('The classification accuracy is %.2f%%' % (float(best[2]) * 100))\r\n\r\n    # \u52a0\u8f7d\u6d4b\u8bd5\u6570\u636e\r\n    cur_dir = os.path.dirname(os.path.realpath(__file__))\r\n    img = utils.load_image(cur_dir + '\/data\/image\/infer_3.png',28,28)\r\n\r\n    # \u4f7f\u7528\u4fdd\u5b58\u7684\u6a21\u578b\u53c2\u6570+\u6d4b\u8bd5\u56fe\u7247\u8fdb\u884c\u9884\u6d4b\r\n    inferencer = Inferencer(\r\n        # infer_func=utils.softmax_regression, # uncomment for softmax regression\r\n        # infer_func=utils.multilayer_perceptron, # uncomment for MLP\r\n        infer_func=utils.convolutional_neural_network,  # uncomment for LeNet5\r\n        param_path=params_dirname,\r\n        place=place)\r\n    results = inferencer.infer({'img': img})\r\n    lab = numpy.argsort(results)  # probs and lab are the results of one batch data\r\n    print(\"Inference result of image\/infer_3.png is: %d\" % lab[0][0][-1])\r\n\r\n\r\nif __name__ == '__main__':\r\n    main()<\/code><\/pre>\n<pre class=\"pure-highlightjs\"><code class=\"\">vim utils.py\r\n#!\/usr\/bin\/env python\r\n# -*- coding: utf-8 -*-\r\nfrom __future__ import print_function\r\nimport os\r\nimport platform\r\nimport subprocess\r\nfrom PIL import Image\r\nfrom PIL import ImageOps\r\nimport cv2\r\nimport numpy\r\nimport paddle\r\nimport paddle.fluid as fluid\r\ntry:\r\n    from paddle.fluid.contrib.trainer import *\r\n    from paddle.fluid.contrib.inferencer import *\r\nexcept ImportError:\r\n    print(\r\n        \"In the fluid 1.0, the trainer and inferencer are moving to paddle.fluid.contrib\",\r\n        file=sys.stderr)\r\n    from paddle.fluid.trainer import *\r\n    from paddle.fluid.inferencer import *\r\n\r\n\r\n# \u5b9a\u4e49\u8f93\u5165\u5c42\u53ca\u7f51\u7edc\u7ed3\u6784: \u5355\u5c42\u5168\u8fde\u63a5\u5c42+softmax\r\ndef softmax_regression():\r\n    img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')\r\n    predict = fluid.layers.fc(input=img, size=10, act='softmax')\r\n    return predict\r\n\r\n# \u5b9a\u4e49\u8f93\u5165\u5c42\u53ca\u7f51\u7edc\u7ed3\u6784: \u591a\u5c42\u611f\u77e5\u5668+relu*2+softmax(Multilayer Perceptron, MLP) \r\ndef multilayer_perceptron():\r\n    img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')\r\n    # first fully-connected layer, using ReLu as its activation function\r\n    hidden = fluid.layers.fc(input=img, size=128, act='relu')\r\n    # second fully-connected layer, using ReLu as its activation function\r\n    hidden = fluid.layers.fc(input=hidden, size=64, act='relu')\r\n    # The thrid fully-connected layer, note that the hidden size should be 10,\r\n    # which is the number of unique digits\r\n    prediction = fluid.layers.fc(input=hidden, size=10, act='softmax')\r\n    return prediction\r\n\r\n# \u5b9a\u4e49\u8f93\u5165\u5c42\u53ca\u7f51\u7edc\u7ed3\u6784: \u5377\u79ef\u795e\u7ecf\u7f51\u7edc(Convolutional Neural Network, CNN)\r\ndef convolutional_neural_network():\r\n    img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')\r\n    # first conv pool\r\n    conv_pool_1 = fluid.nets.simple_img_conv_pool(\r\n        input=img,\r\n        filter_size=5,\r\n        num_filters=20,\r\n        pool_size=2,\r\n        pool_stride=2,\r\n        act=\"relu\")\r\n    conv_pool_1 = fluid.layers.batch_norm(conv_pool_1)\r\n    # second conv pool\r\n    conv_pool_2 = fluid.nets.simple_img_conv_pool(\r\n        input=conv_pool_1,\r\n        filter_size=5,\r\n        num_filters=50,\r\n        pool_size=2,\r\n        pool_stride=2,\r\n        act=\"relu\")\r\n    # output layer with softmax activation function. size = 10 since there are only 10 possible digits.\r\n    prediction = fluid.layers.fc(input=conv_pool_2, size=10, act='softmax')\r\n    return prediction\r\n\r\n\r\n# \u5b9a\u4e49\u8bad\u7ec3\u635f\u5931\u51fd\u6570 \r\ndef train_program():\r\n    # \u5b9a\u4e49\u8bad\u7ec3\u7528label\u6570\u636e\u5c42\r\n    label = fluid.layers.data(name='label', shape=[1], dtype='int64')\r\n\r\n    # \u5b9a\u4e49\u7f51\u7edc\u7ed3\u6784\r\n    # predict = softmax_regression() # uncomment for Softmax\r\n    # predict = multilayer_perceptron() # uncomment for MLP\r\n    predict = convolutional_neural_network()  # uncomment for LeNet5\r\n\r\n    # \u5b9a\u4e49cost\u635f\u5931\u51fd\u6570\r\n    cost = fluid.layers.cross_entropy(input=predict, label=label)\r\n    avg_cost = fluid.layers.mean(cost)\r\n    # acc\u7528\u4e8e\u5728\u8fed\u4ee3\u8fc7\u7a0b\u4e2dprint \r\n    acc = fluid.layers.accuracy(input=predict, label=label)\r\n    return [avg_cost, acc]\r\n\r\n# \u5b9a\u4e49\u4f18\u5316\u5668\r\ndef optimizer_program():\r\n    return fluid.optimizer.Adam(learning_rate=0.001)\r\n\r\n# \u81ea\u5b9a\u4e49mnist\u6570\u636e\u96c6reader\r\ndef mnist_reader_creator(image_filename,label_filename,buffer_size):\r\n    def reader():\r\n        #\u8c03\u7528\u547d\u4ee4\u8bfb\u53d6\u6587\u4ef6\uff0cLinux\u4e0b\u4f7f\u7528zcat\r\n        if platform.system()=='Linux':\r\n            zcat_cmd = 'zcat'\r\n        else:\r\n            raise NotImplementedError(\"This program is suported on Linux,\\\r\n                                      but your platform is\" + platform.system())\r\n        \r\n        # \u8bfb\u53d6mnist\u56fe\u7247\u96c6\r\n        sub_img = subprocess.Popen([zcat_cmd, image_filename], stdout = subprocess.PIPE)\r\n        sub_img.stdout.read(16) # \u8df3\u8fc7\u524d16\u4e2amagic\u5b57\u8282\r\n\r\n        # \u8bfb\u53d6mnist\u6807\u7b7e\u96c6\r\n        sub_lab = subprocess.Popen([zcat_cmd, label_filename], stdout = subprocess.PIPE)\r\n        sub_lab.stdout.read(8)  # \u8df3\u8fc7\u524d8\u4e2amagic\u5b57\u8282\r\n        \r\n    \ttry:\r\n            while True:         #\u524d\u9762\u4f7f\u7528try,\u6545\u82e5\u518d\u8bfb\u53d6\u8fc7\u7a0b\u4e2d\u9047\u5230\u7ed3\u675f\u5219\u4f1a\u9000\u51fa\r\n\t\t# \u6279\u91cf\u8bfb\u53d6label\uff0c\u6bcf\u4e2alabel\u53601\u4e2a\u5b57\u8282\r\n                labels = numpy.fromfile(sub_lab.stdout,'ubyte',count=buffer_size).astype(\"int\")\r\n                if labels.size != buffer_size:\r\n                    break\r\n\t\t# \u6279\u91cf\u8bfb\u53d6image\uff0c\u6bcf\u4e2aimage\u536028*28\u4e2a\u5b57\u8282\uff0c\u5e76\u8f6c\u6362\u4e3a28*28\u7684\u4e8c\u7ef4float\u6570\u7ec4\r\n                images = numpy.fromfile(sub_img.stdout,'ubyte',count=buffer_size * 28 * 28).reshape(buffer_size, 28, 28).astype(\"float32\")\r\n        \t# \u50cf\u7d20\u503c\u6620\u5c04\u5230(-1,1)\u8303\u56f4\u5185\u7528\u4e8e\u8bad\u7ec3\r\n                images = images \/ 255.0 * 2.0 - 1.0;\r\n                for i in xrange(buffer_size):\r\n                    yield images[i,:],int(labels[i]) #\u5c06\u56fe\u50cf\u4e0e\u6807\u7b7e\u629b\u51fa\uff0c\u5faa\u5e8f\u4e0efeed_order\u5bf9\u5e94\uff01\r\n        finally:\r\n            try:\r\n        \t#\u7ed3\u675fimg\u8bfb\u53d6\u8fdb\u7a0b\r\n                sub_img.terminate()\r\n            except:\r\n                pass\r\n            try:\r\n        \t#\u7ed3\u675flabel\u8bfb\u53d6\u8fdb\u7a0b\r\n                sub_lab.terminate()\r\n            except:\r\n                pass\r\n    return reader\r\n\r\n# \u81ea\u5b9a\u4e49image\u76ee\u5f55\u6587\u4ef6\u5217\u8868reader\r\ndef image_reader_creator(img_path,height,width):\r\n    def reader():\r\n        imgs = os.listdir(img_path)\r\n        for i in xrange(len(imgs)):\r\n\t    #imgs[i] = '0-5.png'\r\n\t    #print(imgs[i])\r\n\t    label = imgs[i].split('.')[0].split('-')[1]\r\n\t    image = load_image(img_path + imgs[i],width,height)\r\n\t    #print(img_path + imgs[i])\r\n\t    yield image[0][0],int(label)\r\n \r\n    return reader\r\n\r\n# \u52a0\u8f7d\u6d4b\u8bd5\u56fe\u7247\u6570\u636e\r\ndef load_image(img_path,height,width,rotate=0,invert=False,sobel=False,ksize=5,dilate=0,erode=0,save_resize=False):\r\n    if sobel: #\u8fb9\u7f18\u68c0\u6d4b\r\n\timg_path = image_sobel(img_path, ksize=ksize, dilate=dilate, erode=erode)\r\n    #\u52a0\u8f7d\u56fe\u7247\r\n    im = Image.open(img_path).convert('L')\r\n    #\u7f29\u7565\u56fe\r\n    im = im.resize((height, width), Image.ANTIALIAS)\r\n    #\u65cb\u8f6c\r\n    if rotate != 0: #\u65cb\u8f6c\u5ea6\u6570\r\n        im = im.rotate(rotate)\r\n    #\u53cd\u8f6c\u989c\u8272(\u4e0d\u8981\u8ddfsobel\u4e00\u8d77\u7528\uff0c\u56e0\u4e3asobel\u5df2\u7ecf\u81ea\u52a8\u8f6c\u4e3a\u9ed1\u5e95+\u767d\u8fb9\u7f18\u4e86)\r\n    if invert:\r\n        im = ImageOps.invert(im)\r\n    #\u4e34\u65f6\u4fdd\u5b58\r\n    if save_resize:\r\n        name = img_path.split('\/')[-1]\r\n        resize_path = img_path.replace(name,'') + '..\/tmp\/' + name.split('.')[0]+\"_\"+str(height)+\"x\"+str(width)+\".\"+name.split('.')[1]\r\n        print(resize_path)\r\n        im.save(resize_path)\r\n    #\u8fd4\u56de\u6570\u636e\r\n    im = numpy.array(im).reshape(1, 1, height, width).astype(numpy.float32)  #[N C H W] N\u51e0\u5f20\u56fe;C=1\u7070\u56fe;H\u9ad8;W\u5bbd\r\n    im = im \/ 255.0 * 2.0 - 1.0\r\n    return im\r\n\r\ndef image_sobel(img_path, ksize=5, dilate=0, erode=0, dilate2=0):\r\n    \"\"\"\u56fe\u7247\u8fb9\u7f18\u68c0\u6d4b\"\"\"\r\n    img = cv2.imread(img_path)\r\n    #\u7070\u5ea6\u56fe\r\n    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\r\n    #write_image(gray, img_path, 'gray')\r\n    # \u9ad8\u65af\u5e73\u6ed1\r\n    gaussian = cv2.GaussianBlur(gray, (3, 3), 0, 0, cv2.BORDER_DEFAULT)\r\n    #write_image(gaussian, img_path, 'gaussion')\r\n    # \u4e2d\u503c\u6ee4\u6ce2\r\n    median = cv2.medianBlur(gaussian, 5)\r\n    #write_image(median, img_path, 'median')\r\n    # Sobel\u7b97\u5b50\uff0cX\u65b9\u5411\u6c42\u68af\u5ea6,\u5bf9\u56fe\u50cf\u8fdb\u884c\u8fb9\u7f18\u68c0\u6d4b\r\n    sobel = cv2.Sobel(median, cv2.CV_8U, 1, 0, ksize=ksize) #ksize:1\/3\/5\/7   cv2.CV_8U\/cv2.CV_16S\r\n    #sobel = cv2.Sobel(median, cv2.CV_16S, 1, 0, ksize=ksize) #ksize:1\/3\/5\/7   cv2.CV_8U\/cv2.CV_16S\r\n    sobel = cv2.convertScaleAbs(sobel)\r\n    # \u4e8c\u503c\u5316\r\n    ret, binary = cv2.threshold(sobel, 170, 255, cv2.THRESH_BINARY)\r\n    threshold_path = write_image(binary, img_path, 'threshold')\r\n    if dilate == 0 and erode == 0: \r\n\treturn threshold_path\r\n    else:\r\n        # \u81a8\u80c0\u548c\u8150\u8680\u64cd\u4f5c\u7684\u6838\u51fd\u6570\r\n        element1 = cv2.getStructuringElement(cv2.MORPH_RECT, (9, 1))\r\n        element2 = cv2.getStructuringElement(cv2.MORPH_RECT, (9, 7))\r\n        # \u81a8\u80c0\u4e00\u6b21\uff0c\u8ba9\u8f6e\u5ed3\u7a81\u51fa\r\n        dilation = cv2.dilate(binary, element2, iterations=dilate) #iterations=1\r\n        dilation_path = write_image(dilation, img_path, 'dilation')\r\n\tif erode &gt; 0:# \u8150\u8680\uff0c\u53bb\u6389\u7ec6\u8282\r\n            dilation = cv2.erode(dilation, element1, iterations=erode) #iterations=1\r\n            dilation_path = write_image(dilation, img_path, 'erosion')\r\n\tif dilate2 &gt; 0: # \u518d\u6b21\u81a8\u80c0\uff0c\u8ba9\u8f6e\u5ed3\u660e\u663e\u4e00\u4e9b\r\n            dilation2 = cv2.dilate(erosion, element2, iterations=dilate2) #iterations=3\u8bbe\u7f6e\u592a\u5927\u4f46\u8f66\u724c\u533a\u57df\u5f88\u5c0f\u65f6\u975e\u8f66\u724c\u533a\u57df\u5bb9\u6613\u8fb9\u7f18\u8fde\u7247\u8fc7\u5ea6\uff0c\u8bbe\u7f6e\u592a\u5c0f\u4f46\u8f66\u724c\u5360\u6bd4\u8fc7\u5927\u65f6\u5bb9\u6613\u7701\u7b80\u79f0\u548c\u540e\u8fb9\u8fde\u4e0d\u4e0a\r\n            dilation_path = write_image(dilation2, img_path, 'dilation2')\r\n        return dilation_path\r\n\r\ndef write_image(img, img_path, step='', path='tmp'):\r\n    \"\"\"\u4fdd\u5b58\u56fe\u7247\u5e76\u6253\u5370\"\"\"\r\n    name = img_path.split('\/')[-1]\r\n    img_path = img_path.replace(name,'')\r\n    #print(name)\r\n    #print(img_path)\r\n    if step != '':\r\n        img_file = img_path+'..\/'+path+'\/'+name.split('.')[0]+'_'+step+'.'+name.split('.')[1]\r\n    else:\r\n        img_file = img_path+'..\/'+path+'\/'+name\r\n    cv2.imwrite(img_file, img)\r\n    print(img_file)\r\n    return img_file\r\n\r\ndef mkdir(path):\r\n    \"\"\"\u68c0\u67e5\u5e76\u521b\u5efa\u76ee\u5f55\"\"\"\r\n    if not os.path.exists(path):\r\n        os.makedirs(path)\r\n\r\nif __name__ == '__main__':\r\n    #\u51fd\u6570\u6d4b\u8bd5\r\n    mnist_path = '\/home\/work\/.cache\/paddle\/dataset\/mnist\/'\r\n    train_image   = mnist_path + 'train-images-idx3-ubyte.gz'\r\n    train_label   = mnist_path + 'train-labels-idx1-ubyte.gz'\r\n    for img,label in mnist_reader_creator(train_image,train_label,1)():  #reader\r\n        print(img)\r\n        print(len(img))\r\n        print(len(img[0]))\r\n        print(label)\r\n\tbreak\r\n                             \r\n    img_path = '\/home\/work\/paddle\/sample\/recognize_digits\/train\/data\/train\/'\r\n    for img,label in image_reader_creator(img_path,28,28)():  #reader\r\n        print(img)\r\n        print(len(img))\r\n        print(len(img[0]))\r\n        print(label)\r\n\tbreak<\/code><\/pre>\n<p>\u8fd0\u884c\u6253\u5370\u4fe1\u606f\uff1a<\/p>\n<p><a href=\"https:\/\/yanjingang.com\/blog\/?attachment_id=2001\" rel=\"attachment wp-att-2001\"><img loading=\"lazy\" class=\"alignnone wp-image-2001 size-large\" src=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/cnn_debug-662x1024.png\" alt=\"\" width=\"660\" height=\"1021\" srcset=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/cnn_debug-662x1024.png 662w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/cnn_debug-194x300.png 194w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/cnn_debug-768x1188.png 768w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/cnn_debug.png 1056w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><\/p>\n<p>\u6700\u4f18\u6a21\u578b\u51c6\u786e\u738798.56%\uff0c\u6a21\u578b\u4fdd\u5b58\u5230\u4e86.\/model\u76ee\u5f55\u5185\u3002<\/p>\n<p>\u4f7f\u7528\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u8fdb\u884c\u8bc6\u522b\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">vim infer.py\r\n#!\/usr\/bin\/env python\r\n# -*- coding: utf-8 -*-\r\n# \u624b\u5199\u6570\u5b57\u8bc6\u522b\u6a21\u578b\u6d4b\u8bd5\r\n#cmd: python infer.py infer_0.jpeg\r\nfrom __future__ import print_function\r\nimport sys\r\nimport os\r\nimport platform\r\nimport subprocess\r\nfrom PIL import Image\r\nfrom PIL import ImageOps\r\nimport numpy\r\nimport paddle\r\nimport paddle.fluid as fluid\r\ntry:\r\n    from paddle.fluid.contrib.trainer import *\r\n    from paddle.fluid.contrib.inferencer import *\r\nexcept ImportError:\r\n    print(\r\n        \"In the fluid 1.0, the trainer and inferencer are moving to paddle.fluid.contrib\",\r\n        file=sys.stderr)\r\n    from paddle.fluid.trainer import *\r\n    from paddle.fluid.inferencer import *\r\nimport utils\r\nimport getopt\r\n\r\ndef main():\r\n    opts, args = getopt.getopt(sys.argv[1:], \"p:\", [\"infer_file=\"])\r\n    if len(args) == 0:\r\n        print(\"usage:  python infer.py [infer_file_name]  \\n\\tpython infer.py infer_5.jpeg\")\r\n        return\r\n    infer_file = args[0]\r\n\r\n\r\n    # \u662f\u5426\u4f7f\u7528GPU\r\n    use_cuda = False  # set to True if training with GPU\r\n    place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()\r\n\r\n    params_dirname = \"model\/\"  # \u6a21\u578b\u53c2\u6570\u4fdd\u5b58\u76ee\u5f55\r\n    cur_dir = os.path.dirname(os.path.realpath(__file__))\r\n    height = width = 28\r\n\r\n    # \u52a0\u8f7d\u6d4b\u8bd5\u6570\u636e\r\n    #infer_img = cur_dir + '\/data\/image\/infer_3.png'\r\n    infer_img = cur_dir + '\/data\/image\/' + infer_file\r\n    imgs = [] #\u4f7f\u7528\u591a\u79cd\u4e0d\u540c\u7684\u9884\u5904\u7406\u65b9\u6cd5\r\n    imgs_weight = [1,0.99,0.99] #\u4e0d\u540c\u9884\u5904\u7406\u65b9\u6cd5\u7684\u7ed3\u679c\u6743\u91cd\r\n    try: #\u6d4b\u8bd5\u96c6\u56fe\u7247\r\n        imgs.append(utils.load_image(infer_img,height,width))\r\n    except:\r\n\timgs.append([])\r\n    try: #\u767d\u7eb8\u624b\u5199\u7167\u7247\r\n        print(len(infer_file.split('_')[1].split('.')[0]))\r\n\tif len(infer_file.split('_')[1].split('.')[0])&gt;=2 and int(infer_file.split('_')[1][1:2]) &gt; 0:\r\n\t    imgs_weight[1] = 5 \r\n        imgs.append(utils.load_image(infer_img, height, width, rotate=0, sobel=True, save_resize=True,ksize=5,dilate=1))\r\n    except:\r\n\timgs.append([])\r\n    try: #\u9ed1\u7eb8\u7c97\u7b14\u5199\u7167\u7247\r\n        imgs.append(utils.load_image(infer_img, height, width, rotate=0, sobel=True, save_resize=True,ksize=3,dilate=6,erode=1))\r\n    except:\r\n\timgs.append([])\r\n\r\n    # \u4f7f\u7528\u4fdd\u5b58\u7684\u6a21\u578b\u53c2\u6570+\u6d4b\u8bd5\u56fe\u7247\u8fdb\u884c\u9884\u6d4b\r\n    inferencer = Inferencer(\r\n        # infer_func=softmax_regression, # uncomment for softmax regression\r\n        # infer_func=multilayer_perceptron, # uncomment for MLP\r\n        infer_func=utils.convolutional_neural_network,  # uncomment for LeNet5\r\n        param_path=params_dirname,\r\n        place=place)\r\n\r\n    label = -1\r\n    result_cnt = 0 \r\n    results_sum = numpy.ndarray([])\r\n    results_max = numpy.ndarray([])\r\n    numpy.set_printoptions(precision=2)\r\n    for i in xrange(len(imgs)):\r\n        if len(imgs[i])==0:continue\r\n        result = inferencer.infer({'img': imgs[i]}) #\u6b64\u8f93\u5165img\u7684\u5404label\u6982\u7387\r\n        result = numpy.where(result[0][0]&gt;0.001 ,result[0][0],0) #\u6982\u7387&lt;0.1%\u7684\u76f4\u63a5\u8bbe\u7f6e\u4e3a0\r\n        print(result)\r\n        print(numpy.argsort(result))\r\n        results_sum = results_sum + result*imgs_weight[i]   #\u7d2f\u52a0label\u4e0b\u6807\u6982\u7387\r\n        result_cnt+=1\r\n    #print(imgs_weight)\r\n    #\u6309\u6982\u7387\u6392\u5e8f\r\n    lab = numpy.argsort(results_sum)  # probs and lab are the results of one batch data\r\n    label = lab[-1]  #\u6982\u7387\u5012\u6392\u6700\u540e\u4e00\u4e2a\r\n    print(\"\u6982\u7387\u52a0\u548c&amp;\u6392\u5e8f: \")\r\n    print(results_sum)\r\n    print(lab)\r\n    print(\"\u6d4b\u8bd5\u56fe\u7247: %s\" % infer_img)\r\n    print(\"\u6a21\u578b\u8bc6\u522b\u7ed3\u679c: %d \u6982\u7387: %f\" % (label,results_sum[label]\/result_cnt))\r\n\r\n\r\nif __name__ == '__main__':\r\n    main()<\/code><\/pre>\n<p>\u8ba9\u513f\u5b50\u624b\u5199\u4e86\u4e9b\u6570\u5b57<span class=\"s1\">(\u4e0b\u56fe)<\/span>\uff0c\u4f7f\u7528\u6a21\u578b\u8bc6\u522b\uff0c\u80fd\u6b63\u5e38\u8bc6\u522b\u51fa\u662f\u6570\u5b576<\/p>\n<p><a href=\"https:\/\/yanjingang.com\/blog\/?attachment_id=2121\" rel=\"attachment wp-att-2121\"><img loading=\"lazy\" class=\"alignnone wp-image-2121 size-thumbnail\" src=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/infer_62-150x150.jpeg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p><a href=\"https:\/\/yanjingang.com\/blog\/?attachment_id=2122\" rel=\"attachment wp-att-2122\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-2122\" src=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/infer.png\" alt=\"\" width=\"719\" height=\"272\" srcset=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/infer.png 719w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/infer-300x113.png 300w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/infer-624x236.png 624w\" sizes=\"(max-width: 719px) 100vw, 719px\" \/><\/a><\/p>\n<p>*\u6ce8\uff1a\u56e0\u6a21\u578b\u662f\u4f7f\u7528\u6bd4\u8f83\u5e72\u51c0\u7684\u9ed1\u5e95\u767d\u5b57\u56fe\u7247\u8bad\u7ec3\u7684\uff0c\u76f4\u63a5\u62ff\u62cd\u7684\u624b\u5199\u7167\u7247\u662f\u8bc6\u522b\u4e0d\u51fa\u6765\u7684\uff0c\u53e6\u5916\u4e0d\u540c\u7c97\u7ec6\u7684\u7b14\u5bf9\u6a21\u578b\u8bc6\u522b\u4e5f\u662f\u6709\u5f71\u54cd\uff0c\u6240\u4ee5\u5728\u6a21\u578b\u8bc6\u522b\u524d\u9700\u8981\u505a\u4e9b\u9884\u5904\u7406\uff0c\u4e0e\u8bad\u7ec3\u96c6\u4fdd\u6301\u4e00\u81f4\uff0c\u4f8b\u5982\u8f6c\u6362\u6210\u9ed1\u80cc\u666f+\u767d\u5b57\uff0c\u5177\u4f53\u53ef\u53c2\u8003\u201c#\u52a0\u8f7d\u6d4b\u8bd5\u6570\u636e #\u767d\u7eb8\u624b\u5199\u7167\u7247\u201d\u90e8\u5206\u3002<\/p>\n<p>yan 2018.12.2 23:35<\/p>\n<p>\u505a\u4e86\u4e2a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0c\u76f4\u63a5\u62cd\u7167\u65b9\u4fbf\u70b9\uff0c\u4e0d\u7528\u624b\u52a8\u4e0a\u4f20\u4e86<\/p>\n<p><a href=\"https:\/\/yanjingang.com\/blog\/?attachment_id=2186\" rel=\"attachment wp-att-2186\"><img loading=\"lazy\" class=\"alignnone wp-image-2186 size-medium\" src=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/9b29f7c4b326e6247eb081ca3-169x300.jpg\" alt=\"\" width=\"169\" height=\"300\" srcset=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/9b29f7c4b326e6247eb081ca3-169x300.jpg 169w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/9b29f7c4b326e6247eb081ca3-576x1024.jpg 576w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/9b29f7c4b326e6247eb081ca3-624x1110.jpg 624w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/9b29f7c4b326e6247eb081ca3.jpg 750w\" sizes=\"(max-width: 169px) 100vw, 169px\" \/><\/a> <a href=\"https:\/\/yanjingang.com\/blog\/?attachment_id=2187\" rel=\"attachment wp-att-2187\"><img loading=\"lazy\" class=\"alignnone wp-image-2187 size-medium\" src=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/debc6cb8da4a046344b0f1285-169x300.jpg\" alt=\"\" width=\"169\" height=\"300\" srcset=\"https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/debc6cb8da4a046344b0f1285-169x300.jpg 169w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/debc6cb8da4a046344b0f1285-576x1024.jpg 576w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/debc6cb8da4a046344b0f1285-624x1110.jpg 624w, https:\/\/yanjingang.com\/blog\/wp-content\/uploads\/2018\/12\/debc6cb8da4a046344b0f1285.jpg 750w\" sizes=\"(max-width: 169px) 100vw, 169px\" \/><\/a><\/p>\n<p>yan 2018.12.19 22:13<\/p>\n<p>\u53c2\u8003\uff1a<\/p>\n<p>http:\/\/www.paddlepaddle.org\/documentation\/book\/zh\/develop\/02.recognize_digits\/index.cn.html<\/p>\n<p>http:\/\/www.cnblogs.com\/dzqiu\/p\/9514447.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u6bb5\u65f6\u95f4\u5fd9\u4e86\u597d\u4e00\u9635\uff0c\u7ec8\u4e8e\u6709\u65f6\u95f4\u7ee7\u7eed\u5b66\u4e60\u4e86\uff0c\u4eca\u5929\u5f00\u59cb\u901a\u8fc7paddlepaddle\u7684\u624b\u5199\u6570\u5b57\u8bc6\u522b\u770b\u4e00\u4e0b\u7b80\u5355\u7684cnn [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[535],"tags":[677,676,671,679,536,674,678,855,672,329,675,732,670,673],"_links":{"self":[{"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1994"}],"collection":[{"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1994"}],"version-history":[{"count":0,"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1994\/revisions"}],"wp:attachment":[{"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}