{"id":7907,"date":"2022-09-17T21:21:00","date_gmt":"2022-09-17T13:21:00","guid":{"rendered":"http:\/\/139.9.1.231\/?p=7907"},"modified":"2022-09-17T21:21:02","modified_gmt":"2022-09-17T13:21:02","slug":"aiweght","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/09\/17\/aiweght\/","title":{"rendered":"AI\u90e8\u7f72\u7cfb\u5217\uff1a\u4f60\u77e5\u9053\u6a21\u578b\u6743\u91cd\u7684\u5c0f\u79d8\u5bc6\u5417\uff1f\uff1f\uff1f"},"content":{"rendered":"\n<p>\u4eca\u5929\u7b80\u5355\u804a\u804a<strong>\u6a21\u578b\u6743\u91cd<\/strong>\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u4fd7\u79f0\u7684<strong>weight<\/strong>\u3002<\/p>\n\n\n\n<p>\u6df1\u5ea6\u5b66\u4e60\u4e2d\uff0c\u6211\u4eec\u4e00\u76f4\u5728\u8bad\u7ec3\u6a21\u578b\uff0c\u901a\u8fc7<strong>\u53cd\u5411\u4f20\u64ad\u6c42\u5bfc\u66f4\u65b0<\/strong>\u6a21\u578b\u7684\u6743\u91cd\uff0c\u6700\u7ec8\u5f97\u5230\u4e00\u4e2a<strong>\u6cdb\u5316\u80fd\u529b\u6bd4\u8f83\u5f3a<\/strong>\u7684\u6a21\u578b\u3002\u540c\u6837\uff0c\u5982\u679c\u6211\u4eec\u4e0d\u8bad\u7ec3\uff0c\u4ec5\u4ec5\u968f\u673a\u521d\u59cb\u5316\u6743\u91cd\uff0c\u540c\u6837\u80fd\u591f\u5f97\u5230\u4e00\u4e2a\u540c\u6837\u5927\u5c0f\u7684\u6a21\u578b\u3002\u867d\u7136\u4e24\u8005\u5927\u5c0f\u4e00\u6837\uff0c\u4e0d\u8fc7\u4e24\u8005\u5176\u4e2d\u7684\u6743\u91cd\u4fe1\u606f\u5206\u5e03\u76f8\u5dee\u4f1a\u5f88\u5927\uff0c\u4e00\u4e2a\u8111\u5b50\u88c5\u6ee1\u4e86\u77e5\u8bc6\u3001\u4e00\u4e2a\u8111\u5b50\u90fd\u662f\u6c34\uff0c\u5dee\u4e0d\u591a\u5c31\u8fd9\u4e2a\u610f\u601d\u3002<\/p>\n\n\n\n<p>\u6240\u8c13\u7684AI\u6a21\u578b\u90e8\u7f72\u9636\u6bb5\uff0c\u8bf4\u767d\u4e86\u5c31\u662f\u5c06\u8bad\u7ec3\u597d\u7684\u6743\u91cd\u632a\u5230\u53e6\u4e00\u4e2a\u5730\u65b9\u53bb\u8dd1\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u6743\u91cd\u4fe1\u606f\u4ee5\u53ca\u6743\u91cd\u5206\u5e03\u57fa\u672c\u4e0d\u4f1a\u53d8\uff08\u53ef\u80fd\u4f1a\u6539\u53d8\u7cbe\u5ea6\u3001\u4e5f\u53ef\u80fd\u4f1a\u5408\u5e76\u4e00\u4e9b\u6743\u91cd\uff09\u3002<\/p>\n\n\n\n<p>\u4e0d\u8fc7\u6267\u884c\u6a21\u578b\u64cd\u4f5c\uff08\u5377\u79ef\u3001\u5168\u8fde\u63a5\u3001\u53cd\u5377\u79ef\uff09\u7684\u7b97\u5b50\u4f1a\u53d8\u5316\uff0c\u53ef\u80fd\u4ecePytorch-&gt;TensorRT\u6216\u8005TensorFlow-&gt;TFLITE\uff0c\u4e5f\u5c31\u662f\u5b9e\u73b0\u7b97\u5b50\u7684\u65b9\u5f0f\u53d8\u4e86\uff0c\u540c\u4e00\u4e2a\u5377\u79ef\u64cd\u4f5c\uff0c\u5728Pytorch\u6846\u67b6\u4e2d\u662f\u4e00\u79cd\u5b9e\u73b0\uff0c\u5728TensorRT\u53c8\u662f\u53e6\u4e00\u79cd\u65f6\u95f4\uff0c\u4e24\u8005\u7684\u57fa\u672c\u539f\u7406\u662f\u4e00\u6837\u7684\uff0c\u4f46\u662f\u7cbe\u5ea6\u548c\u901f\u5ea6\u4e0d\u4e00\u6837\uff0cTensorRT\u53ef\u4ee5\u501f\u52a9Pytorch\u8bad\u7ec3\u597d\u7684\u5377\u79ef\u7684\u6743\u91cd\uff0c\u5b9e\u73b0\u4e0ePytorch\u4e2d\u4e00\u6837\u7684\u64cd\u4f5c\uff0c\u4e0d\u8fc7\u53ef\u80fd\u66f4\u5feb\u4e9b\u3002<\/p>\n\n\n\n<h1 id=\"%E6%9D%83%E9%87%8Dweightcheckpoint\">\u6743\u91cd\/Weight\/CheckPoint<\/h1>\n\n\n\n<p>\u90a3\u4e48\u6743\u91cd\u90fd\u6709\u54ea\u4e9b\u5462\uff1f\u4ed6\u4eec\u957f\u4ec0\u4e48\u6837\uff1f<\/p>\n\n\n\n<p>\u8fd9\u8fd8\u771f\u4e0d\u597d\u63cf\u8ff0\u2026\u5176\u5b9e\u5c31\u662f\u4e00\u5806\u6570\u636e\u3002\u5bf9\u7684\uff0c\u6211\u4eec<strong>\u5343\u8f9b\u4e07\u82e6\u4e0d\u65ad\u8c03\u4f18<\/strong>\u8bad\u7ec3\u51fa\u6765\u7684\u6743\u91cd\uff0c\u5c31\u662f\u4e00\u5806\u6570\u636e\u800c\u5df2\u3002\u4e5f\u5c31\u662f\u8fd9\u4e2a\u795e\u5947\u7684\u6570\u636e\uff0c\u642d\u914d\u5404\u79cd\u795e\u7ecf\u7f51\u7edc\u7684\u7b97\u5b50\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u5404\u79cd\u68c0\u6d4b\u3001\u5206\u7c7b\u3001\u8bc6\u522b\u7684\u4efb\u52a1\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"947\" height=\"641\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-203.png\" alt=\"\" class=\"wp-image-7908\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-203.png 947w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-203-300x203.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-203-768x520.png 768w\" sizes=\"(max-width: 947px) 100vw, 947px\" \/><\/figure>\n\n\n\n<p>\u4f8b\u5982\u4e0a\u56fe\uff0c\u6211\u4eec\u7528<a href=\"https:\/\/github.com\/lutzroeder\/netron\" target=\"_blank\" rel=\"noreferrer noopener\">Netron<\/a>\u8fd9\u4e2a\u5de5\u5177\u53bb\u67e5\u770b\u67d0\u4e2aONNX\u6a21\u578b\u7684\u7b2c\u4e00\u4e2a\u5377\u79ef\u6743\u91cd\u3002\u5f88\u663e\u7136\u8fd9\u4e2a\u5377\u79ef\u53ea\u6709\u4e00\u4e2aW\u6743\u91cd\uff0c\u6ca1\u6709\u504f\u7f6eb\u3002\u800c\u8fd9\u4e2a\u5377\u79ef\u7684\u6743\u91cd\u503c\u7684\u7ef4\u5ea6\u662f<code>[64,3,7,7]<\/code>\uff0c\u4e5f\u5c31\u662f\u8f93\u5165\u901a\u90533\u3001\u8f93\u51fa\u901a\u905364\u3001\u5377\u79ef\u6838\u5927\u5c0f<code>7x7<\/code>\u3002<\/p>\n\n\n\n<p>\u518d\u4ed4\u7ec6\u770b\uff0c\u5176\u5b9e\u8fd9\u4e2a\u6743\u91cd\u7684\u6570\u503c\u8303\u56f4\u76f8\u5dee\u8fd8\u662f\u5f88\u5927\uff0c\u6700\u5927\u7684\u4e5f\u5c310.1\u7684\u7ea7\u522b\u3002\u4f46\u662f\u6700\u5c0f\u7684\u5462\uff0c\u8089\u773c\u770b\u4e86\u4e0b\uff08\u5176\u5b9e\u5e94\u8be5\u7edf\u8ba1\u4e00\u6ce2\uff09\uff0c\u6700\u5c0f\u7684\u7adf\u7136\u6709<code>1e-10<\/code>\u7ea7\u522b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"718\" height=\"616\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-204.png\" alt=\"\" class=\"wp-image-7909\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-204.png 718w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-204-300x257.png 300w\" sizes=\"(max-width: 718px) 100vw, 718px\" \/><\/figure>\n\n\n\n<p>\u4e00\u822c\u6211\u4eec\u8bad\u7ec3\u7684\u65f6\u5019\uff0c\u8f93\u5165\u6743\u91cd\u90fd\u662f<code>0-1<\/code>\uff0c\u5f53\u7136\u4e5f\u6709<code>0-255<\/code>\u7684\u60c5\u51b5\uff0c\u4f46\u4e0d\u8bba\u662f0-1\u8fd8\u662f0-255\uff0c\u53ea\u8981\u4e0d\u6ea2\u51fa\u7cbe\u5ea6\u4e0a\u9650\u548c\u4e0b\u9650\uff0c\u5c31\u6ca1\u5565\u95ee\u9898\u3002\u5bf9\u4e8eFP32\u6765\u8bf4\uff0c<code>1e-10<\/code>\u662f\u5c0fcase\uff0c\u4f46\u662f\u5bf9\u4e8eFP16\u6765\u8bf4\u5c31\u4e0d\u4e00\u5b9a\u4e86\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u77e5\u9053FP16\u7684\u666e\u904d\u7cbe\u5ea6\u662f<code>~5.96e\u22128 (6.10e\u22125) \u2026 65504<\/code>\uff0c\u5177\u4f53\u7684\u7cbe\u5ea6\u7ec6\u8282\u5148\u4e0d\u8bf4\uff0c\u4f46\u662f\u53ef\u4ee5\u5f88\u660e\u663e\u7684\u770b\u5230\uff0c\u4e0a\u8ff0\u7684<code>1e-10<\/code>\u7684\u7cbe\u5ea6\uff0c\u5df2\u7ecf\u6ea2\u51fa\u4e86FP16\u7684\u7cbe\u5ea6\u4e0b\u9650\u3002<strong>\u5982\u679c\u4e00\u4e2a\u6a21\u578b\u4e2d\u7684\u6743\u91cd\u5206\u5e03\u5927\u90e8\u5206\u90fd\u5904\u5728\u6ea2\u51fa\u8fb9\u7f18\u7684\u8bdd<\/strong>\uff0c\u90a3\u4e48\u6a21\u578b\u8f6c\u6362\u5b8cFP16\u7cbe\u5ea6\u7684\u6a21\u578b\u6307\u6807\u53ef\u80fd\u4f1a\u5927\u5927\u4e0b\u964d\u3002<\/p>\n\n\n\n<p>\u9664\u4e86<code>FP16<\/code>\uff0c\u5f53\u7136\u8fd8\u6709\u5f88\u591a\u5176\u4ed6\u7cbe\u5ea6(TF32\u3001BF16\u3001IN8)\uff0c\u8fd9\u91cc\u6682\u4e14\u4e0d\u8c08\uff0c\u4e0d\u8fc7\u6709\u7bc7<a href=\"https:\/\/moocaholic.medium.com\/fp64-fp32-fp16-bfloat16-tf32-and-other-members-of-the-zoo-a1ca7897d407\" target=\"_blank\" rel=\"noreferrer noopener\">\u8ba8\u8bba\u5404\u79cd\u7cbe\u5ea6\u7684\u6587\u7ae0<\/a>\u53ef\u4ee5\u5148\u4e86\u89e3\u4e0b\u3002<\/p>\n\n\n\n<p>\u8bdd\u8bf4\u56de\u6765\uff0c\u6211\u4eec\u8be5\u5982\u4f55\u7edf\u8ba1\u8be5\u5c42\u7684\u6743\u91cd\u4fe1\u606f\u5462\uff1f\u5229\u7528Pytorch\u4e2d\u539f\u751f\u7684\u4ee3\u7801\u5c31\u53ef\u4ee5\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u5047\u8bbev\u662f\u67d0\u4e00\u5c42conv\u7684\u6743\u91cd\uff0c\u6211\u4eec\u53ef\u4ee5\u7b80\u5355\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u5230\u8be5\u6743\u91cd\u7684\u5206\u5e03\nv.max()\ntensor(0.8559)\nv.min()\ntensor(-0.9568)\nv.abs()\ntensor([[0.0314, 0.0045, 0.0182,  ..., 0.0309, 0.0204, 0.0345],\n        [0.0295, 0.0486, 0.0746,  ..., 0.0363, 0.0262, 0.0108],\n        [0.0328, 0.0582, 0.0149,  ..., 0.0932, 0.0444, 0.0221],\n        ...,\n        [0.0337, 0.0518, 0.0280,  ..., 0.0174, 0.0078, 0.0010],\n        [0.0022, 0.0297, 0.0167,  ..., 0.0472, 0.0006, 0.0128],\n        [0.0631, 0.0144, 0.0232,  ..., 0.0072, 0.0704, 0.0479]])\nv.abs().min() # \u53ef\u4ee5\u770b\u5230\u6743\u91cd\u7edd\u5bf9\u503c\u7684\u6700\u5c0f\u503c\u662f1e-10\u7ea7\u522b\ntensor(2.0123e-10)\nv.abs().max()\ntensor(0.9568)\ntorch.histc(v.abs()) # \u8fd9\u91cc\u7edf\u8ba1\u6743\u91cd\u7684\u5206\u5e03\uff0c\u5206\u4e3a100\u4efd\uff0c\u6700\u5c0f\u6700\u5927\u5206\u522b\u662f[-0.9558,0.8559]\ntensor([3.3473e+06, 3.2437e+06, 3.0395e+06, 2.7606e+06, 2.4251e+06, 2.0610e+06,\n        1.6921e+06, 1.3480e+06, 1.0352e+06, 7.7072e+05, 5.5376e+05, 3.8780e+05,\n        2.6351e+05, 1.7617e+05, 1.1414e+05, 7.3327e+04, 4.7053e+04, 3.0016e+04,\n        1.9576e+04, 1.3106e+04, 9.1220e+03, 6.4780e+03, 4.6940e+03, 3.5140e+03,\n        2.8330e+03, 2.2040e+03, 1.7220e+03, 1.4020e+03, 1.1130e+03, 1.0200e+03,\n        8.2400e+02, 7.0600e+02, 5.7900e+02, 4.6400e+02, 4.1600e+02, 3.3400e+02,\n        3.0700e+02, 2.4100e+02, 2.3200e+02, 1.9000e+02, 1.5600e+02, 1.1900e+02,\n        1.0800e+02, 9.9000e+01, 6.9000e+01, 5.2000e+01, 4.9000e+01, 2.2000e+01,\n        1.8000e+01, 2.8000e+01, 1.2000e+01, 1.3000e+01, 8.0000e+00, 3.0000e+00,\n        4.0000e+00, 3.0000e+00, 1.0000e+00, 1.0000e+00, 0.0000e+00, 1.0000e+00,\n        1.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,\n        1.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 2.0000e+00,\n        0.0000e+00, 2.0000e+00, 1.0000e+00, 0.0000e+00, 1.0000e+00, 0.0000e+00,\n        2.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,\n        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00,\n        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,\n        0.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00])\n<\/pre>\n\n\n\n<p>\u8fd9\u6837\u770b\u5982\u679c\u89c9\u7740\u4e0d\u662f\u5f88\u76f4\u89c2\uff0c\u90a3\u4e48\u4e5f\u53ef\u4ee5\u81ea\u5df1\u753b\u56fe\u6216\u8005\u901a\u8fc7Tensorboard\u6765\u65f6\u5019\u770b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"968\" height=\"462\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-205.png\" alt=\"\" class=\"wp-image-7910\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-205.png 968w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-205-300x143.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-205-768x367.png 768w\" sizes=\"(max-width: 968px) 100vw, 968px\" \/><\/figure>\n\n\n\n<p>\u90a3\u4e48\u770b\u6743\u91cd\u5206\u5e03\u6709\u4ec0\u4e48\u7528\u5462\uff1f<\/p>\n\n\n\n<p>\u80af\u5b9a\u662f\u6709\u7528\u5904\u7684\uff0c\u8bad\u7ec3\u548c\u90e8\u7f72\u7684\u65f6\u5019\u6743\u91cd\u5206\u5e03\u53ef\u4ee5\u4f5c\u4e3a\u6a21\u578b\u662f\u5426\u6b63\u5e38\uff0c\u7cbe\u5ea6\u662f\u5426\u4fdd\u6301\u7684\u4e00\u4e2a\u91cd\u8981\u4fe1\u606f\u3002\u4e0d\u8fc7\u8fd9\u91cc\u5148\u4e0d\u5c55\u5f00\u8bf4\u4e86\u3002<\/p>\n\n\n\n<h1 id=\"%E6%9C%89%E6%9D%83%E9%87%8D%E6%89%80%E4%BB%A5%E9%87%8D%E7%82%B9%E5%85%B3%E7%85%A7\">\u6709\u6743\u91cd\uff0c\u6240\u4ee5\u91cd\u70b9\u5173\u7167<\/h1>\n\n\n\n<p>\u5728\u6a21\u578b\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\uff0c\u6709\u5f88\u591a\u9700\u8981\u901a\u8fc7<strong>\u53cd\u5411\u4f20\u64ad\u66f4\u65b0<\/strong>\u7684\u6743\u91cd\uff0c\u5e38\u89c1\u7684\u6709\uff1a<\/p>\n\n\n\n<ul><li>\u5377\u79ef\u5c42<\/li><li>\u5168\u8fde\u63a5\u5c42<\/li><li>\u6279\u5904\u7406\u5316\u5c42(BN\u5c42\u3001\u6216\u8005\u5404\u79cd\u5176\u4ed6LN\u3001IN\u3001GN)<\/li><li>transformer-encoder\u5c42<\/li><li>DCN\u5c42<\/li><\/ul>\n\n\n\n<p>\u8fd9\u4e9b\u5c42\u4e00\u822c\u90fd\u662f\u795e\u7ecf\u7f51\u7edc\u7684\u6838\u5fc3\u90e8\u5206\uff0c\u5f53\u7136\u90fd\u662f\u6709\u53c2\u6570\u7684\uff0c\u4e00\u5b9a\u4f1a<strong>\u53c2\u4e0e\u6a21\u578b\u7684\u53cd\u5411\u4f20\u64ad\u66f4\u65b0<\/strong>\uff0c\u662f\u6211\u4eec\u5728\u8bad\u7ec3\u6a21\u578b\u65f6\u5019\u9700\u8981\u6ce8\u610f\u7684\u91cd\u8981\u53c2\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Pytorch\u4e2dconv\u5c42\u7684\u90e8\u5206\u4ee3\u7801\uff0c\u53ef\u4ee5\u770b\u5230\u53c2\u6570\u7684\u7ef4\u5ea6\u7b49\u4fe1\u606f\nself._reversed_padding_repeated_twice = _reverse_repeat_tuple(self.padding, 2)\nif transposed:\n    self.weight = Parameter(torch.Tensor(\n        in_channels, out_channels \/\/ groups, *kernel_size))\nelse:\n    self.weight = Parameter(torch.Tensor(\n        out_channels, in_channels \/\/ groups, *kernel_size))\nif bias:\n    self.bias = Parameter(torch.Tensor(out_channels))\n<\/pre>\n\n\n\n<p>\u4e5f\u6709<strong>\u4e0d\u53c2\u4e0e<\/strong>\u53cd\u5411\u4f20\u64ad\uff0c\u4f46\u4e5f\u4f1a\u968f\u7740\u8bad\u7ec3\u4e00\u8d77\u66f4\u65b0\u7684\u53c2\u6570\u3002\u6bd4\u8f83\u5e38\u89c1\u7684\u5c31\u662fBN\u5c42\u4e2d\u7684<code>running_mean<\/code>\u548c<code>running_std<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u622a\u53d6\u4e86Pytorch\u4e2dBN\u5c42\u7684\u90e8\u5206\u4ee3\u7801\ndef __init__(\n    self,\n    num_features: int,\n    eps: float = 1e-5,\n    momentum: float = 0.1,\n    affine: bool = True,\n    track_running_stats: bool = True\n) -&gt; None:\n    super(_NormBase, self).__init__()\n    self.num_features = num_features\n    self.eps = eps\n    self.momentum = momentum\n    self.affine = affine\n    self.track_running_stats = track_running_stats\n    if self.affine:\n        self.weight = Parameter(torch.Tensor(num_features))\n        self.bias = Parameter(torch.Tensor(num_features))\n    else:\n        self.register_parameter('weight', None)\n        self.register_parameter('bias', None)\n    if self.track_running_stats:\n        # \u53ef\u4ee5\u770b\u5230\u5728\u4f7f\u7528track_running_stats\u65f6\uff0cBN\u5c42\u4f1a\u66f4\u65b0\u8fd9\u4e09\u4e2a\u53c2\u6570\n        self.register_buffer('running_mean', torch.zeros(num_features))\n        self.register_buffer('running_var', torch.ones(num_features))\n        self.register_buffer('num_batches_tracked', torch.tensor(0, dtype=torch.long))\n    else:\n        self.register_parameter('running_mean', None)\n        self.register_parameter('running_var', None)\n        self.register_parameter('num_batches_tracked', None)\n    self.reset_parameters()\n<\/pre>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u4e0a\u8ff0\u4ee3\u7801\u7684\u6ce8\u518c<code>\u533a\u522b<\/code>\uff0c\u5bf9\u4e8eBN\u5c42\u4e2d\u7684\u6743\u91cd\u548c\u504f\u7f6e\u4f7f\u7528\u7684\u662f<code>register_parameter<\/code>\uff0c\u800c\u5bf9\u4e8e<code>running_mean<\/code>\u548c<code>running_var<\/code>\u5219\u4f7f\u7528<code>register_buffer<\/code>\uff0c\u90a3\u4e48\u8fd9\u4e24\u8005\u6709\u4ec0\u4e48\u533a\u522b\u5462\uff0c\u90a3\u5c31\u662f\u6ce8\u518c\u4e3abuffer\u7684\u53c2\u6570\u5f80\u5f80\u4e0d\u4f1a\u53c2\u4e0e\u53cd\u5411\u4f20\u64ad\u7684\u8ba1\u7b97\uff0c\u4f46\u4ecd\u7136\u4f1a\u5728\u6a21\u578b\u8bad\u7ec3\u7684\u65f6\u5019\u66f4\u65b0\uff0c\u6240\u4ee5\u4e5f\u9700\u8981\u8ba4\u771f\u5bf9\u5f85\u3002<\/p>\n\n\n\n<p>\u5173\u4e8eBN\u5c42\uff0c\u8f6c\u6362\u6a21\u578b\u548c\u8bad\u7ec3\u6a21\u578b\u7684\u65f6\u5019\u4f1a\u6709<a>\u6697\u5751<\/a>\uff0c\u9700\u8981\u6ce8\u610f\u4e00\u4e0b\u3002<\/p>\n\n\n\n<p>\u521a\u624d\u63cf\u8ff0\u7684\u8fd9\u4e9b\u5c42\u90fd\u662f<strong>\u6709\u53c2\u6570<\/strong>\u7684\uff0c\u90a3\u4e48\u8fd8\u6709\u4e00\u4e9b\u6ca1\u6709\u53c2\u6570\u7684\u5c42\u6709\u54ea\u4e9b\u5462\uff1f\u5f53\u7136\u6709\uff0c\u6211\u4eec\u7684\u7f51\u7edc\u4e2d\u5176\u5b9e\u6709\u5f88\u591aop\uff0c\u4ec5\u4ec5\u662f\u505a\u4e00\u4e9b\u7ef4\u5ea6\u53d8\u6362\u3001\u7d22\u5f15\u53d6\u503c\u6216\u8005\u4e0a\/\u4e0b\u91c7\u6837\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul><li>Reshape<\/li><li>Squeeze<\/li><li>Unsqueeze<\/li><li>Split<\/li><li>Transpose<\/li><li>Gather<\/li><\/ul>\n\n\n\n<p>\u7b49\u7b49\u7b49\u7b49\uff0c\u8fd9\u4e9b\u64cd\u4f5c\u6ca1\u6709\u53c2\u6570\u4ec5\u4ec5\u662f\u5bf9\u4e0a\u4e00\u5c42\u4f20\u9012\u8fc7\u6765\u7684\u5f20\u91cf\u8fdb\u884c\u7ef4\u5ea6\u53d8\u6362\uff0c\u7528\u4e8e\u5b9e\u73b0\u4e00\u4e9b\u201d\u70ab\u6280\u201c\u7684\u64cd\u4f5c\u3002\u81f3\u4e8e\u8fd9\u4e9b\u70ab\u6280\u5417\uff0c\u6709\u4e9b<strong>\u5f88\u6709\u7528<\/strong>\u6709\u4e9b\u5c31\u6709\u4e9b\u65e0\u804a\u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"616\" height=\"798\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-206.png\" alt=\"\" class=\"wp-image-7911\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-206.png 616w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-206-232x300.png 232w\" sizes=\"(max-width: 616px) 100vw, 616px\" \/><\/figure>\n\n\n\n<p>\u4e0a\u56fe\u8fd9\u4e00\u5806\u4e71\u4e03\u516b\u69fd\u7684op\uff0c\u5982\u679c\u5355\u72ec\u62c6\u51fa\u6765\u90fd\u8ba4\u8bc6\uff0c\u4f46\u662f\u5982\u679c\u90fd\u8fde\u8d77\u6765\uff08\u50cf\u4e0a\u56fe\u8fd9\u6837\uff09\uff0c\u4f30\u8ba1\u8fde\u5b83\u7238\u90fd\u4e0d\u8ba4\u8bc6\u4e86\u3002<\/p>\n\n\n\n<p>\u5f00\u4e2a\u73a9\u7b11\uff0c\u5176\u5b9e\u6709\u65f6\u5019\u5728\u901a\u8fc7Pytorch\u8f6c\u6362\u4e3aONNX\u7684\u65f6\u5019\uff0c\u5076\u5c14\u4f1a\u53d1\u751f\u4e00\u4e9b\u8f6c\u6362\u8be1\u5f02\u7684\u60c5\u51b5\u3002\u6bd4\u5982\u4e00\u4e2a\u7b80\u5355\u7684reshape\u4f1a\u56db\u5206\u4e94\u88c2\u4e3agather+slip+concat\uff0c\u8fd9\u79cd\u64cd\u4f5c\u76f8\u5f53\u4e8e\u590d\u6742\u5316\u4e86\uff0c\u4e0d\u8fc7\u4e00\u822c\u6765\u8bf4\u8fd9\u79cd\u60c5\u51b5\u53ef\u4ee5\u4f7f\u7528<code>ONNX-SIMPLIFY<\/code>\u53bb\u4f18\u5316\u6389\uff0c\u5f53\u7136\u9047\u5230\u8f83\u4e3a\u590d\u6742\u7684\u5c31\u9700\u8981\u81ea\u884c\u4f18\u5316\u4e86\u3002<\/p>\n\n\n\n<p>\u54e6\u5bf9\u4e86\uff0c\u5bf9\u4e8e\u8fd9\u4e9b\u53d8\u5f62\u7c7b\u7684\u64cd\u4f5c\u7b97\u5b50\uff0c\u5176\u5b9e\u6709\u4e9b\u662f\u6709\u53c2\u6570\u7684\uff0c\u4f8b\u5982\u4e0b\u56fe\u7684<code>reshap<\/code>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"558\" height=\"874\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-207.png\" alt=\"\" class=\"wp-image-7912\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-207.png 558w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-207-192x300.png 192w\" sizes=\"(max-width: 558px) 100vw, 558px\" \/><\/figure>\n\n\n\n<p>\u50cf\u8fd9\u79cd\u7684op\uff0c\u600e\u4e48\u8bf4\u5462\uff0c\u6709\u65f6\u5019\u4f1a\u6bd4\u8f83\u68d8\u624b\u3002\u5982\u679c\u6211\u4eec\u60f3\u8981\u5c06\u8fd9\u4e2aONNX\u6a21\u578b\u8f6c\u6362\u4e3aTensorRT\uff0c\u90a3\u4e48100%\u4f1a\u9047\u5230\u95ee\u9898\uff0c\u56e0\u4e3aTensorRT\u7684\u89e3\u91ca\u5668\u5728\u89e3\u6790ONNX\u7684\u65f6\u5019\uff0c\u4e0d\u652f\u6301reshape\u5c42\u7684shape\u662f\u8f93\u5165TensorRT\uff0c\u800c\u662f\u628a\u8fd9\u4e2ashape\u5f53\u6210<code>attribute<\/code>\u6765\u5904\u7406\uff0c\u800cONNX\u7684\u63a8\u7406\u6846\u67b6Inference\u5219\u662f\u652f\u6301\u7684\u3002<\/p>\n\n\n\n<p>\u4e0d\u8fc7\u8fd9\u4e9b\u90fd\u662f\u5c0f\u95ee\u9898\uff0c\u5927\u90e8\u5206\u60c5\u51b5\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6539\u6a21\u578b\u6216\u8005\u6362\u7ed3\u6784\u89e3\u51b3\uff0c\u800c\u4e14\u6210\u672c\u4e5f\u4e0d\u9ad8\u3002\u4f46\u662f\u8fd8\u4f1a\u6709\u4e00\u4e9b\u5176\u4ed6\u590d\u6742\u7684\u95ee\u9898\uff0c\u53ef\u80fd\u5c31\u9700\u8981\u6211\u4eec\u91cd\u70b9\u7814\u7a76\u4e0b\u4e86\u3002<\/p>\n\n\n\n<h1 id=\"%E6%8F%90%E5%8F%96%E6%9D%83%E9%87%8D\">\u63d0\u53d6\u6743\u91cd<\/h1>\n\n\n\n<p>\u60f3\u8981\u5c06\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u4ece\u8fd9\u4e2a\u5e73\u53f0\u90e8\u7f72\u81f3\u53e6\u4e00\u4e2a\u5e73\u53f0\uff0c\u90a3\u4e48\u9996\u8981\u7684\u5c31\u662f<strong>\u8f6c\u79fb\u6743\u91cd<\/strong>\u3002\u4e0d\u8fc7\u5b9e\u9645\u4e2d\u5927\u90e8\u5206\u7684\u8f6c\u6362\u5668\u90fd\u5e2e\u6211\u4eec\u505a\u597d\u4e86\uff08\u6bd4\u5982<a href=\"https:\/\/github.com\/onnx\/onnx-tensorrt\" target=\"_blank\" rel=\"noreferrer noopener\">onnx-TensorRT<\/a>\uff09\uff0c\u4e0d\u7528\u6211\u4eec\u81ea\u5df1\u64cd\u5fc3\uff01<\/p>\n\n\n\n<p>\u4e0d\u8fc7\u5982\u679c\u60f3\u8981\u5bf9\u6a21\u578b\u6743\u91cd\u7684\u6709\u4e2a\u6574\u4f53\u8ba4\u77e5\u7684\u8bdd\uff0c\u8fd8\u662f\u5efa\u8bae\u81ea\u5df1\u4eb2\u624b\u8bd5\u4e00\u8bd5\u3002<\/p>\n\n\n\n<h2 id=\"caffe2pytorch\">Caffe2Pytorch<\/h2>\n\n\n\n<p>\u5148\u7b80\u5355\u8bf4\u4e0bCaffe\u548cPytorch\u4e4b\u95f4\u7684\u6743\u91cd\u8f6c\u6362\u3002\u8fd9\u91cc\u63a8\u8350\u4e00\u4e2a\u5f00\u6e90\u4ed3\u5e93<a href=\"https:\/\/github.com\/marvis\/pytorch-caffe\" target=\"_blank\" rel=\"noreferrer noopener\">Caffe-python<\/a>\uff0c\u5df2\u7ecf\u5e2e\u6211\u4eec\u5199\u597d\u4e86\u63d0\u53d6Caffemodel\u6743\u91cd\u548c\u6839\u636eprototxt\u6784\u5efa\u5bf9\u5e94Pytorch\u6a21\u578b\u7ed3\u6784\u7684\u8fc7\u7a0b\uff0c\u4e0d\u9700\u8981\u6211\u4eec\u91cd\u590d\u9020\u8f6e\u5b50\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u90fd\u77e5\u9053Caffe\u7684\u6743\u91cd\u4f7f\u7528<code>Caffemodel<\/code>\u8868\u793a\uff0c\u800c\u76f8\u5e94\u7684\u7ed3\u6784\u662f<code>prototxt<\/code>\u3002\u5982\u4e0a\u56fe\uff0c\u5de6\u9762\u662f<code>prototxt<\/code>\u53f3\u9762\u662f<code>caffemodel<\/code>\uff0c\u800ccaffemodel\u4f7f\u7528\u7684\u662fprotobuf\u8fd9\u4e2a\u6570\u636e\u7ed3\u6784\u8868\u793a\u7684\u3002\u6211\u4eec\u5f53\u7136\u4e5f\u8981\u5148\u8bfb\u51fa\u6765\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">model = caffe_pb2.NetParameter()\nprint('Loading caffemodel: ' + caffemodel)\nwith open(caffemodel, 'rb') as fp:\n    model.ParseFromString(fp.read())\n<\/pre>\n\n\n\n<p><code>caffe_pb2<\/code>\u5c31\u662fcaffemodel\u683c\u5f0f\u7684protobuf\u7ed3\u6784\uff0c\u5177\u4f53\u7684\u53ef\u4ee5\u770b\u4e0a\u65b9\u8001\u6f58\u63d0\u4f9b\u7684\u5e93\uff0c\u603b\u4e4b\u5c31\u662f\u5b9a\u4e49\u4e86\u4e00\u4e9bCaffe\u6a21\u578b\u7684\u7ed3\u6784\u3002<\/p>\n\n\n\n<p>\u800c\u63d0\u53d6\u5230\u6a21\u578b\u6743\u91cd\u540e\uff0c\u901a\u8fc7<code>prototxt<\/code>\u4e2d\u7684\u6a21\u578b\u4fe1\u606f\uff0c\u6328\u4e2a\u4ece<code>caffemodel<\/code>\u7684protobuf\u6743\u91cd\u4e2d\u627e\uff0c\u7136\u540e\u590d\u5236\u6743\u91cd\u5230Pytorch\u7aef\uff0c\u4ed4\u7ec6\u770b\u8fd9\u53e5<code>caffe_weight = torch.from_numpy(caffe_weight).view_as(self.models[lname].weight)<\/code>\uff0c\u5176\u4e2d<code>self.models[lname]<\/code>\u5c31\u662f\u5df2\u7ecf\u642d\u5efa\u597d\u7684\u5bf9\u5e94Pytorch\u7684\u5377\u79ef\u5c42\uff0c\u8fd9\u91cc\u53d6<code>weight<\/code>\u4e4b\u540e\u901a\u8fc7<code>self.models[lname].weight.data.copy_(caffe_weight)<\/code>\u5c06caffe\u7684\u6743\u91cd\u653e\u5230Pytorch\u4e2d\u3002<\/p>\n\n\n\n<p>\u5f88\u7b80\u5355\u5427\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">if ltype in ['Convolution', 'Deconvolution']:\n    print('load weights %s' % lname)\n    convolution_param = layer['convolution_param']\n    bias = True\n    if 'bias_term' in convolution_param and convolution_param['bias_term'] == 'false':\n        bias = False\n    # weight_blob = lmap[lname].blobs[0]\n    # print('caffe weight shape', weight_blob.num, weight_blob.channels, weight_blob.height, weight_blob.width)\n    caffe_weight = np.array(lmap[lname].blobs[0].data)\n    caffe_weight = torch.from_numpy(caffe_weight).view_as(self.models[lname].weight)\n    # print(\"caffe_weight\", caffe_weight.view(1,-1)[0][0:10])\n    self.models[lname].weight.data.copy_(caffe_weight)\n    if bias and len(lmap[lname].blobs) &gt; 1:\n        self.models[lname].bias.data.copy_(torch.from_numpy(np.array(lmap[lname].blobs[1].data)))\n        print(\"convlution %s has bias\" % lname)\n<\/pre>\n\n\n\n<h2 id=\"pytorch2tensorrt\">Pytorch2TensorRT<\/h2>\n\n\n\n<p>\u5148\u4e3e\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u4e00\u822c\u6211\u4eec\u4f7f\u7528Pytorch\u6a21\u578b\u8fdb\u884c\u8bad\u7ec3\u3002\u8bad\u7ec3\u5f97\u5230\u7684\u6743\u91cd\uff0c\u6211\u4eec\u4e00\u822c\u90fd\u4f1a\u4f7f\u7528<code>torch.save()<\/code>\u4fdd\u5b58\u4e3a<code>.pth<\/code>\u7684\u683c\u5f0f\u3002<\/p>\n\n\n\n<p>PTH\u662fPytorch\u4f7f\u7528python\u4e2d\u5185\u7f6e\u6a21\u5757<code>pickle<\/code>\u6765\u4fdd\u5b58\u548c\u8bfb\u53d6\uff0c\u6211\u4eec\u4f7f\u7528<code>netron<\/code>\u770b\u4e00\u4e0bpth\u957f\u4ec0\u4e48\u6837\u3002\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"967\" height=\"641\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-208.png\" alt=\"\" class=\"wp-image-7913\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-208.png 967w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-208-300x199.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-208-768x509.png 768w\" sizes=\"(max-width: 967px) 100vw, 967px\" \/><\/figure>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u53ea\u6709\u6a21\u578b\u4e2d<strong>\u6709\u53c2\u6570\u6743\u91cd\u7684<\/strong>\u8868\u793a\uff0c\u5e76\u4e0d\u5305\u542b\u6a21\u578b\u7ed3\u6784\u3002\u4e0d\u8fc7\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<code>.py<\/code>\u7684\u6a21\u578b\u7ed3\u6784\u4e00\u4e00\u52a0\u8f7d<code>.pth<\/code>\u7684\u6743\u91cd\u5230\u6211\u4eec\u6a21\u578b\u4e2d\u5373\u53ef\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"953\" height=\"654\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-209.png\" alt=\"\" class=\"wp-image-7914\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-209.png 953w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-209-300x206.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-209-768x527.png 768w\" sizes=\"(max-width: 953px) 100vw, 953px\" \/><\/figure>\n\n\n\n<p>\u770b\u4e00\u4e0b\u6211\u4eec\u8bfb\u53d6<code>.pth<\/code>\u540e\uff0c<code>state_dict<\/code>\u7684<code>key<\/code>\u3002\u8fd9\u4e9bkey\u4e5f\u5c31\u5bf9\u5e94\u7740\u6211\u4eec\u5728\u6784\u5efa\u6a21\u578b\u65f6\u5019\u6ce8\u518c\u6bcf\u4e00\u5c42\u7684\u6743\u91cd\u540d\u79f0\u548c\u6743\u91cd\u4fe1\u606f\uff08\u4e5f\u5305\u62ec\u7ef4\u5ea6\u548c\u7c7b\u578b\u7b49\uff09\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"999\" height=\"332\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-210.png\" alt=\"\" class=\"wp-image-7915\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-210.png 999w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-210-300x100.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-210-768x255.png 768w\" sizes=\"(max-width: 999px) 100vw, 999px\" \/><\/figure>\n\n\n\n<p>\u5f53\u7136\u8fd9\u4e2a<code>pth<\/code>\u4e5f\u53ef\u4ee5\u5305\u542b\u5176\u4ed6\u5b57\u7b26\u6bb5<code>{'epoch': 190, 'state_dict': OrderedDict([('conv1.weight', tensor([[...<\/code>\uff0c\u6bd4\u5982\u8bad\u7ec3\u5230\u591a\u5c11\u4e2aepoch\uff0c\u5b66\u4e60\u7387\u5565\u7684\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e<code>pth<\/code>\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u5c06\u5176\u63d0\u53d6\u51fa\u6765\uff0c\u5b58\u653e\u4e3a<code>TensorRT<\/code>\u7684\u6743\u91cd\u683c\u5f0f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def extract_weight(args):\n    # Load model\n    state_dict = torch.load(args.weight)\n    with open(args.save_path, \"w\") as f:\n        f.write(\"{}\\n\".format(len(state_dict.keys())))\n        for k, v in state_dict.items():\n            vr = v.reshape(-1).cpu().numpy()\n            f.write(\"{} {} \".format(k, len(vr)))\n            for vv in vr:\n                f.write(\" \")\n                f.write(struct.pack(\"&gt;f\", float(vv)).hex())\n            f.write(\"\\n\")\n<\/pre>\n\n\n\n<p>\u9700\u8981\u6ce8\u610f\uff0c\u8fd9\u91cc\u7684<code>TensorRT<\/code>\u6743\u91cd\u683c\u5f0f\u6307\u7684\u662f\u5728build\u4e4b\u524d\u7684\u6743\u91cd\uff0c<code>TensorRT<\/code>\u4ec5\u4ec5\u662f\u62ff\u6765\u53bb\u6784\u5efa\u6574\u4e2a\u7f51\u7edc\uff0c\u5c06\u6bcf\u4e2a\u89e3\u6790\u5230\u7684\u5c42\u7684\u6743\u91cd\u4f20\u9012\u8fdb\u53bb\uff0c\u7136\u540e\u901a\u8fc7TensorRT\u7684<code>network<\/code>\u53bbbuild\u597d<code>engine<\/code>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ Load weights from files shared with TensorRT samples.\n\/\/ TensorRT weight files have a simple space delimited format:\n\/\/ [type] [size] &lt;data x size in hex&gt;\nstd::map&lt;std::string, Weights&gt; loadWeights(const std::string file)\n{\n    std::cout &lt;&lt; \"Loading weights: \" &lt;&lt; file &lt;&lt; std::endl;\n    std::map&lt;std::string, Weights&gt; weightMap;\n\n    \/\/ Open weights file\n    std::ifstream input(file);\n    assert(input.is_open() &amp;&amp; \"Unable to load weight file.\");\n\n    \/\/ Read number of weight blobs\n    int32_t count;\n    input &gt;&gt; count;\n    assert(count &gt; 0 &amp;&amp; \"Invalid weight map file.\");\n\n    while (count--)\n    {\n        Weights wt{DataType::kFLOAT, nullptr, 0};\n        uint32_t size;\n\n        \/\/ Read name and type of blob\n        std::string name;\n        input &gt;&gt; name &gt;&gt; std::dec &gt;&gt; size;\n        wt.type = DataType::kFLOAT;\n\n        \/\/ Load blob\n        uint32_t *val = reinterpret_cast&lt;uint32_t *&gt;(malloc(sizeof(val) * size));\n        for (uint32_t x = 0, y = size; x &lt; y; ++x)\n        {\n            input &gt;&gt; std::hex &gt;&gt; val[x];\n        }\n        wt.values = val;\n        wt.count = size;\n        weightMap[name] = wt;\n    }\n    std::cout &lt;&lt; \"Finished Load weights: \" &lt;&lt; file &lt;&lt; std::endl;\n    return weightMap;\n}\n<\/pre>\n\n\n\n<p>\u90a3\u4e48\u88abTensorRT\u4f18\u5316\u540e\uff1f\u6a21\u578b\u53c8\u957f\u4ec0\u4e48\u6837\u5b50\u5462\uff1f\u6211\u4eec\u7684\u6743\u91cd\u653e\u54ea\u513f\u4e86\u5462\uff1f<\/p>\n\n\n\n<p>\u80af\u5b9a\u5728build\u597d\u540e\u7684<code>engine<\/code>\u91cc\u5934\uff0c\u4e0d\u8fc7\u8fd9\u4e9b\u6743\u91cd\u56e0\u4e3aTensorRT\u7684\u4f18\u5316\uff0c\u53ef\u80fd\u5df2\u7ecf\u88ab\u5408\u5e76\/\u79fb\u9664\/merge\u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"982\" height=\"442\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-211.png\" alt=\"\" class=\"wp-image-7916\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-211.png 982w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-211-300x135.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-211-768x346.png 768w\" sizes=\"(max-width: 982px) 100vw, 982px\" \/><\/figure>\n\n\n\n<p>\u6a21\u578b\u53c2\u6570\u7684\u5b66\u95ee\u8fd8\u662f\u5f88\u591a\uff0c\u8fd1\u671f\u4e5f\u6709\u5f88\u591a\u76f8\u5173\u7684\u7814\u7a76\uff0c\u6bd4\u5982<code>\u53c2\u6570\u91cd\u53c2\u5316<\/code>\uff0c\u662f\u76f8\u5f53solid\u7684\u5de5\u4f5c\uff0c\u5728\u5f88\u591a\u8bad\u7ec3\u548c\u90e8\u7f72\u573a\u666f\u4e2d\u7ecf\u5e38\u4f1a\u7528\u5230\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u7b80\u5355\u804a\u804a\u6a21\u578b\u6743\u91cd\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u4fd7\u79f0\u7684weight\u3002 \u6df1\u5ea6\u5b66\u4e60\u4e2d\uff0c\u6211\u4eec\u4e00\u76f4\u5728\u8bad\u7ec3\u6a21\u578b\uff0c\u901a\u8fc7\u53cd\u5411\u4f20\u64ad\u6c42\u5bfc\u66f4\u65b0\u6a21\u578b &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/09\/17\/aiweght\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">AI\u90e8\u7f72\u7cfb\u5217\uff1a\u4f60\u77e5\u9053\u6a21\u578b\u6743\u91cd\u7684\u5c0f\u79d8\u5bc6\u5417\uff1f\uff1f\uff1f<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/7907"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=7907"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/7907\/revisions"}],"predecessor-version":[{"id":7917,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/7907\/revisions\/7917"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=7907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=7907"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=7907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}