{"id":148,"date":"2024-12-05T23:13:47","date_gmt":"2024-12-05T15:13:47","guid":{"rendered":"https:\/\/codeloveme.com\/?p=148"},"modified":"2024-12-05T23:35:12","modified_gmt":"2024-12-05T15:35:12","slug":"%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80","status":"publish","type":"post","link":"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/","title":{"rendered":"\u795e\u7ecf\u7f51\u7edc\u57fa\u7840"},"content":{"rendered":"<h1>\u673a\u5668\u5b66\u4e60\u5165\u95e8\u4e0e\u8fdb\u9636<\/h1>\n<p>\u672c\u6587\u6863\u8be6\u7ec6\u8bb2\u89e3\u4e86\u673a\u5668\u5b66\u4e60\u7684\u91cd\u8981\u6982\u5ff5\u548c\u6280\u672f\uff0c\u4ee5\u795e\u7ecf\u7f51\u7edc\u4e3a\u6838\u5fc3\uff0c\u7ed3\u5408\u5b9e\u8df5\u5de5\u5177TensorFlow\uff0c\u5e2e\u52a9\u8bfb\u8005\u6df1\u5165\u7406\u89e3\u673a\u5668\u5b66\u4e60\u4e2d\u7684\u7406\u8bba\u4e0e\u5b9e\u73b0\u3002<\/p>\n<hr \/>\n<h2>1. \u795e\u7ecf\u7f51\u7edc\u57fa\u7840<\/h2>\n<h3>1.1 \u611f\u77e5\u673a<\/h3>\n<p>\u611f\u77e5\u673a\u662f\u6700\u65e9\u7684\u4eba\u5de5\u795e\u7ecf\u7f51\u7edc\u6a21\u578b\u4e4b\u4e00\uff0c\u7531Frank Rosenblatt\u63d0\u51fa\u3002\u5b83\u7684\u57fa\u672c\u7ed3\u6784\u662f\u4e00\u4e2a\u5355\u5c42\u795e\u7ecf\u5143\uff0c\u5177\u6709\u4ee5\u4e0b\u7279\u6027\uff1a<\/p>\n<ul>\n<li><strong>\u8f93\u5165<\/strong>\uff1a\u5411\u91cf\u5f62\u5f0f\u7684\u7279\u5f81\u503c &#40; (x_1, x_2, ..., x_n) &#41;<\/li>\n<li><strong>\u6743\u91cd<\/strong>\uff1a\u4e0e\u8f93\u5165\u5bf9\u5e94\u7684\u6743\u91cd &#40; (w_1, w_2, ..., w_n) &#41;<\/li>\n<li><strong>\u504f\u7f6e<\/strong>\uff1a\u4e00\u4e2a\u5e38\u6570 &#40; b &#41;<\/li>\n<li><strong>\u8f93\u51fa<\/strong>\uff1a\u901a\u8fc7\u6fc0\u6d3b\u51fd\u6570 &#40; f &#41; \u8ba1\u7b97\u5f97\u51fa\uff1a<\/li>\n<\/ul>\n<p><span class=\"katex math multi-line\">y = f\\left(\\sum_{i=1}^{n} w_i x_i + b\\right)<\/span><\/p>\n<p>\u5176\u4e2d\uff0c&#40; f &#41; \u901a\u5e38\u662f\u4e00\u4e2a\u9636\u8dc3\u51fd\u6570\u6216\u5176\u4ed6\u975e\u7ebf\u6027\u6fc0\u6d3b\u51fd\u6570\u3002<\/p>\n<h4>\u7279\u70b9\uff1a<\/h4>\n<ul>\n<li><strong>\u7ebf\u6027\u53ef\u5206\u95ee\u9898<\/strong>\uff1a\u611f\u77e5\u673a\u80fd\u591f\u6709\u6548\u89e3\u51b3\u7ebf\u6027\u53ef\u5206\u95ee\u9898\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b83\u80fd\u591f\u627e\u5230\u4e00\u6761\u51b3\u7b56\u8fb9\u754c\u5c06\u4e0d\u540c\u7c7b\u522b\u7684\u6837\u672c\u5206\u5f00\u3002<\/li>\n<li><strong>\u5c40\u9650\u6027<\/strong>\uff1a\u611f\u77e5\u673a\u65e0\u6cd5\u89e3\u51b3\u66f4\u590d\u6742\u7684\u975e\u7ebf\u6027\u95ee\u9898\uff0c\u4f8b\u5982\u5f02\u6216\uff08XOR\uff09\u95ee\u9898\uff0c\u56e0\u5176\u53ea\u80fd\u901a\u8fc7\u7ebf\u6027\u51b3\u7b56\u8fb9\u754c\u8fdb\u884c\u5206\u7c7b\u3002<\/li>\n<\/ul>\n<p>\u611f\u77e5\u673a\u662f\u795e\u7ecf\u7f51\u7edc\u7684\u57fa\u7840\uff0c\u4e3a\u540e\u6765\u7684\u591a\u5c42\u611f\u77e5\u673a\uff08MLP\uff09\u548c\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u7684\u63d0\u51fa\u5960\u5b9a\u4e86\u57fa\u7840\u3002<\/p>\n<hr \/>\n<h3>1.2 \u591a\u5c42\u611f\u77e5\u673a\uff08MLP\uff09<\/h3>\n<p>\u591a\u5c42\u611f\u77e5\u673a\u901a\u8fc7\u589e\u52a0\u9690\u85cf\u5c42\u7684\u6570\u91cf\u89e3\u51b3\u4e86\u611f\u77e5\u673a\u65e0\u6cd5\u5904\u7406\u975e\u7ebf\u6027\u95ee\u9898\u7684\u9650\u5236\u3002MLP\u7684\u7279\u70b9\uff1a<br \/>\n- \u591a\u5c42\u7ed3\u6784\uff1a\u5305\u542b\u8f93\u5165\u5c42\u3001\u4e00\u4e2a\u6216\u591a\u4e2a\u9690\u85cf\u5c42\u3001\u8f93\u51fa\u5c42\u3002<br \/>\n- \u6fc0\u6d3b\u51fd\u6570\uff1a\u5e38\u7528\u7684\u6709Sigmoid\u3001ReLU\u7b49\u3002<br \/>\n- \u524d\u5411\u4f20\u64ad\uff1a\u8f93\u5165\u7ecf\u8fc7\u6bcf\u4e00\u5c42\u7684\u6743\u91cd\u3001\u504f\u7f6e\u548c\u6fc0\u6d3b\u51fd\u6570\u4f9d\u6b21\u4f20\u9012\u5230\u8f93\u51fa\u5c42\u3002<\/p>\n<p>MLP\u662f\u5b9e\u73b0\u6df1\u5ea6\u5b66\u4e60\u7684\u57fa\u672c\u6a21\u578b\u4e4b\u4e00\u3002<\/p>\n<hr \/>\n<h3>1.3 \u6574\u6d41\u7ebf\u6027\u5355\u5143\uff08ReLU\uff09<\/h3>\n<p>ReLU\uff08Rectified Linear Unit\uff09\u662f\u6df1\u5ea6\u5b66\u4e60\u4e2d\u5e7f\u6cdb\u4f7f\u7528\u7684\u6fc0\u6d3b\u51fd\u6570\uff0c\u5176\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n<p><span class=\"katex math multi-line\">f(x) = \\max(0, x)<\/span><\/p>\n<h4>\u4f18\u70b9\uff1a<\/h4>\n<ul>\n<li><strong>\u8ba1\u7b97\u7b80\u5355<\/strong>\uff1aReLU\u7684\u8ba1\u7b97\u975e\u5e38\u7b80\u5355\uff0c\u5bf9\u4e8e\u8f93\u5165\u503c &#40; x &#41;\uff0c\u5982\u679c &#40; x > 0 &#41;\uff0c\u5219\u8f93\u51fa\u4e3a &#40; x &#41;\uff0c\u5426\u5219\u8f93\u51fa\u4e3a 0\u3002\u8fd9\u4f7f\u5f97ReLU\u5728\u8ba1\u7b97\u65f6\u975e\u5e38\u9ad8\u6548\u3002<\/li>\n<li><strong>\u907f\u514d\u4e86\u68af\u5ea6\u6d88\u5931\u95ee\u9898<\/strong>\uff1a\u4f20\u7edf\u7684\u6fc0\u6d3b\u51fd\u6570\u5982Sigmoid\u548cTanh\u5728\u8f83\u5927\u7684\u8f93\u5165\u503c\u4e0b\u5bb9\u6613\u51fa\u73b0\u68af\u5ea6\u6d88\u5931\u7684\u95ee\u9898\uff0c\u800cReLU\u901a\u8fc7\u5c06\u8d1f\u503c\u5f52\u96f6\uff0c\u4ec5\u4fdd\u7559\u6b63\u503c\uff0c\u907f\u514d\u4e86\u8fd9\u4e00\u95ee\u9898\u3002<\/li>\n<li><strong>\u52a0\u901f\u7f51\u7edc\u6536\u655b<\/strong>\uff1a\u7531\u4e8eReLU\u7684\u975e\u7ebf\u6027\u548c\u68af\u5ea6\u7684\u6709\u6548\u4f20\u64ad\uff0c\u5b83\u901a\u5e38\u80fd\u52a0\u901f\u7f51\u7edc\u7684\u6536\u655b\u901f\u5ea6\u3002<\/li>\n<\/ul>\n<p>ReLU\u5df2\u6210\u4e3a\u73b0\u4ee3\u795e\u7ecf\u7f51\u7edc\u4e2d\u6700\u5e38\u7528\u7684\u6fc0\u6d3b\u51fd\u6570\uff0c\u5c24\u5176\u5728\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\u548c\u6df1\u5ea6\u795e\u7ecf\u7f51\u7edc\uff08DNN\uff09\u4e2d\u5177\u6709\u91cd\u8981\u5e94\u7528\u3002<\/p>\n<h3>1.4 \u795e\u7ecf\u7f51\u7edc\u5185\u79ef\u95ee\u9898<\/h3>\n<p>\u795e\u7ecf\u7f51\u7edc\u7684\u6838\u5fc3\u8ba1\u7b97\u662f\u5185\u79ef\u8fd0\u7b97\uff0c\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p><span class=\"katex math multi-line\">z = \\sum_{i=1}^{n} w_i x_i + b<\/span><\/p>\n<p>\u5176\u4e2d\uff1a<br \/>\n- &#40; w_i &#41; \u662f\u7b2c &#40; i &#41; \u4e2a\u7279\u5f81\u7684\u6743\u91cd\uff0c<br \/>\n- &#40; x_i &#41; \u662f\u7b2c &#40; i &#41; \u4e2a\u7279\u5f81\u7684\u8f93\u5165\uff0c<br \/>\n- &#40; b &#41; \u662f\u504f\u7f6e\u9879\uff0c<br \/>\n- &#40; n &#41; \u662f\u7279\u5f81\u7684\u603b\u6570\u3002<\/p>\n<h4>\u95ee\u9898\uff1a<\/h4>\n<ol>\n<li><strong>\u5927\u89c4\u6a21\u6570\u636e\u8ba1\u7b97\u65f6\u6548\u7387\u4f4e<\/strong>\uff1a\u5bf9\u4e8e\u5927\u89c4\u6a21\u6570\u636e\u96c6\uff0c\u5185\u79ef\u8fd0\u7b97\u9700\u8981\u5904\u7406\u5927\u91cf\u7684\u8ba1\u7b97\uff0c\u5bfc\u81f4\u6548\u7387\u8f83\u4f4e\u3002\u901a\u5e38\u9700\u8981\u91c7\u7528\u4f18\u5316\u65b9\u6cd5\u6216\u5e76\u884c\u8ba1\u7b97\u6765\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5185\u79ef\u8fd0\u7b97\u53d7\u8f93\u5165\u503c\u548c\u6743\u91cd\u521d\u59cb\u5316\u7684\u5f71\u54cd<\/strong>\uff1a\u5185\u79ef\u8fd0\u7b97\u7684\u7ed3\u679c\u4f9d\u8d56\u4e8e\u8f93\u5165\u7279\u5f81\u548c\u6743\u91cd\u7684\u521d\u59cb\u5316\u3002\u82e5\u521d\u59cb\u6743\u91cd\u8bbe\u7f6e\u4e0d\u5f53\uff0c\u53ef\u80fd\u5bfc\u81f4\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u7684\u68af\u5ea6\u6d88\u5931\u6216\u68af\u5ea6\u7206\u70b8\u95ee\u9898\u3002\u56e0\u6b64\uff0c\u5408\u7406\u7684\u6743\u91cd\u521d\u59cb\u5316\u548c\u8f93\u5165\u6570\u636e\u5f52\u4e00\u5316\uff08\u5982\u6807\u51c6\u5316\u6216\u5f52\u4e00\u5316\uff09\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<\/li>\n<\/ol>\n<hr \/>\n<h3>1.5 TensorFlow\u521d\u4f7f\u7528<\/h3>\n<p>TensorFlow\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u673a\u5668\u5b66\u4e60\u6846\u67b6\uff0c\u5177\u6709\u9ad8\u6548\u7684\u6570\u503c\u8ba1\u7b97\u80fd\u529b\u3002\u7b80\u5355\u7684\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python line-numbers\">import tensorflow as tf\n\n# \u521b\u5efa\u4e00\u4e2a\u5f20\u91cf\nx = tf.constant([[1.0, 2.0], [3.0, 4.0]])\ny = tf.constant([[5.0, 6.0], [7.0, 8.0]])\n\n# \u8ba1\u7b97\u77e9\u9635\u4e58\u6cd5\nresult = tf.matmul(x, y)\nprint(result)\n<\/code><\/pre>\n<h3>1.6 \u635f\u5931\u51fd\u6570<\/h3>\n<p>\u635f\u5931\u51fd\u6570\u662f\u8861\u91cf\u6a21\u578b\u9884\u6d4b\u503c\u4e0e\u771f\u5b9e\u503c\u5dee\u8ddd\u7684\u6307\u6807\uff0c\u5e38\u7528\u7684\u635f\u5931\u51fd\u6570\u5305\u62ec\uff1a<br \/>\n- <strong>\u5747\u65b9\u8bef\u5dee\uff08MSE\uff09<\/strong>\uff1a\u7528\u4e8e\u56de\u5f52\u95ee\u9898\uff0c\u8ba1\u7b97\u9884\u6d4b\u503c\u4e0e\u771f\u5b9e\u503c\u4e4b\u95f4\u7684\u5e73\u65b9\u5dee\u7684\u5e73\u5747\u503c\u3002<br \/>\n- <strong>\u4ea4\u53c9\u71b5\uff08Cross-Entropy\uff09<\/strong>\uff1a\u7528\u4e8e\u5206\u7c7b\u95ee\u9898\uff0c\u8861\u91cf\u4e24\u4e2a\u6982\u7387\u5206\u5e03\u4e4b\u95f4\u7684\u5dee\u5f02\uff0c\u901a\u5e38\u7528\u4e8e\u591a\u5206\u7c7b\u95ee\u9898\u3002<\/p>\n<h3>1.7 \u53cd\u5411\u4f20\u64ad<\/h3>\n<p>\u53cd\u5411\u4f20\u64ad\uff08Backpropagation\uff09\u662f\u795e\u7ecf\u7f51\u7edc\u8bad\u7ec3\u7684\u5173\u952e\u7b97\u6cd5\uff0c\u7528\u4e8e\u8ba1\u7b97\u6bcf\u4e2a\u53c2\u6570\u7684\u68af\u5ea6\u503c\u3002\u5176\u57fa\u672c\u6b65\u9aa4\uff1a<br \/>\n1. <strong>\u8ba1\u7b97\u635f\u5931\u51fd\u6570<\/strong>\uff1a\u6839\u636e\u6a21\u578b\u7684\u8f93\u51fa\u548c\u771f\u5b9e\u6807\u7b7e\uff0c\u8ba1\u7b97\u635f\u5931\u503c\u3002<br \/>\n2. <strong>\u9010\u5c42\u8ba1\u7b97\u8bef\u5dee\u7684\u68af\u5ea6<\/strong>\uff1a\u4ece\u8f93\u51fa\u5c42\u5f00\u59cb\uff0c\u9010\u5c42\u5411\u8f93\u5165\u5c42\u53cd\u5411\u4f20\u64ad\u8bef\u5dee\u3002<br \/>\n3. <strong>\u5229\u7528\u94fe\u5f0f\u6cd5\u5219\u66f4\u65b0\u53c2\u6570<\/strong>\uff1a\u6839\u636e\u68af\u5ea6\u66f4\u65b0\u6a21\u578b\u7684\u6743\u91cd\u548c\u504f\u7f6e\u3002<\/p>\n<h3>1.8 \u795e\u7ecf\u7f51\u7edc\u6c42\u68af\u5ea6\u503c<\/h3>\n<p>\u68af\u5ea6\u662f\u4f18\u5316\u7b97\u6cd5\u4e2d\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u7528\u4e8e\u6307\u793a\u635f\u5931\u51fd\u6570\u5728\u5f53\u524d\u53c2\u6570\u7a7a\u95f4\u7684\u4e0b\u964d\u65b9\u5411\u3002\u5728TensorFlow\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>GradientTape<\/code>\u8ba1\u7b97\u68af\u5ea6\uff1a<\/p>\n<pre><code class=\"language-python line-numbers\">with tf.GradientTape() as tape:\n    y_pred = model(x)  # \u6a21\u578b\u7684\u524d\u5411\u4f20\u64ad\n    loss = loss_function(y_true, y_pred)  # \u8ba1\u7b97\u635f\u5931\n\ngradients = tape.gradient(loss, model.trainable_variables)  # \u8ba1\u7b97\u68af\u5ea6\n<\/code><\/pre>\n<h3>1.9 \u9ad8\u9636\u5185\u5bb9<\/h3>\n<h4>1.9.1 \u795e\u7ecf\u7f51\u7edc\u53cd\u5411\u4f20\u64ad\u6c42\u68af\u5ea6<\/h4>\n<p>\u94fe\u5f0f\u6cd5\u5219\u7528\u4e8e\u53cd\u5411\u4f20\u64ad\u65f6\u8ba1\u7b97\u6bcf\u4e00\u5c42\u7684\u68af\u5ea6\u3002\u5bf9\u4e8e\u4e00\u4e2a\u591a\u5c42\u795e\u7ecf\u7f51\u7edc\uff0c\u68af\u5ea6\u8ba1\u7b97\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p><span class=\"katex math multi-line\">\\frac{\\partial L}{\\partial w} = \\frac{\\partial L}{\\partial y} \\cdot \\frac{\\partial y}{\\partial z} \\cdot \\frac{\\partial z}{\\partial w}<\/span><\/p>\n<p>\u5176\u4e2d\uff1a<br \/>\n- &#40; L &#41; \u662f\u635f\u5931\u51fd\u6570\uff0c<br \/>\n- &#40; y &#41; \u662f\u5f53\u524d\u5c42\u7684\u8f93\u51fa\uff0c<br \/>\n- &#40; z &#41; \u662f\u5f53\u524d\u5c42\u7684\u52a0\u6743\u8f93\u5165\uff0c<br \/>\n- &#40; w &#41; \u662f\u5f53\u524d\u5c42\u7684\u6743\u91cd\u3002<\/p>\n<p>\u8fd9\u4e2a\u516c\u5f0f\u901a\u8fc7\u94fe\u5f0f\u6cd5\u5219\u5c06\u68af\u5ea6\u4ece\u8f93\u51fa\u5c42\u9010\u5c42\u4f20\u64ad\u56de\u8f93\u5165\u5c42\uff0c\u8ba1\u7b97\u6bcf\u4e00\u5c42\u7684\u6743\u91cd\u68af\u5ea6\u3002<\/p>\n<h4>1.9.2 \u795e\u7ecf\u7f51\u7edc\u5168\u5fae\u5206\u516c\u5f0f\u6c42\u504f\u5bfc\uff08\u68af\u5ea6\uff09<\/h4>\n<p>\u5229\u7528\u5168\u5fae\u5206\u516c\u5f0f\uff0c\u9010\u5c42\u5c55\u5f00\u8ba1\u7b97\u6bcf\u4e00\u5c42\u7684\u504f\u5bfc\u6570\uff0c\u9012\u5f52\u66f4\u65b0\u6743\u91cd\u3002\u901a\u8fc7\u53cd\u5411\u4f20\u64ad\u7b97\u6cd5\uff0c\u8ba1\u7b97\u635f\u5931\u51fd\u6570\u76f8\u5bf9\u4e8e\u6bcf\u4e2a\u53c2\u6570\u7684\u68af\u5ea6\uff0c\u5e76\u4f7f\u7528\u8fd9\u4e9b\u68af\u5ea6\u6765\u66f4\u65b0\u6a21\u578b\u7684\u53c2\u6570\u3002<\/p>\n<h4>1.9.3 SGD\u4f18\u5316<\/h4>\n<p>\u968f\u673a\u68af\u5ea6\u4e0b\u964d\uff08SGD\uff09\u662f\u6700\u7b80\u5355\u7684\u4f18\u5316\u7b97\u6cd5\uff0c\u6838\u5fc3\u516c\u5f0f\uff1a<\/p>\n<p><span class=\"katex math multi-line\">\\theta_{t+1} = \\theta_t - \\eta \\nabla_{\\theta} J(\\theta_t; x^{(i)}, y^{(i)})<\/span><\/p>\n<p>\u5176\u4e2d\uff1a<br \/>\n- &#40; \\theta_t &#41; \u662f\u5f53\u524d\u53c2\u6570\u5411\u91cf\uff0c<br \/>\n- &#40; \\theta_{t+1} &#41; \u662f\u66f4\u65b0\u540e\u7684\u53c2\u6570\u5411\u91cf\uff0c<br \/>\n- &#40; \\eta &#41; \u662f\u5b66\u4e60\u7387\uff0c<br \/>\n- &#40; \\nabla_{\\theta} J(\\theta_t; x^{(i)}, y^{(i)}) &#41; \u662f\u76ee\u6807\u51fd\u6570 &#40; J &#41; \u76f8\u5bf9\u4e8e\u53c2\u6570 &#40; \\theta &#41; \u7684\u68af\u5ea6\uff0c\u8ba1\u7b97\u65f6\u4ec5\u4f7f\u7528\u5355\u4e2a\u6837\u672c &#40; (x^{(i)}, y^{(i)}) &#41;\u3002<\/p>\n<h4>1.9.4 \u4e94\u5c42\u795e\u7ecf\u7f51\u7edc\uff08fivelayerNN\uff09<\/h4>\n<p>\u4e94\u5c42\u795e\u7ecf\u7f51\u7edc\u901a\u5e38\u5305\u62ec\uff1a<\/p>\n<ol>\n<li><strong>\u8f93\u5165\u5c42<\/strong>\uff1a\u63a5\u6536\u8f93\u5165\u6570\u636e\u3002<\/li>\n<li><strong>\u4e09\u4e2a\u9690\u85cf\u5c42<\/strong>\uff1a\u901a\u8fc7\u975e\u7ebf\u6027\u6fc0\u6d3b\u51fd\u6570\uff08\u5982ReLU\uff09\u8fdb\u884c\u8f6c\u6362\u3002<\/li>\n<li><strong>\u8f93\u51fa\u5c42<\/strong>\uff1a\u6839\u636e\u4efb\u52a1\u7c7b\u578b\uff08\u56de\u5f52\u6216\u5206\u7c7b\uff09\u8f93\u51fa\u7ed3\u679c\u3002<\/li>\n<\/ol>\n<p>\u6bcf\u4e00\u5c42\u7684\u8ba1\u7b97\u90fd\u5305\u62ec\u52a0\u6743\u6c42\u548c\u548c\u6fc0\u6d3b\u51fd\u6570\uff0c\u6700\u540e\u901a\u8fc7\u53cd\u5411\u4f20\u64ad\u8c03\u6574\u6743\u91cd\u548c\u504f\u7f6e\u3002<\/p>\n<hr \/>\n<h2>2. \u795e\u7ecf\u7f51\u7edc\u9ad8\u7ea7\u6280\u672f<\/h2>\n<h3>2.1 Dropout\uff080-10\uff09<\/h3>\n<p>Dropout\u662f\u4e00\u79cd\u6b63\u5219\u5316\u6280\u672f\uff0c\u65e8\u5728\u51cf\u5c11\u8fc7\u62df\u5408\u3002\u5b83\u901a\u8fc7\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u968f\u673a\u201c\u4e22\u5f03\u201d\u90e8\u5206\u795e\u7ecf\u5143\u6765\u8feb\u4f7f\u6a21\u578b\u66f4\u52a0\u9c81\u68d2\u3002\u901a\u5e38Dropout\u7684\u503c\u57280\u52301\u4e4b\u95f4\uff0c\u5b9e\u8df5\u4e2d\u5e38\u53d60.2\u52300.5\u3002<\/p>\n<h3>2.2 \u6d4b\u8bd5im2col\u4f18\u5316<\/h3>\n<p><code>im2col<\/code> \u662fCNN\u8ba1\u7b97\u4e2d\u7684\u4f18\u5316\u65b9\u6cd5\uff0c\u5c06\u5377\u79ef\u64cd\u4f5c\u8f6c\u5316\u4e3a\u77e9\u9635\u4e58\u6cd5\uff0c\u63d0\u5347\u8ba1\u7b97\u6548\u7387\u3002\u5b83\u901a\u8fc7\u5c06\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u5f62\u5f0f\uff0c\u4f7f\u5f97\u5377\u79ef\u8fc7\u7a0b\u53ef\u4ee5\u4f7f\u7528\u9ad8\u6548\u7684\u77e9\u9635\u4e58\u6cd5\u6765\u52a0\u901f\u8fd0\u7b97\u3002<\/p>\n<h3>2.3 CNN\u6a21\u578b\u642d\u5efa<\/h3>\n<p>\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\u662f\u5904\u7406\u56fe\u50cf\u4efb\u52a1\u7684\u6838\u5fc3\u6a21\u578b\uff0c\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u5c42\uff1a<\/p>\n<ol>\n<li><strong>\u5377\u79ef\u5c42<\/strong>\uff1a\u63d0\u53d6\u56fe\u50cf\u7684\u5c40\u90e8\u7279\u5f81\u3002<\/li>\n<li><strong>\u6c60\u5316\u5c42<\/strong>\uff1a\u901a\u8fc7\u4e0b\u91c7\u6837\u964d\u4f4e\u7279\u5f81\u56fe\u7684\u7ef4\u5ea6\u3002<\/li>\n<li><strong>\u5168\u8fde\u63a5\u5c42<\/strong>\uff1a\u7528\u4e8e\u6700\u540e\u7684\u5206\u7c7b\u6216\u56de\u5f52\u4efb\u52a1\u3002<\/li>\n<\/ol>\n<p>\u4e00\u4e2a\u7b80\u5355\u7684CNN\u6a21\u578b\u53ef\u4ee5\u4f7f\u7528TensorFlow\u6784\u5efa\uff1a<\/p>\n<pre><code class=\"language-python line-numbers\">import tensorflow as tf\nfrom tensorflow.keras import layers, models\n\nmodel = models.Sequential([\n    layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),\n    layers.MaxPooling2D((2, 2)),\n    layers.Flatten(),\n    layers.Dense(64, activation='relu'),\n    layers.Dense(10, activation='softmax')\n])\n<\/code><\/pre>\n<p>\u4ee5\u4e0a\u662f\u795e\u7ecf\u7f51\u7edc\u7684\u57fa\u7840\u7406\u8bba\u548c\u6280\u672f\u5b9e\u73b0\uff0c\u6db5\u76d6\u4e86\u4ece\u611f\u77e5\u673a\u5230\u6df1\u5ea6\u795e\u7ecf\u7f51\u7edc\u7684\u6f14\u8fdb\uff0c\u5305\u542b\u5e38\u7528\u7684\u4f18\u5316\u65b9\u6cd5\u548cTensorFlow\u5b9e\u73b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728\u73b0\u4ee3\u673a\u5668\u5b66\u4e60\u7684\u6d6a\u6f6e\u4e2d\uff0c\u795e\u7ecf\u7f51\u7edc\u4f5c\u4e3a\u6838\u5fc3\u6280\u672f\uff0c\u5f15\u9886\u7740\u65e0\u6570\u521b\u65b0\u4e0e\u7a81\u7834\u3002\u4ece\u7b80\u5355\u7684\u611f\u77e5\u673a\u5230\u591a\u5c42\u611f\u77e5\u673a\uff08MLP\uff09\u3001\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\uff0c\u6211\u4eec\u9010\u6b65\u63ed\u5f00\u590d\u6742\u95ee\u9898\u7684\u9762\u7eb1\u3002\u672c\u6587\u5c06\u5e26\u60a8\u6df1\u5165\u63a2\u7d22\u795e\u7ecf\u7f51\u7edc\u7684\u57fa\u672c\u6784\u6210\u3001\u5173\u952e\u7b97\u6cd5\u53ca\u5176\u4e0eTenso","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[9],"tags":[14,12,11,10,13],"class_list":["post-148","post","type-post","status-publish","format-standard","hentry","category-9","tag-sgd","tag-12","tag-11","tag-10","tag-13"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u795e\u7ecf\u7f51\u7edc\u57fa\u7840 - \u4ee3\u7801\u604b\u7231\u6307\u5357<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/\u795e\u7ecf\u7f51\u7edc\u57fa\u7840\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u795e\u7ecf\u7f51\u7edc\u57fa\u7840 - \u4ee3\u7801\u604b\u7231\u6307\u5357\" \/>\n<meta property=\"og:description\" content=\"\u673a\u5668\u5b66\u4e60\u5165\u95e8\u4e0e\u8fdb\u9636 \u672c\u6587\u6863\u8be6\u7ec6\u8bb2\u89e3\u4e86\u673a\u5668\u5b66\u4e60\u7684\u91cd\u8981\u6982\u5ff5\u548c\u6280\u672f\uff0c\u4ee5\u795e\u7ecf\u7f51\u7edc\u4e3a\u6838\u5fc3\uff0c\u7ed3\u5408\u5b9e\u8df5\u5de5\u5177TensorFlow\uff0c\u5e2e\u52a9\u8bfb\u8005\u6df1\u5165\u7406\u89e3 ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/\u795e\u7ecf\u7f51\u7edc\u57fa\u7840\/\" \/>\n<meta property=\"og:site_name\" content=\"\u4ee3\u7801\u604b\u7231\u6307\u5357\" \/>\n<meta property=\"article:published_time\" content=\"2024-12-05T15:13:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-12-05T15:35:12+00:00\" \/>\n<meta name=\"author\" content=\"beizou\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"beizou\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/\"},\"author\":{\"name\":\"beizou\",\"@id\":\"https:\/\/codeloveme.com\/#\/schema\/person\/81a4181217586206bf536360ebdbc737\"},\"headline\":\"\u795e\u7ecf\u7f51\u7edc\u57fa\u7840\",\"datePublished\":\"2024-12-05T15:13:47+00:00\",\"dateModified\":\"2024-12-05T15:35:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/\"},\"wordCount\":171,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/codeloveme.com\/#\/schema\/person\/81a4181217586206bf536360ebdbc737\"},\"keywords\":[\"SGD\",\"\u53cd\u5411\u4f20\u64ad\",\"\u635f\u5931\u51fd\u6570\",\"\u795e\u7ecf\u7f51\u7edc\",\"\u968f\u673a\u68af\u5ea6\u4e0b\u964d\"],\"articleSection\":[\"\u673a\u5668\u5b66\u4e60\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/\",\"url\":\"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/\",\"name\":\"\u795e\u7ecf\u7f51\u7edc\u57fa\u7840 - \u4ee3\u7801\u604b\u7231\u6307\u5357\",\"isPartOf\":{\"@id\":\"https:\/\/codeloveme.com\/#website\"},\"datePublished\":\"2024-12-05T15:13:47+00:00\",\"dateModified\":\"2024-12-05T15:35:12+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/codeloveme.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u795e\u7ecf\u7f51\u7edc\u57fa\u7840\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/codeloveme.com\/#website\",\"url\":\"https:\/\/codeloveme.com\/\",\"name\":\"\u4ee3\u7801\u604b\u7231\u6307\u5357\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/codeloveme.com\/#\/schema\/person\/81a4181217586206bf536360ebdbc737\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/codeloveme.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/codeloveme.com\/#\/schema\/person\/81a4181217586206bf536360ebdbc737\",\"name\":\"beizou\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/codeloveme.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/codeloveme.com\/wp-content\/uploads\/2024\/11\/\u540e\u85e4\u72ec.jpg\",\"contentUrl\":\"https:\/\/codeloveme.com\/wp-content\/uploads\/2024\/11\/\u540e\u85e4\u72ec.jpg\",\"width\":1080,\"height\":1060,\"caption\":\"beizou\"},\"logo\":{\"@id\":\"https:\/\/codeloveme.com\/#\/schema\/person\/image\/\"},\"description\":\"\u5f31\u70b9\uff1a\u7231\u60c5 \u4f18\u70b9\uff1a\u6ca1\u6709\u7231\u60c5\",\"sameAs\":[\"http:\/\/codeloveme.com\"],\"url\":\"https:\/\/codeloveme.com\/index.php\/author\/beizou\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u795e\u7ecf\u7f51\u7edc\u57fa\u7840 - \u4ee3\u7801\u604b\u7231\u6307\u5357","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/\u795e\u7ecf\u7f51\u7edc\u57fa\u7840\/","og_locale":"zh_CN","og_type":"article","og_title":"\u795e\u7ecf\u7f51\u7edc\u57fa\u7840 - \u4ee3\u7801\u604b\u7231\u6307\u5357","og_description":"\u673a\u5668\u5b66\u4e60\u5165\u95e8\u4e0e\u8fdb\u9636 \u672c\u6587\u6863\u8be6\u7ec6\u8bb2\u89e3\u4e86\u673a\u5668\u5b66\u4e60\u7684\u91cd\u8981\u6982\u5ff5\u548c\u6280\u672f\uff0c\u4ee5\u795e\u7ecf\u7f51\u7edc\u4e3a\u6838\u5fc3\uff0c\u7ed3\u5408\u5b9e\u8df5\u5de5\u5177TensorFlow\uff0c\u5e2e\u52a9\u8bfb\u8005\u6df1\u5165\u7406\u89e3 ...","og_url":"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/\u795e\u7ecf\u7f51\u7edc\u57fa\u7840\/","og_site_name":"\u4ee3\u7801\u604b\u7231\u6307\u5357","article_published_time":"2024-12-05T15:13:47+00:00","article_modified_time":"2024-12-05T15:35:12+00:00","author":"beizou","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"beizou","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/#article","isPartOf":{"@id":"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/"},"author":{"name":"beizou","@id":"https:\/\/codeloveme.com\/#\/schema\/person\/81a4181217586206bf536360ebdbc737"},"headline":"\u795e\u7ecf\u7f51\u7edc\u57fa\u7840","datePublished":"2024-12-05T15:13:47+00:00","dateModified":"2024-12-05T15:35:12+00:00","mainEntityOfPage":{"@id":"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/"},"wordCount":171,"commentCount":0,"publisher":{"@id":"https:\/\/codeloveme.com\/#\/schema\/person\/81a4181217586206bf536360ebdbc737"},"keywords":["SGD","\u53cd\u5411\u4f20\u64ad","\u635f\u5931\u51fd\u6570","\u795e\u7ecf\u7f51\u7edc","\u968f\u673a\u68af\u5ea6\u4e0b\u964d"],"articleSection":["\u673a\u5668\u5b66\u4e60"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/","url":"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/","name":"\u795e\u7ecf\u7f51\u7edc\u57fa\u7840 - \u4ee3\u7801\u604b\u7231\u6307\u5357","isPartOf":{"@id":"https:\/\/codeloveme.com\/#website"},"datePublished":"2024-12-05T15:13:47+00:00","dateModified":"2024-12-05T15:35:12+00:00","breadcrumb":{"@id":"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codeloveme.com\/index.php\/2024\/12\/05\/%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e5%9f%ba%e7%a1%80\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/codeloveme.com\/"},{"@type":"ListItem","position":2,"name":"\u795e\u7ecf\u7f51\u7edc\u57fa\u7840"}]},{"@type":"WebSite","@id":"https:\/\/codeloveme.com\/#website","url":"https:\/\/codeloveme.com\/","name":"\u4ee3\u7801\u604b\u7231\u6307\u5357","description":"","publisher":{"@id":"https:\/\/codeloveme.com\/#\/schema\/person\/81a4181217586206bf536360ebdbc737"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codeloveme.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/codeloveme.com\/#\/schema\/person\/81a4181217586206bf536360ebdbc737","name":"beizou","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/codeloveme.com\/#\/schema\/person\/image\/","url":"https:\/\/codeloveme.com\/wp-content\/uploads\/2024\/11\/\u540e\u85e4\u72ec.jpg","contentUrl":"https:\/\/codeloveme.com\/wp-content\/uploads\/2024\/11\/\u540e\u85e4\u72ec.jpg","width":1080,"height":1060,"caption":"beizou"},"logo":{"@id":"https:\/\/codeloveme.com\/#\/schema\/person\/image\/"},"description":"\u5f31\u70b9\uff1a\u7231\u60c5 \u4f18\u70b9\uff1a\u6ca1\u6709\u7231\u60c5","sameAs":["http:\/\/codeloveme.com"],"url":"https:\/\/codeloveme.com\/index.php\/author\/beizou\/"}]}},"_links":{"self":[{"href":"https:\/\/codeloveme.com\/index.php\/wp-json\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeloveme.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeloveme.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeloveme.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeloveme.com\/index.php\/wp-json\/wp\/v2\/comments?post=148"}],"version-history":[{"count":10,"href":"https:\/\/codeloveme.com\/index.php\/wp-json\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":169,"href":"https:\/\/codeloveme.com\/index.php\/wp-json\/wp\/v2\/posts\/148\/revisions\/169"}],"wp:attachment":[{"href":"https:\/\/codeloveme.com\/index.php\/wp-json\/wp\/v2\/media?parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeloveme.com\/index.php\/wp-json\/wp\/v2\/categories?post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeloveme.com\/index.php\/wp-json\/wp\/v2\/tags?post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}