{"id":85916,"date":"2026-07-28T00:24:47","date_gmt":"2026-07-27T16:24:47","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/85916.html"},"modified":"2026-07-28T00:24:47","modified_gmt":"2026-07-27T16:24:47","slug":"ai%e7%ad%91%e5%9f%ba%e5%bd%95-%e5%8d%b7%e7%a7%af%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c%e7%af%87","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/85916.html","title":{"rendered":"AI\u7b51\u57fa\u5f55\u2014\u2014\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7bc7"},"content":{"rendered":"<h2>\u524d\u8a00<\/h2>\n<p>\u524d\u9762\u51e0\u671f\u7684\u5185\u5bb9&#xff0c;\u6211\u4eec\u628a\u795e\u7ecf\u7f51\u7edc\u5927\u90e8\u5206\u77e5\u8bc6\u70b9\u5b66\u4e60\u4e86&#xff0c;\u8fd9\u4e00\u8bb2\u6211\u4eec\u5c06\u7528\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u4f5c\u4e3a\u4f8b\u5b50&#xff0c;\u5e26\u7740\u5927\u5bb6\u5206\u6790\u4ee3\u7801\u90e8\u5206\u8fd8\u6709\u5269\u4e0b\u7684\u539f\u7406\u90e8\u5206&#xff0c;\u6211\u76f8\u4fe1\u8fd9\u4e00\u8bb2\u4f1a\u5f88\u6709\u8da3&#xff01;\u6211\u4eec\u91c7\u7528\u7684\u6570\u636e\u96c6\u662fMNIST\u624b\u5199\u6570\u636e\u96c6&#xff1b;\u5982\u679c\u524d\u9762\u51e0\u671f\u7684\u5185\u5bb9\u6ca1\u6709\u770b\u7684&#xff0c;\u53ef\u4ee5\u70b9\u51fb\u4e0b\u9762\u7684\u94fe\u63a5&#xff01;\u89c9\u5f97\u5185\u5bb9\u6709\u5e2e\u52a9\u7684&#xff0c;\u5e0c\u671b\u53ef\u4ee5\u5173\u6ce8\u4e00\u4e0b\u535a\u4e3b&#xff01;\u535a\u4e3b\u5c06\u6301\u7eed\u66f4\u65b0\u4e13\u680f\u00a0AI\u7b51\u57fa\u5f55\u00a0<\/p>\n<p>AI\u7b51\u57fa\u5f55\u2014\u2014\u635f\u5931\u51fd\u6570\u7bc7-CSDN\u535a\u5ba2<\/p>\n<p>AI\u7b51\u57fa\u5f55\u2014\u2014\u6fc0\u6d3b\u51fd\u6570\u7bc7-CSDN\u535a\u5ba2<\/p>\n<p>AI\u7b51\u57fa\u5f55\u2014\u2014\u68af\u5ea6\u4e0b\u964d\u7bc7-CSDN\u535a\u5ba2<\/p>\n<p>AI\u7b51\u57fa\u5f55\u2014\u2014\u5377\u79ef\u7bc7-CSDN\u535a\u5ba2<\/p>\n<h2>\u5377\u79ef\u795e\u7ecf\u7f51\u7edc<\/h2>\n<p>\u5728\u6b63\u5f0f\u642d\u5efa\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u4e4b\u524d&#xff0c;\u6211\u4eec\u9996\u5148\u8981\u77e5\u9053&#xff0c;\u4e00\u4e2a\u795e\u7ecf\u7f51\u7edc\u7a76\u7adf\u53ef\u4ee5\u7528\u6765\u505a\u4ec0\u4e48&#xff1f;\u7b80\u5355\u7684\u8bf4\u795e\u7ecf\u7f51\u7edc\u7684\u4efb\u52a1\u5c31\u662f\u5b66\u4e60\u8f93\u5165\u548c\u8f93\u51fa\u4e4b\u95f4\u7684\u5173\u7cfb&#xff0c;\u6211\u4eec\u7ed9\u795e\u7ecf\u7f51\u7edc\u5927\u91cf\u5e26\u6709\u7b54\u6848\u7684\u6570\u636e&#xff0c;\u795e\u7ecf\u7f51\u7edc\u901a\u8fc7\u4e0d\u65ad\u8c03\u6574\u5185\u90e8\u53c2\u6570&#xff0c;\u9010\u6e10\u5b66\u4f1a\u5982\u4f55\u6839\u636e\u8f93\u5165\u5f97\u5230\u6b63\u786e\u8f93\u51fa&#xff1b;\u53ef\u4ee5\u7528\u4e8e\u5206\u7c7b\u4efb\u52a1&#xff0c;\u56de\u5f52\u4efb\u52a1&#xff0c;\u751f\u6210\u4efb\u52a1&#xff1b;<\/p>\n<h3>\u6570\u636e\u96c6<\/h3>\n<p>\u7f51\u7edc\u6216\u8005\u6a21\u578b\u90fd\u662f\u901a\u8fc7\u8bad\u7ec3\u624d\u62e5\u6709\u80fd\u529b\u7684&#xff0c;\u6240\u4ee5\u6211\u4eec\u7684\u6574\u4f53\u7684\u6d41\u7a0b\u5206\u4e3a\u8bad\u7ec3\u548c\u6d4b\u8bd5&#xff1b;\u8fd9\u4e9b\u8bad\u7ec3\u6216\u8005\u6d4b\u8bd5\u90fd\u9700\u8981\u6570\u636e&#xff0c;\u90a3\u4e48\u8fd9\u6837\u7684\u201c\u517b\u5206\u201d\u6211\u4eec\u79f0\u4e3a\u6570\u636e\u96c6&#xff1b;\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u770b\u51fa&#xff0c;\u8bad\u7ec3\u96c6\u5e94\u8be5\u662f\u5206\u4e3a\u6d4b\u8bd5\u96c6\u548c\u8bad\u7ec3\u96c6&#xff0c;\u5b9e\u9645\u4e0a\u8fd8\u53ef\u4ee5\u5206\u591a\u4e00\u4e2a\u9a8c\u8bc1\u96c6&#xff0c;\u540e\u9762\u6211\u4eec\u4f1a\u4e13\u95e8\u51fa\u4e00\u671f\u5185\u5bb9\u662f\u5173\u4e8e\u6570\u636e\u5982\u4f55\u642d\u5efa&#xff0c;\u5904\u7406\u7684\u6587\u7ae0&#xff0c;\u8fd9\u8fb9\u4e0d\u5c55\u5f00\u63cf\u8ff0<\/p>\n<p>\u6211\u4eec\u73b0\u5728\u4ecb\u7ecd\u4e00\u4e0b MNIST \u624b\u5199\u8bad\u7ec3\u96c6&#xff0c;7 \u4e07\u5f20 28\u00d728 \u50cf\u7d20\u7684\u624b\u5199\u6570\u5b57\u7070\u5ea6\u56fe&#xff0c;\u6bcf\u5f20\u56fe\u7247\u90fd\u6709\u5bf9\u5e94\u6807\u7b7e&#xff08;\u6807\u7b7e\u4e5f\u5c31\u662f\u6570\u636e\u5bf9\u5e94\u7684\u6b63\u786e\u7b54\u6848&#xff09;&#xff0c;\u53ef\u8c13\u662f\u662f\u6df1\u5ea6\u5b66\u4e60\u9886\u57df\u7684 &#034;Hello World&#034;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"700\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260727162445-6a67864d27447.png\" width=\"1373\" \/><\/p>\n<p>\u56fe\u7247\u5728\u8ba1\u7b97\u673a\u7684\u5f62\u72b6&#xff1a;[1,28,28]&#xff0c;\u5206\u522b\u662f\u901a\u9053\u6570\u548c\u957f\u5bbd&#xff0c;\u56e0\u4e3a\u8bad\u7ec3\u7684\u8fc7\u7a0b\u4e2d\u6211\u4eec\u662f\u6279\u6b21\u8f93\u5165&#xff0c;\u56e0\u6b64\u524d\u9762\u8fd8\u591a\u4e00\u4e2a B \u8fd9\u4e2a\u7ef4\u5ea6&#xff1b;<\/p>\n<h3>\u73af\u5883\u914d\u7f6e<\/h3>\n<p>\u914d\u7f6e\u73af\u5883\u662f\u4e00\u95e8\u57fa\u672c\u529f&#xff0c;\u4f46\u662f\u6709\u65f6\u5019\u786e\u5b9e\u4e5f\u662f\u975e\u5e38\u75db\u82e6&#xff1b;\u4f46\u662f\u8fd9\u4e2a\u5f88\u7b80\u5355\u914d\u7f6e&#xff0c;\u800c\u4e14\u6709\u4e86 AI \u4e4b\u540e\u57fa\u672c\u90fd\u662f\u5b83\u5e2e\u52a9\u6211\u4eec\u914d\u7f6e\u5373\u53ef&#xff1b;\u8fd9\u8fb9\u5efa\u8bae\u4e0b\u8f7d Anaconda&#xff0c;\u5e93\u7ba1\u7406\u5e73\u53f0&#xff1b;<\/p>\n<p>\u8fd9\u4e2a\u4efb\u52a1\u6211\u4eec\u53ea\u9700\u8981 PyTorch &#043; torchvision&#xff0c;\u6ca1\u6709\u5176\u4ed6\u7b2c\u4e09\u65b9\u5e93<\/p>\n<p>\u5b89\u88c5 PyTorch&#xff1a;\u63a8\u8350\u7528 Conda \u521b\u5efa\u72ec\u7acb\u73af\u5883&#xff0c;\u907f\u514d\u5305\u51b2\u7a81<\/p>\n<p># \u521b\u5efa\u73af\u5883&#xff08;Python 3.10&#043;&#xff09;<br \/>\nconda create -n cnn_mnist python&#061;3.11 -y<br \/>\nconda activate cnn_mnist<\/p>\n<p># \u5b89\u88c5 PyTorch&#xff08;GPU \u7248&#xff0c;CUDA 12.x&#xff09;<br \/>\npip install torch torchvision &#8211;index-url https:\/\/download.pytorch.org\/whl\/cu124<\/p>\n<p>\u901a\u5e38\u6211\u4eec\u90fd\u662f\u5728 GPU \u4e0a\u8bad\u7ec3\u7684&#xff0c;\u8bad\u7ec3\u901f\u5ea6\u4f1a\u6bd4 CPU \u5feb&#xff1b;<\/p>\n<p>\u6570\u636e\u96c6\u90e8\u5206\u4e0d\u7528\u4e13\u95e8\u53bb\u5b98\u7f51\u4e0b\u8f7d&#xff0c;\u4e00\u884c\u4ee3\u7801\u5c31\u53ef\u4ee5\u76f4\u63a5\u641e\u5b9a&#xff0c;\u81ea\u52a8\u4e0b\u8f7d\u5230\u672c\u5730\u7f13\u5b58<\/p>\n<p>torchvision.datasets.MNIST <\/p>\n<h3>\u6838\u5fc3\u6a21\u5757<\/h3>\n<p>\u5377\u79ef\u795e\u7ecf\u7f51\u7edc&#xff0c;\u5377\u79ef\u4e00\u5b9a\u662f\u5bf9\u5e94\u7684\u6838\u5fc3&#xff0c;\u6211\u4eec\u770b\u770b\u4ee3\u7801\u90e8\u5206(\u4ece\u4e0a\u5230\u4e0b\u5206\u6790&#xff0c;\u51e0\u4e4e\u9010\u884c\u5206\u6790)&#xff1a;<\/p>\n<p>class CNNNet(nn.Module):<\/p>\n<p>    def __init__(self, num_classes&#061;10):<br \/>\n        super().__init__()<\/p>\n<p>        self.conv1 &#061; nn.Conv2d(1, 32, kernel_size&#061;3, stride&#061;1, padding&#061;1)<br \/>\n        self.bn1 &#061; nn.BatchNorm2d(32)<\/p>\n<p>        self.conv2 &#061; nn.Conv2d(32, 64, kernel_size&#061;3, stride&#061;1, padding&#061;1)<br \/>\n        self.bn2 &#061; nn.BatchNorm2d(64)<\/p>\n<p>        self.conv3 &#061; nn.Conv2d(64, 128, kernel_size&#061;3, stride&#061;1, padding&#061;1)<br \/>\n        self.bn3 &#061; nn.BatchNorm2d(128)<\/p>\n<p>        self.pool &#061; nn.MaxPool2d(2, 2)<\/p>\n<p>        self.dropout &#061; nn.Dropout(0.3)<\/p>\n<p>        # 28 \u2192 pool \u2192 14 \u2192 pool \u2192 7 \u2192 pool \u2192 3 (int)<br \/>\n        # \u5b9e\u9645: 28\/2&#061;14 \u2192 14\/2&#061;7 \u2192 conv3 \u540e pool: 7\/2&#061;3&#xff0c;\u6240\u4ee5 128 * 3 * 3 &#061; 1152<br \/>\n        self.fc1 &#061; nn.Linear(128 * 3 * 3, 256)<br \/>\n        self.fc2 &#061; nn.Linear(256, num_classes)<\/p>\n<p>    def forward(self, x):<br \/>\n        x &#061; self.pool(F.relu(self.bn1(self.conv1(x))))   # (B,32,14,14)<br \/>\n        x &#061; self.pool(F.relu(self.bn2(self.conv2(x))))   # (B,64,7,7)<br \/>\n        x &#061; self.pool(F.relu(self.bn3(self.conv3(x))))   # (B,128,3,3)<\/p>\n<p>        x &#061; x.view(x.size(0), -1)                         # flatten<br \/>\n        x &#061; F.relu(self.fc1(self.dropout(x)))<br \/>\n        x &#061; self.fc2(x)<br \/>\n        return x <\/p>\n<p>\u6211\u4eec\u901a\u5e38\u662f\u91c7\u7528\u7c7b\u53bb\u5b9a\u4e49\u6a21\u5757&#xff0c;\u56e0\u4e3a\u5177\u6709\u7ee7\u627f\u7684\u529f\u80fd&#xff1b;\u50cf\u00a0nn.Module \u53ef\u4ee5\u7406\u89e3\u4e3a PyTorch \u63d0\u4f9b\u7684\u201c\u795e\u7ecf\u7f51\u7edc\u57fa\u7840\u6a21\u677f\u201d&#xff0c;\u6211\u4eec\u81ea\u5df1\u8bbe\u8ba1\u7f51\u7edc\u65f6&#xff0c;\u901a\u5e38\u90fd\u9700\u8981\u7ee7\u627f\u5b83&#xff1b;<\/p>\n<p>\u521d\u59cb\u5316\u51fd\u6570__init__ \u7528\u6765\u63d0\u524d\u5b9a\u4e49\u7f51\u7edc\u4e2d\u9700\u8981\u4f7f\u7528\u53d8\u91cf&#xff0c;\u56e0\u4e3a\u6211\u4eec\u6700\u540e\u662f\u505a\u5206\u7c7b&#xff0c;\u56e0\u6b64\u6211\u4eec\u8981\u6700\u540e\u7684\u7c7b\u522b\u6570&#xff0c;\u4e00\u5171\u6709 10 \u7c7b<\/p>\n<p>\u5377\u79ef\u5c42&#xff0c;\u53c2\u6570\u4ece\u5de6\u5230\u53f3\u5206\u522b\u8868\u793a\u8f93\u5165\u901a\u9053&#xff0c;\u8f93\u51fa\u901a\u9053&#xff0c;\u5377\u79ef\u6838&#xff0c;\u6b65\u957f&#xff0c;\u586b\u5145&#xff1b;\u6bd4\u5982\u7b2c\u4e00\u5c42\u5377\u79ef\u4e2d\u7684\u8f93\u51fa\u901a\u9053\u662f 32&#xff0c;\u8868\u793a\u7684\u662f\u6bcf\u4e2a\u5377\u79ef\u6838\u90fd\u53ef\u4ee5\u5c1d\u8bd5\u5bfb\u627e\u4e00\u79cd\u4e0d\u540c\u7684\u56fe\u50cf\u7279\u5f81&#xff0c;\u4f8b\u5982\u6a2a\u7ebf\u3001\u7ad6\u7ebf\u3001\u8fb9\u7f18\u3001\u62d0\u89d2\u7b49&#xff0c;32 \u4e2a\u5377\u79ef\u6838\u5904\u7406\u540e&#xff0c;\u5c31\u4f1a\u5f97\u5230 32 \u5f20\u7279\u5f81\u56fe&#xff1b;<\/p>\n<p>\u5f52\u4e00\u5316&#xff0c;\u6211\u4eec\u524d\u9762\u8bb2\u8fc7&#xff0c;\u8fd9\u4e2a\u5c31\u662f\u5bf9\u8f93\u51fa\u901a\u9053\u8fdb\u884c\u5f52\u4e00\u5316&#xff1b;\u539f\u56e0\u6211\u4eec\u89e3\u91ca\u4e00\u904d&#xff1a;\u5377\u79ef\u5c42\u63d0\u53d6\u51fa\u6765\u7684\u6570\u636e\u6709\u7684\u53ef\u80fd\u7279\u522b\u5927&#xff0c;\u6709\u7684\u53ef\u80fd\u7279\u522b\u5c0f&#xff0c;BatchNorm \u4f1a\u5bf9\u8fd9\u4e9b\u6570\u636e\u505a\u4e00\u6b21\u6574\u7406&#xff0c;\u907f\u514d\u6570\u636e\u5dee\u8ddd\u8fc7\u5927&#xff1b;<\/p>\n<p>\u6c60\u5316\u5c42&#xff0c;\u4fdd\u7559\u660e\u663e\u7279\u5f81&#xff0c;\u540c\u65f6\u7f29\u5c0f\u7279\u5f81\u56fe&#xff0c;\u51cf\u5c11\u540e\u7eed\u8ba1\u7b97\u91cf&#xff1b;\u8fd9\u8fb9\u91c7\u53d6\u7684\u7a97\u53e3\u5927\u5c0f\u662f 2 &#xff1b;<\/p>\n<p>\u8fd9\u8fb9\u6709\u4e00\u4e2a\u70b9\u6ce8\u610f\u4e00\u4e0b&#xff0c;\u540e\u8005\u5377\u79ef\u5c42\u7684\u8f93\u5165\u4e00\u5b9a\u548c\u524d\u8005\u5377\u79ef\u5c42\u7684\u8f93\u51fa\u7684\u901a\u9053\u6570\u5927\u5c0f\u4e00\u81f4&#xff0c;\u5426\u5219\u4f1a\u62a5\u9519&#xff1b;<\/p>\n<h4>Dropout<\/h4>\n<p>\u8fd9\u4e2a\u524d\u9762\u6211\u4eec\u6ca1\u6709\u8bf4\u8fc7&#xff0c;\u8fd9\u4e2a\u662f\u795e\u7ecf\u5143\u968f\u673a\u4e22\u5f03&#xff1b;\u5982\u679c\u6bcf\u6b21\u8bad\u7ec3\u90fd\u4f9d\u8d56\u56fa\u5b9a\u7684\u51e0\u4e2a\u795e\u7ecf\u5143&#xff0c;\u6a21\u578b\u53ef\u80fd\u53ea\u662f\u8bb0\u4f4f\u4e86\u8bad\u7ec3\u6570\u636e&#xff0c;\u800c\u6ca1\u6709\u771f\u6b63\u5b66\u4f1a\u8bc6\u522b\u6570\u5b57\u3002Dropout \u4f1a\u968f\u673a\u5173\u95ed\u4e00\u90e8\u5206\u795e\u7ecf\u5143&#xff0c;\u8feb\u4f7f\u7f51\u7edc\u5b66\u4e60\u66f4\u52a0\u7a33\u5b9a\u3001\u66f4\u52a0\u901a\u7528\u7684\u7279\u5f81&#xff1b;\u50cf\u4ee3\u7801\u91cc\u8868\u793a\u6709 30% \u7684\u795e\u7ecf\u5143\u4f1a\u88ab\u4e22\u5f03&#xff1b;<\/p>\n<h4>\u5168\u8fde\u63a5\u5c42<\/h4>\n<p>\u5168\u8fde\u63a5\u5c42\u8d1f\u8d23\u5c06\u5377\u79ef\u540e\u7684\u7279\u5f81\u7efc\u5408\u8d77\u6765&#xff0c;\u5c55\u5f00\u4e3a\u4e00\u884c&#xff0c;\u4f5c\u51fa\u6700\u7ec8\u5224\u65ad&#xff1b;<\/p>\n<p>self.fc2 &#061; nn.Linear(256, num_classes) <\/p>\n<p>\u8fd9\u4e2a\u5c31\u662f\u628a\u5377\u79ef\u5230\u7684\u6700\u540e\u7279\u5f81\u76f4\u63a5\u8f93\u51fa\u6210 10 \u4e2alogit\u5f97\u5206&#xff0c;\u54ea\u4e2a\u6570\u5b57\u5bf9\u5e94\u7684\u5206\u6570\u6700\u9ad8&#xff0c;\u6a21\u578b\u5c31\u66f4\u503e\u5411\u4e8e\u8ba4\u4e3a\u56fe\u7247\u4e2d\u5199\u7684\u662f\u54ea\u4e2a\u6570\u5b57&#xff1b;<\/p>\n<p>\u524d\u5411\u4f20\u64ad forward\u00a0\u5b9a\u4e49\u4e86\u6570\u636e\u8fdb\u5165\u7f51\u7edc\u4ee5\u540e&#xff0c;\u5177\u4f53\u6309\u7167\u4ec0\u4e48\u987a\u5e8f\u5411\u524d\u4f20\u64ad&#xff1b;\u6bd4\u5982\u8fd9\u8fb9\u5c31\u662f\u6309\u7167\u5377\u79ef&#xff0c;\u5f52\u4e00&#xff0c;\u6c60\u5316\u4f5c\u4e3a\u4e00\u4e2a block \u91cd\u590d 3 \u6b21\u4e3a\u987a\u5e8f&#xff1b;\u6700\u540e\u5c55\u5f00(\u4e3a\u5168\u8fde\u63a5\u505a\u51c6\u5907)&#xff0c;\u6700\u540e\u7ecf\u8fc7\u5168\u8fde\u63a5\u5f97\u5230\u5206\u6570&#xff1b;<\/p>\n<h3>\u8bad\u7ec3\u6a21\u5757<\/h3>\n<p>\u8bad\u7ec3\u6a21\u5757\u4efb\u52a1\u5c31\u662f\u8ba9\u6a21\u578b\u628a\u6574\u4e2a\u8bad\u7ec3\u96c6\u5b66\u4e60\u4e00\u904d&#xff0c;\u8fd9\u8fb9\u6709\u4e00\u4e2a\u6982\u5ff5\u53eb\u505a EPOCH&#xff0c;\u5f53\u8fd9\u4e2a\u503c\u4e3a 10 \u7684\u65f6\u5019&#xff0c;\u8868\u793a\u7684\u662f\u8fd9\u4e2a\u8bad\u7ec3\u96c6\u88ab\u7f51\u7edc\u770b\u4e86 10 \u6b21&#xff1b;<\/p>\n<p>def train_one_epoch(model, loader, optimizer, criterion, device):<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u4f7f\u7528\u6574\u4e2a\u8bad\u7ec3\u96c6\u8bad\u7ec3\u6a21\u578b\u4e00\u8f6e\u3002<\/p>\n<p>    \u8fd4\u56de&#xff1a;<br \/>\n        \u5e73\u5747\u8bad\u7ec3\u635f\u5931<br \/>\n        \u8bad\u7ec3\u96c6\u51c6\u786e\u7387<br \/>\n    &#034;&#034;&#034;<\/p>\n<p>    # \u5207\u6362\u5230\u8bad\u7ec3\u6a21\u5f0f<br \/>\n    # Dropout \u548c BatchNorm \u4f1a\u6309\u7167\u8bad\u7ec3\u72b6\u6001\u5de5\u4f5c<br \/>\n    model.train()<\/p>\n<p>    # \u8bb0\u5f55\u6574\u8f6e\u8bad\u7ec3\u7684\u603b\u635f\u5931\u3001\u6b63\u786e\u6570\u91cf\u548c\u6837\u672c\u603b\u6570<br \/>\n    total_loss &#061; 0<br \/>\n    correct &#061; 0<br \/>\n    total &#061; 0<\/p>\n<p>    # \u6bcf\u6b21\u4ece DataLoader \u4e2d\u53d6\u51fa\u4e00\u6279\u56fe\u7247\u548c\u6807\u7b7e<br \/>\n    for x, y in loader:<\/p>\n<p>        # \u5c06\u56fe\u7247\u548c\u6807\u7b7e\u79fb\u52a8\u5230 CPU \u6216 GPU<br \/>\n        x &#061; x.to(device)<br \/>\n        y &#061; y.to(device)<\/p>\n<p>        # \u6e05\u7a7a\u4e0a\u4e00\u6279\u6570\u636e\u8ba1\u7b97\u51fa\u7684\u68af\u5ea6<br \/>\n        optimizer.zero_grad()<\/p>\n<p>        # \u524d\u5411\u4f20\u64ad&#xff1a;\u6a21\u578b\u6839\u636e\u56fe\u7247\u8fdb\u884c\u9884\u6d4b<br \/>\n        out &#061; model(x)<\/p>\n<p>        # \u6bd4\u8f83\u9884\u6d4b\u7ed3\u679c\u548c\u771f\u5b9e\u6807\u7b7e&#xff0c;\u8ba1\u7b97\u635f\u5931<br \/>\n        loss &#061; criterion(out, y)<\/p>\n<p>        # \u53cd\u5411\u4f20\u64ad&#xff1a;\u8ba1\u7b97\u6bcf\u4e2a\u53c2\u6570\u7684\u68af\u5ea6<br \/>\n        loss.backward()<\/p>\n<p>        # \u6839\u636e\u68af\u5ea6\u66f4\u65b0\u6a21\u578b\u53c2\u6570<br \/>\n        optimizer.step()<\/p>\n<p>        # \u5f53\u524d loss \u662f\u8fd9\u4e00\u6279\u56fe\u7247\u7684\u5e73\u5747\u635f\u5931<br \/>\n        # \u4e58\u4ee5\u6279\u6b21\u5927\u5c0f&#xff0c;\u5f97\u5230\u8fd9\u4e00\u6279\u56fe\u7247\u7684\u635f\u5931\u603b\u548c<br \/>\n        total_loss &#043;&#061; loss.item() * x.size(0)<\/p>\n<p>        # \u627e\u5230\u6bcf\u5f20\u56fe\u7247\u5206\u6570\u6700\u9ad8\u7684\u7c7b\u522b&#xff0c;\u5e76\u7edf\u8ba1\u9884\u6d4b\u6b63\u786e\u6570\u91cf<br \/>\n        predictions &#061; out.argmax(dim&#061;1)<br \/>\n        correct &#043;&#061; (predictions &#061;&#061; y).sum().item()<\/p>\n<p>        # \u7d2f\u52a0\u5df2\u7ecf\u5904\u7406\u8fc7\u7684\u56fe\u7247\u6570\u91cf<br \/>\n        total &#043;&#061; x.size(0)<\/p>\n<p>    # \u8fd4\u56de\u6574\u4e2a\u8bad\u7ec3\u96c6\u7684\u5e73\u5747\u635f\u5931\u548c\u51c6\u786e\u7387<br \/>\n    average_loss &#061; total_loss \/ total<br \/>\n    accuracy &#061; 100.0 * correct \/ total<\/p>\n<p>    return average_loss, accuracy <\/p>\n<p>\u51fd\u6570\u63a5\u53d7\u4e86 5 \u4e2a\u53c2\u6570&#xff0c;\u5206\u522b\u662f\u6a21\u578b&#xff0c;\u52a0\u8f7d\u5668&#xff0c;\u4f18\u5316\u5668&#xff0c;\u635f\u5931\u51fd\u6570&#xff0c;\u8bbe\u5907&#xff1b;<\/p>\n<p>\u4e4b\u6240\u4ee5\u9700\u8981\u4e13\u95e8\u8bbe\u7f6e\u8bad\u7ec3\u6a21\u5f0f&#xff0c;\u662f\u56e0\u4e3a\u6a21\u578b\u4e2d\u6709\u4e00\u4e9b\u5c42\u5728\u8bad\u7ec3\u548c\u6d4b\u8bd5\u65f6\u8868\u73b0\u4e0d\u540c&#xff1b;\u4ee3\u7801\u7684\u6ce8\u91ca\u5199\u7684\u7b97\u662f\u6bd4\u8f83\u76f8\u4fe1\u7684&#xff0c;\u56e0\u6b64\u6211\u5c31\u7b80\u5355\u7684\u8bf4\u4e00\u4e0b&#xff1a;<\/p>\n<p>\u5faa\u73af\u7684 x\u3001y \u8868\u793a\u5c31\u662f\u56fe\u7247\u548c\u6807\u7b7e&#xff0c;\u6211\u4eec\u653e\u5230 GPU \u4e2d\u8fdb\u884c\u52a0\u8f7d&#xff0c;\u63a5\u7740\u5c31\u662f\u628a\u4e0a\u4e00\u8f6e\u7684\u68af\u5ea6\u6e05\u96f6&#xff0c;\u63a5\u7740\u5c31\u662f\u8fdb\u884c\u6a21\u578b\u9884\u6d4b&#xff0c;\u635f\u5931\u51fd\u6570\u5bf9\u6bd4\u540e\u8fdb\u884c\u53cd\u5411\u4f20\u64ad&#xff0c;\u6700\u540e\u7528\u4f18\u5316\u5668\u8ddf\u65b0\u53c2\u6570&#xff1b;\u7ed3\u5408\u6211\u4eec\u4e4b\u524d\u7684\u539f\u7406\u90e8\u5206&#xff0c;\u8fd9\u4e2a\u4ee3\u7801\u8fd8\u662f\u5f88\u6e05\u6670\u7406\u89e3\u7684&#xff1b;\u6700\u540e\u5c31\u662f\u5bf9\u7b80\u5355\u7684\u7ed3\u679c\u8fdb\u884c\u8ba1\u7b97&#xff1b;<\/p>\n<h3>\u63a8\u7406\u6a21\u5757<\/h3>\n<p>\u63a8\u7406\u6a21\u5757\u7684\u4efb\u52a1\u5c31\u662f\u770b\u6a21\u578b\u8bad\u7ec3\u7684\u6548\u679c\u600e\u4e48\u6837&#xff0c;\u4e00\u822c\u662f\u5728\u9a8c\u8bc1\u96c6\u6216\u8005\u662f\u6d4b\u8bd5\u96c6\u4e0a\u63a8\u7406&#xff1b;<\/p>\n<p>&#064;torch.no_grad()<br \/>\ndef evaluate(model, loader, criterion, device):<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u5728\u9a8c\u8bc1\u96c6\u6216\u6d4b\u8bd5\u96c6\u4e0a\u8bc4\u4f30\u6a21\u578b\u3002<\/p>\n<p>    \u8fd4\u56de&#xff1a;<br \/>\n        \u5e73\u5747\u635f\u5931<br \/>\n        \u5206\u7c7b\u51c6\u786e\u7387<br \/>\n    &#034;&#034;&#034;<\/p>\n<p>    # \u5c06\u6a21\u578b\u5207\u6362\u5230\u8bc4\u4f30\u6a21\u5f0f<br \/>\n    # Dropout \u505c\u6b62\u968f\u673a\u5173\u95ed\u795e\u7ecf\u5143<br \/>\n    # BatchNorm \u4f7f\u7528\u8bad\u7ec3\u65f6\u4fdd\u5b58\u7684\u7edf\u8ba1\u4fe1\u606f<br \/>\n    model.eval()<\/p>\n<p>    # \u8bb0\u5f55\u603b\u635f\u5931\u3001\u9884\u6d4b\u6b63\u786e\u6570\u91cf\u548c\u6837\u672c\u603b\u6570<br \/>\n    total_loss &#061; 0<br \/>\n    correct &#061; 0<br \/>\n    total &#061; 0<\/p>\n<p>    # \u6bcf\u6b21\u53d6\u51fa\u4e00\u6279\u56fe\u7247\u548c\u6807\u7b7e<br \/>\n    for x, y in loader:<\/p>\n<p>        # \u5c06\u6570\u636e\u79fb\u52a8\u5230 CPU \u6216 GPU<br \/>\n        x &#061; x.to(device)<br \/>\n        y &#061; y.to(device)<\/p>\n<p>        # \u524d\u5411\u4f20\u64ad&#xff0c;\u5f97\u5230\u5341\u4e2a\u7c7b\u522b\u5206\u6570<br \/>\n        out &#061; model(x)<\/p>\n<p>        # \u8ba1\u7b97\u5f53\u524d\u6279\u6b21\u7684\u635f\u5931<br \/>\n        loss &#061; criterion(out, y)<\/p>\n<p>        # \u7d2f\u8ba1\u5f53\u524d\u6279\u6b21\u7684\u635f\u5931\u603b\u548c<br \/>\n        total_loss &#043;&#061; loss.item() * x.size(0)<\/p>\n<p>        # \u627e\u5230\u6bcf\u5f20\u56fe\u7247\u5206\u6570\u6700\u9ad8\u7684\u7c7b\u522b<br \/>\n        predictions &#061; out.argmax(dim&#061;1)<\/p>\n<p>        # \u7edf\u8ba1\u9884\u6d4b\u6b63\u786e\u7684\u56fe\u7247\u6570\u91cf<br \/>\n        correct &#043;&#061; (predictions &#061;&#061; y).sum().item()<\/p>\n<p>        # \u7d2f\u8ba1\u5df2\u7ecf\u5904\u7406\u7684\u56fe\u7247\u6570\u91cf<br \/>\n        total &#043;&#061; x.size(0)<\/p>\n<p>    # \u8ba1\u7b97\u6574\u4e2a\u6570\u636e\u96c6\u7684\u5e73\u5747\u635f\u5931<br \/>\n    average_loss &#061; total_loss \/ total<\/p>\n<p>    # \u8ba1\u7b97\u6574\u4e2a\u6570\u636e\u96c6\u7684\u51c6\u786e\u7387<br \/>\n    accuracy &#061; 100.0 * correct \/ total<\/p>\n<p>    return average_loss, accuracy <\/p>\n<p>\u51fd\u6570\u63a5\u53d7\u4e86 4\u00a0\u4e2a\u53c2\u6570&#xff0c;\u5206\u522b\u662f\u6a21\u578b&#xff0c;\u52a0\u8f7d\u5668&#xff0c;\u635f\u5931\u51fd\u6570&#xff0c;\u8bbe\u5907<\/p>\n<p>\u4e0e\u8bad\u7ec3\u8fc7\u7a0b\u4e0d\u540c&#xff0c;\u8bc4\u4f30\u9636\u6bb5\u53ea\u9700\u8981\u8fdb\u884c\u524d\u5411\u4f20\u64ad&#xff0c;\u4e0d\u9700\u8981\u8ba1\u7b97\u68af\u5ea6&#xff0c;\u4e5f\u4e0d\u9700\u8981\u66f4\u65b0\u6a21\u578b\u53c2\u6570\u3002\u56e0\u6b64&#xff0c;\u6211\u4eec\u4f7f\u7528 &#064;torch.no_grad() \u5173\u95ed\u68af\u5ea6\u8bb0\u5f55&#xff0c;\u4ece\u800c\u51cf\u5c11\u8ba1\u7b97\u91cf\u548c\u663e\u5b58\u5360\u7528&#xff1b;\u5f53\u6240\u6709\u56fe\u7247\u6d4b\u8bd5\u5b8c\u6210\u540e&#xff0c;\u51fd\u6570\u4f1a\u8fd4\u56de\u6574\u4e2a\u6570\u636e\u96c6\u7684\u5e73\u5747\u635f\u5931\u548c\u51c6\u786e\u7387<\/p>\n<h3>\u4e3b\u51fd\u6570<\/h3>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    # \u53ea\u6709\u76f4\u63a5\u8fd0\u884c\u5f53\u524d\u6587\u4ef6\u65f6&#xff0c;\u4e0b\u9762\u7684\u4ee3\u7801\u624d\u4f1a\u6267\u884c<\/p>\n<p>    print(&#034;-&#034; * 50)<br \/>\n    print(&#034;CNN \u624b\u5199\u6570\u5b57\u8bc6\u522b (MNIST) \u8bad\u7ec3\u4e0e\u6d4b\u8bd5&#034;)<br \/>\n    print(&#034;-&#034; * 50)<\/p>\n<p>    # \u81ea\u52a8\u9009\u62e9 GPU \u6216 CPU<br \/>\n    device &#061; torch.device(<br \/>\n        &#034;cuda&#034; if torch.cuda.is_available() else &#034;cpu&#034;<br \/>\n    )<br \/>\n    print(f&#034;[Device] {device}&#034;)<\/p>\n<p>    # &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 1. \u51c6\u5907\u6570\u636e &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/p>\n<p>    # \u5b9a\u4e49\u56fe\u7247\u9884\u5904\u7406\u65b9\u5f0f<br \/>\n    transform &#061; transforms.Compose([<br \/>\n        # \u5c06\u56fe\u7247\u8f6c\u6362\u6210 PyTorch \u5f20\u91cf<br \/>\n        transforms.ToTensor(),<\/p>\n<p>        # \u5bf9 MNIST \u56fe\u7247\u8fdb\u884c\u6807\u51c6\u5316<br \/>\n        transforms.Normalize((0.1307,), (0.3081,))<br \/>\n    ])<\/p>\n<p>    # \u52a0\u8f7d MNIST \u8bad\u7ec3\u96c6<br \/>\n    train_ds &#061; datasets.MNIST(<br \/>\n        root&#061;&#034;data\/mnist&#034;,<br \/>\n        train&#061;True,<br \/>\n        download&#061;True,<br \/>\n        transform&#061;transform<br \/>\n    )<\/p>\n<p>    # \u52a0\u8f7d MNIST \u6d4b\u8bd5\u96c6<br \/>\n    test_ds &#061; datasets.MNIST(<br \/>\n        root&#061;&#034;data\/mnist&#034;,<br \/>\n        train&#061;False,<br \/>\n        download&#061;True,<br \/>\n        transform&#061;transform<br \/>\n    )<\/p>\n<p>    # \u6bcf\u6b21\u53d6\u51fa 128 \u5f20\u8bad\u7ec3\u56fe\u7247<br \/>\n    train_loader &#061; DataLoader(<br \/>\n        train_ds,<br \/>\n        batch_size&#061;128,<br \/>\n        shuffle&#061;True,<br \/>\n        num_workers&#061;2<br \/>\n    )<\/p>\n<p>    # \u6bcf\u6b21\u53d6\u51fa 128 \u5f20\u6d4b\u8bd5\u56fe\u7247<br \/>\n    test_loader &#061; DataLoader(<br \/>\n        test_ds,<br \/>\n        batch_size&#061;128,<br \/>\n        shuffle&#061;False,<br \/>\n        num_workers&#061;2<br \/>\n    )<\/p>\n<p>    print(<br \/>\n        f&#034;[Data] Train: {len(train_ds)} \u00b7 &#034;<br \/>\n        f&#034;Test: {len(test_ds)}&#034;<br \/>\n    )<\/p>\n<p>    # &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 2. \u521b\u5efa\u6a21\u578b &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/p>\n<p>    # \u521b\u5efa 10 \u5206\u7c7b\u7684\u5377\u79ef\u795e\u7ecf\u7f51\u7edc&#xff0c;\u5e76\u79fb\u52a8\u5230 CPU \u6216 GPU<br \/>\n    model &#061; CNNNet(num_classes&#061;10).to(device)<\/p>\n<p>    # \u7edf\u8ba1\u6a21\u578b\u53c2\u6570\u91cf<br \/>\n    total_params &#061; (<br \/>\n        sum(p.numel() for p in model.parameters()) \/ 1e6<br \/>\n    )<br \/>\n    print(f&#034;[Model] \u53c2\u6570\u91cf: {total_params:.2f}M&#034;)<\/p>\n<p>    # \u5b9a\u4e49\u4ea4\u53c9\u71b5\u635f\u5931\u51fd\u6570<br \/>\n    criterion &#061; nn.CrossEntropyLoss()<\/p>\n<p>    # \u5b9a\u4e49 Adam \u4f18\u5316\u5668&#xff0c;\u5b66\u4e60\u7387\u4e3a 0.001<br \/>\n    optimizer &#061; torch.optim.Adam(<br \/>\n        model.parameters(),<br \/>\n        lr&#061;0.001<br \/>\n    )<\/p>\n<p>    # &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 3. \u8bad\u7ec3\u6a21\u578b &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/p>\n<p>    # \u5c06\u6574\u4e2a\u8bad\u7ec3\u96c6\u5b66\u4e60 5 \u904d<br \/>\n    epochs &#061; 5<\/p>\n<p>    for epoch in range(1, epochs &#043; 1):<br \/>\n        # \u4f7f\u7528\u8bad\u7ec3\u96c6\u8bad\u7ec3\u4e00\u8f6e<br \/>\n        train_loss, train_acc &#061; train_one_epoch(<br \/>\n            model,<br \/>\n            train_loader,<br \/>\n            optimizer,<br \/>\n            criterion,<br \/>\n            device<br \/>\n        )<\/p>\n<p>        # \u4f7f\u7528\u6d4b\u8bd5\u96c6\u68c0\u67e5\u5f53\u524d\u6a21\u578b\u6548\u679c<br \/>\n        test_loss, test_acc &#061; evaluate(<br \/>\n            model,<br \/>\n            test_loader,<br \/>\n            criterion,<br \/>\n            device<br \/>\n        )<\/p>\n<p>        # \u6253\u5370\u5f53\u524d\u8f6e\u6b21\u7684\u8bad\u7ec3\u548c\u6d4b\u8bd5\u7ed3\u679c<br \/>\n        print(<br \/>\n            f&#034;Epoch {epoch:2d} | &#034;<br \/>\n            f&#034;Train Loss: {train_loss:.4f} &#034;<br \/>\n            f&#034;Acc: {train_acc:.2f}% | &#034;<br \/>\n            f&#034;Test Loss: {test_loss:.4f} &#034;<br \/>\n            f&#034;Acc: {test_acc:.2f}%&#034;<br \/>\n        )<\/p>\n<p>    # \u6253\u5370\u6700\u540e\u4e00\u8f6e\u7684\u6d4b\u8bd5\u51c6\u786e\u7387<br \/>\n    print(&#034;-&#034; * 50)<br \/>\n    print(f&#034;[Result] \u6700\u7ec8\u6d4b\u8bd5\u51c6\u786e\u7387: {test_acc:.2f}%&#034;)<br \/>\n    print(&#034;-&#034; * 50)<\/p>\n<p>    # &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 4. \u5355\u5f20\u56fe\u7247\u9884\u6d4b &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/p>\n<p>    # \u5c06\u6a21\u578b\u5207\u6362\u5230\u8bc4\u4f30\u6a21\u5f0f<br \/>\n    model.eval()<\/p>\n<p>    # \u53d6\u51fa\u6d4b\u8bd5\u96c6\u4e2d\u7684\u7b2c\u4e00\u5f20\u56fe\u7247\u548c\u771f\u5b9e\u6807\u7b7e<br \/>\n    sample, label &#061; test_ds[0]<\/p>\n<p>    # \u5355\u5f20\u9884\u6d4b\u4e0d\u9700\u8981\u8ba1\u7b97\u68af\u5ea6<br \/>\n    with torch.no_grad():<br \/>\n        # \u539f\u5f62\u72b6&#xff1a;[1, 28, 28]<br \/>\n        # \u589e\u52a0\u6279\u6b21\u7ef4\u5ea6\u540e&#xff1a;[1, 1, 28, 28]<br \/>\n        sample &#061; sample.unsqueeze(0).to(device)<\/p>\n<p>        # \u5f97\u5230\u6a21\u578b\u8f93\u51fa<br \/>\n        out &#061; model(sample)<\/p>\n<p>        # \u627e\u5230\u5206\u6570\u6700\u9ad8\u7684\u6570\u5b57\u7c7b\u522b<br \/>\n        pred &#061; out.argmax(dim&#061;1).item()<\/p>\n<p>    # \u8f93\u51fa\u771f\u5b9e\u7b54\u6848\u548c\u6a21\u578b\u9884\u6d4b\u7ed3\u679c<br \/>\n    result &#061; &#034;\u2713&#034; if pred &#061;&#061; label else &#034;\u2717&#034;<\/p>\n<p>    print(<br \/>\n        f&#034;[Inference] \u7b2c\u4e00\u5f20\u56fe: &#034;<br \/>\n        f&#034;\u771f\u5b9e&#061;{label}, \u9884\u6d4b&#061;{pred} {result}&#034;<br \/>\n    ) <\/p>\n<p>\u4ee3\u7801\u7684\u6ce8\u91ca\u8db3\u591f\u8be6\u7ec6&#xff0c;\u56e0\u6b64\u8fd9\u8fb9\u5c31\u8bf4\u51e0\u4e2a\u70b9&#xff1a;<\/p>\n<li>\u56fe\u7247\u6700\u540e\u8981\u53d8\u6210 tensor \u7684\u683c\u5f0f&#xff0c;\u56e0\u4e3a MNIST \u539f\u672c\u662f\u4e00\u5f20\u56fe\u7247&#xff0c;\u8ba1\u7b97\u673a\u9700\u8981\u5148\u628a\u5b83\u8f6c\u6362\u6210 PyTorch \u80fd\u591f\u5904\u7406\u7684\u5f20\u91cf&#xff1b;<\/li>\n<li>\u6570\u636e\u56e0\u4e3a\u662f\u4e00\u6279\u4e00\u6279\u5904\u7406\u7684&#xff0c;\u56e0\u6b64\u6211\u4eec\u8981\u7528\u52a0\u8f7d\u5668\u6253\u5305&#xff1b;<\/li>\n<li>\u5b50\u8fdb\u7a0b\u5e2e\u52a9\u8bfb\u53d6\u548c\u5904\u7406\u6570\u636e&#xff0c;\u4e00\u822c\u8fd9\u6837\u7684\u8bdd\u901f\u5ea6\u4f1a\u6bd4\u8f83\u5feb&#xff0c;\u540c\u65f6\u663e\u5361\u7684\u5360\u7528\u7387\u4f1a\u63d0\u9ad8<\/li>\n<h3>\u6548\u679c<\/h3>\n<p>\u7b80\u5355\u7684\u8fd0\u884c\u4e86\u4e00\u4e0b&#xff0c;\u53ef\u4ee5\u770b\u770b\u6548\u679c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"421\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260727162445-6a67864dbf8d7.png\" width=\"1108\" \/><\/p>\n<p>\u5b8c\u6574\u4ee3\u7801&#xff1a;<\/p>\n<p>import torch<br \/>\nimport torch.nn as nn<br \/>\nimport torch.nn.functional as F<br \/>\nfrom torch.utils.data import DataLoader<br \/>\nfrom torchvision import datasets, transforms<\/p>\n<p>class CNNNet(nn.Module):<br \/>\n    &#034;&#034;&#034;\u7b80\u5355\u7684 CNN&#xff0c;\u7528\u4e8e MNIST \u624b\u5199\u6570\u5b57\u5206\u7c7b&#xff08;28&#215;28 \u7070\u5ea6\u56fe \u2192 10 \u7c7b&#xff09;&#034;&#034;&#034;<br \/>\n    def __init__(self, num_classes&#061;10):<br \/>\n        super().__init__()<\/p>\n<p>        self.conv1 &#061; nn.Conv2d(1, 32, kernel_size&#061;3, stride&#061;1, padding&#061;1)<br \/>\n        self.bn1 &#061; nn.BatchNorm2d(32)<\/p>\n<p>        self.conv2 &#061; nn.Conv2d(32, 64, kernel_size&#061;3, stride&#061;1, padding&#061;1)<br \/>\n        self.bn2 &#061; nn.BatchNorm2d(64)<\/p>\n<p>        self.conv3 &#061; nn.Conv2d(64, 128, kernel_size&#061;3, stride&#061;1, padding&#061;1)<br \/>\n        self.bn3 &#061; nn.BatchNorm2d(128)<\/p>\n<p>        self.pool &#061; nn.MaxPool2d(2, 2)<\/p>\n<p>        self.dropout &#061; nn.Dropout(0.3)<\/p>\n<p>        # 28 \u2192 pool \u2192 14 \u2192 pool \u2192 7 \u2192 pool \u2192 3 (int)<br \/>\n        # \u5b9e\u9645: 28\/2&#061;14 \u2192 14\/2&#061;7 \u2192 conv3 \u540e pool: 7\/2&#061;3&#xff0c;\u6240\u4ee5 128 * 3 * 3 &#061; 1152<br \/>\n        self.fc1 &#061; nn.Linear(128 * 3 * 3, 256)<br \/>\n        self.fc2 &#061; nn.Linear(256, num_classes)<\/p>\n<p>    def forward(self, x):<br \/>\n        x &#061; self.pool(F.relu(self.bn1(self.conv1(x))))   # (B,32,14,14)<br \/>\n        x &#061; self.pool(F.relu(self.bn2(self.conv2(x))))   # (B,64,7,7)<br \/>\n        x &#061; self.pool(F.relu(self.bn3(self.conv3(x))))   # (B,128,3,3)<\/p>\n<p>        x &#061; x.view(x.size(0), -1)                         # flatten<br \/>\n        x &#061; F.relu(self.fc1(self.dropout(x)))<br \/>\n        x &#061; self.fc2(x)<br \/>\n        return x<\/p>\n<p>def train_one_epoch(model, loader, optimizer, criterion, device):<br \/>\n    model.train()<br \/>\n    total_loss, correct, total &#061; 0, 0, 0<br \/>\n    for x, y in loader:<br \/>\n        x, y &#061; x.to(device), y.to(device)<\/p>\n<p>        optimizer.zero_grad()<br \/>\n        out &#061; model(x)<br \/>\n        loss &#061; criterion(out, y)<br \/>\n        loss.backward()<br \/>\n        optimizer.step()<\/p>\n<p>        total_loss &#043;&#061; loss.item() * x.size(0)<br \/>\n        correct &#043;&#061; (out.argmax(1) &#061;&#061; y).sum().item()<br \/>\n        total &#043;&#061; x.size(0)<\/p>\n<p>    return total_loss \/ total, 100.0 * correct \/ total<\/p>\n<p>&#064;torch.no_grad()<br \/>\ndef evaluate(model, loader, criterion, device):<br \/>\n    model.eval()<br \/>\n    total_loss, correct, total &#061; 0, 0, 0<br \/>\n    for x, y in loader:<br \/>\n        x, y &#061; x.to(device), y.to(device)<br \/>\n        out &#061; model(x)<br \/>\n        loss &#061; criterion(out, y)<\/p>\n<p>        total_loss &#043;&#061; loss.item() * x.size(0)<br \/>\n        correct &#043;&#061; (out.argmax(1) &#061;&#061; y).sum().item()<br \/>\n        total &#043;&#061; x.size(0)<\/p>\n<p>    return total_loss \/ total, 100.0 * correct \/ total<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    print(&#034;-&#034; * 50)<br \/>\n    print(&#034;CNN \u624b\u5199\u6570\u5b57\u8bc6\u522b (MNIST) \u8bad\u7ec3\u4e0e\u6d4b\u8bd5&#034;)<br \/>\n    print(&#034;-&#034; * 50)<\/p>\n<p>    device &#061; torch.device(&#034;cuda&#034; if torch.cuda.is_available() else &#034;cpu&#034;)<br \/>\n    print(f&#034;[Device] {device}&#034;)<\/p>\n<p>    # &#8212;&#8212;&#8212;- \u6570\u636e &#8212;&#8212;&#8212;-<br \/>\n    transform &#061; transforms.Compose([<br \/>\n        transforms.ToTensor(),<br \/>\n        transforms.Normalize((0.1307,), (0.3081,))<br \/>\n    ])<\/p>\n<p>    train_ds &#061; datasets.MNIST(&#034;data\/mnist&#034;, train&#061;True, download&#061;True, transform&#061;transform)<br \/>\n    test_ds &#061; datasets.MNIST(&#034;data\/mnist&#034;, train&#061;False, download&#061;True, transform&#061;transform)<\/p>\n<p>    train_loader &#061; DataLoader(train_ds, batch_size&#061;128, shuffle&#061;True, num_workers&#061;2)<br \/>\n    test_loader &#061; DataLoader(test_ds, batch_size&#061;128, shuffle&#061;False, num_workers&#061;2)<\/p>\n<p>    print(f&#034;[Data] Train: {len(train_ds)} \u00b7 Test: {len(test_ds)}&#034;)<\/p>\n<p>    # &#8212;&#8212;&#8212;- \u6a21\u578b &#8212;&#8212;&#8212;-<br \/>\n    model &#061; CNNNet(num_classes&#061;10).to(device)<br \/>\n    total_params &#061; sum(p.numel() for p in model.parameters()) \/ 1e6<br \/>\n    print(f&#034;[Model] \u53c2\u6570\u91cf: {total_params:.2f}M&#034;)<\/p>\n<p>    criterion &#061; nn.CrossEntropyLoss()<br \/>\n    optimizer &#061; torch.optim.Adam(model.parameters(), lr&#061;1e-3)<\/p>\n<p>    # &#8212;&#8212;&#8212;- \u8bad\u7ec3 &#8212;&#8212;&#8212;-<br \/>\n    epochs &#061; 5<br \/>\n    for epoch in range(1, epochs &#043; 1):<br \/>\n        train_loss, train_acc &#061; train_one_epoch(model, train_loader, optimizer, criterion, device)<br \/>\n        test_loss, test_acc &#061; evaluate(model, test_loader, criterion, device)<br \/>\n        print(f&#034;Epoch {epoch:2d} | &#034;<br \/>\n              f&#034;Train Loss: {train_loss:.4f} Acc: {train_acc:.2f}% | &#034;<br \/>\n              f&#034;Test Loss: {test_loss:.4f} Acc: {test_acc:.2f}%&#034;)<\/p>\n<p>    print(&#034;-&#034; * 50)<br \/>\n    print(f&#034;[Result] \u6700\u7ec8\u6d4b\u8bd5\u51c6\u786e\u7387: {test_acc:.2f}%&#034;)<br \/>\n    print(&#034;-&#034; * 50)<\/p>\n<p>    # &#8212;&#8212;&#8212;- \u5355\u5f20\u9884\u6d4b\u9a8c\u8bc1 &#8212;&#8212;&#8212;-<br \/>\n    model.eval()<br \/>\n    sample, label &#061; test_ds[0]<br \/>\n    with torch.no_grad():<br \/>\n        pred &#061; model(sample.unsqueeze(0).to(device)).argmax(1).item()<br \/>\n    print(f&#034;[Inference] \u7b2c\u4e00\u5f20\u56fe: \u771f\u5b9e&#061;{label}, \u9884\u6d4b&#061;{pred} {&#039;\u2713&#039; if pred &#061;&#061; label else &#039;\u2717&#039;}&#034;)<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u56e0\u4e3a\u8fd9\u4e00\u5757\u7684\u4ee3\u7801\u6ce8\u91ca\u786e\u5b9e\u662f\u771f\u7684\u5f88\u8be6\u7ec6&#xff0c;\u5982\u679c\u6211\u518d\u7ee7\u7eed\u8d58\u8ff0\u786e\u5b9e\u663e\u5f97\u6bd4\u8f83\u65e0\u804a&#xff1b;\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4e00\u4e2a\u7b80\u5355\u7684\u795e\u7ecf\u7f51\u7edc\u7684\u8109\u7edc\u662f\u6bd4\u8f83\u7b80\u5355\u7684&#xff1b;\u5e0c\u671b\u5927\u5bb6\u53ef\u4ee5\u505a\u5230\u624b\u6413\u8fd9\u6837\u7684\u5377\u79ef\u7f51\u7edc&#xff0c;\u96be\u5ea6\u4e0d\u5927\u7684&#xff1b;\u6211\u4eec\u5728\u6700\u540e\u7ed3\u679c\u53ef\u4ee5\u53d1\u73b0\u5b9e\u9645\u4e0a\u8fd9\u6837\u7684\u4e00\u4e2a\u7b80\u5355\u7684\u7f51\u7edc\u53c2\u6570\u91cf\u8fd8\u662f\u5f88\u591a\u7684&#xff0c;\u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u770b\u770b\u6211\u4e4b\u524d\u4e3b\u9875\u7684mapping net&#xff0c;\u8fd9\u7bc7\u6587\u7ae0\u5c31\u662f\u6709\u5c11\u91cf\u7684\u53c2\u6570\u53bb\u903c\u8fd1\u5927\u53c2\u6570\u7684\u6548\u679c&#xff1b;<\/p>\n<p>AI\u7b51\u57fa\u5f55\u00a0\u7684\u4e13\u680f\u4f1a\u6162\u6162\u66f4\u65b0\u5b8c&#xff0c;\u5e26\u5927\u5bb6\u6709\u4f53\u7cfb\u7684\u7406\u89e3\u795e\u7ecf\u7f51\u7edc\u7684\u7531\u6765&#xff01;\u5236\u4f5c\u4e0d\u6613&#xff0c;\u559c\u6b22\u535a\u4e3b\u6587\u7ae0\u7684\u53ef\u4ee5\u70b9\u8d5e\u6536\u85cf\u5173\u6ce8&#xff0c;\u8fd9\u4e9b\u90fd\u662f\u6211\u6301\u7eed\u66f4\u65b0\u7684\u52a8\u529b&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00<br \/>\n\u524d\u9762\u51e0\u671f\u7684\u5185\u5bb9&#xff0c;\u6211\u4eec\u628a\u795e\u7ecf\u7f51\u7edc\u5927\u90e8\u5206\u77e5\u8bc6\u70b9\u5b66\u4e60\u4e86&#xff0c;\u8fd9\u4e00\u8bb2\u6211\u4eec\u5c06\u7528\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u4f5c\u4e3a\u4f8b\u5b50&#xff0c;\u5e26\u7740\u5927\u5bb6\u5206\u6790\u4ee3\u7801\u90e8\u5206\u8fd8\u6709\u5269\u4e0b\u7684\u539f\u7406\u90e8\u5206&#xff0c;\u6211\u76f8\u4fe1\u8fd9\u4e00\u8bb2\u4f1a\u5f88\u6709\u8da3&#xff01;\u6211\u4eec\u91c7\u7528\u7684\u6570\u636e\u96c6\u662fMNIST\u624b\u5199\u6570\u636e\u96c6&#xff1b;\u5982\u679c\u524d\u9762\u51e0\u671f\u7684\u5185\u5bb9\u6ca1\u6709\u770b\u7684&#xff0c;\u53ef\u4ee5\u70b9\u51fb\u4e0b\u9762\u7684\u94fe\u63a5&#xff01;\u89c9\u5f97\u5185\u5bb9\u6709\u5e2e\u52a9\u7684&#xff0c;\u5e0c\u671b\u53ef\u4ee5\u5173\u6ce8\u4e00\u4e0b\u535a\u4e3b&#xff01;\u535a\u4e3b\u5c06\u6301\u7eed\u66f4\u65b0\u4e13\u680f\u00a0AI\u7b51\u57fa\u5f55\u00a0<br \/>\nAI\u7b51\u57fa\u5f55\u2014\u2014\u635f\u5931\u51fd<\/p>\n","protected":false},"author":2,"featured_media":85914,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,152,50,2863,86],"topic":[],"class_list":["post-85916","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-python","tag-pytorch","tag-50","tag-2863","tag-86"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>AI\u7b51\u57fa\u5f55\u2014\u2014\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7bc7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/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:\/\/www.wsisp.com\/helps\/85916.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"AI\u7b51\u57fa\u5f55\u2014\u2014\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7bc7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u524d\u8a00 \u524d\u9762\u51e0\u671f\u7684\u5185\u5bb9&#xff0c;\u6211\u4eec\u628a\u795e\u7ecf\u7f51\u7edc\u5927\u90e8\u5206\u77e5\u8bc6\u70b9\u5b66\u4e60\u4e86&#xff0c;\u8fd9\u4e00\u8bb2\u6211\u4eec\u5c06\u7528\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u4f5c\u4e3a\u4f8b\u5b50&#xff0c;\u5e26\u7740\u5927\u5bb6\u5206\u6790\u4ee3\u7801\u90e8\u5206\u8fd8\u6709\u5269\u4e0b\u7684\u539f\u7406\u90e8\u5206&#xff0c;\u6211\u76f8\u4fe1\u8fd9\u4e00\u8bb2\u4f1a\u5f88\u6709\u8da3&#xff01;\u6211\u4eec\u91c7\u7528\u7684\u6570\u636e\u96c6\u662fMNIST\u624b\u5199\u6570\u636e\u96c6&#xff1b;\u5982\u679c\u524d\u9762\u51e0\u671f\u7684\u5185\u5bb9\u6ca1\u6709\u770b\u7684&#xff0c;\u53ef\u4ee5\u70b9\u51fb\u4e0b\u9762\u7684\u94fe\u63a5&#xff01;\u89c9\u5f97\u5185\u5bb9\u6709\u5e2e\u52a9\u7684&#xff0c;\u5e0c\u671b\u53ef\u4ee5\u5173\u6ce8\u4e00\u4e0b\u535a\u4e3b&#xff01;\u535a\u4e3b\u5c06\u6301\u7eed\u66f4\u65b0\u4e13\u680f\u00a0AI\u7b51\u57fa\u5f55\u00a0 AI\u7b51\u57fa\u5f55\u2014\u2014\u635f\u5931\u51fd\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/85916.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-27T16:24:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260727162445-6a67864d27447.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/85916.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/85916.html\",\"name\":\"AI\u7b51\u57fa\u5f55\u2014\u2014\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7bc7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-27T16:24:47+00:00\",\"dateModified\":\"2026-07-27T16:24:47+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/85916.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/85916.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/85916.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AI\u7b51\u57fa\u5f55\u2014\u2014\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7bc7\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"AI\u7b51\u57fa\u5f55\u2014\u2014\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7bc7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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:\/\/www.wsisp.com\/helps\/85916.html","og_locale":"zh_CN","og_type":"article","og_title":"AI\u7b51\u57fa\u5f55\u2014\u2014\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7bc7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u524d\u8a00 \u524d\u9762\u51e0\u671f\u7684\u5185\u5bb9&#xff0c;\u6211\u4eec\u628a\u795e\u7ecf\u7f51\u7edc\u5927\u90e8\u5206\u77e5\u8bc6\u70b9\u5b66\u4e60\u4e86&#xff0c;\u8fd9\u4e00\u8bb2\u6211\u4eec\u5c06\u7528\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u4f5c\u4e3a\u4f8b\u5b50&#xff0c;\u5e26\u7740\u5927\u5bb6\u5206\u6790\u4ee3\u7801\u90e8\u5206\u8fd8\u6709\u5269\u4e0b\u7684\u539f\u7406\u90e8\u5206&#xff0c;\u6211\u76f8\u4fe1\u8fd9\u4e00\u8bb2\u4f1a\u5f88\u6709\u8da3&#xff01;\u6211\u4eec\u91c7\u7528\u7684\u6570\u636e\u96c6\u662fMNIST\u624b\u5199\u6570\u636e\u96c6&#xff1b;\u5982\u679c\u524d\u9762\u51e0\u671f\u7684\u5185\u5bb9\u6ca1\u6709\u770b\u7684&#xff0c;\u53ef\u4ee5\u70b9\u51fb\u4e0b\u9762\u7684\u94fe\u63a5&#xff01;\u89c9\u5f97\u5185\u5bb9\u6709\u5e2e\u52a9\u7684&#xff0c;\u5e0c\u671b\u53ef\u4ee5\u5173\u6ce8\u4e00\u4e0b\u535a\u4e3b&#xff01;\u535a\u4e3b\u5c06\u6301\u7eed\u66f4\u65b0\u4e13\u680f\u00a0AI\u7b51\u57fa\u5f55\u00a0 AI\u7b51\u57fa\u5f55\u2014\u2014\u635f\u5931\u51fd","og_url":"https:\/\/www.wsisp.com\/helps\/85916.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-27T16:24:47+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260727162445-6a67864d27447.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/85916.html","url":"https:\/\/www.wsisp.com\/helps\/85916.html","name":"AI\u7b51\u57fa\u5f55\u2014\u2014\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7bc7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-27T16:24:47+00:00","dateModified":"2026-07-27T16:24:47+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/85916.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/85916.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/85916.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"AI\u7b51\u57fa\u5f55\u2014\u2014\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7bc7"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/85916","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=85916"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/85916\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/85914"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=85916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=85916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=85916"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=85916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}