{"id":44113,"date":"2025-06-17T01:43:27","date_gmt":"2025-06-16T17:43:27","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/44113.html"},"modified":"2025-06-17T01:43:27","modified_gmt":"2025-06-16T17:43:27","slug":"python%e6%89%93%e5%8d%a1%e7%ac%ac52%e5%a4%a9","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/44113.html","title":{"rendered":"python\u6253\u5361\u7b2c52\u5929"},"content":{"rendered":"<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u77e5\u8bc6\u70b9\u56de\u987e&#xff1a;<\/span><\/p>\n<li style=\"text-align:justify\"><span style=\"color:#333333\">\u968f\u673a\u79cd\u5b50<\/span><\/li>\n<li style=\"text-align:justify\"><span style=\"color:#333333\">\u5185\u53c2\u7684\u521d\u59cb\u5316<\/span><\/li>\n<li style=\"text-align:justify\"><span style=\"color:#333333\">\u795e\u7ecf\u7f51\u7edc\u8c03\u53c2\u6307\u5357<\/span>\n<li style=\"text-align:justify\"><span style=\"color:#333333\">\u53c2\u6570\u7684\u5206\u7c7b<\/span><\/li>\n<li style=\"text-align:justify\"><span style=\"color:#333333\">\u8c03\u53c2\u7684\u987a\u5e8f<\/span><\/li>\n<li style=\"text-align:justify\"><span style=\"color:#333333\">\u5404\u90e8\u5206\u53c2\u6570\u7684\u8c03\u6574\u5fc3\u5f97<\/span><\/li>\n<\/li>\n<p>\u00a0## \u968f\u673a\u79cd\u5b50<\/p>\n<p>import torch<br \/>\nimport torch.nn as nn<\/p>\n<p># \u5b9a\u4e49\u7b80\u5355\u7684\u7ebf\u6027\u6a21\u578b&#xff08;\u65e0\u9690\u85cf\u5c42&#xff09;<br \/>\n# \u8f93\u51652\u4e2a\u7eac\u5ea6\u7684\u6570\u636e&#xff0c;\u5f97\u52301\u4e2a\u7eac\u5ea6\u7684\u8f93\u51fa<br \/>\nclass SimpleNet(nn.Module):<br \/>\n    def __init__(self):<br \/>\n        super(SimpleNet, self).__init__()<br \/>\n        # \u7ebf\u6027\u5c42&#xff1a;2\u4e2a\u8f93\u5165\u7279\u5f81&#xff0c;1\u4e2a\u8f93\u51fa\u7279\u5f81<br \/>\n        self.linear &#061; nn.Linear(2, 1)<\/p>\n<p>    def forward(self, x):<br \/>\n        # \u524d\u5411\u4f20\u64ad&#xff1a;y &#061; w1*x1 &#043; w2*x2 &#043; b<br \/>\n        return self.linear(x)<\/p>\n<p># \u521b\u5efa\u6a21\u578b\u5b9e\u4f8b<br \/>\nmodel &#061; SimpleNet()<\/p>\n<p># \u67e5\u770b\u6a21\u578b\u53c2\u6570<br \/>\nprint(&#034;\u6a21\u578b\u53c2\u6570:&#034;)<br \/>\nfor name, param in model.named_parameters():<br \/>\n    print(f&#034;{name}: {param.data}&#034;) <\/p>\n<p>### \u968f\u673a\u79cd\u5b50<\/p>\n<p>\u4e4b\u524d\u6211\u4eec\u8bf4\u8fc7&#xff0c;torch\u4e2d\u5f88\u591a\u573a\u666f\u90fd\u4f1a\u5b58\u5728\u968f\u673a\u6570<\/p>\n<p>1. \u6743\u91cd\u3001\u504f\u7f6e\u7684\u968f\u673a\u521d\u59cb\u5316<\/p>\n<p>2. \u6570\u636e\u52a0\u8f7d&#xff08;shuffling\u6253\u4e71&#xff09;\u4e0e\u6279\u6b21\u52a0\u8f7d&#xff08;\u968f\u673a\u6279\u6b21\u52a0\u8f7d&#xff09;\u7684\u968f\u673a\u5316<\/p>\n<p>3. \u6570\u636e\u589e\u5f3a\u7684\u968f\u673a\u5316&#xff08;\u968f\u673a\u65cb\u8f6c\u3001\u7f29\u653e\u3001\u5e73\u79fb\u3001\u88c1\u526a\u7b49&#xff09;<\/p>\n<p>4. \u968f\u673a\u6b63\u5219\u5316dropout<\/p>\n<p>5. \u4f18\u5316\u5668\u4e2d\u7684\u968f\u673a\u6027<\/p>\n<p>import torch<br \/>\nimport numpy as np<br \/>\nimport os<br \/>\nimport random<\/p>\n<p># \u5168\u5c40\u968f\u673a\u51fd\u6570<br \/>\ndef set_seed(seed&#061;42, deterministic&#061;True):<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u8bbe\u7f6e\u5168\u5c40\u968f\u673a\u79cd\u5b50&#xff0c;\u786e\u4fdd\u5b9e\u9a8c\u53ef\u91cd\u590d\u6027<\/p>\n<p>    \u53c2\u6570:<br \/>\n        seed: \u968f\u673a\u79cd\u5b50\u503c&#xff0c;\u9ed8\u8ba4\u4e3a42<br \/>\n        deterministic: \u662f\u5426\u542f\u7528\u786e\u5b9a\u6027\u6a21\u5f0f&#xff0c;\u9ed8\u8ba4\u4e3aTrue<br \/>\n    &#034;&#034;&#034;<br \/>\n    # \u8bbe\u7f6ePython\u7684\u968f\u673a\u79cd\u5b50<br \/>\n    random.seed(seed)<br \/>\n    os.environ[&#039;PYTHONHASHSEED&#039;] &#061; str(seed) # \u786e\u4fddPython\u54c8\u5e0c\u51fd\u6570\u7684\u968f\u673a\u6027\u4e00\u81f4&#xff0c;\u6bd4\u5982\u5b57\u5178\u3001\u96c6\u5408\u7b49\u65e0\u5e8f<\/p>\n<p>    # \u8bbe\u7f6eNumPy\u7684\u968f\u673a\u79cd\u5b50<br \/>\n    np.random.seed(seed)<\/p>\n<p>    # \u8bbe\u7f6ePyTorch\u7684\u968f\u673a\u79cd\u5b50<br \/>\n    torch.manual_seed(seed) # \u8bbe\u7f6eCPU\u4e0a\u7684\u968f\u673a\u79cd\u5b50<br \/>\n    torch.cuda.manual_seed(seed) # \u8bbe\u7f6eGPU\u4e0a\u7684\u968f\u673a\u79cd\u5b50<br \/>\n    torch.cuda.manual_seed_all(seed)  # \u5982\u679c\u4f7f\u7528\u591aGPU<\/p>\n<p>    # \u914d\u7f6ecuDNN\u4ee5\u786e\u4fdd\u7ed3\u679c\u53ef\u91cd\u590d<br \/>\n    if deterministic:<br \/>\n        torch.backends.cudnn.deterministic &#061; True<br \/>\n        torch.backends.cudnn.benchmark &#061; False<\/p>\n<p># \u8bbe\u7f6e\u968f\u673a\u79cd\u5b50<br \/>\nset_seed(42) <\/p>\n<p>\u00a0<\/p>\n<p>\u4ecb\u7ecd\u4e00\u4e0b\u8fd9\u4e2a\u968f\u673a\u51fd\u6570\u7684\u51e0\u4e2a\u90e8\u5206<\/p>\n<p>1. python\u7684\u968f\u673a\u79cd\u5b50&#xff0c;\u9700\u8981\u786e\u4fddrandom\u6a21\u5757\u3001\u4ee5\u53ca\u4e00\u4e9b\u65e0\u5e8f\u6570\u636e\u7ed3\u6784\u7684\u4e00\u81f4\u6027<\/p>\n<p>2. numpy\u7684\u968f\u673a\u79cd\u5b50&#xff0c;\u63a7\u5236\u6570\u7ec4\u7684\u968f\u673a\u6027<\/p>\n<p>3. torch\u7684\u968f\u673a\u79cd\u5b50&#xff0c;\u63a7\u5236\u5f20\u91cf\u7684\u968f\u673a\u6027&#xff0c;\u5728cpu\u548cgpu\u4e0a\u5747\u9002\u7528<\/p>\n<p>4. cuDNN&#xff08;CUDA Deep Neural Network library &#xff0c;CUDA \u6df1\u5ea6\u795e\u7ecf\u7f51\u7edc\u5e93&#xff09;\u7684\u968f\u673a\u6027&#xff0c;\u9488\u5bf9cuda\u7684\u4f18\u5316\u7b97\u6cd5\u7684\u968f\u673a\u6027<\/p>\n<\/p>\n<p>\u4e0a\u8ff0\u79cd\u5b50\u53ef\u4ee5\u5904\u7406\u5927\u90e8\u5206\u573a\u666f&#xff0c;\u5b9e\u9645\u4e0a\u8fd8\u6709\u5c11\u90e8\u5206\u573a\u666f&#xff08;\u5177\u4f53\u7684\u51fd\u6570&#xff09;\u53ef\u80fd\u9700\u8981\u81ea\u884c\u8bbe\u7f6e\u5176\u5bf9\u5e94\u7684\u968f\u673a\u79cd\u5b50\u3002<\/p>\n<p>\u65e5\u5e38\u4f7f\u7528\u4e2d&#xff0c;\u5728\u6700\u5f00\u59cb\u8c03\u7528\u8fd9\u90e8\u5206\u5df2\u7ecf\u8db3\u591f<\/p>\n<p>\u6211\u4eec\u90fd\u77e5\u9053&#xff0c;\u795e\u7ecf\u7f51\u7edc\u7684\u6743\u91cd\u9700\u8981\u901a\u8fc7\u53cd\u5411\u4f20\u64ad\u6765\u5b9e\u73b0\u66f4\u65b0&#xff0c;\u90a3\u4e48\u6700\u5f00\u59cb\u80af\u5b9a\u9700\u8981\u4e00\u4e2a\u503c\u624d\u53ef\u4ee5\u66f4\u65b0\u53c2\u6570<\/p>\n<\/p>\n<p>\u8fd9\u4e2a\u6700\u5f00\u59cb\u7684\u503c\u662f\u4ec0\u4e48\u6837\u5b50\u7684\u5462&#xff1f;\u5982\u679c\u6070\u597d\u4ed6\u4eec\u5c31\u662f\u90a3\u4e00\u7ec4\u6700\u4f73\u7684\u53c2\u6570\u9644\u8fd1\u7684\u6570&#xff0c;\u90a3\u4e48\u53ef\u80fd\u6211\u8bad\u7ec3\u7684\u901f\u5ea6\u4f1a\u5feb\u5f88\u591a<\/p>\n<\/p>\n<p>\u4e3a\u4e86\u641e\u61c2\u8fd9\u4e2a\u95ee\u9898&#xff0c;\u5e2e\u52a9\u6211\u4eec\u771f\u6b63\u7406\u89e3\u795e\u7ecf\u7f51\u7edc\u53c2\u6570\u7684\u672c\u8d28&#xff0c;\u6211\u4eec\u9700\u8981\u6df1\u5165\u5256\u6790\u4e00\u4e0b&#xff0c;\u5173\u6ce8\u4ee5\u4e0b\u51e0\u4e2a\u95ee\u9898&#xff1a;<\/p>\n<p>1. \u521d\u59cb\u503c\u7684\u533a\u95f4<\/p>\n<p>2. \u521d\u59cb\u503c\u7684\u5206\u5e03<\/p>\n<p>3. \u521d\u59cb\u503c\u662f\u591a\u5c11<\/p>\n<p>\u5148\u4ecb\u7ecd\u4e00\u4e0b\u795e\u7ecf\u7f51\u7edc\u7684\u5bf9\u79f0\u6027&#8212;-\u4e3a\u4ec0\u4e48\u795e\u7ecf\u5143\u7684\u521d\u59cb\u503c\u9700\u8981\u5404\u4e0d\u76f8\u540c&#xff1f;<\/p>\n<\/p>\n<p>\u672c\u8d28\u795e\u7ecf\u7f51\u7edc\u7684\u6bcf\u4e00\u4e2a\u795e\u7ecf\u5143\u90fd\u662f\u5728\u505a\u4e00\u4ef6\u4e8b&#xff0c;\u8f93\u5165x&#8211;\u8f93\u51fay\u7684\u6620\u5c04&#xff0c;\u8fd9\u91cc\u6211\u4eec\u5047\u8bbe\u6fc0\u6d3b\u51fd\u6570\u662fsigmoid<\/p>\n<\/p>\n<p>y&#061;sigmoid&#xff08;wx&#043;b&#xff09;&#xff0c;\u5176\u4e2dw\u662f\u8fde\u63a5\u5230\u8be5\u795e\u7ecf\u5143\u7684\u6743\u91cd\u77e9\u9635&#xff0c;b\u662f\u8be5\u795e\u7ecf\u5143\u7684\u504f\u7f6e<\/p>\n<\/p>\n<p>\u5982\u679c\u6240\u6709\u795e\u7ecf\u5143\u7684\u6743\u91cd\u548c\u504f\u7f6e\u90fd\u4e00\u6837&#xff0c;<\/p>\n<p>1. \u5982\u679c\u90fd\u4e3a0&#xff0c;\u90a3\u4e48\u6240\u6709\u795e\u7ecf\u5143\u7684\u8f93\u51fa\u90fd\u4e00\u81f4&#xff0c;\u65e0\u6cd5\u533a\u5206\u4e0d\u540c\u7279\u5f81&#xff1b;\u6b64\u65f6\u53cd\u5411\u4f20\u64ad\u7684\u65f6\u5019\u68af\u5ea6\u90fd\u4e00\u6837&#xff0c;\u65e0\u6cd5\u5b66\u4e60\u5230\u7279\u5f81&#xff0c;\u66f4\u65b0\u540e\u7684\u6743\u91cd\u4e5f\u5b8c\u5168\u4e00\u81f4\u3002<\/p>\n<p>2. \u5982\u679c\u4e0d\u4e3a0&#xff0c;\u540c\u4e0a<\/p>\n<\/p>\n<p>\u6240\u4ee5&#xff0c;\u65e0\u8bba\u521d\u59cb\u503c\u662f\u5426\u4e3a 0&#xff0c;\u76f8\u540c\u7684\u6743\u91cd\u548c\u504f\u7f6e\u4f1a\u5bfc\u81f4\u795e\u7ecf\u5143\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u59cb\u7ec8\u4fdd\u6301\u540c\u6b65\u3002&#xff08;\u56e0\u4e3a\u795e\u7ecf\u7f51\u7edc\u7684\u524d\u5411\u4f20\u64ad\u662f\u5bfc\u81f4\u6743\u91cd\u7684\u6570\u5b66\u542b\u4e49\u662f\u5b8c\u5168\u5bf9\u79f0\u7684&#xff09;\u5177\u4f53\u8868\u73b0\u4e3a&#xff1a;<\/p>\n<\/p>\n<p>\u540c\u4e00\u5c42\u7684\u795e\u7ecf\u5143\u76f8\u5f53\u4e8e\u5728\u505a\u5b8c\u5168\u76f8\u540c\u7684\u8ba1\u7b97&#xff0c;\u65e0\u8bba\u8f93\u5165\u5982\u4f55\u53d8\u5316&#xff0c;\u5b83\u4eec\u7684\u8f93\u51fa\u6a21\u5f0f\u59cb\u7ec8\u4e00\u81f4\u3002\u4f8b\u5982&#xff1a;\u8f93\u5165\u56fe\u50cf\u4e2d\u4e0d\u540c\u4f4d\u7f6e\u7684\u8fb9\u7f18\u7279\u5f81&#xff0c;\u4f1a\u88ab\u8fd9\u4e9b\u795e\u7ecf\u5143\u4ee5\u76f8\u540c\u65b9\u5f0f\u5904\u7406&#xff0c;\u65e0\u6cd5\u5b66\u4e60\u5230\u7a7a\u95f4\u5206\u5e03\u7684\u5dee\u5f02\u3002<\/p>\n<\/p>\n<p>\u6240\u4ee5\u9700\u8981\u968f\u673a\u521d\u59cb\u5316&#xff0c;\u8ba9\u521d\u59cb\u7684\u795e\u7ecf\u5143\u5404\u4e0d\u76f8\u540c\u3002\u5373\u4f7f\u521d\u59cb\u5dee\u5f02\u5f88\u5c0f&#xff0c;\u4f46\u6fc0\u6d3b\u51fd\u6570\u7684\u975e\u7ebf\u6027&#xff08;\u68af\u5ea6\u4e0d\u540c&#xff09;\u4f1a\u653e\u5927\u8fd9\u79cd\u5dee\u5f02\u3002\u968f\u7740\u8bad\u7ec3\u8fdb\u884c&#xff0c;\u8fd9\u79cd\u5206\u6b67\u4f1a\u9010\u6e10\u6269\u5927&#xff0c;\u6700\u7ec8\u5f62\u6210\u529f\u80fd\u5404\u5f02\u7684\u795e\u7ecf\u5143\u3002<\/p>\n<p>\u6240\u4ee5&#xff0c;\u660e\u767d\u4e86\u4e0a\u8ff0\u601d\u60f3&#xff0c;\u4f60\u5c31\u77e5\u9053\u521d\u59cb\u503c\u4e4b\u524d\u7684\u5dee\u5f02\u5e76\u4e0d\u9700\u8981\u5de8\u5927\u3002<\/p>\n<p>\u4e8b\u5b9e\u4e0a&#xff0c;\u795e\u7ecf\u7f51\u7edc\u7684\u521d\u59cb\u6743\u91cd\u901a\u5e38\u8bbe\u7f6e\u5728\u63a5\u8fd1 0 \u7684\u5c0f\u8303\u56f4\u5185&#xff08;\u5982 [-0.1, 0.1] \u6216 [-0.01, 0.01]&#xff09;&#xff0c;\u6216\u901a\u8fc7\u7279\u5b9a\u5206\u5e03&#xff08;\u5982\u6b63\u6001\u5206\u5e03\u3001\u5747\u5300\u5206\u5e03&#xff09;\u751f\u6210\u5c0f\u503c&#xff0c;\u6709\u5f88\u591a\u597d\u5904 ![image.png](attachment:image.png)<\/p>\n<p>\u907f\u514d\u68af\u5ea6\u6d88\u5931 \/ \u7206\u70b8&#xff1a; \u4ee5 sigmoid \u6fc0\u6d3b\u51fd\u6570\u4e3a\u4f8b&#xff0c;\u5176\u5bfc\u6570\u5728\u8f93\u5165\u7edd\u5bf9\u503c\u8f83\u5927\u65f6\u8d8b\u8fd1\u4e8e 0&#xff08;\u5982 | x|&gt;5 \u65f6&#xff0c;\u5bfc\u6570\u22480&#xff09;\u3002\u82e5\u521d\u59cb\u6743\u91cd\u8fc7\u5927&#xff0c;\u8f93\u5165 x&#061;w\u30fbinput&#043;b \u53ef\u80fd\u5bfc\u81f4\u6fc0\u6d3b\u51fd\u6570\u8fdb\u5165 \u201c\u9971\u548c\u533a\u201d&#xff0c;\u53cd\u5411\u4f20\u64ad\u65f6\u68af\u5ea6\u63a5\u8fd1 0&#xff0c;\u6743\u91cd\u66f4\u65b0\u7f13\u6162&#xff08;\u68af\u5ea6\u6d88\u5931&#xff09;\u3002 \u7c7b\u6bd4&#xff1a;\u82e5\u521d\u59cb\u6743\u91cd\u662f \u201c\u5927\u503c\u201d&#xff0c;\u76f8\u5f53\u4e8e\u8ba9\u795e\u7ecf\u5143\u4e00\u5f00\u59cb\u5c31\u8fdb\u5165 \u201c\u6781\u7aef\u72b6\u6001\u201d&#xff0c;\u5931\u53bb\u5bf9\u8f93\u5165\u53d8\u5316\u7684\u654f\u611f\u5ea6\u3002<\/p>\n<p>\u5982\u679c\u68af\u5ea6\u76f8\u5bf9\u8f83\u5927&#xff0c;\u5c31\u53ef\u4ee5\u8ba9\u53d8\u5316\u5904\u4e8esigmoid\u51fd\u6570\u7684\u975e\u9971\u548c\u533a<\/p>\n<p>\u6240\u4ee5\u5176\u5b9e\u5bf9\u4e8e\u4e0d\u540c\u7684\u6fc0\u6d3b\u51fd\u6570 &#xff0c;\u90fd\u6709\u5bf9\u5e94\u7684\u9971\u548c\u533a\u548c\u975e\u9971\u548c\u533a&#xff0c;\u6df1\u5c42\u7f51\u7edc\u4e2d&#xff0c;\u9971\u548c\u533a\u4f1a\u4f7f\u68af\u5ea6\u5728\u53cd\u5411\u4f20\u64ad\u65f6\u9010\u5c42\u8870\u51cf&#xff0c;\u5e95\u5c42\u53c2\u6570\u51e0\u4e4e\u65e0\u6cd5\u66f4\u65b0&#xff1b;<\/p>\n<p>\u6ce8\u610f\u4e0b&#xff0c;\u8fd9\u91cc\u662fwx\u540e\u624d\u4f1a\u7ecf\u8fc7\u6fc0\u6d3b\u51fd\u6570&#xff0c;\u662f\u591a\u4e2a\u6743\u91cd\u5370\u8c61\u7684\u7ed3\u679c&#xff0c;\u4e0d\u662f\u6536\u5230\u5355\u4e2a\u6743\u91cd\u51b3\u5b9a\u7684&#xff0c;\u6240\u4ee5\u5355\u4e2a\u6743\u91cd\u53ef\u4ee5\u53d6\u8d1f\u6570&#xff0c;\u4f46\u662f\u5982\u679c\u6c42\u548c\u540e\u4ecd\u7136\u5c0f\u4e8e0&#xff0c;\u90a3\u4e48\u8f93\u51fa\u4f1a\u4e3a0 \u00a0<\/p>\n<p>import torch<br \/>\nimport torch.nn as nn<br \/>\nimport matplotlib.pyplot as plt<br \/>\nimport numpy as np<\/p>\n<p># \u8bbe\u7f6e\u8bbe\u5907<br \/>\ndevice &#061; torch.device(&#034;cuda:0&#034; if torch.cuda.is_available() else &#034;cpu&#034;)<\/p>\n<p># \u5b9a\u4e49\u6781\u7b80CNN\u6a21\u578b&#xff08;\u4ec51\u4e2a\u5377\u79ef\u5c42&#043;1\u4e2a\u5168\u8fde\u63a5\u5c42&#xff09;<br \/>\nclass SimpleCNN(nn.Module):<br \/>\n    def __init__(self):<br \/>\n        super(SimpleCNN, self).__init__()<\/p>\n<p>        # \u5377\u79ef\u5c42&#xff1a;\u8f93\u51653\u901a\u9053&#xff0c;\u8f93\u51fa16\u901a\u9053&#xff0c;\u5377\u79ef\u68383&#215;3<br \/>\n        self.conv1 &#061; nn.Conv2d(3, 16, kernel_size&#061;3, padding&#061;1)<\/p>\n<p>        # \u6c60\u5316\u5c42&#xff1a;2&#215;2\u7a97\u53e3&#xff0c;\u5c3a\u5bf8\u51cf\u534a<br \/>\n        self.pool &#061; nn.MaxPool2d(kernel_size&#061;2)<\/p>\n<p>        # \u5168\u8fde\u63a5\u5c42&#xff1a;\u5c55\u5e73\u540e\u8fde\u63a5\u523010\u4e2a\u8f93\u51fa&#xff08;\u5bf9\u5e9410\u4e2a\u7c7b\u522b&#xff09;<br \/>\n        # \u8f93\u5165\u5c3a\u5bf8&#xff1a;16\u901a\u9053 \u00d7 16&#215;16\u7279\u5f81\u56fe &#061; 16\u00d716\u00d716&#061;4096<br \/>\n        self.fc &#061; nn.Linear(16 * 16 * 16, 10)<\/p>\n<p>    def forward(self, x):<br \/>\n        # \u5377\u79ef&#043;\u6c60\u5316<br \/>\n        x &#061; self.pool(self.conv1(x))  # \u8f93\u51fa\u5c3a\u5bf8: [batch, 16, 16, 16]<\/p>\n<p>        # \u5c55\u5e73<br \/>\n        x &#061; x.view(-1, 16 * 16 * 16)  # \u5c55\u5e73\u4e3a: [batch, 4096]<\/p>\n<p>        # \u5168\u8fde\u63a5<br \/>\n        x &#061; self.fc(x)  # \u8f93\u51fa\u5c3a\u5bf8: [batch, 10]<\/p>\n<p>        return x<\/p>\n<p># \u521d\u59cb\u5316\u6a21\u578b<br \/>\nmodel &#061; SimpleCNN()<br \/>\nmodel &#061; model.to(device)<\/p>\n<p># \u67e5\u770b\u6a21\u578b\u7ed3\u6784<br \/>\nprint(model)<\/p>\n<p># \u67e5\u770b\u521d\u59cb\u6743\u91cd\u7edf\u8ba1\u4fe1\u606f<br \/>\ndef print_weight_stats(model):<br \/>\n    # \u5377\u79ef\u5c42<br \/>\n    conv_weights &#061; model.conv1.weight.data<br \/>\n    print(&#034;\\\\n\u5377\u79ef\u5c42 \u6743\u91cd\u7edf\u8ba1:&#034;)<br \/>\n    print(f&#034;  \u5747\u503c: {conv_weights.mean().item():.6f}&#034;)<br \/>\n    print(f&#034;  \u6807\u51c6\u5dee: {conv_weights.std().item():.6f}&#034;)<br \/>\n    print(f&#034;  \u7406\u8bba\u6807\u51c6\u5dee (Kaiming): {np.sqrt(2\/3):.6f}&#034;)  # \u8f93\u5165\u901a\u9053\u6570\u4e3a3<\/p>\n<p>    # \u5168\u8fde\u63a5\u5c42<br \/>\n    fc_weights &#061; model.fc.weight.data<br \/>\n    print(&#034;\\\\n\u5168\u8fde\u63a5\u5c42 \u6743\u91cd\u7edf\u8ba1:&#034;)<br \/>\n    print(f&#034;  \u5747\u503c: {fc_weights.mean().item():.6f}&#034;)<br \/>\n    print(f&#034;  \u6807\u51c6\u5dee: {fc_weights.std().item():.6f}&#034;)<br \/>\n    print(f&#034;  \u7406\u8bba\u6807\u51c6\u5dee (Kaiming): {np.sqrt(2\/(16*16*16)):.6f}&#034;)<\/p>\n<p># \u6539\u8fdb\u7684\u53ef\u89c6\u5316\u6743\u91cd\u5206\u5e03\u51fd\u6570<br \/>\ndef visualize_weights(model, layer_name, weights, save_path&#061;None):<br \/>\n    plt.figure(figsize&#061;(12, 5))<\/p>\n<p>    # \u6743\u91cd\u76f4\u65b9\u56fe<br \/>\n    plt.subplot(1, 2, 1)<br \/>\n    plt.hist(weights.cpu().numpy().flatten(), bins&#061;50)<br \/>\n    plt.title(f&#039;{layer_name} \u6743\u91cd\u5206\u5e03&#039;)<br \/>\n    plt.xlabel(&#039;\u6743\u91cd\u503c&#039;)<br \/>\n    plt.ylabel(&#039;\u9891\u6b21&#039;)<\/p>\n<p>    # \u6743\u91cd\u70ed\u56fe<br \/>\n    plt.subplot(1, 2, 2)<br \/>\n    if len(weights.shape) &#061;&#061; 4:  # \u5377\u79ef\u5c42\u6743\u91cd [out_channels, in_channels, kernel_size, kernel_size]<br \/>\n        # \u53ea\u663e\u793a\u7b2c\u4e00\u4e2a\u8f93\u5165\u901a\u9053\u7684\u524d10\u4e2a\u6ee4\u6ce2\u5668<br \/>\n        w &#061; weights[:10, 0].cpu().numpy()<br \/>\n        plt.imshow(w.reshape(-1, weights.shape[2]), cmap&#061;&#039;viridis&#039;)<br \/>\n    else:  # \u5168\u8fde\u63a5\u5c42\u6743\u91cd [out_features, in_features]<br \/>\n        # \u53ea\u663e\u793a\u524d10\u4e2a\u795e\u7ecf\u5143\u7684\u6743\u91cd&#xff0c;\u91cd\u5851\u4e3a\u66f4\u5408\u7406\u7684\u77e9\u5f62<br \/>\n        w &#061; weights[:10].cpu().numpy()<\/p>\n<p>        # \u8ba1\u7b97\u66f4\u5408\u7406\u7684\u4e8c\u7ef4\u5f62\u72b6&#xff08;\u5c1d\u8bd5\u63a5\u8fd1\u6b63\u65b9\u5f62&#xff09;<br \/>\n        n_features &#061; w.shape[1]<br \/>\n        side_length &#061; int(np.sqrt(n_features))<\/p>\n<p>        # \u5982\u679c\u4e0d\u80fd\u5b8c\u7f8e\u6574\u9664&#xff0c;\u6dfb\u52a0\u96f6\u586b\u5145\u4f7f\u80fd\u91cd\u5851<br \/>\n        if n_features % side_length !&#061; 0:<br \/>\n            new_size &#061; (side_length &#043; 1) * side_length<br \/>\n            w_padded &#061; np.zeros((w.shape[0], new_size))<br \/>\n            w_padded[:, :n_features] &#061; w<br \/>\n            w &#061; w_padded<\/p>\n<p>        # \u91cd\u5851\u5e76\u663e\u793a<br \/>\n        plt.imshow(w.reshape(w.shape[0] * side_length, -1), cmap&#061;&#039;viridis&#039;)<\/p>\n<p>    plt.colorbar()<br \/>\n    plt.title(f&#039;{layer_name} \u6743\u91cd\u70ed\u56fe&#039;)<\/p>\n<p>    plt.tight_layout()<br \/>\n    if save_path:<br \/>\n        plt.savefig(f&#039;{save_path}_{layer_name}.png&#039;)<br \/>\n    plt.show()<\/p>\n<p># \u6253\u5370\u6743\u91cd\u7edf\u8ba1<br \/>\nprint_weight_stats(model)<\/p>\n<p># \u53ef\u89c6\u5316\u5404\u5c42\u6743\u91cd<br \/>\nvisualize_weights(model, &#034;Conv1&#034;, model.conv1.weight.data, &#034;initial_weights&#034;)<br \/>\nvisualize_weights(model, &#034;FC&#034;, model.fc.weight.data, &#034;initial_weights&#034;)<\/p>\n<p># \u53ef\u89c6\u5316\u504f\u7f6e<br \/>\nplt.figure(figsize&#061;(12, 5))<\/p>\n<p># \u5377\u79ef\u5c42\u504f\u7f6e<br \/>\nconv_bias &#061; model.conv1.bias.data<br \/>\nplt.subplot(1, 2, 1)<br \/>\nplt.bar(range(len(conv_bias)), conv_bias.cpu().numpy())<br \/>\nplt.title(&#039;\u5377\u79ef\u5c42 \u504f\u7f6e&#039;)<\/p>\n<p># \u5168\u8fde\u63a5\u5c42\u504f\u7f6e<br \/>\nfc_bias &#061; model.fc.bias.data<br \/>\nplt.subplot(1, 2, 2)<br \/>\nplt.bar(range(len(fc_bias)), fc_bias.cpu().numpy())<br \/>\nplt.title(&#039;\u5168\u8fde\u63a5\u5c42 \u504f\u7f6e&#039;)<\/p>\n<p>plt.tight_layout()<br \/>\nplt.savefig(&#039;biases_initial.png&#039;)<br \/>\nplt.show()<\/p>\n<p>print(&#034;\\\\n\u504f\u7f6e\u7edf\u8ba1:&#034;)<br \/>\nprint(f&#034;\u5377\u79ef\u5c42\u504f\u7f6e \u5747\u503c: {conv_bias.mean().item():.6f}&#034;)<br \/>\nprint(f&#034;\u5377\u79ef\u5c42\u504f\u7f6e \u6807\u51c6\u5dee: {conv_bias.std().item():.6f}&#034;)<br \/>\nprint(f&#034;\u5168\u8fde\u63a5\u5c42\u504f\u7f6e \u5747\u503c: {fc_bias.mean().item():.6f}&#034;)<br \/>\nprint(f&#034;\u5168\u8fde\u63a5\u5c42\u504f\u7f6e \u6807\u51c6\u5dee: {fc_bias.std().item():.6f}&#034;)<\/p>\n<p>\u90a3\u6211\u4eec\u76d1\u63a7\u6743\u91cd\u56fe\u7684\u76ee\u7684\u662f\u4ec0\u4e48\u5462&#xff1f;<\/p>\n<\/p>\n<p>\u8bad\u7ec3\u65f6&#xff0c;\u6743\u91cd\u4f1a\u968f\u53cd\u5411\u4f20\u64ad\u8fed\u4ee3\u66f4\u65b0\u3002\u901a\u8fc7\u6743\u91cd\u5206\u5e03\u56fe&#xff0c;\u80fd\u76f4\u89c2\u770b\u5230\u5176\u4ece\u521d\u59cb\u5316&#xff08;\u5982\u968f\u673a\u5206\u5e03&#xff09;\u5230\u9010\u6e10\u6536\u655b\u3001\u5f62\u6210\u89c4\u5f8b\u6a21\u5f0f\u7684\u52a8\u6001\u53d8\u5316&#xff0c;\u7406\u89e3\u6a21\u578b\u5982\u4f55\u4e00\u6b65\u6b65 \u201c\u5b66\u4e60\u201d \u7279\u5f81 \u3002\u6bd4\u5982&#xff0c;\u5377\u79ef\u5c42\u6743\u91cd\u521d\u671f\u6742\u4e71&#xff0c;\u8bad\u7ec3\u540e\u53ef\u80fd\u805a\u7126\u4e8e\u8fb9\u7f18\u3001\u7eb9\u7406\u7b49\u7279\u5b9a\u6a21\u5f0f\u3002<\/p>\n<\/p>\n<p>\u8bc6\u522b\u68af\u5ea6\u5f02\u5e38&#xff1a;<\/p>\n<p>1. \u68af\u5ea6\u6d88\u5931&#xff1a;\u82e5\u6743\u91cd\u5206\u5e03\u8d8a\u6765\u8d8a\u96c6\u4e2d\u5728 0 \u9644\u8fd1&#xff0c;\u4e14\u66f4\u65b0\u5e45\u5ea6\u6781\u5c0f&#xff0c;\u53ef\u80fd\u662f\u68af\u5ea6\u6d88\u5931&#xff0c;\u6a21\u578b\u96be\u5b66\u5230\u6709\u6548\u7279\u5f81&#xff08;\u6bd4\u5982\u6df1\u5c42\u7f51\u7edc\u7528 Sigmoid \u6fc0\u6d3b\u6613\u51fa\u73b0 &#xff09;\u3002<\/p>\n<p>2. \u68af\u5ea6\u7206\u70b8&#xff1a;\u6743\u91cd\u503c\u7a81\u7136\u5927\u5e45\u9707\u8361\u3001\u8d85\u51fa\u5408\u7406\u8303\u56f4&#xff08;\u6bd4\u5982\u4ece [-0.1, 0.1] \u8df3\u5230 [-10, 10] &#xff09;&#xff0c;\u8981\u8b66\u60d5\u68af\u5ea6\u7206\u70b8&#xff0c;\u53ef\u80fd\u8ba9\u8bad\u7ec3\u5d29\u6e83\u3002<\/p>\n<\/p>\n<p>\u501f\u52a9tensorboard\u53ef\u4ee5\u770b\u5230\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u6743\u91cd\u56fe\u7684\u53d8\u5316<\/p>\n<p>## \u795e\u7ecf\u7f51\u7edc\u8c03\u53c2\u6307\u5357<\/p>\n<\/p>\n<p>\u5927\u90e8\u5206\u65f6\u5019&#xff0c;\u7531\u4e8e\u5149\u662f\u56fa\u5b9a\u8d85\u53c2\u6570\u7684\u60c5\u51b5\u4e0b&#xff0c;\u8bad\u7ec3\u5b8c\u6a21\u578b\u5c31\u5df2\u7ecf\u5f88\u8017\u65f6\u4e86&#xff0c;\u6240\u4ee5\u6b63\u5e38\u800c\u8a00&#xff0c;\u57fa\u672c\u4e0d\u4f1a\u91c7\u7528\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u7684\u90a3\u4e9b\u8d85\u53c2\u6570\u65b9\u6cd5&#xff0c;\u7f51\u683c\u3001\u8d1d\u53f6\u65af\u3001optuna\u4e4b\u7c7b\u7684&#xff0c;\u770b\u5230\u4e00\u4e9b\u535a\u4e3b\u7528\u8fd9\u4e9b\u5199\u6587\u6848\u5565\u7684&#xff0c;\u611f\u89c9\u8fd9\u4e9b\u4eba\u90fd\u662f\u8111\u5b50\u6709\u95ee\u9898\u7684&#xff0c;\u4f30\u8ba1\u4e5f\u6ca1\u5b66\u8fc7\u673a\u5668\u5b66\u4e60\u76f4\u63a5\u5c31\u5b66\u6df1\u5ea6\u5b66\u4e60\u4e86&#xff0c;\u641e\u6df7\u4e86\u4e8c\u8005\u7684\u5173\u7cfb\u3002<\/p>\n<\/p>\n<p>\u5de5\u4e1a\u754c\u5361\u7279\u522b\u591a\u7684\u60c5\u51b5\u4e0b&#xff0c;\u53ef\u80fd\u53ef\u4ee5\u8003\u8651&#xff0c;\u5c24\u5176\u662f\u5728\u63a2\u7a76\u4e00\u4e2a\u65b0\u67b6\u6784\u7684\u65f6\u5019&#xff0c;\u6211\u4eec\u76f4\u63a5\u5ffd\u89c6\u8fd9\u4e9b\u5373\u53ef&#xff0c;\u53ea\u6709\u624b\u52a8\u8c03\u53c2\u8fd9\u4e00\u6761\u8def\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf12\u6b21\u3002\u5927\u90e8\u5206\u65f6\u5019\uff0c\u7531\u4e8e\u5149\u662f\u56fa\u5b9a\u8d85\u53c2\u6570\u7684\u60c5\u51b5\u4e0b\uff0c\u8bad\u7ec3\u5b8c\u6a21\u578b\u5c31\u5df2\u7ecf\u5f88\u8017\u65f6\u4e86\uff0c\u6240\u4ee5\u6b63\u5e38\u800c\u8a00\uff0c\u57fa\u672c\u4e0d\u4f1a\u91c7\u7528\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u7684\u90a3\u4e9b\u8d85\u53c2\u6570\u65b9\u6cd5\uff0c\u7f51\u683c\u3001\u8d1d\u53f6\u65af\u3001optuna\u4e4b\u7c7b\u7684\uff0c\u770b\u5230\u4e00\u4e9b\u535a\u4e3b\u7528\u8fd9\u4e9b\u5199\u6587\u6848\u5565\u7684\uff0c\u611f\u89c9\u8fd9\u4e9b\u4eba\u90fd\u662f\u8111\u5b50\u6709\u95ee\u9898\u7684\uff0c\u4f30\u8ba1\u4e5f\u6ca1\u5b66\u8fc7\u673a\u5668\u5b66\u4e60\u76f4\u63a5\u5c31\u5b66\u6df1\u5ea6\u5b66\u4e60\u4e86\uff0c\u641e\u6df7\u4e86\u4e8c\u8005\u7684\u5173\u7cfb\u3002\u540c\u4e00\u5c42\u7684\u795e\u7ecf\u5143\u76f8\u5f53\u4e8e\u5728\u505a\u5b8c\u5168\u76f8\u540c\u7684\u8ba1\u7b97\uff0c\u65e0\u8bba\u8f93\u5165\u5982\u4f55\u53d8\u5316\uff0c\u5b83\u4eec\u7684\u8f93\u51fa\u6a21\u5f0f\u59cb\u7ec8\u4e00\u81f4\u3002\u6ce8\u610f\u4e0b\uff0c\u8fd9\u91cc\u662fwx\u540e\u624d\u4f1a\u7ecf\u8fc7\u6fc0\u6d3b\u51fd\u6570\uff0c\u662f\u591a\u4e2a\u6743\u91cd\u5370\u8c61\u7684\u7ed3\u679c\uff0c\u4e0d\u662f\u6536\u5230\u5355\u4e2a\u6743\u91cd\u51b3\u5b9a\u7684\uff0c\u6240\u4ee5\u5355\u4e2a\u6743\u91cd\u53ef\u4ee5\u53d6\u8d1f\u6570\uff0c\u4f46\u662f\u5982\u679c\u6c42\u548c\u540e\u4ecd\u7136\u5c0f\u4e8e0\uff0c\u90a3\u4e48\u8f93\u51fa\u4f1a\u4e3a0\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,4103,152,86],"topic":[],"class_list":["post-44113","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-python-","tag-pytorch","tag-86"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>python\u6253\u5361\u7b2c52\u5929 - \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\/44113.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"python\u6253\u5361\u7b2c52\u5929 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf12\u6b21\u3002\u5927\u90e8\u5206\u65f6\u5019\uff0c\u7531\u4e8e\u5149\u662f\u56fa\u5b9a\u8d85\u53c2\u6570\u7684\u60c5\u51b5\u4e0b\uff0c\u8bad\u7ec3\u5b8c\u6a21\u578b\u5c31\u5df2\u7ecf\u5f88\u8017\u65f6\u4e86\uff0c\u6240\u4ee5\u6b63\u5e38\u800c\u8a00\uff0c\u57fa\u672c\u4e0d\u4f1a\u91c7\u7528\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u7684\u90a3\u4e9b\u8d85\u53c2\u6570\u65b9\u6cd5\uff0c\u7f51\u683c\u3001\u8d1d\u53f6\u65af\u3001optuna\u4e4b\u7c7b\u7684\uff0c\u770b\u5230\u4e00\u4e9b\u535a\u4e3b\u7528\u8fd9\u4e9b\u5199\u6587\u6848\u5565\u7684\uff0c\u611f\u89c9\u8fd9\u4e9b\u4eba\u90fd\u662f\u8111\u5b50\u6709\u95ee\u9898\u7684\uff0c\u4f30\u8ba1\u4e5f\u6ca1\u5b66\u8fc7\u673a\u5668\u5b66\u4e60\u76f4\u63a5\u5c31\u5b66\u6df1\u5ea6\u5b66\u4e60\u4e86\uff0c\u641e\u6df7\u4e86\u4e8c\u8005\u7684\u5173\u7cfb\u3002\u540c\u4e00\u5c42\u7684\u795e\u7ecf\u5143\u76f8\u5f53\u4e8e\u5728\u505a\u5b8c\u5168\u76f8\u540c\u7684\u8ba1\u7b97\uff0c\u65e0\u8bba\u8f93\u5165\u5982\u4f55\u53d8\u5316\uff0c\u5b83\u4eec\u7684\u8f93\u51fa\u6a21\u5f0f\u59cb\u7ec8\u4e00\u81f4\u3002\u6ce8\u610f\u4e0b\uff0c\u8fd9\u91cc\u662fwx\u540e\u624d\u4f1a\u7ecf\u8fc7\u6fc0\u6d3b\u51fd\u6570\uff0c\u662f\u591a\u4e2a\u6743\u91cd\u5370\u8c61\u7684\u7ed3\u679c\uff0c\u4e0d\u662f\u6536\u5230\u5355\u4e2a\u6743\u91cd\u51b3\u5b9a\u7684\uff0c\u6240\u4ee5\u5355\u4e2a\u6743\u91cd\u53ef\u4ee5\u53d6\u8d1f\u6570\uff0c\u4f46\u662f\u5982\u679c\u6c42\u548c\u540e\u4ecd\u7136\u5c0f\u4e8e0\uff0c\u90a3\u4e48\u8f93\u51fa\u4f1a\u4e3a0\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/44113.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-16T17:43:27+00:00\" \/>\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=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/44113.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/44113.html\",\"name\":\"python\u6253\u5361\u7b2c52\u5929 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-06-16T17:43:27+00:00\",\"dateModified\":\"2025-06-16T17:43:27+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/44113.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/44113.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/44113.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"python\u6253\u5361\u7b2c52\u5929\"}]},{\"@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":"python\u6253\u5361\u7b2c52\u5929 - \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\/44113.html","og_locale":"zh_CN","og_type":"article","og_title":"python\u6253\u5361\u7b2c52\u5929 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf12\u6b21\u3002\u5927\u90e8\u5206\u65f6\u5019\uff0c\u7531\u4e8e\u5149\u662f\u56fa\u5b9a\u8d85\u53c2\u6570\u7684\u60c5\u51b5\u4e0b\uff0c\u8bad\u7ec3\u5b8c\u6a21\u578b\u5c31\u5df2\u7ecf\u5f88\u8017\u65f6\u4e86\uff0c\u6240\u4ee5\u6b63\u5e38\u800c\u8a00\uff0c\u57fa\u672c\u4e0d\u4f1a\u91c7\u7528\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u7684\u90a3\u4e9b\u8d85\u53c2\u6570\u65b9\u6cd5\uff0c\u7f51\u683c\u3001\u8d1d\u53f6\u65af\u3001optuna\u4e4b\u7c7b\u7684\uff0c\u770b\u5230\u4e00\u4e9b\u535a\u4e3b\u7528\u8fd9\u4e9b\u5199\u6587\u6848\u5565\u7684\uff0c\u611f\u89c9\u8fd9\u4e9b\u4eba\u90fd\u662f\u8111\u5b50\u6709\u95ee\u9898\u7684\uff0c\u4f30\u8ba1\u4e5f\u6ca1\u5b66\u8fc7\u673a\u5668\u5b66\u4e60\u76f4\u63a5\u5c31\u5b66\u6df1\u5ea6\u5b66\u4e60\u4e86\uff0c\u641e\u6df7\u4e86\u4e8c\u8005\u7684\u5173\u7cfb\u3002\u540c\u4e00\u5c42\u7684\u795e\u7ecf\u5143\u76f8\u5f53\u4e8e\u5728\u505a\u5b8c\u5168\u76f8\u540c\u7684\u8ba1\u7b97\uff0c\u65e0\u8bba\u8f93\u5165\u5982\u4f55\u53d8\u5316\uff0c\u5b83\u4eec\u7684\u8f93\u51fa\u6a21\u5f0f\u59cb\u7ec8\u4e00\u81f4\u3002\u6ce8\u610f\u4e0b\uff0c\u8fd9\u91cc\u662fwx\u540e\u624d\u4f1a\u7ecf\u8fc7\u6fc0\u6d3b\u51fd\u6570\uff0c\u662f\u591a\u4e2a\u6743\u91cd\u5370\u8c61\u7684\u7ed3\u679c\uff0c\u4e0d\u662f\u6536\u5230\u5355\u4e2a\u6743\u91cd\u51b3\u5b9a\u7684\uff0c\u6240\u4ee5\u5355\u4e2a\u6743\u91cd\u53ef\u4ee5\u53d6\u8d1f\u6570\uff0c\u4f46\u662f\u5982\u679c\u6c42\u548c\u540e\u4ecd\u7136\u5c0f\u4e8e0\uff0c\u90a3\u4e48\u8f93\u51fa\u4f1a\u4e3a0\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/44113.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-06-16T17:43:27+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/44113.html","url":"https:\/\/www.wsisp.com\/helps\/44113.html","name":"python\u6253\u5361\u7b2c52\u5929 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-06-16T17:43:27+00:00","dateModified":"2025-06-16T17:43:27+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/44113.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/44113.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/44113.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"python\u6253\u5361\u7b2c52\u5929"}]},{"@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\/44113","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=44113"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/44113\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=44113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=44113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=44113"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=44113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}