{"id":12472,"date":"2023-02-01T20:32:56","date_gmt":"2023-02-01T12:32:56","guid":{"rendered":"http:\/\/139.9.1.231\/?p=12472"},"modified":"2023-02-03T09:37:39","modified_gmt":"2023-02-03T01:37:39","slug":"tensorrt","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2023\/02\/01\/tensorrt\/","title":{"rendered":"NVIDIA TensorRT&#8212;\u63a8\u7406\u5f15\u64ce\u52a0\u901f\u6df1\u5ea6\u5b66\u4e60\u63a8\u7406"},"content":{"rendered":"\n<p class=\"has-text-align-center has-light-pink-background-color has-background\"><strong><em> \u6a21\u578b\u8f6c\u6362\u5de5\u5177\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/convertmodel.com\/\" target=\"_blank\"> https:\/\/convertmodel.com\/<\/a> <\/em><\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-2.png\" alt=\"\" class=\"wp-image-12560\" width=\"553\" height=\"247\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-2.png 735w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-2-300x134.png 300w\" sizes=\"(max-width: 553px) 100vw, 553px\" \/><\/figure><\/div>\n\n\n\n<p>\u6df1\u5ea6\u5b66\u4e60\u7684\u5de5\u4f5c\u6d41\u7a0b\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u53ef\u5206\u4e3a\u8bad\u7ec3\u548c\u63a8\u7406\u4e24\u4e2a\u90e8\u5206\u3002<br><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-3-1024x648.png\" alt=\"\" class=\"wp-image-12568\" width=\"543\" height=\"343\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-3-1024x648.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-3-300x190.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-3-768x486.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-3.png 1105w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/><\/figure><\/div>\n\n\n\n<p>\u8bad\u7ec3\u8fc7\u7a0b\u901a\u8fc7\u8bbe\u5b9a\u6570\u636e\u5904\u7406\u65b9\u5f0f\uff0c\u5e76\u8bbe\u8ba1\u5408\u9002\u7684\u7f51\u7edc\u6a21\u578b\u7ed3\u6784\u4ee5\u53ca\u635f\u5931\u51fd\u6570\u548c\u4f18\u5316\u7b97\u6cd5\uff0c\u5728\u6b64\u57fa\u7840\u4e0a\u5c06\u6570\u636e\u96c6\u4ee5\u5c0f\u6279\u91cf\u7684\u65b9\u5f0f\uff08mini-batch\uff09\u53cd\u590d\u8fdb\u884c\u524d\u5411\u8ba1\u7b97\u5e76\u8ba1\u7b97\u635f\u5931\uff0c\u7136\u540e \u53cd\u5411\u8ba1\u7b97\u68af\u5ea6\u5229\u7528\u7279\u5b9a\u7684\u4f18\u5316\u51fd\u6570\u6765\u66f4\u65b0\u6a21\u578b\uff0c\u6765\u4f7f\u5f97\u635f\u5931\u51fd\u6570\u8fbe\u5230\u6700\u4f18\u7684\u7ed3\u679c\u3002\u8bad\u7ec3\u8fc7\u7a0b\u6700\u91cd\u8981\u7684\u5c31\u662f\u68af\u5ea6\u7684\u8ba1\u7b97\u548c\u53cd\u5411\u4f20\u64ad\u3002<\/p>\n\n\n\n<p>\u800c\u63a8\u7406\u5c31\u662f\u5728\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u7ed3\u6784\u548c\u53c2\u6570\u57fa\u7840\u4e0a\uff0c\u505a\u4e00\u6b21\u524d\u5411\u4f20\u64ad\u5f97\u5230\u6a21\u578b\u8f93\u51fa\u7684\u8fc7\u7a0b\u3002\u76f8\u5bf9\u4e8e\u8bad\u7ec3\u800c\u8a00\uff0c\u63a8\u7406\u4e0d\u6d89\u53ca\u68af\u5ea6\u548c\u635f\u5931\u4f18\u5316\u3002\u63a8\u7406\u7684\u6700\u7ec8\u76ee\u6807\u662f\u5c06\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u90e8\u7f72\u751f\u4ea7\u73af\u5883\u4e2d\u3002<\/p>\n\n\n\n<p>       <\/p>\n\n\n\n<h3 id=\"slide-3\">\u9ad8\u6027\u80fd\u63a8\u7406\u5f15\u64ce\u7684\u5de5\u4f5c\u9879<\/h3>\n\n\n\n<p>\u867d\u7136\u63a8\u7406\u5c31\u662f\u6570\u636e\u7ecf\u8fc7\u6a21\u578b\u7684\u4e00\u6b21\u524d\u5411\u8ba1\u7b97\uff0c\u4f46\u662f\u63a8\u7406\u662f\u9762\u5411\u4e0d\u540c\u7684\u7ec8\u7aef\u90e8\u7f72\uff0c\u4e00\u822c\u63a8\u7406\u9700\u8981\u6ee1\u8db3\uff1a<\/p>\n\n\n\n<ul><li>\u7cbe\u5ea6\u8981\u6c42: \u63a8\u7406\u7684\u7cbe\u5ea6\u9700\u8981\u548c\u8bad\u7ec3\u7684\u7cbe\u5ea6\u4fdd\u6301\u4e00\u81f4\uff0c<\/li><li>\u6548\u7387\u8981\u6c42\uff1a\u6027\u80fd\u5c3d\u53ef\u80fd\u7684\u5feb<\/li><li>\u5f02\u6784\u7684\u63a8\u7406\u8bbe\u5907\uff1a\u751f\u4ea7\u73af\u5883\u56e0\u4e3a\u573a\u666f\u4e0d\u540c\uff0c\u652f\u6301\u4e0d\u540c\u7684\u8bbe\u5907\u5982TPU\uff0cCPU\uff0cGPU\uff0c NPU\u7b49<\/li><\/ul>\n\n\n\n<p>\u6240\u4ee5\u63a8\u7406\u6846\u67b6\u4e00\u822c\u5305\u62ec\u6a21\u578b\u4f18\u5316\u548c\u63a8\u7406\u52a0\u901f\uff0c\u4ee5\u4fbf\u4e8e\u652f\u6301\u9ad8\u6027\u80fd\u7684\u63a8\u7406\u8981\u6c42\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u4e00\u4e2a\u63a8\u7406\u6846\u67b6\u8981\u505a\u54ea\u4e9b\u4e8b\u60c5\u5462\uff1f<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u56e0\u4e3a\u63a8\u7406\u6846\u67b6\u8981\u652f\u6301\u73b0\u6709\u6d41\u884c\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u5982TensorFlow\u548cPytorch\u7b49\uff0c\u800c\u4e0d\u540c\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u5185\u5728\u7684\u4e0d\u4e00\u81f4\u6027\uff0c\u5c31\u8981\u6c42\u63a8\u7406\u6846\u67b6\u9700\u8981\u6709\u4e00\u79cd\u540c\u4e00\u4e2a\u8868\u8fbe\u5f62\u5f0f\uff0c\u6765\u7edf\u4e00\u5916\u90e8\u7684\u4e0d\u4e00\u81f4\u6027\uff0c\u8fd9\u5c31\u9700\u8981\u63a8\u7406\u6846\u67b6\u5916\u90e8\u6a21\u578b\u89e3\u6790\u548c\u8f6c\u6362\u4e3a\u5185\u5728\u5f62\u5f0f\u7684\u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u5176\u6b21\uff0c\u4e3a\u4e86\u8ffd\u6c42\u6027\u80fd\u7684\u63d0\u5347\uff0c\u9700\u8981\u80fd\u591f\u5bf9\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u9488\u5bf9\u7279\u5b9a\u63a8\u7406\u8bbe\u5907\u8fdb\u884c\u7279\u5b9a\u7684\u4f18\u5316\uff0c\u4e3b\u8981\u4f18\u5316\u53ef\u4ee5\u5305\u62ec<\/p>\n\n\n\n<ul><li>\u4f4e\u7cbe\u5ea6\u4f18\u5316\uff1aFP16\u4f4e\u7cbe\u5ea6\u8f6c\u6362\uff0cINT8\u540e\u8bad\u7ec3\u91cf\u5316<\/li><li>\u7b97\u5b50\u7f16\u8bd1\u4f18\u5316<\/li><li>\u5185\u5b58\u4f18\u5316<\/li><li>\u8ba1\u7b97\u56fe\u8c03\u5ea6<\/li><\/ul>\n\n\n\n<h3 id=\"slide-4\">\u4f4e\u7cbe\u5ea6\u4f18\u5316<\/h3>\n\n\n\n<p>\u4e00\u822c\u6a21\u578b\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u90fd\u662f\u91c7\u7528FP32\u6216\u8005FP64\u9ad8\u7cbe\u5ea6\u7684\u65b9\u5f0f\u8fdb\u884c\u5b58\u50a8\u6a21\u578b\u53c2\u6570\uff0c\u4e3b\u8981\u662f\u56e0\u4e3a\u68af\u5ea6\u8ba1\u7b97\u66f4\u65b0\u7684\u53ef\u80fd\u662f\u5f88\u5c0f\u7684\u4e00\u4e2a\u5c0f\u6570\u3002\u9ad8\u7cbe\u5ea6\u4f7f\u5f97\u6a21\u578b\u66f4\u5927\uff0c\u5e76\u4e14\u8ba1\u7b97\u5f88\u8017\u65f6\u3002\u800c\u5728\u63a8\u7406\u4e0d\u9700\u8981\u68af\u5ea6\u66f4\u65b0\uff0c\u6240\u4ee5\u901a\u5e38\u5982\u679c\u7cbe\u5ea6\u4eceFP32\u964d\u4f4e\u5230FP16\uff0c\u6a21\u578b\u5c31\u4f1a\u53d8\u5c0f\u5f88\u591a\uff0c\u5e76\u4e14\u8ba1\u7b97\u91cf\u4e5f\u4e0b\u964d\uff0c\u800c\u76f8\u5bf9\u4e8e\u6a21\u578b\u7684\u63a8\u7406\u6548\u679c\u51e0\u4e4e\u4e0d\u4f1a\u6709\u4efb\u4f55\u7684\u53d8\u5316\uff0c<strong>\u4e00\u822c\u90fd\u4f1a\u505aFP16\u7684\u7cbe\u5ea6\u88c1\u526a<\/strong>\u3002<\/p>\n\n\n\n<p>\u800cFP32\u5982\u679c\u8f6c\u6362\u5230INT8\uff0c\u63a8\u7406\u6027\u80fd\u4f1a\u63d0\u9ad8\u5f88\u591a\uff0c\u4f46\u662f\u88c1\u526a\u4e0d\u662f\u76f4\u63a5\u88c1\u526a\uff0c\u53c2\u6570\u53d8\u52a8\u5f88\u591a\uff0c\u4f1a\u5f71\u54cd\u6a21\u578b\u7684\u63a8\u7406\u6548\u679c\uff0c\u9700\u8981\u505a\u91cd\u65b0\u7684\u8bad\u7ec3\uff0c\u6765\u5c3d\u53ef\u80fd\u4fdd\u6301\u6a21\u578b\u7684\u6548\u679c<\/p>\n\n\n\n<h3 id=\"slide-5\">\u7b97\u5b50\u7f16\u8bd1\u4f18\u5316<\/h3>\n\n\n\n<p>\u6211\u4eec\u5148\u6765\u4e86\u89e3\u4e0b\u8ba1\u7b97\u56fe\u7684\u6982\u5ff5\uff0c\u8ba1\u7b97\u56fe\u662f\u7531\u7b97\u5b50\u548c\u5f20\u91cf\u6784\u5efa\u6210\u4e00\u4e2a\u6570\u636e\u8ba1\u7b97\u6d41\u5411\u56fe\uff0c\u901a\u5e38\u6df1\u5ea6\u5b66\u4e60\u7f51\u7edc\u90fd\u53ef\u4ee5\u770b\u6210\u4e00\u4e2a\u8ba1\u7b97\u56fe\u3002\u800c\u63a8\u7406\u53ef\u4ee5\u7406\u89e3\u6210\u6570\u636e\u4ece\u8ba1\u7b97\u56fe\u8d77\u70b9\u5230\u7ec8\u70b9\u7684\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-4.png\" alt=\"\" class=\"wp-image-12571\" width=\"216\" height=\"320\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-4.png 427w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-4-202x300.png 202w\" sizes=\"(max-width: 216px) 100vw, 216px\" \/><\/figure><\/div>\n\n\n\n<p>\u7b97\u5b50\u7f16\u8bd1\u4f18\u5316\u5176\u4e2d\u4e00\u9879\u4f18\u5316\u5c31\u662f<strong>\u8ba1\u7b97\u56fe\u7684\u4f18\u5316<\/strong>\u3002\u8ba1\u7b97\u56fe\u4f18\u5316\u7684\u76ee\u6807\u662f\u5bf9\u8ba1\u7b97\u56fe\u8fdb\u884c\u7b49\u4ef7\u7684\u7ec4\u5408\u53d8\u6362\uff0c\u4f7f\u5f97\u51cf\u5c11\u7b97\u5b50\u7684\u8bfb\u5199\u64cd\u4f5c\u63d0\u4f9b\u6548\u7387\u3002<\/p>\n\n\n\n<p><strong>\u6700\u7b80\u5355\u7684\u60c5\u51b5\uff0c\u5c31\u662f\u7b97\u5b50\u878d\u5408\u3002\u6bd4\u5982\u5e38\u89c1Conv+ReLu\u7684\u4e24\u4e2a\u7b97\u5b50<\/strong>\uff0c\u56e0\u4e3aConv\u9700\u8981\u505a\u5927\u91cf\u5377\u79ef\u8ba1\u7b97\uff0c\u9700\u8981\u5bc6\u96c6\u7684\u8ba1\u7b97\u5355\u5143\u652f\u6301\uff0c\u800cRelu\u51e0\u4e4e\u4e0d\u9700\u8981\u8ba1\u7b97\uff0c\u5982\u679cRelu\u7b97\u5b50\u5355\u72ec\u8fd0\u7b97\uff0c\u5219\u4e0d\u4ec5\u9700\u8981\u4e00\u4e2a\u8ba1\u7b97\u5355\u5143\u652f\u6301\u5176\u5b9e\u4e0d\u9700\u8981\u600e\u4e48\u8ba1\u7b97\u7684\u7b97\u5b50\uff0c\u540c\u65f6\u53c8\u8981\u5bf9\u524d\u7aef\u7684\u6570\u636e\u8fdb\u884c\u4e00\u6b21\u8bfb\u64cd\u4f5c\uff0c\u5f88\u6d6a\u8d39\u8d44\u6e90\u548c\u589e\u52a0I\/O\u64cd\u4f5c\uff1b \u6b64\u65f6\uff0c\u53ef\u4ee5\u5c06Conv\u548cRelu\u5408\u5e76\u878d\u5408\u6210\u4e00\u4e2a\u7b97\u5b50\uff0c\u53ef\u4ee5\u8282\u7701I\/O\u8bbf\u95ee\u548c\u5e26\u5bbd\u5f00\u9500\uff0c\u4e5f\u53ef\u4ee5\u8282\u7701\u8ba1\u7b97\u5355\u5143\u3002<\/p>\n\n\n\n<p>\u8fd9\u79cd\u7b97\u5b50\u878d\u5408\u5bf9\u4e8e\u6240\u6709\u63a8\u7406\u8bbe\u5907\u90fd\u662f\u652f\u6301\uff0c\u662f\u901a\u7528\u7684\u786c\u4ef6\u4f18\u5316\u3002\u6709\u4e9b\u662f\u9488\u5bf9\u7279\u5b9a\u786c\u4ef6\u4f18\u5316\uff0c\u6bd4\u5982\u67d0\u4e9b\u786c\u4ef6\u7684\u8ba1\u7b97\u5355\u5143\u4e0d\u652f\u6301\u8fc7\u5927\u7b97\u5b50\u8f93\u5165\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u5bf9\u7b97\u5b50\u8fdb\u884c\u62c6\u89e3\u3002<\/p>\n\n\n\n<p>\u8ba1\u7b97\u56fe\u7684\u4f18\u5316\u53ef\u4ee5\u603b\u7ed3\u4e3a\u7b97\u5b50\u62c6\u89e3\u3001\u7b97\u5b50\u805a\u5408\u3001\u7b97\u5b50\u91cd\u5efa\uff0c\u4ee5\u4fbf\u8fbe\u5230\u5728\u786c\u4ef6\u8bbe\u5907\u4e0a\u66f4\u597d\u7684\u6027\u80fd\u3002<\/p>\n\n\n\n<p>\u7b97\u5b50\u7f16\u8bd1\u4f18\u5316\u7684\u53e6\u4e00\u4e2a\u4f18\u5316\u5c31\u662f<strong>\u6570\u636e\u6392\u5e03\u4f18\u5316<\/strong>\u3002\u6211\u4eec\u77e5\u9053\uff0c\u5728TensorFlow\u6846\u67b6\u7684\u8f93\u5165\u683c\u5f0fNHWC\uff0c\u800cpytorch\u662fNCHW\u3002\u8fd9\u4e9b\u683c\u5f0f\u662f\u6846\u67b6\u62bd\u8c61\u51fa\u6765\u7684\u77e9\u9635\u683c\u5f0f\uff0c\u5b9e\u9645\u5728\u5185\u5b58\u4e2d\u7684\u5b58\u50a8\u90fd\u662f\u6309\u71671\u7ef4\u7684\u5f62\u5f0f\u5b58\u50a8\u3002\u8fd9\u5c31\u6d89\u53ca\u7269\u7406\u5b58\u50a8\u548c\u903b\u8f91\u5b58\u50a8\u4e4b\u95f4\u7684\u6620\u5c04\u5173\u7cfb\uff0c\u5982\u4f55\u66f4\u597d\u7684\u5e03\u5c40\u6570\u636e\u80fd\u5e26\u6765\u5b58\u50a8\u6570\u636e\u7684\u8bbf\u95ee\u662f\u4e00\u4e2a\u4f18\u5316\u65b9\u5411\uff1b\u53e6\u5916\u5728\u786c\u4ef6\u5c42\u9762\uff0c\u6709\u4e9b\u786c\u4ef6\u5728\u67d0\u79cd\u5b58\u50a8\u4e0b\u6709\u6700\u4f73\u7684\u6027\u80fd\uff0c\u901a\u5e38\u53ef\u4ee5\u6839\u636e\u786c\u4ef6\u7684\u8bfb\u5199\u7279\u70b9\u8fdb\u884c\u4f18\u5316\u3002<\/p>\n\n\n\n<h3 id=\"slide-6\">\u5185\u5b58\u4f18\u5316<\/h3>\n\n\n\n<p>\u6211\u4eec\u63a8\u7406\u7684\u65f6\u5019\u90fd\u9700\u8981\u501f\u52a9\u989d\u5916\u7684\u786c\u4ef6\u8bbe\u5907\u6765\u8fbe\u5230\u9ad8\u901f\u63a8\u7406\uff0c\u5982GPU\uff0cNPU\u7b49\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u518dCPU\u548c\u8fd9\u4e9b\u786c\u4ef6\u8bbe\u5907\u8fdb\u884c\u4ea4\u4e92\uff1b\u4ee5GPU\u4e3a\u4f8b\uff0c\u63a8\u7406\u65f6\u9700\u8981\u5c06CPU\u4e2d\u7684\u6570\u636ecopy\u5230GPU\u663e\u5b58\u4e2d\uff0c\u7136\u540e\u8fdb\u884c\u6a21\u578b\u63a8\u7406\uff0c\u63a8\u7406\u5b8c\u6210\u540e\u7684\u6570\u636e\u662f\u5728GPU\u663e\u5b58\u4e2d\uff0c\u6b64\u65f6\u53c8\u9700\u8981\u5c06GPU\u663e\u5b58\u4e2d\u7684\u6570\u636ecopy\u56decpu\u4e2d\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u8fc7\u7a0b\u5c31\u6d89\u53ca\u5230\u5b58\u50a8\u8bbe\u5907\u7684\u7533\u8bf7\u3001\u91ca\u653e\u4ee5\u53ca\u5185\u5b58\u5bf9\u9f50\u7b49\u64cd\u4f5c\uff0c\u800c\u8fd9\u90e8\u5206\u4e5f\u662f\u6bd4\u8f83\u8017\u65f6\u7684\u3002<\/p>\n\n\n\n<p>\u56e0\u6b64\u5185\u5b58\u4f18\u5316\u7684\u65b9\u5411\uff0c\u901a\u5e38\u662f\u51cf\u5c11\u9891\u7e41\u7684\u8bbe\u5907\u5185\u5b58\u7a7a\u95f4\u7684\u7533\u8bf7\u548c\u5c3d\u91cf\u505a\u5230\u5185\u5b58\u7684\u590d\u7528\u3002<\/p>\n\n\n\n<p>\u4e00\u822c\u7684\uff0c\u53ef\u4ee5\u6839\u636e\u5f20\u91cf\u751f\u547d\u5468\u671f\u6765\u7533\u8bf7\u7a7a\u95f4\uff1a<\/p>\n\n\n\n<ul><li>\u9759\u6001\u5185\u5b58\u5206\u914d\uff1a\u6bd4\u5982\u4e00\u4e9b\u56fa\u5b9a\u7684\u7b97\u5b50\u5728\u6574\u4e2a\u8ba1\u7b97\u56fe\u4e2d\u90fd\u4f1a\u4f7f\u7528\uff0c\u6b64\u65f6\u9700\u8981\u518d\u6a21\u578b\u521d\u59cb\u5316\u65f6\u4e00\u6b21\u6027\u7533\u8bf7\u5b8c\u5185\u5b58\u7a7a\u95f4\uff0c\u5728\u5b9e\u9645\u63a8\u7406\u65f6\u4e0d\u9700\u8981\u9891\u7e41\u7533\u8bf7\u64cd\u4f5c\uff0c\u63d0\u9ad8\u6027\u80fd<\/li><li>\u52a8\u6001\u5185\u5b58\u5206\u914d\uff1a\u5bf9\u4e8e\u4e2d\u95f4\u4e34\u65f6\u7684\u5185\u5b58\u9700\u6c42\uff0c\u53ef\u4ee5\u8fdb\u884c\u4e34\u65f6\u7533\u8bf7\u548c\u91ca\u653e\uff0c\u8282\u7701\u5185\u5b58\u4f7f\u7528\uff0c\u63d0\u9ad8\u6a21\u578b\u5e76\u53d1\u80fd\u529b<\/li><li>\u5185\u5b58\u590d\u7528\uff1a\u5bf9\u4e8e\u540c\u4e00\u7c7b\u540c\u4e00\u4e2a\u5927\u5c0f\u7684\u5185\u5b58\u5f62\u5f0f\uff0c\u53c8\u6ee1\u8db3\u4e34\u65f6\u6027\uff0c\u53ef\u4ee5\u590d\u7528\u5185\u5b58\u5730\u5740\uff0c\u51cf\u5c11\u5185\u5b58\u7533\u8bf7\u3002<\/li><\/ul>\n\n\n\n<h3 id=\"slide-7\">\u8ba1\u7b97\u56fe\u8c03\u5ea6<\/h3>\n\n\n\n<p>\u5728\u8ba1\u7b97\u56fe\u4e2d\uff0c\u5b58\u5728\u67d0\u4e9b\u7b97\u5b50\u662f\u4e32\u884c\u4f9d\u8d56\uff0c\u800c\u67d0\u4e9b\u7b97\u5b50\u662f\u4e0d\u4f9d\u8d56\u6027\uff1b\u8fd9\u4e9b\u76f8\u4e92\u72ec\u7acb\u7684\u5b50\u8ba1\u7b97\u56fe\uff0c\u5c31\u53ef\u4ee5\u8fdb\u884c\u5e76\u884c\u8ba1\u7b97\uff0c\u63d0\u9ad8\u63a8\u7406\u901f\u5ea6\uff0c\u8fd9\u5c31\u662f\u8ba1\u7b97\u56fe\u7684\u8c03\u5ea6\u3002<\/p>\n\n\n\n<h2 id=\"slide-8\">TensorRT<\/h2>\n\n\n\n<p>    \u6211\u4eec\u8bb2\u89e3\u4e86\u63a8\u7406\u5f15\u64ce\u7684\u4e00\u822c\u5de5\u4f5c\u6d41\u7a0b\u548c\u4f18\u5316\u601d\u8def\uff0c\u8fd9\u4e00\u90e8\u5206\u4ecb\u7ecd\u4e00\u4e2a\u5177\u4f53\u7684\u63a8\u7406\u5f15\u64ce\u6846\u67b6\uff1aTensorRT\u3002NVIDIA TensorRT \u662f\u4e00\u4e2a\u7528\u4e8e\u6df1\u5ea6\u5b66\u4e60\u63a8\u7406\u7684 SDK \u3002 TensorRT \u63d0\u4f9b\u4e86 API \u548c\u89e3\u6790\u5668\uff0c\u53ef\u4ee5\u4ece\u6240\u6709\u4e3b\u8981\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u4e2d\u5bfc\u5165\u7ecf\u8fc7\u8bad\u7ec3\u7684\u6a21\u578b\u3002\u7136\u540e\uff0c\u5b83\u751f\u6210\u53ef\u5728\u6570\u636e\u4e2d\u5fc3\u4ee5\u53ca\u6c7d\u8f66\u548c\u5d4c\u5165\u5f0f\u73af\u5883\u4e2d\u90e8\u7f72\u7684\u4f18\u5316\u8fd0\u884c\u65f6\u5f15\u64ce\u3002TensorRT\u662fNVIDIA\u51fa\u54c1\u7684\u9488\u5bf9\u6df1\u5ea6\u5b66\u4e60\u7684\u9ad8\u6027\u80fd\u63a8\u7406SDK\u3002<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background\">   <strong><em>  \u76ee\u524d\uff0cTensorRT\u53ea\u652f\u6301NVIDIA\u81ea\u5bb6\u7684\u8bbe\u5907\u7684\u63a8\u7406\u670d\u52a1\uff0c\u5982\u670d\u52a1\u5668GPUTesla v100\u3001NVIDIA GeForce\u7cfb\u5217\u4ee5\u53ca\u652f\u6301\u8fb9\u7f18\u7684NVIDIA Jetson\u7b49\u3002<\/em><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"362\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-5-1024x362.png\" alt=\"\" class=\"wp-image-12581\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-5-1024x362.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-5-300x106.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-5-768x272.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-5.png 1171w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>TensorRT\u901a\u8fc7\u5c06\u73b0\u6709\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u5982TensorFlow\u3001mxnet\u3001pytorch\u3001caffe2\u4ee5\u53catheano\u7b49\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u8fdb\u884c\u8f6c\u6362\u548c\u4f18\u5316\uff0c\u5e76\u751f\u6210TensorRT\u7684\u8fd0\u884c\u65f6\uff08Runtime Engine\uff09\uff0c\u5229\u7528TensorRT\u63d0\u4f9b\u7684\u63a8\u7406\u63a5\u53e3\uff08\u652f\u6301\u4e0d\u540c\u524d\u7aef\u8bed\u8a00\u5982c++\/python\u7b49\uff09\uff0c\u90e8\u7f72\u4e0d\u540c\u7684NVIDIA GPU\u8bbe\u5907\u4e0a\uff0c\u63d0\u4f9b\u9ad8\u6027\u80fd\u4eba\u5de5\u667a\u80fd\u7684\u670d\u52a1\u3002<\/p>\n\n\n\n<p>\u5728\u6027\u80fd\u65b9\u9762\uff0cTensorRT\u5728\u81ea\u5bb6\u7684\u8bbe\u5907\u4e0a\u63d0\u4f9b\u4e86\u4f18\u8d8a\u7684\u6027\u80fd\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"198\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-6-1024x198.png\" alt=\"\" class=\"wp-image-12588\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-6-1024x198.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-6-300x58.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-6-768x148.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-6.png 1151w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u5bf9\u4e8eTensorRT\u800c\u8a00\uff0c\u4e3b\u8981\u4f18\u5316\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul><li>\u7b97\u5b50\u548c\u5f20\u91cf\u7684\u878d\u5408 Layer &amp; Tensor Fusion<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"497\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-7-1024x497.png\" alt=\"\" class=\"wp-image-12592\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-7-1024x497.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-7-300x145.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-7-768x372.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-7.png 1126w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u4ee5\u4e0a\u9762Inception\u6a21\u5757\u7684\u8ba1\u7b97\u56fe\u4e3a\u4f8b\u5b50\uff0c\u5de6\u8fb9\u662f\u672a\u4f18\u5316\u539f\u59cb\u7684\u7ed3\u6784\u56fe\uff0c\u53f3\u8fb9\u662f\u7ecf\u8fc7TensorRT\u4f18\u5316\u8fc7\u7684\u8ba1\u7b97\u56fe\u3002\u4f18\u5316\u7684\u76ee\u6807\u662f\u51cf\u5c11GPU\u6838\u6570\u7684\u4f7f\u7528\uff0c\u4ee5\u4fbf\u4e8e\u51cf\u5c11GPU\u6838\u8ba1\u7b97\u9700\u8981\u7684\u6570\u636e\u8bfb\u5199\uff0c\u63d0\u9ad8GPU\u6838\u6570\u7684\u8ba1\u7b97\u6548\u7387<\/p>\n\n\n\n<ul><li>\u9996\u5148\u662f\u5408\u5e76conv+bias+relu\u4e3a\u4e00\u4e2aCBR\u6a21\u5757\uff0c\u51cf\u5c112\/3 \u6838\u7684\u4f7f\u7528<\/li><li>\u7136\u540e\u662f\u5bf9\u4e8e\u540c\u4e00\u8f93\u51651x1conv\uff0c\u5408\u5e76\u4e3a\u4e00\u4e2a\u5927\u7684CBR\uff0c\u8f93\u51fa\u4fdd\u6301\u4e0d\u53d8\uff0c\u51cf\u5c11\u4e862\u6b21\u7684\u76f8\u540c\u6570\u636e\u7684\u8bfb\u5199<\/li><li>\u6709\u6ca1\u6709\u53d1\u73b0\u8fd8\u5c11\u4e86\u4e00\u4e2aconcat\u5c42\uff0c\u8fd9\u4e2a\u662f\u600e\u4e48\u505a\u5230\u7684\uff1fconcat\u64cd\u4f5c\u53ef\u4ee5\u7406\u89e3\u4e3a\u6570\u636e\u7684\u5408\u5e76\uff0cTensorRT\u91c7\u7528\u9884\u5148\u5148\u7533\u8bf7\u8db3\u591f\u7684\u7f13\u5b58\uff0c\u76f4\u63a5\u628a\u9700\u8981concat\u7684\u6570\u636e\u653e\u5230\u76f8\u5e94\u7684\u4f4d\u7f6e\u5c31\u53ef\u4ee5\u8fbe\u5230concat\u7684\u6548\u679c\u3002<\/li><\/ul>\n\n\n\n<p>\u7ecf\u8fc7\u4f18\u5316\uff0c\u4f7f\u5f97\u6574\u4e2a\u6a21\u578b\u5c42\u6570\u66f4\u5c11\uff0c\u5360\u7528\u66f4\u5c11GPU\u6838\uff0c\u8fd0\u884c\u6548\u7387\u66f4\u5feb\u3002<\/p>\n\n\n\n<ul><li>\u7cbe\u5ea6\u88c1\u526a Precision Calibration<br><strong>\u8fd9\u4e2a\u662f\u6240\u6709\u63a8\u7406\u5f15\u64ce\u90fd\u6709\u90e8\u5206\uff0cTensorRT\u652f\u6301\u4f4e\u7cbe\u5ea6FP16\u548cINT8\u7684\u6a21\u578b\u7cbe\u5ea6\u88c1\u526a\uff0c\u5728\u5c3d\u91cf\u4e0d\u964d\u4f4e\u6a21\u578b\u6027\u80fd\u7684\u60c5\u51b5\uff0c\u901a\u8fc7\u88c1\u526a\u7cbe\u5ea6\uff0c\u964d\u4f4e\u6a21\u578b\u5927\u5c0f\uff0c\u63d0\u4f9b\u63a8\u7406\u901f\u5ea6\u3002\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a\u4e0d\u4e00\u5b9aFP16\u5c31\u4e00\u5b9a\u6bd4FP32\u7684\u8981\u5feb\u3002\u8fd9\u53d6\u51b3\u4e8e\u8bbe\u5907\u7684\u4e0d\u540c\u7cbe\u5ea6\u8ba1\u7b97\u5355\u5143\u7684\u6570\u91cf\uff0c\u6bd4\u5982\u5728GeForce 1080Ti\u8bbe\u5907\u4e0a\u7531\u4e8eFP16\u7684\u8ba1\u7b97\u5355\u5143\u8981\u8fdc\u5c11\u4e8eFP32\u7684\uff0c\u88c1\u526a\u540e\u53cd\u800c\u6548\u7387\u964d\u4f4e\uff0c\u800cGeForce 2080Ti\u5219\u76f8\u53cd\u3002<\/strong><\/li><li>Dynamic Tensor Memory\uff1a \u8fd9\u5c5e\u4e8e\u63d0\u9ad8\u5185\u5b58\u5229\u7528\u7387<\/li><li>Multi-Stream Execution\uff1a \u8fd9\u5c5e\u4e8e\u5185\u90e8\u6267\u884c\u8fdb\u7a0b\u63a7\u5236\uff0c\u652f\u6301\u591a\u8def\u5e76\u884c\u6267\u884c\uff0c\u63d0\u4f9b\u6548\u7387<\/li><li>Auto-Tuning \u53ef\u7406\u89e3\u4e3aTensorRT\u9488\u5bf9NVIDIA GPU\u6838\uff0c\u8bbe\u8ba1\u6709\u9488\u5bf9\u6027\u7684GPU\u6838\u4f18\u5316\u6a21\u578b\uff0c\u5982\u4e0a\u9762\u6240\u8bf4\u7684\u7b97\u5b50\u7f16\u8bd1\u4f18\u5316\u3002<\/li><\/ul>\n\n\n\n<h3 id=\"slide-11\">&nbsp;TensorRT\u5b89\u88c5<\/h3>\n\n\n\n<p>\u4e86\u89e3\u4e86TensorRT\u662f\u4ec0\u4e48\u548c\u5982\u4f55\u505a\u4f18\u5316\uff0c\u6211\u4eec\u5b9e\u9645\u64cd\u4f5c\u4e0bTensorRT\uff0c \u5148\u6765\u770b\u770bTensorRT\u7684\u5b89\u88c5\u3002<\/p>\n\n\n\n<p>TensorRT\u662f\u9488\u5bf9NVIDIA GPU\u7684\u63a8\u7406\u5f15\u64ce\uff0c\u6240\u4ee5\u9700\u8981CUDA\u548ccudnn\u7684\u652f\u6301\uff0c\u9700\u8981\u6ce8\u610f\u7248\u672c\u7684\u5bf9\u5e94\u5173\u7cfb\uff1b \u4ee5TensorRT 7.1.3.4\u4e3a\u4f8b\uff0c\u9700\u8981\u81f3\u5c11CUDA10.2\u548ccudnn 8.x\u3002<\/p>\n\n\n\n<p>\u672c\u8d28\u4e0a TensorRT\u7684\u5b89\u88c5\u5305\u5c31\u662f\u52a8\u6001\u5e93\u6587\u4ef6\uff08CUDA\u548ccudnn\u4e5f\u662f\u5982\u6b64\uff09\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662fTensorRT\u63d0\u4f9b\u7684\u6a21\u578b\u8f6c\u6362\u5de5\u5177\u3002<\/p>\n\n\n\n<p>\u4e0b\u8f7d\u53ef\u53c2\u8003<\/p>\n\n\n\n<ul><li>\u5b98\u7f51\u5b89\u88c5\u6559\u7a0b\uff1a&nbsp;<a href=\"https:\/\/docs.nvidia.com\/deeplearning\/sdk\/tensorrt-install-guide\/index.html#gettingstarted\">https:\/\/docs.nvidia.com\/deeplearning\/sdk\/tensorrt-install-guide\/index.html#gettingstarted<\/a><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>rpm -i cuda-repo-rhel7-10-2-local-10.2.89-440.33.01-1.0-1.x86_64.rpm\ntar -zxvf cudnn-10.2-linux-x64-v8.0.1.13.tgz\n# tar -xzvf TensorRT-${version}.Linux.${arch}-gnu.${cuda}.${cudnn}.tar.gz\ntar -xzvf TensorRT-7.1.3.4.CentOS-7.6.x86_64-gnu.cuda-10.2.cudnn8.0.tar.gz\n<\/code><\/pre>\n\n\n\n<p>TensorRT\u4e5f\u63d0\u4f9b\u4e86python\u7248\u672c\uff08\u5e95\u5c42\u8fd8\u662fc\u7684\u52a8\u6001\u5e93\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#1.\u521b\u5efa\u865a\u62df\u73af\u5883 tensorrt\n  conda create -n tensorrt python=3.6\n  \n  #\u5b89\u88c5\u5176\u4ed6\u9700\u8981\u7684\u5de5\u5177\u5305, \u6309\u9700\u5305\u62ec\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\n  pip install keras,opencv-python,numpy,tensorflow-gpu==1.14,pytorch,torchvision\n \n#2. \u5b89\u88c5pycuda\n  #\u9996\u5148\u4f7f\u7528nvcc\u786e\u8ba4cuda\u7248\u672c\u662f\u5426\u6ee1\u8db3\u8981\u6c42: nvcc -V\n  pip install 'pycuda&gt;=2019.1.1'\n       \n#3. \u5b89\u88c5TensorRT\n  # \u4e0b\u8f7d\u89e3\u538b\u7684tar\u5305\n  tar -xzvf TensorRT-7.1.3.4.CentOS-7.6.x86_64-gnu.cuda-10.2.cudnn8.0.tar.gz\n  \n  #\u89e3\u538b\u5f97\u5230 TensorRT-7.1.3.4\u7684\u6587\u4ef6\u5939\uff0c\u5c06\u91cc\u9762lib\u7edd\u5bf9\u8def\u5f84\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u4e2d\n  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:\/usr\/local\/TensorRT-7.1.3.4\/lib\n  \n  #\u5b89\u88c5TensorRT\n  cd TensorRT-7.1.3.4\/python\n  pip install pip install tensorrt-7.1.3.4-cp36-none-linux_x86_64.whl\n \n#4.\u5b89\u88c5UFF\n  cd TensorRT-7.1.3.4\/uff\n  pip install uff-0.6.9-py2.py3-none-any.whl\n \n#5. \u5b89\u88c5graphsurgeon\n  cd TensorRT-7.1.3.4\/graphsurgeon\n  pip install uff-0.6.9-py2.py3-none-any.whl\n \n#6. \u73af\u5883\u6d4b\u8bd5\n  #\u8fdb\u5165python shell\uff0c\u5bfc\u5165\u76f8\u5173\u5305\u6ca1\u6709\u62a5\u9519\uff0c\u5219\u5b89\u88c5\u6210\u529f\n  import tensorrt\n  import uff<\/code><\/pre>\n\n\n\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5728\u8be5\u8def\u5f84\u7684samples\/python\u7ed9\u4e86\u5f88\u591a\u4f7f\u7528tensorrt\u7684python\u63a5\u53e3\u8fdb\u884c\u63a8\u7406\u7684\u4f8b\u5b50(\u56fe\u50cf\u5206\u7c7b\u3001\u76ee\u6807\u68c0\u6d4b\u7b49)\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u4e0d\u540c\u7684\u6a21\u578b\u89e3\u6790\u63a5\u53e3(uff,onnx,caffe)\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\u7ed9\u4e86\u4e00\u4e2acommon.py\u6587\u4ef6\uff0c\u5c01\u88c5\u4e86tensorrt\u5982\u4f55\u4e3aengine\u5206\u914d\u663e\u5b58\uff0c\u5982\u4f55\u8fdb\u884c\u63a8\u7406\u7b49\u64cd\u4f5c\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528\u8be5\u6587\u4ef6\u5185\u7684\u76f8\u5173\u51fd\u6570\u8fdb\u884ctensorrt\u7684\u63a8\u7406\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h3 id=\"slide-12\">TensorRT\u5de5\u4f5c\u6d41\u7a0b<\/h3>\n\n\n\n<p>\u5728\u5b89\u88c5TensorRT\u4e4b\u540e\uff0c\u5982\u4f55\u4f7f\u7528TensorRT\u5462\uff1f\u6211\u4eec\u5148\u6765\u4e86\u89e3\u4e0bTensorRT\u7684\u5de5\u4f5c\u6d41\u7a0b<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"481\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-8-1024x481.png\" alt=\"\" class=\"wp-image-12595\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-8-1024x481.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-8-300x141.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-8-768x361.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-8.png 1358w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u603b\u4f53\u6d41\u7a0b\u53ef\u4ee5\u62c6\u5206\u6210\u4e24\u5757\uff1a<\/p>\n\n\n\n<ul><li>\u6a21\u578b\u8f6c\u6362<br>TensorRT\u9700\u8981\u5c06\u4e0d\u540c\u8bad\u7ec3\u6846\u67b6\u8bad\u7ec3\u51fa\u6765\u7684\u6a21\u578b\uff0c\u8f6c\u6362\u4e3aTensorRT\u652f\u6301\u7684\u4e2d\u95f4\u8868\u8fbe\uff08IR\uff09\uff0c\u5e76\u505a\u8ba1\u7b97\u56fe\u7684\u4f18\u5316\u7b49\uff0c\u5e76\u5e8f\u5217\u5316\u751f\u6210plan\u6587\u4ef6\u3002<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"237\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-9-1024x237.png\" alt=\"\" class=\"wp-image-12596\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-9-1024x237.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-9-300x69.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-9-768x178.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-9.png 1319w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul><li>\u6a21\u578b\u63a8\u7406\uff1a\u5728\u6a21\u578b\u8f6c\u6362\u597d\u540e\u4e4b\u540e\uff0c\u5728\u63a8\u7406\u65f6\uff0c\u9700\u8981\u52a0plan\u6587\u4ef6\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u52a0\u8f7d\u6a21\u578b\uff0c\u5e76\u901a\u8fc7TensorRT\u8fd0\u884c\u65f6\u8fdb\u884c\u6a21\u578b\u63a8\u7406\uff0c\u8f93\u51fa\u7ed3\u679c<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"209\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-10-1024x209.png\" alt=\"\" class=\"wp-image-12598\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-10-1024x209.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-10-300x61.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-10-768x156.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-10.png 1262w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 id=\"slide-13\">\u6a21\u578b\u8f6c\u6362<\/h3>\n\n\n\n<p>\u7531\u4e8e\u4e0d\u540c\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u7684\u5b9e\u73b0\u903b\u8f91\u4e0d\u540c\uff0cTensorRT\u5728\u8f6c\u6362\u6a21\u578b\u65f6\u91c7\u7528\u4e0d\u540c\u9002\u914d\u65b9\u6cd5\u3002\u4ee5\u5f53\u524d\u6700\u6d41\u884c\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6TensorFlow\u548cPytorch\u4e3a\u4f8b\u4e3a\u4f8b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"834\" height=\"174\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-11.png\" alt=\"\" class=\"wp-image-12600\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-11.png 834w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-11-300x63.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-11-768x160.png 768w\" sizes=\"(max-width: 834px) 100vw, 834px\" \/><\/figure>\n\n\n\n<p><strong>\u7531\u4e8epytorch\u91c7\u7528\u52a8\u6001\u7684\u8ba1\u7b97\u56fe\uff0c\u4e5f\u5c31\u662f\u6ca1\u6709\u56fe\u7684\u6982\u5ff5\uff0c\u9700\u8981\u501f\u52a9ONNX\u751f\u6210\u9759\u6001\u56fe\u3002<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>Open Neural Network Exchange\uff08ONNX\uff0c\u5f00\u653e\u795e\u7ecf\u7f51\u7edc\u4ea4\u6362\uff09\u683c\u5f0f\uff0c\u662f\u4e00\u4e2a\u7528\u4e8e\u8868\u793a\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u7684\u6807\u51c6\uff0c\u53ef\u4f7f\u6a21\u578b\u5728\u4e0d\u540c\u6846\u67b6\u4e4b\u95f4\u8fdb\u884c\u8f6c\u79fb.\u6700\u521d\u7684ONNX\u4e13\u6ce8\u4e8e\u63a8\u7406\uff08\u8bc4\u4f30\uff09\u6240\u9700\u7684\u529f\u80fd\u3002 ONNX\u89e3\u91ca\u8ba1\u7b97\u56fe\u7684\u53ef\u79fb\u690d\uff0c\u5b83\u4f7f\u7528graph\u7684\u5e8f\u5217\u5316\u683c\u5f0f<\/p><\/blockquote>\n\n\n\n<p><strong>pth \u8f6c\u6362\u4e3aonnx<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import onnx\nimport torch\ndef export_onnx(onnx_model_path, model, cuda, height, width, dummy_input=None):\n    model.eval()\n    if dummy_input is None:\n        dummy_input = torch.randn(1, 3, height, width).float()\n    dummy_input.requires_grad = True\n    print(\"dummy_input shape: \", dummy_input.shape, dummy_input.requires_grad)\n\n    if cuda:\n        dummy_input = dummy_input.cuda()\n\n    torch.onnx.export(\n        model,  <em># model being run<\/em>\n        dummy_input,  <em># model input (or a tuple for multiple inputs)<\/em>\n        onnx_model_path,  <em># where to save the model (can be a file or file-like object)<\/em>\n        export_params=True,  <em># store the trained parameter weights inside the model file<\/em>\n        opset_version=10,  <em># the ONNX version to export the model to<\/em>\n        do_constant_folding=True,  <em># whether to execute constant folding for optimization<\/em>\n        verbose=True,\n        input_names=&#91;'input'],  <em># the model's input names<\/em>\n        output_names=&#91;'output'],  <em># the model's output names<\/em>\n    )<\/code><\/pre>\n\n\n\n<p>\u4ece\u4e0a\u53ef\u77e5\uff0connx\u901a\u8fc7pytorch\u6a21\u578b\u5b8c\u6210\u4e00\u6b21\u6a21\u578b\u8f93\u5165\u548c\u8f93\u51fa\u7684\u8fc7\u7a0b\u6765\u904d\u5386\u6574\u4e2a\u7f51\u7edc\u7684\u65b9\u5f0f\u6765\u6784\u5efa\u5b8c\u6210\u7684\u8ba1\u7b97\u56fe\u7684\u4e2d\u95f4\u8868\u793a\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u4e09\u4e2a\u91cd\u8981\u7684\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul><li>opset_version: \u8fd9\u4e2a\u662fonnx\u652f\u6301\u7684op\u7b97\u5b50\u7684\u96c6\u5408\u7684\u7248\u672c\uff0c\u56e0\u4e3aonnx\u76ee\u6807\u662f\u5728\u4e0d\u540c\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u4e4b\u95f4\u505a\u6a21\u578b\u8f6c\u6362\u7684\u4e2d\u95f4\u683c\u5f0f\uff0c\u7406\u8bba\u4e0aonnx\u5e94\u8be5\u652f\u6301\u5176\u4ed6\u6846\u67b6\u7684\u6240\u6709\u7b97\u5b50\uff0c\u4f46\u662f\u5b9e\u9645\u4e0aonnx\u652f\u6301\u7684\u7b97\u5b50\u603b\u662f\u6ede\u540e\u7684\uff0c\u6240\u4ee5\u9700\u8981\u77e5\u9053\u90a3\u4e2a\u7248\u672c\u652f\u6301\u4ec0\u4e48\u7b97\u5b50\uff0c\u5982\u679c\u8f6c\u6362\u5b58\u5728\u95ee\u9898\uff0c\u5927\u90e8\u5206\u5f53\u524d\u7684\u7248\u672c\u4e0d\u652f\u6301\u9700\u8981\u8f6c\u6362\u7684\u7b97\u5b50\u3002<\/li><li>input_names\uff1a\u6a21\u578b\u7684\u8f93\u5165\uff0c\u5982\u679c\u662f\u591a\u4e2a\u8f93\u5165\uff0c\u7528\u5217\u8868\u7684\u65b9\u5f0f\u8868\u793a\uff0c\u5982[&#8220;input&#8221;, &#8220;scale&#8221;]<\/li><li>output_names\uff1a \u6a21\u578b\u7684\u8f93\u51fa\uff0c \u591a\u4e2a\u8f93\u51fa\uff0c\u901ainput_names<\/li><\/ul>\n\n\n\n<p class=\"has-light-pink-background-color has-background\"><strong>onnx\u8f6c\u6362\u4e3aplan engine\u6a21\u578b<\/strong><\/p>\n\n\n\n<p>\u8fd9\u91cc\u7ed9\u51fa\u7684\u901a\u8fc7TensorRT\u7684python\u63a5\u53e3\u6765\u5b8c\u6210onnx\u5230plan engine\u6a21\u578b\u7684\u8f6c\u6362\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import tensorrt as trt\ndef build_engine(onnx_path):\n          EXPLICIT_BATCH = 1 &lt;&lt; (int)(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)\n        with trt.Builder(TRT_LOGGER) as builder, builder.create_network(EXPLICIT_BATCH) as network, trt.OnnxParser(network, TRT_LOGGER) as parser:\n            builder.max_batch_size = 128\n            builder.max_workspace_size = 1&lt;&lt;15\n            builder.fp16_mode = True\n            builder.strict_type_constraints = True\n            with open(onnx_path, 'rb') as model:\n                parser.parse(model.read())\n            <em># Build and return an engine.<\/em>\n            return builder.build_cuda_engine(network)<\/code><\/pre>\n\n\n\n<p>\u4ece\u4e0a\u9762\u7684\u8f6c\u6362\u8fc7\u7a0b\u53ef\u77e5\uff0cTensortRT\u7684\u8f6c\u6362\u6d89\u53ca\u5230\u51e0\u4e2a\u5173\u952e\u7684\u6982\u5ff5\uff1a<code>builder<\/code>&nbsp;\u3001&nbsp;<code>network<\/code>&nbsp;\u3001<code>parser<\/code><\/p>\n\n\n\n<ul><li>builder\uff1aTensorRT\u6784\u5efa\u5668\uff0c\u5728\u6784\u5efa\u5668\u4e2d\u8bbe\u7f6e\u6a21\u578b\uff0c\u89e3\u6790\u5668\u548c\u63a8\u7406\u7684\u53c2\u6570\u8bbe\u7f6e\u7b49&nbsp;<code>trt.Builder(TRT_LOGGER)<\/code><\/li><li>network: TensorRT\u80fd\u8bc6\u522b\u7684\u6a21\u578b\u7ed3\u6784\uff08\u8ba1\u7b97\u56fe\uff09<\/li><li>parser\uff1a\u8fd9\u91cc\u662f\u6307\u89e3\u6790onnx\u6a21\u578b\u7ed3\u6784\uff08\u8ba1\u7b97\u56fe\uff09<\/li><\/ul>\n\n\n\n<p>\u4ece\u603b\u4f53\u4e0a\u770b\uff0cTensorRT\u7684\u8f6c\u6362\u6a21\u578b\u662f\uff0c\u5c06onnx\u7684\u6a21\u578b\u7ed3\u6784\uff08\u4ee5\u53ca\u53c2\u6570\uff09\u8f6c\u6362\u5230TensorRT\u7684network\u4e2d\uff0c\u540c\u65f6\u8bbe\u7f6e\u6a21\u578b\u63a8\u7406\u548c\u4f18\u5316\u7684\u53c2\u6570\uff08\u5982\u7cbe\u5ea6\u88c1\u526a\u7b49\uff09\u3002 \u7528\u4e00\u5f20\u56fe\u6765\u603b\u7ed3\u4e0b\u4e0a\u8ff0\u8fc7\u7a0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"353\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-12-1024x353.png\" alt=\"\" class=\"wp-image-12606\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-12-1024x353.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-12-300x103.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-12-768x264.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-12.png 1182w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>\u4fdd\u5b58engine\u548c\u8bfb\u53d6engine<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>#\u89e3\u6790\u6a21\u578b\uff0c\u6784\u5efaengine\u5e76\u4fdd\u5b58<\/em>\nwith build_engine(onnx_path) as engine:\n    with open(engine_path, \"wb\") as f:\n        f.write(engine.serialize())\n\n<em>#\u76f4\u63a5\u52a0\u8f7dengine   <\/em>\nwith open(engine_path, \"rb\") as f, trt.Runtime(TRT_LOGGER) as runtime:\n    engine = runtime.deserialize_cuda_engine(f.read())<\/code><\/pre>\n\n\n\n<h3>TensorFlow \/ Keras<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"138\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-13-1024x138.png\" alt=\"\" class=\"wp-image-12609\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-13-1024x138.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-13-300x41.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-13-768x104.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-13.png 1139w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>TensorFlow\u6216\u8005Keras\uff08\u540e\u53f0\u4e3aTensorFlow\uff09\u91c7\u7528\u7684\u662f\u9759\u6001\u7684\u8ba1\u7b97\u56fe\uff0c\u672c\u8eab\u5c31\u6709\u56fe\u7684\u5b8c\u6574\u7ed3\u6784\uff0c\u4e00\u822c\u6a21\u578b\u8bad\u7ec3\u8fc7\u7a0b\u4f1a\u4fdd\u7559ckpt\u683c\u5f0f\uff0c\u6709\u5f88\u591a\u5197\u4f59\u7684\u4fe1\u606f\uff0c\u9700\u8981\u8f6c\u6362\u4e3apb\u683c\u5f0f\u3002\u9488\u5bf9TensorFlow\uff0cTensorRT\u63d0\u4f9b\u4e86\u4e24\u79cd\u8f6c\u6362\u65b9\u5f0f\uff0c\u4e00\u79cd\u662fpb\u76f4\u63a5\u8f6c\u6362\uff0c\u8fd9\u79cd\u65b9\u5f0f\u52a0\u901f\u6548\u679c\u6709\u9650\u6240\u4ee5\u4e0d\u63a8\u8350\uff1b\u53e6\u4e00\u79cd\u662f\u8f6c\u6362uff\u683c\u5f0f\uff0c\u52a0\u901f\u6548\u679c\u660e\u663e\u3002<\/p>\n\n\n\n<ul><li>\u8f6c\u6362\u4e3apb<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from tensorflow.python.framework import graph_io\nfrom tensorflow.python.framework import graph_util\nfrom tensorflow.python.platform import gfile\n<em># \u8bbe\u7f6e\u8f93\u51fa\u8282\u70b9\u4e3a\u56fa\u5b9a\u540d\u79f0<\/em>\nOUTPUT_NODE_PREFIX = 'output_'\nNUMBER_OF_OUTPUTS = 1\n<em>#\u8f93\u5165\u548c\u8f93\u51fa\u8282\u70b9\u540d\u79f0<\/em>\noutput_names = &#91;'output_']\ninput_names = &#91;'input_']\ninput_tensor_name = input_names&#91;0] + \":0\"\noutput_tensor_name = output_names&#91;0] + \":0\"\n\ndef keras_to_pb(model_path, pb_path):\n    K.clear_session()<em>#\u53ef\u4ee5\u4fdd\u6301\u8f93\u5165\u8f93\u51fa\u8282\u70b9\u7684\u540d\u79f0\u6bcf\u6b21\u6267\u884c\u90fd\u4e00\u81f4<\/em>\n    K.set_learning_phase(0)\n    sess = K.get_session()\n    try:\n        model = load_model(model_path)<em># h5 model file_path<\/em>\n    except ValueError as err:\n        print('Please check the input saved model file')\n        raise err\n\n    output = &#91;None]*NUMBER_OF_OUTPUTS\n    output_node_names = &#91;None]*NUMBER_OF_OUTPUTS\n    for i in range(NUMBER_OF_OUTPUTS):\n        output_node_names&#91;i] = OUTPUT_NODE_PREFIX+str(i)\n        output&#91;i] = tf.identity(model.outputs&#91;i], name=output_node_names&#91;i])\n    \n    try:\n        frozen_graph = graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), output_node_names)\n        graph_io.write_graph(frozen_graph, os.path.dirname(pb_path), os.path.basename(pb_path), as_text=False)\n        print('Frozen graph ready for inference\/serving at {}'.format(pb_path))\n    except:\n        print(\"error !\")<\/code><\/pre>\n\n\n\n<ul><li>pb \u5230uff<\/li><\/ul>\n\n\n\n<p>\u91c7\u7528TensorRT\u63d0\u4f9b\u7684uff\u6a21\u5757\u7684<code>from_tensorflow_frozen_model()<\/code>\u5c06pb\u683c\u5f0f\u6a21\u578b\u8f6c\u6362\u6210uff\u683c\u5f0f\u6a21\u578b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import uff\ndef pb_to_uff(pb_path, uff_path, output_names):\n        uff_model = uff.from_tensorflow_frozen_model(pb_path, output_names, output_filename=uff_path)<\/code><\/pre>\n\n\n\n<p>uff\u8f6c\u6362\u6210plan engine\u6a21\u578b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import tensorrt as trt\n\nTRT_LOGGER = trt.Logger(trt.Logger.INFO)\nimg_size_tr = (3,224,224) <em>#CHW<\/em>\ninput_names = &#91;'input_0']\noutput_names = &#91;'output_0']\n\ndef build_engine(uff_path):\n    with trt.Builder(TRT_LOGGER) as builder, builder.create_network() as network, trt.UffParser() as parser:\n        builder.max_batch_size = 128 <em>#must bigger than batch_size<\/em>\n        builder.max_workspace_size =1&lt;&lt;15  <em>#cuda buffer size<\/em>\n        builder.fp16_mode = True  <em>#set dtype: fp32, fp16, int8<\/em>\n        builder.strict_type_constraints = True\n        <em># Parse the Uff Network<\/em>\n        parser.register_input(input_names&#91;0], img_size_tr)<em>#NCHW<\/em>\n        parser.register_output(output_names&#91;0])\n        parser.parse(uff_path, network)\n        <em># Build and return an engine.<\/em>\n        return builder.build_cuda_engine(network)<\/code><\/pre>\n\n\n\n<p>\u5728\u7ed1\u5b9a\u5b8c\u8f93\u5165\u8f93\u51fa\u8282\u70b9\u4e4b\u540e\uff0cparser.parse()\u53ef\u4ee5\u89e3\u6790uff\u683c\u5f0f\u6587\u4ef6\uff0c\u5e76\u4fdd\u5b58\u76f8\u5e94\u7f51\u7edc\u5230network\u3002\u800c\u540e\u901a\u8fc7builder.build_cuda_engine()\u5f97\u5230\u53ef\u4ee5\u76f4\u63a5\u5728cuda\u6267\u884c\u7684engine\u6587\u4ef6\u3002\u8be5engine\u6587\u4ef6\u7684\u6784\u5efa\u9700\u8981\u4e00\u5b9a\u65f6\u95f4\uff0c\u53ef\u4ee5\u4fdd\u5b58\u4e0b\u6765\uff0c\u4e0b\u6b21\u76f4\u63a5\u52a0\u8f7d\u8be5\u6587\u4ef6\uff0c\u800c\u4e0d\u9700\u8981\u89e3\u6790\u6a21\u578b\u540e\u518d\u6784\u5efa\u3002<\/p>\n\n\n\n<p>TensorFlow\u7684\u6a21\u578b\u8f6c\u6362\u57fa\u672c\u548connx\u662f\u4e00\u6837\u7684\uff0c\u4e3b\u8981\u662f\u89e3\u6790\u5668\u4e0d\u4e00\u6837\u662fUffParser\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>#\u89e3\u6790\u6a21\u578b\uff0c\u6784\u5efaengine\u5e76\u4fdd\u5b58<\/em>\nwith build_engine(uff_path) as engine:\n    with open(engine_path, \"wb\") as f:\n        f.write(engine.serialize())\n\n<em>#\u76f4\u63a5\u52a0\u8f7dengine   <\/em>\nwith open(engine_path, \"rb\") as f, trt.Runtime(TRT_LOGGER) as runtime:\n    engine = runtime.deserialize_cuda_engine(f.read())<\/code><\/pre>\n\n\n\n<h3 id=\"slide-16\">\u6a21\u578b\u63a8\u7406<\/h3>\n\n\n\n<p>\u901a\u8fc7TensorRT\u7684\u6a21\u578b\u8f6c\u6362\u540e\uff0c\u5916\u90e8\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u90fd\u88abTensorRT\u7edf\u4e00\u6210TensorRT\u53ef\u8bc6\u522b\u7684engine\u6587\u4ef6\uff08\u5e76\u4f18\u5316\u8fc7\uff09\u3002\u5728\u63a8\u7406\u65f6\uff0c\u53ea\u8981\u901a\u8fc7TensorRT\u7684\u63a8\u7406SDK\u5c31\u53ef\u4ee5\u5b8c\u6210\u63a8\u7406\u3002<\/p>\n\n\n\n<p>\u5177\u4f53\u7684\u63a8\u7406\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"703\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-14-1024x703.png\" alt=\"\" class=\"wp-image-12610\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-14-1024x703.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-14-300x206.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-14-768x527.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-14.png 1103w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul><li>\u901a\u8fc7TensorRT\u8fd0\u884c\u65f6\uff0c\u52a0\u8f7d\u8f6c\u6362\u597d\u7684engine<\/li><li>\u63a8\u7406\u524d\u51c6\u5907\uff1a\uff081\uff09\u5728CPU\u4e2d\u5904\u7406\u597d\u8f93\u5165\uff08\u5982\u8bfb\u53d6\u6570\u636e\u548c\u6807\u51c6\u5316\u7b49\uff09\uff082\uff09\u5229\u7528TensorRT\u7684\u63a8\u7406SDK\u4e2dcommon\u6a21\u5757\u8fdb\u884c\u8f93\u5165\u548c\u8f93\u51faGPU\u663e\u5b58\u5206\u914d<\/li><li>\u6267\u884c\u63a8\u7406\uff1a\uff081\uff09\u5c06CPU\u7684\u8f93\u5165\u62f7\u8d1d\u5230GPU\u4e2d \uff082\uff09\u5728GPU\u4e2d\u8fdb\u884c\u63a8\u7406\uff0c\u5e76\u5c06\u6a21\u578b\u8f93\u51fa\u653e\u5165GPU\u663e\u5b58\u4e2d<\/li><li>\u63a8\u7406\u540e\u5904\u7406\uff1a\uff081\uff09\u5c06\u8f93\u51fa\u4eceGPU\u663e\u5b58\u4e2d\u62f7\u8d1d\u5230CPU\u4e2d \uff082\uff09\u5728CPU\u4e2d\u8fdb\u884c\u5176\u4ed6\u540e\u5904\u7406<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>import common\nimport numpy as np\nimport cv2\nimport tensorrt as trt\n\ndef inference_test(engine_path, img_file):\n\n    <em># process input<\/em>\n    input_image = cv2.imread(img_file)\n    input_image = input_image&#91;..., ::-1] \/ 255.0\n    input_image = np.expand_dims(input_image, axis=0)\n    \n    input_image = input_image.transpose((0, 3, 1, 2))  <em># NCHW for pytorch<\/em>\n    input_image = input_image.reshape(1, -1)  <em># .ravel()<\/em>\n        \n    <em># infer<\/em>\n    batch_size = 1\n    TRT_LOGGER = trt.Logger(trt.Logger.INFO)\n    with open(engine_path, \"rb\") as f, trt.Runtime(TRT_LOGGER) as runtime:\n        engine = runtime.deserialize_cuda_engine(f.read())\n        <em># Allocate buffers and create a CUDA stream<\/em>\n        inputs, outputs, bindings, stream = common.allocate_buffers(engine, batch_size)\n        <em># Contexts are used to perform inference.<\/em>\n        with engine.create_execution_context() as context:\n             np.copyto(inputs&#91;0].host, input_image)\n             &#91;output] = common.do_inference(context, bindings=bindings, inputs=inputs, outputs=outputs, stream=stream, batch_size=batch_size)<\/code><\/pre>\n\n\n\n<h3 id=\"slide-17\">TensorRT\u8fdb\u9636\u548c\u7f3a\u70b9<\/h3>\n\n\n\n<p>\u524d\u9762\u8f83\u5168\u9762\u4e86\u4ecb\u7ecd\u4e86TensorRT\u7684\u7279\u70b9\uff08\u4f18\u70b9\uff09\u548c\u5de5\u4f5c\u6d41\u7a0b\uff1b\u5e0c\u671b\u80fd\u611f\u53d7\u5230TensorRT\u7684\u9b45\u529b\u6240\u5728\u3002<\/p>\n\n\n\n<p>\u5728\u5b9e\u9645\u4ee3\u7801\u4e2d\u4e3b\u8981\u662f\u901a\u8fc7python\u7684\u63a5\u53e3\u6765\u8bb2\u89e3\uff0cTensorRT\u4e5f\u63d0\u4f9b\u4e86C++\u7684\u8f6c\u6362\u548c\u63a8\u7406\u65b9\u5f0f\uff0c\u4f46\u662f\u4e3b\u8981\u7684\u5173\u952e\u6982\u5ff5\u662f\u4e00\u6837<\/p>\n\n\n\n<p>\u90a3TensorRT\u6709\u4ec0\u4e48\u5c40\u9650\u6027\u5417\uff1f<\/p>\n\n\n\n<p>\u9996\u5148\uff0cTensorRT\u53ea\u652f\u6301NVIDIA\u81ea\u5bb6\u7684\u8bbe\u5907\uff0c\u5e76\u6839\u636e\u81ea\u5bb6\u8bbe\u5907\u7684\u7279\u70b9\uff0c\u505a\u4e86\u5f88\u591a\u7684\u4f18\u5316\uff0c\u5982\u679c\u662f\u5176\u4ed6\u8bbe\u5907\uff0cTensorRT\u5c31\u4e0d\u9002\u7528\u4e86\u3002\u8fd9\u65f6\u5019\u53ef\u4ee5\u8003\u8651\u5176\u4ed6\u7684\u63a8\u7406\u6846\u67b6\uff0c\u6bd4\u5982\u4ee5\u63a8\u7406\u7f16\u8bd1\u4e3a\u57fa\u7840\u7684TVM\uff0c \u9488\u5bf9\u79fb\u52a8\u5e73\u53f0\u63a8\u7406NCNN\uff0cMACE\u3001MNN\u4ee5\u53caTFLite\u7b49\uff0c\u4ee5\u53ca\u9488\u5bf9Intel CPU\u7684OPENVINO\u3002<\/p>\n\n\n\n<p>\u5176\u6b21\uff0c\u7b97\u5b50\u7684\u652f\u6301\u7a0b\u5ea6\uff1b\u8fd9\u51e0\u4e4e\u662f\u6240\u6709\u7b2c\u4e09\u65b9\u63a8\u7406\u6846\u67b6\u90fd\u9047\u5230\u7684\u95ee\u9898\uff0cTensorRT\u5728\u67d0\u4e9b\u4e0d\u652f\u6301\u7684\u7b97\u5b50\u7684\u60c5\u51b5\u4e0b\uff0cTensorRT\u63d0\u4f9b\u4e86plugin\u7684\u65b9\u5f0f\uff0cplugin\u63d0\u4f9b\u4e86\u6807\u51c6\u63a5\u53e3\uff0c\u5141\u8bb8\u81ea\u5df1\u5f00\u53d1\u65b0\u7684\u7b97\u5b50\uff0c\u5e76\u4ee5\u63d2\u4ef6\u7684\u65b9\u5f0f\u52a0\u5165TensorRT\uff08\u540e\u9762\u4f1a\u4e13\u95e8\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5173\u6ce8\uff09\u3002<\/p>\n\n\n\n<h3 id=\"slide-18\">\u603b\u7ed3<\/h3>\n\n\n\n<ul><li>\u8bad\u7ec3\u9700\u8981\u524d\u5411\u8ba1\u7b97\u548c\u53cd\u5411\u68af\u5ea6\u66f4\u65b0\uff0c\u63a8\u7406\u53ea\u9700\u8981\u524d\u5411\u8ba1\u7b97<\/li><li>\u63a8\u7406\u6846\u67b6\u4f18\u5316\uff1a\u4f4e\u7cbe\u5ea6\u4f18\u5316\u3001\u7b97\u5b50\u7f16\u8bd1\u4f18\u5316\u3001\u5185\u5b58\u4f18\u5316\u3001\u8ba1\u7b97\u56fe\u8c03\u5ea6<\/li><li>TensorRT\u662f\u9488\u5bf9NVIDIA\u8bbe\u5907\u7684\u9ad8\u6027\u80fd\u63a8\u7406\u6846\u67b6<\/li><li>TensorRT\u5de5\u4f5c\u6d41\u7a0b\u5305\u62ec\u6a21\u578b\u8f6c\u6362\u548c\u6a21\u578b\u63a8\u7406<\/li><li>\u9488\u5bf9Pytorch\uff0c TensorRT\u6a21\u578b\u8f6c\u6362\u94fe\u8def\u4e3a\uff1apth-&gt;onnx-&gt;trt plan<\/li><li>\u9488\u5bf9TensorFlow\uff0cTensorRT\u6a21\u578b\u8f6c\u6362\u94fe\u8def\u4e3a\uff1ackpt-&gt;pb-&gt;uff-&gt;trt plan<\/li><li>TensorRT\u6a21\u578b\u8f6c\u6362\u5173\u952e\u70b9\u4e3abuild\uff0cnetwork\u548cparse<\/li><li>TensorRT\u6a21\u578b\u63a8\u7406\u5173\u952e\u70b9\u4e3a\uff1atensorrt runtime\uff0cengine context\uff0c\u663e\u5b58\u64cd\u4f5c\u548c\u63a8\u7406<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6a21\u578b\u8f6c\u6362\u5de5\u5177\uff1a https:\/\/convertmodel.com\/ \u6df1\u5ea6\u5b66\u4e60\u7684\u5de5\u4f5c\u6d41\u7a0b\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u53ef\u5206\u4e3a\u8bad\u7ec3 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2023\/02\/01\/tensorrt\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">NVIDIA TensorRT&#8212;\u63a8\u7406\u5f15\u64ce\u52a0\u901f\u6df1\u5ea6\u5b66\u4e60\u63a8\u7406<\/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,4,26],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/12472"}],"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=12472"}],"version-history":[{"count":43,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/12472\/revisions"}],"predecessor-version":[{"id":12675,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/12472\/revisions\/12675"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=12472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=12472"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=12472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}