{"id":14153,"date":"2023-02-17T17:46:05","date_gmt":"2023-02-17T09:46:05","guid":{"rendered":"http:\/\/139.9.1.231\/?p=14153"},"modified":"2023-06-06T09:53:40","modified_gmt":"2023-06-06T01:53:40","slug":"tensorrt-1","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2023\/02\/17\/tensorrt-1\/","title":{"rendered":"TensorRT &#8211; \u4f7f\u7528trtexec\u5de5\u5177\u8f6c\u6362\u6a21\u578b\u3001\u8fd0\u884c\u6a21\u578b\u3001\u6d4b\u8bd5\u7f51\u7edc\u6027\u80fd"},"content":{"rendered":"\n\n\n<h2>\u8f6c\u6362\u6a21\u578b\u5c06onnx\u8f6c\u6362\u4e3aTensorRT:<\/h2>\n\n\n\n<h3 id=\"h1\">\u65b9\u6cd5\u4e00\u3001trtexec<\/h3>\n\n\n\n<p>trtexec\u662f\u5728tensorrt\u5305\u4e2d\u81ea\u5e26\u7684\u8f6c\u6362\u7a0b\u5e8f\uff0c\u8be5\u7a0b\u5e8f\u4f4d\u4e8ebin\u76ee\u5f55\u4e0b\uff0c\u7528\u8d77\u6765\u6bd4\u8f83\u65b9\u4fbf\uff0c\u4e5f\u662f\u6700\u7b80\u5355\u7684trt\u6a21\u578b\u8f6c\u6362\u65b9\u5f0f\uff0c\u5728\u4f7f\u7528\u4e4b\u524d\u9700\u8981\u7cfb\u7edf\u5b89\u88c5\u597dcuda\u548ccudnn\uff0c\u5426\u5219\u65e0\u6cd5\u6b63\u5e38\u8fd0\u884c\u3002\u4f7f\u7528\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\u9996\u5148\u5c06pytorch\u6a21\u578b\u5148\u8f6c\u6362\u6210onnx\u6a21\u578b\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def torch2onnx(model_path,onnx_path):<br>    model = load_model(model_path)<br>    test_arr = torch.randn(1,3,32,448)<br>    input_names = ['input']<br>    output_names = ['output']<br>    tr_onnx.export(<br>        model,<br>        test_arr,<br>        onnx_path,<br>        verbose=False,<br>        opset_version=11,<br>        input_names=input_names,<br>        output_names=output_names,<br>        dynamic_axes={\"input\":{3:\"width\"}}            #\u52a8\u6001\u63a8\u7406W\u7eac\u5ea6\uff0c\u82e5\u9700\u5176\u4ed6\u52a8\u6001\u7eac\u5ea6\u53ef\u4ee5\u81ea\u884c\u4fee\u6539\uff0c\u4e0d\u9700\u8981\u52a8\u6001\u63a8\u7406\u7684\u8bdd\u53ef\u4ee5\u6ce8\u91ca\u8fd9\u884c<br>    )<br>    print('-&gt;&gt;\u6a21\u578b\u8f6c\u6362\u6210\u529f\uff01')<\/pre>\n\n\n\n<p>trtexec\u8f6c\u6362\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background\"><strong>\u56fa\u5b9a\u5c3a\u5bf8\u6a21\u578b\u8f6c\u6362\uff1a<\/strong>\u5c06ONNX\u6a21\u578b\u8f6c\u6362\u4e3a\u9759\u6001batchsize\u7684TensorRT\u6a21\u578b\uff0c\u542f\u52a8\u6240\u6709\u7cbe\u5ea6\u4ee5\u8fbe\u5230\u6700\u4f73\u6027\u80fd\uff0c\u5de5\u4f5c\u533a\u5927\u5c0f\u8bbe\u7f6e\u4e3a1024M<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/trtexec --onnx=repvgg_a1.onnx --saveEngine=repvgg_a1.engine --workspace=1024  --fp16 --verbose<\/code><\/pre>\n\n\n\n<p>\u52a8\u6001\u5c3a\u5bf8\u6a21\u578b\u8f6c\u6362\uff1a\u5c06ONNX\u6a21\u578b\u8f6c\u6362\u4e3a\u52a8\u6001batchsize\u7684TensorRT\u6a21\u578b\uff0c\u542f\u52a8\u6240\u6709\u7cbe\u5ea6\u4ee5\u8fbe\u5230\u6700\u4f73\u6027\u80fd\uff0c\u5de5\u4f5c\u533a\u5927\u5c0f\u8bbe\u7f6e\u4e3a1024M<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/trtexec --onnx=repvgg_a1.onnx --saveEngine=repvgg_a1.engine --workspace=1024 --minShapes=input:1x3x32x32 --optShapes=input:1x3x32x320 --maxShapes=input:1x3x32x640 --fp16\n\n\u6ce8\u610f:\n\u2013minShapes\uff0c\u2013optShapes \uff0c\u2013maxShapes\u5fc5\u987b\u5168\u90e8\u8bbe\u7f6e\uff0c\u8bbe\u7f6e\u7684\u5f62\u5f0f\u4e3a\uff1abatchsize x \u901a\u9053\u6570 x \u8f93\u5165\u5c3a\u5bf8x x \u8f93\u5165\u5c3a\u5bf8y\n\n\u4f8b\u5982\uff1a\n--minShapes=input:1x3x416x416\n--optShapes=input:8x3x416x416\n--maxShapes=input:8x3x416x416<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"75\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-430-1024x75.png\" alt=\"\" class=\"wp-image-14465\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-430-1024x75.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-430-300x22.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-430-768x56.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-430.png 1066w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-light-pink-background-color has-background\">\u53c2\u770b\u547d\u540d\u8be6\u89e3\uff1a .\/trtexec  &#8211;help, -h<\/p>\n\n\n\n<h2 id=\"trtexec\u7684\u53c2\u6570\u4f7f\u7528\u8bf4\u660e\">trtexec\u7684\u53c2\u6570\u4f7f\u7528\u8bf4\u660e<\/h2>\n\n\n\n<p><strong>1.1 Model Option \u6a21\u578b\u9009\u9879<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u2013uff : UFF\u6a21\u578b\u6587\u4ef6\u540d\u2013onnx : ONNX\u6a21\u578b\u6587\u4ef6\u540d\u2013model : Caffe\u6a21\u578b\u6587\u4ef6\u540d\uff0c\u6a21\u5f0f\u65f6\u65e0\u6a21\u578b\uff0c\u4f7f\u7528\u968f\u673a\u6743\u91cd\u2013deploy : Caffe prototxt \u6587\u4ef6\u540d\u2013output : \u8f93\u51fa\u540d\u79f0\uff08\u53ef\u591a\u6b21\u6307\u5b9a\uff09\uff1bUFF\u548cCaffe\u81f3\u5c11\u9700\u8981\u4e00\u4e2a\u8f93\u51fa\u2013uffInput : \u8f93\u5165blob\u540d\u79f0\u53ca\u5176\u7ef4\u5ea6\uff08X\u3001Y\u3001Z=C\u3001H\u3001W\uff09\uff0c\u53ef\u4ee5\u591a\u6b21\u6307\u5b9a\uff1bUFF\u578b\u53f7\u81f3\u5c11\u9700\u8981\u4e00\u4e2a\u2013uffNHWC : \u8bbe\u7f6e\u8f93\u5165\u662f\u5426\u5728NHWC\u5e03\u5c40\u4e2d\u800c\u4e0d\u662fNCHW\u4e2d\uff08\u5728\u2013uffInput\u4e2d\u4f7f\u7528X\u3001Y\u3001Z=H\u3001W\u3001C\u987a\u5e8f\uff09<\/code><\/pre>\n\n\n\n<p><strong>1.2 Build Options \u6784\u5efa\u9009\u9879<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u2013maxBatch \uff1a \u8bbe\u7f6e\u6700\u5927\u6279\u5904\u7406\u5927\u5c0f\u5e76\u6784\u5efa\u9690\u5f0f\u6279\u5904\u7406\u5f15\u64ce\uff08\u9ed8\u8ba4\u503c=1\uff09\u2013explicitBatch \uff1a\u6784\u5efa\u5f15\u64ce\u65f6\u4f7f\u7528\u663e\u5f0f\u6279\u91cf\u5927\u5c0f\uff08\u9ed8\u8ba4 = \u9690\u5f0f\uff09\u2013minShapes=spec \uff1a \u4f7f\u7528\u63d0\u4f9b\u7684\u6700\u5c0f\u5f62\u72b6\u7684\u914d\u7f6e\u6587\u4ef6\u6784\u5efa\u52a8\u6001\u5f62\u72b6\u2013optShapes=spec \uff1a \u4f7f\u7528\u63d0\u4f9b\u7684 opt \u5f62\u72b6\u7684\u914d\u7f6e\u6587\u4ef6\u6784\u5efa\u52a8\u6001\u5f62\u72b6\u2013maxShapes=spec \uff1a \u4f7f\u7528\u63d0\u4f9b\u7684\u6700\u5927\u5f62\u72b6\u7684\u914d\u7f6e\u6587\u4ef6\u6784\u5efa\u52a8\u6001\u5f62\u72b6\u2013minShapesCalib=spec \uff1a \u4f7f\u7528\u63d0\u4f9b\u7684\u6700\u5c0f\u5f62\u72b6\u7684\u914d\u7f6e\u6587\u4ef6\u6821\u51c6\u52a8\u6001\u5f62\u72b6\u2013optShapesCalib=spec \uff1a \u4f7f\u7528\u63d0\u4f9b\u7684 opt \u5f62\u72b6\u7684\u914d\u7f6e\u6587\u4ef6\u6821\u51c6\u52a8\u6001\u5f62\u72b6\u2013maxShapesCalib=spec \uff1a\u4f7f\u7528\u63d0\u4f9b\u7684\u6700\u5927\u5f62\u72b6\u7684\u914d\u7f6e\u6587\u4ef6\u6821\u51c6\u52a8\u6001\u5f62\u72b6\u6ce8\u610f\uff1a\u5fc5\u987b\u63d0\u4f9b\u6240\u6709\u4e09\u4e2a min\u3001opt \u548c max \u5f62\u72b6\u3002\u4f46\u662f\uff0c\u5982\u679c\u53ea\u63d0\u4f9b\u4e86 opt \u5f62\u72b6\uff0c\u90a3\u4e48\u5b83\u5c06\u88ab\u6269\u5c55\uff0c\u4ee5\u4fbf\u5c06\u6700\u5c0f\u5f62\u72b6\u548c\u6700\u5927\u5f62\u72b6\u8bbe\u7f6e\u4e3a\u4e0e opt \u5f62\u72b6\u76f8\u540c\u7684\u503c\u3002\u6b64\u5916\uff0c\u4f7f\u7528 \u52a8\u6001\u5f62\u72b6\u610f\u5473\u7740\u663e\u5f0f\u6279\u5904\u7406\u3002 \u8f93\u5165\u540d\u79f0\u53ef\u4ee5\u7528\u8f6c\u4e49\u5355\u5f15\u53f7\u62ec\u8d77\u6765\uff08\u4f8b\u5982\uff1a\u2018Input:0\u2019\uff09\u3002\u793a\u4f8b\u8f93\u5165\u5f62\u72b6\u89c4\u8303\uff1ainput0:1x3x256x256,input1:1x3x128x128 \u6bcf\u4e2a\u8f93\u5165\u5f62\u72b6\u90fd\u4f5c\u4e3a\u952e\u503c\u5bf9\u63d0\u4f9b\uff0c\u5176\u4e2d key \u662f\u8f93\u5165\u540d\u79f0 \u503c\u662f\u7528\u4e8e\u8be5\u8f93\u5165\u7684\u7ef4\u5ea6\uff08\u5305\u62ec\u6279\u6b21\u7ef4\u5ea6\uff09\u3002 \u6bcf\u4e2a\u952e\u503c\u5bf9\u90fd\u4f7f\u7528\u5192\u53f7 (\ud83d\ude03 \u5206\u9694\u952e\u548c\u503c\u3002 \u53ef\u4ee5\u901a\u8fc7\u9017\u53f7\u5206\u9694\u7684\u952e\u503c\u5bf9\u63d0\u4f9b\u591a\u4e2a\u8f93\u5165\u5f62\u72b6\u3002\u2013inputIOFormats=spec \uff1a \u6bcf\u4e2a\u8f93\u5165\u5f20\u91cf\u7684\u7c7b\u578b\u548c\u683c\u5f0f\uff08\u9ed8\u8ba4\u6240\u6709\u8f93\u5165\u4e3afp32:chw\uff09\u6ce8\u610f\uff1a\u5982\u679c\u6307\u5b9a\u6b64\u9009\u9879\uff0c\u8bf7\u6309\u7167\u4e0e\u7f51\u7edc\u8f93\u5165ID\u76f8\u540c\u7684\u987a\u5e8f\u4e3a\u6240\u6709\u8f93\u5165\u8bbe\u7f6e\u9017\u53f7\u5206\u9694\u7684\u7c7b\u578b\u548c\u683c\u5f0f\uff08\u5373\u4f7f\u53ea\u6709\u4e00\u4e2a\u8f93\u5165\u9700\u8981\u6307\u5b9aIO\u683c\u5f0f\uff09\u6216\u8bbe\u7f6e\u4e00\u6b21\u7c7b\u578b\u548c\u683c\u5f0f\u4ee5\u8fdb\u884c\u5e7f\u64ad\u3002\u2013outputIOFormats=spec : \u6bcf\u4e2a\u8f93\u51fa\u5f20\u91cf\u7684\u7c7b\u578b\u548c\u683c\u5f0f\uff08\u9ed8\u8ba4\u6240\u6709\u8f93\u5165\u4e3afp32:chw\uff09\u6ce8\u610f\uff1a\u5982\u679c\u6307\u5b9a\u6b64\u9009\u9879\uff0c\u8bf7\u6309\u7167\u4e0e\u7f51\u7edc\u8f93\u51faID\u76f8\u540c\u7684\u987a\u5e8f\u4e3a\u6240\u6709\u8f93\u51fa\u8bbe\u7f6e\u9017\u53f7\u5206\u9694\u7684\u7c7b\u578b\u548c\u683c\u5f0f\uff08\u5373\u4f7f\u53ea\u6709\u4e00\u4e2a\u8f93\u51fa\u9700\u8981\u6307\u5b9aIO\u683c\u5f0f\uff09\u6216\u8bbe\u7f6e\u4e00\u6b21\u7c7b\u578b\u548c\u683c\u5f0f\u4ee5\u8fdb\u884c\u5e7f\u64ad\u3002\u2013workspace=N \uff1a \u4ee5M\u4e3a\u5355\u4f4d\u8bbe\u7f6e\u5de5\u4f5c\u533a\u5927\u5c0f\uff08\u9ed8\u8ba4\u503c = 16\uff09\u2013noBuilderCache : \u5728\u6784\u5efa\u5668\u4e2d\u7981\u7528\u65f6\u5e8f\u7f13\u5b58\uff08\u9ed8\u8ba4\u662f\u542f\u7528\u65f6\u5e8f\u7f13\u5b58\uff09\u2013nvtxMode=mode : \u6307\u5b9a NVTX \u6ce8\u91ca\u8be6\u7ec6\u7a0b\u5ea6\u3002 mode ::= default|verbose|none\u2013minTiming=M : \u8bbe\u7f6e\u5185\u6838\u9009\u62e9\u4e2d\u4f7f\u7528\u7684\u6700\u5c0f\u8fed\u4ee3\u6b21\u6570\uff08\u9ed8\u8ba4\u503c = 1\uff09\u2013avgTiming=M : \u4e3a\u5185\u6838\u9009\u62e9\u8bbe\u7f6e\u6bcf\u6b21\u8fed\u4ee3\u7684\u5e73\u5747\u6b21\u6570\uff08\u9ed8\u8ba4\u503c = 8\uff09\u2013noTF32 : \u7981\u7528 tf32 \u7cbe\u5ea6\uff08\u9ed8\u8ba4\u662f\u542f\u7528 tf32\uff0c\u9664\u4e86 fp32\uff09\u2013refit : \u5c06\u5f15\u64ce\u6807\u8bb0\u4e3a\u53ef\u6539\u88c5\u3002\u8fd9\u5c06\u5141\u8bb8\u68c0\u67e5\u5f15\u64ce\u5185\u7684\u53ef\u6539\u88c5\u5c42\u548c\u91cd\u91cf\u3002\u2013fp16 \uff1a \u9664 fp32 \u5916\uff0c\u542f\u7528 fp16 \u7cbe\u5ea6\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013int8 : \u9664 fp32 \u5916\uff0c\u542f\u7528 int8 \u7cbe\u5ea6\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013best : \u542f\u7528\u6240\u6709\u7cbe\u5ea6\u4ee5\u8fbe\u5230\u6700\u4f73\u6027\u80fd\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013calib= : \u8bfb\u53d6INT8\u6821\u51c6\u7f13\u5b58\u6587\u4ef6\u2013safe : \u4ec5\u6d4b\u8bd5\u5b89\u5168\u53d7\u9650\u6d41\u4e2d\u53ef\u7528\u7684\u529f\u80fd\u2013saveEngine= : \u4fdd\u5b58\u5e8f\u5217\u5316\u6a21\u578b\u7684\u6587\u4ef6\u540d\u2013loadEngine= \uff1a \u52a0\u8f7d\u5e8f\u5217\u5316\u6a21\u578b\u7684\u6587\u4ef6\u540d\u2013tacticSources=tactics \uff1a \u901a\u8fc7\u4ece\u9ed8\u8ba4\u7b56\u7565\u6e90\uff08\u9ed8\u8ba4 = \u6240\u6709\u53ef\u7528\u7b56\u7565\uff09\u4e2d\u6dfb\u52a0 (+) \u6216\u5220\u9664 (-) \u7b56\u7565\u6765\u6307\u5b9a\u8981\u4f7f\u7528\u7684\u7b56\u7565\u3002<\/code><\/pre>\n\n\n\n<p><strong>1.3 Inference Options \u63a8\u7406\u9009\u9879<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u2013batch=N \uff1a \u4e3a\u9690\u5f0f\u6279\u5904\u7406\u5f15\u64ce\u8bbe\u7f6e\u6279\u5904\u7406\u5927\u5c0f\uff08\u9ed8\u8ba4\u503c = 1\uff09\u2013shapes=spec \uff1a \u4e3a\u52a8\u6001\u5f62\u72b6\u63a8\u7406\u8f93\u5165\u8bbe\u7f6e\u8f93\u5165\u5f62\u72b6\u3002\u6ce8\u610f\uff1a\u4f7f\u7528\u52a8\u6001\u5f62\u72b6\u610f\u5473\u7740\u663e\u5f0f\u6279\u5904\u7406\u3002 \u8f93\u5165\u540d\u79f0\u53ef\u4ee5\u7528\u8f6c\u4e49\u7684\u5355\u5f15\u53f7\u62ec\u8d77\u6765\uff08\u4f8b\u5982\uff1a\u2018Input:0\u2019\uff09\u3002 \u793a\u4f8b\u8f93\u5165\u5f62\u72b6\u89c4\u8303\uff1ainput0:1x3x256x256, input1:1x3x128x128 \u6bcf\u4e2a\u8f93\u5165\u5f62\u72b6\u90fd\u4f5c\u4e3a\u952e\u503c\u5bf9\u63d0\u4f9b\uff0c\u5176\u4e2d\u952e\u662f\u8f93\u5165\u540d\u79f0\uff0c\u503c\u662f\u7528\u4e8e\u8be5\u8f93\u5165\u7684\u7ef4\u5ea6\uff08\u5305\u62ec\u6279\u6b21\u7ef4\u5ea6\uff09\u3002 \u6bcf\u4e2a\u952e\u503c\u5bf9\u90fd\u4f7f\u7528\u5192\u53f7 (\ud83d\ude03 \u5206\u9694\u952e\u548c\u503c\u3002 \u53ef\u4ee5\u901a\u8fc7\u9017\u53f7\u5206\u9694\u7684\u952e\u503c\u5bf9\u63d0\u4f9b\u591a\u4e2a\u8f93\u5165\u5f62\u72b6\u3002\u2013loadInputs=spec \uff1a\u4ece\u6587\u4ef6\u52a0\u8f7d\u8f93\u5165\u503c\uff08\u9ed8\u8ba4 = \u751f\u6210\u968f\u673a\u8f93\u5165\uff09\u3002 \u8f93\u5165\u540d\u79f0\u53ef\u4ee5\u7528\u5355\u5f15\u53f7\u62ec\u8d77\u6765\uff08\u4f8b\u5982\uff1a\u2018Input:0\u2019\uff09\u2013iterations=N \uff1a \u81f3\u5c11\u8fd0\u884c N \u6b21\u63a8\u7406\u8fed\u4ee3\uff08\u9ed8\u8ba4\u503c = 10\uff09\u2013warmUp=N \uff1a \u5728\u6d4b\u91cf\u6027\u80fd\u4e4b\u524d\u8fd0\u884c N \u6beb\u79d2\u4ee5\u9884\u70ed\uff08\u9ed8\u8ba4\u503c = 200\uff09\u2013duration=N \uff1a \u8fd0\u884c\u81f3\u5c11 N \u79d2\u6302\u949f\u65f6\u95f4\u7684\u6027\u80fd\u6d4b\u91cf\uff08\u9ed8\u8ba4\u503c = 3\uff09\u2013sleepTime=N \uff1a \u5ef6\u8fdf\u63a8\u7406\u4ee5\u542f\u52a8\u548c\u8ba1\u7b97\u4e4b\u95f4\u7684 N \u6beb\u79d2\u95f4\u9694\u5f00\u59cb\uff08\u9ed8\u8ba4 = 0\uff09\u2013streams=N \uff1a \u5b9e\u4f8b\u5316 N \u4e2a\u5f15\u64ce\u4ee5\u540c\u65f6\u4f7f\u7528\uff08\u9ed8\u8ba4\u503c = 1\uff09\u2013exposeDMA \uff1a \u4e32\u884c\u5316\u8fdb\u51fa\u8bbe\u5907\u7684 DMA \u4f20\u8f93\u3002 \uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013noDataTransfers \uff1a \u5728\u63a8\u7406\u8fc7\u7a0b\u4e2d\uff0c\u8bf7\u52ff\u5c06\u6570\u636e\u4f20\u5165\u548c\u4f20\u51fa\u8bbe\u5907\u3002 \uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013useSpinWait \uff1a \u4e3b\u52a8\u540c\u6b65 GPU \u4e8b\u4ef6\u3002 \u6b64\u9009\u9879\u53ef\u80fd\u4f1a\u51cf\u5c11\u540c\u6b65\u65f6\u95f4\uff0c\u4f46\u4f1a\u589e\u52a0 CPU \u4f7f\u7528\u7387\u548c\u529f\u7387\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013threads \uff1a \u542f\u7528\u591a\u7ebf\u7a0b\u4ee5\u9a71\u52a8\u5177\u6709\u72ec\u7acb\u7ebf\u7a0b\u7684\u5f15\u64ce\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013useCudaGraph \uff1a \u4f7f\u7528 cuda \u56fe\u6355\u83b7\u5f15\u64ce\u6267\u884c\uff0c\u7136\u540e\u542f\u52a8\u63a8\u7406\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013separateProfileRun \uff1a \u4e0d\u8981\u5728\u57fa\u51c6\u6d4b\u8bd5\u4e2d\u9644\u52a0\u5206\u6790\u5668\uff1b \u5982\u679c\u542f\u7528\u5206\u6790\uff0c\u5c06\u6267\u884c\u7b2c\u4e8c\u6b21\u5206\u6790\u8fd0\u884c\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013buildOnly \uff1a \u8df3\u8fc7\u63a8\u7406\u6027\u80fd\u6d4b\u91cf\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09<\/code><\/pre>\n\n\n\n<p><strong>1.4 Build and Inference Batch Options \u6784\u5efa\u548c\u63a8\u7406\u6279\u5904\u7406\u9009\u9879<\/strong><br>\u4f7f\u7528\u9690\u5f0f\u6279\u5904\u7406\u65f6\uff0c\u5f15\u64ce\u7684\u6700\u5927\u6279\u5904\u7406\u5927\u5c0f\uff08\u5982\u679c\u672a\u6307\u5b9a\uff09\u8bbe\u7f6e\u4e3a\u63a8\u7406\u6279\u5904\u7406\u5927\u5c0f\uff1b \u4f7f\u7528\u663e\u5f0f\u6279\u5904\u7406\u65f6\uff0c\u5982\u679c\u4ec5\u6307\u5b9a\u5f62\u72b6\u7528\u4e8e\u63a8\u7406\uff0c\u5b83\u4eec\u4e5f\u5c06\u5728\u6784\u5efa\u914d\u7f6e\u6587\u4ef6\u4e2d\u7528\u4f5c min\/opt\/max\uff1b \u5982\u679c\u53ea\u4e3a\u6784\u5efa\u6307\u5b9a\u4e86\u5f62\u72b6\uff0c\u5219 opt \u5f62\u72b6\u4e5f\u5c06\u7528\u4e8e\u63a8\u7406\uff1b \u5982\u679c\u4e24\u8005\u90fd\u88ab\u6307\u5b9a\uff0c\u5b83\u4eec\u5fc5\u987b\u662f\u517c\u5bb9\u7684\uff1b \u5982\u679c\u542f\u7528\u4e86\u663e\u5f0f\u6279\u5904\u7406\u4f46\u90fd\u672a\u6307\u5b9a\uff0c\u5219\u6a21\u578b\u5fc5\u987b\u4e3a\u6240\u6709\u8f93\u5165\u63d0\u4f9b\u5b8c\u6574\u7684\u9759\u6001\u7ef4\u5ea6\uff0c\u5305\u62ec\u6279\u5904\u7406\u5927\u5c0f<\/p>\n\n\n\n<p><strong>1.5 Reporting Options \u62a5\u544a\u9009\u9879<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u2013verbose \uff1a \u4f7f\u7528\u8be6\u7ec6\u65e5\u5fd7\u8bb0\u5f55\uff08\u9ed8\u8ba4\u503c = false\uff09\u2013avgRuns=N \uff1a \u62a5\u544a N \u6b21\u8fde\u7eed\u8fed\u4ee3\u7684\u5e73\u5747\u6027\u80fd\u6d4b\u91cf\u503c\uff08\u9ed8\u8ba4\u503c = 10\uff09\u2013percentile=P \uff1a \u62a5\u544a P \u767e\u5206\u6bd4\u7684\u6027\u80fd\uff080&lt;=P&lt;=100\uff0c0 \u4ee3\u8868\u6700\u5927\u6027\u80fd\uff0c100 \u4ee3\u8868\u6700\u5c0f\u6027\u80fd\uff1b\uff08\u9ed8\u8ba4 = 99%\uff09\u2013dumpRefit \uff1a \u4ece\u53ef\u6539\u88c5\u5f15\u64ce\u6253\u5370\u53ef\u6539\u88c5\u5c42\u548c\u91cd\u91cf\u2013dumpOutput \uff1a \u6253\u5370\u6700\u540e\u4e00\u6b21\u63a8\u7406\u8fed\u4ee3\u7684\u8f93\u51fa\u5f20\u91cf\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013dumpProfile \uff1a \u6bcf\u5c42\u6253\u5370\u914d\u7f6e\u6587\u4ef6\u4fe1\u606f\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013exportTimes= \uff1a \u5c06\u8ba1\u65f6\u7ed3\u679c\u5199\u5165 json \u6587\u4ef6\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013exportOutput= \uff1a \u5c06\u8f93\u51fa\u5f20\u91cf\u5199\u5165 json \u6587\u4ef6\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013exportProfile= \uff1a \u5c06\u6bcf\u5c42\u7684\u914d\u7f6e\u6587\u4ef6\u4fe1\u606f\u5199\u5165 json \u6587\u4ef6\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09<\/code><\/pre>\n\n\n\n<p><strong>1.6 System Options \u7cfb\u7edf\u9009\u9879<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u2013device=N \uff1a\u9009\u62e9 cuda \u8bbe\u5907 N\uff08\u9ed8\u8ba4 = 0\uff09\u2013useDLACore=N \uff1a \u4e3a\u652f\u6301 DLA \u7684\u5c42\u9009\u62e9 DLA \u6838\u5fc3 N\uff08\u9ed8\u8ba4 = \u65e0\uff09\u2013allowGPUFallback \uff1a \u542f\u7528 DLA \u540e\uff0c\u5141\u8bb8 GPU \u56de\u9000\u4e0d\u53d7\u652f\u6301\u7684\u5c42\uff08\u9ed8\u8ba4 = \u7981\u7528\uff09\u2013plugins \uff1a \u8981\u52a0\u8f7d\u7684\u63d2\u4ef6\u5e93 (.so)\uff08\u53ef\u4ee5\u591a\u6b21\u6307\u5b9a\uff09<\/code><\/pre>\n\n\n\n<p><strong>1.7 Help \u5e2e\u52a9<\/strong><br>\u2013help, -h \uff1a \u6253\u5370\u4ee5\u4e0a\u5e2e\u52a9\u4fe1\u606f<\/p>\n\n\n\n<h3>\u65b9\u6cd52\u3001\u4f7f\u7528python\u811a\u672c<\/h3>\n\n\n\n<p>\u53c2\u8003\u5b98\u65b9\u7ed9\u5230\u7684demo\u5199\u4e00\u4e2a\u811a\u672c\u8f6c\uff1a\u5b98\u65b9\u811a\u672c\u4f4d\u4e8e\u4e0b\u8f7d\u7684\u76ee\u5f55\uff1aTensorRT-7.2.3.4\/samples\/python\/yolov3_onnx\/onnx_to_tensorrt.py<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os \nimport tensorrt as trt\nos.environ&#091;\"CUDA_VISIBLE_DEVICES\"]='0'\nTRT_LOGGER = trt.Logger()\nonnx_file_path = 'Unet375-simple.onnx'\nengine_file_path = 'Unet337.trt'\n\nEXPLICIT_BATCH = 1 &lt;&lt; (int)(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)\nwith trt.Builder(TRT_LOGGER) as builder, builder.create_network(EXPLICIT_BATCH) as network, trt.OnnxParser(network, TRT_LOGGER) as parser:\n            builder.max_workspace_size = 1 &lt;&lt; 28 # 256MiB\n            builder.max_batch_size = 1\n            # Parse model file\n            if not os.path.exists(onnx_file_path):\n                print('ONNX file {} not found, please run yolov3_to_onnx.py first to generate it.'.format(onnx_file_path))\n                exit(0)\n            print('Loading ONNX file from path {}...'.format(onnx_file_path))\n            with open(onnx_file_path, 'rb') as model:\n                print('Beginning ONNX file parsing')\n                if not parser.parse(model.read()):\n                    print ('ERROR: Failed to parse the ONNX file.')\n                    for error in range(parser.num_errors):\n                        print (parser.get_error(error))\n\n            network.get_input(0).shape = &#091;1, 3, 300, 400]\n            print('Completed parsing of ONNX file')\n            print('Building an engine from file {}; this may take a while...'.format(onnx_file_path))\n            #network.mark_output(network.get_layer(network.num_layers-1).get_output(0))\n            engine = builder.build_cuda_engine(network)\n            print(\"Completed creating Engine\")\n            with open(engine_file_path, \"wb\") as f:\n                f.write(engine.serialize())<\/code><\/pre>\n\n\n\n<h2>\u8fd0\u884cONNX\u6a21\u578b<\/h2>\n\n\n\n<ul><li>\u5728\u5177\u6709\u9759\u6001\u8f93\u5165\u5f62\u72b6\u7684\u5168\u7ef4\u6a21\u5f0f\u4e0b\u8fd0\u884c ONNX \u6a21\u578b<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>trtexec --onnx=model.onnx<\/code><\/pre>\n\n\n\n<ul><li>\u4f7f\u7528\u7ed9\u5b9a\u7684\u8f93\u5165\u5f62\u72b6\u5728\u5168\u7ef4\u6a21\u5f0f\u4e0b\u8fd0\u884c ONNX \u6a21\u578b<\/li><\/ul>\n\n\n\n<p>trtexec &#8211;onnx=model.onnx &#8211;shapes=input:32x3x244x244<\/p>\n\n\n\n<ul><li>\u4f7f\u7528\u4e00\u7cfb\u5217\u53ef\u80fd\u7684\u8f93\u5165\u5f62\u72b6\u5bf9 ONNX \u6a21\u578b\u8fdb\u884c\u57fa\u51c6\u6d4b\u8bd5<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>trtexec --onnx=model.onnx --minShapes=input:1x3x244x244 --optShapes=input:16x3x244x244 --maxShapes=input:32x3x244x244 --shapes=input:5x3x244x244\n\n\n\ntrtexec --onnx=depth_feat_model.onnx --minShapes=input:1x4x128x128 --maxShapes=input:1x4x896x896 --shapes=input:1x4x512x512 --saveEngine=depth_feat_model.engine --verbose --workspace=1024 --fp32\n\n<\/code><\/pre>\n\n\n\n<h2>\u7f51\u7edc\u6027\u80fd\u6d4b\u8bd5<\/h2>\n\n\n\n<ul><li>\u52a0\u8f7d\u8f6c\u6362\u540e\u7684TensorRT\u6a21\u578b\u8fdb\u884c\u6027\u80fd\u6d4b\u8bd5\uff0c\u6307\u5b9abatch\u5927\u5c0f<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>trtexec --loadEngine=mnist16.trt --batch=1\n\n\u6253\u5370\u8f93\u51fa\uff1a\ntrtexec\u4f1a\u6253\u5370\u51fa\u5f88\u591a\u65f6\u95f4\uff0c\u8fd9\u91cc\u9700\u8981\u5bf9\u6bcf\u4e2a\u65f6\u95f4\u7684\u542b\u4e49\u8fdb\u884c\u89e3\u91ca\uff0c\u7136\u540e\u5927\u5bb6\u5404\u53d6\u6240\u9700\uff0c\u8fdb\u884c\u8bc4\u6d4b\u3002\u603b\u7684\u6253\u5370\u5982\u4e0b\uff1a\n&#091;09\/06\/2021-13:50:34] &#091;I] Average on 10 runs - GPU latency: 2.74553 ms - Host latency: 3.74192 ms (end to end 4.93066 ms, enqueue 0.624805 ms)  # \u8dd1\u4e8610\u6b21\uff0cGPU latency: GPU\u8ba1\u7b97\u8017\u65f6\uff0c Host latency\uff1aGPU\u8f93\u5165+\u8ba1\u7b97+\u8f93\u51fa\u8017\u65f6\uff0cend to end\uff1aGPU\u7aef\u5230\u7aef\u7684\u8017\u65f6\uff0ceventout - eventin\uff0cenqueue\uff1aCPU\u5f02\u6b65\u8017\u65f6\n&#091;09\/06\/2021-13:50:34] &#091;I] Host Latency\n&#091;09\/06\/2021-13:50:34] &#091;I] min: 3.65332 ms (end to end 3.67603 ms)\n&#091;09\/06\/2021-13:50:34] &#091;I] max: 5.95093 ms (end to end 6.88892 ms)\n&#091;09\/06\/2021-13:50:34] &#091;I] mean: 3.71375 ms (end to end 5.30082 ms)\n&#091;09\/06\/2021-13:50:34] &#091;I] median: 3.70032 ms (end to end 5.32935 ms)\n&#091;09\/06\/2021-13:50:34] &#091;I] percentile: 4.10571 ms at 99% (end to end 6.11792 ms at 99%)\n&#091;09\/06\/2021-13:50:34] &#091;I] throughput: 356.786 qps\n&#091;09\/06\/2021-13:50:34] &#091;I] walltime: 3.00741 s\n&#091;09\/06\/2021-13:50:34] &#091;I] Enqueue Time\n&#091;09\/06\/2021-13:50:34] &#091;I] min: 0.248474 ms\n&#091;09\/06\/2021-13:50:34] &#091;I] max: 2.12134 ms\n&#091;09\/06\/2021-13:50:34] &#091;I] median: 0.273987 ms\n&#091;09\/06\/2021-13:50:34] &#091;I] GPU Compute\n&#091;09\/06\/2021-13:50:34] &#091;I] min: 2.69702 ms\n&#091;09\/06\/2021-13:50:34] &#091;I] max: 4.99219 ms\n&#091;09\/06\/2021-13:50:34] &#091;I] mean: 2.73299 ms\n&#091;09\/06\/2021-13:50:34] &#091;I] median: 2.71875 ms\n&#091;09\/06\/2021-13:50:34] &#091;I] percentile: 3.10791 ms at 99%\n&#091;09\/06\/2021-13:50:34] &#091;I] total compute time: 2.93249 s\n\nHost Latency gpu\uff1a \u8f93\u5165+\u8ba1\u7b97+\u8f93\u51fa \u4e09\u90e8\u5206\u7684\u8017\u65f6\nEnqueue Time\uff1aCPU\u5f02\u6b65\u7684\u65f6\u95f4\uff08\u8be5\u65f6\u95f4\u4e0d\u5177\u6709\u53c2\u8003\u610f\u4e49\uff0c\u56e0\u4e3aGPU\u7684\u8ba1\u7b97\u53ef\u80fd\u8fd8\u6ca1\u6709\u5b8c\u6210\uff09\nGPU Compute\uff1aGPU\u8ba1\u7b97\u7684\u8017\u65f6\n\u7efc\u4e0a\uff0c\u53bb\u4e86Enqueue Time\u65f6\u95f4\u90fd\u662f\u6709\u610f\u4e49\u7684<\/code><\/pre>\n\n\n\n<ul><li>\u6536\u96c6\u548c\u6253\u5370\u65f6\u5e8f\u8ddf\u8e2a\u4fe1\u606f<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>trtexec --deploy=data\/AlexNet\/AlexNet_N2.prototxt --output=prob --exportTimes=trace.json<\/code><\/pre>\n\n\n\n<ul><li>\u4f7f\u7528\u591a\u6d41\u8c03\u6574\u541e\u5410\u91cf<\/li><\/ul>\n\n\n\n<p>\u8c03\u6574\u541e\u5410\u91cf\u53ef\u80fd\u9700\u8981\u8fd0\u884c\u591a\u4e2a\u5e76\u53d1\u6267\u884c\u6d41\u3002\u4f8b\u5982\uff0c\u5f53\u5b9e\u73b0\u7684\u5ef6\u8fdf\u5b8c\u5168\u5728\u6240\u9700\u9608\u503c\u5185\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u589e\u52a0\u541e\u5410\u91cf\uff0c\u5373\u4f7f\u4ee5\u4e00\u4e9b\u5ef6\u8fdf\u4e3a\u4ee3\u4ef7\u3002\u4f8b\u5982\uff0c\u4e3a\u6279\u91cf\u5927\u5c0f 1 \u548c 2 \u4fdd\u5b58\u5f15\u64ce\u5e76\u5047\u8bbe\u4e24\u8005\u90fd\u5728 2ms \u5185\u6267\u884c\uff0c\u5ef6\u8fdf\u9608\u503c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>trtexec --deploy=GoogleNet_N2.prototxt --output=prob --batch=1 --saveEngine=g1.trt --int8 --buildOnly\ntrtexec --deploy=GoogleNet_N2.prototxt --output=prob --batch=2 --saveEngine=g2.trt --int8 --buildOnly<\/code><\/pre>\n\n\n\n<ul><li>\u4fdd\u5b58\u7684\u5f15\u64ce\u53ef\u4ee5\u5c1d\u8bd5\u627e\u5230\u4f4e\u4e8e 2 ms \u7684\u7ec4\u5408\u6279\u6b21\/\u6d41\uff0c\u4ee5\u6700\u5927\u5316\u541e\u5410\u91cf\uff1a<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>trtexec --loadEngine=g1.trt --batch=1 --streams=2\ntrtexec --loadEngine=g1.trt --batch=1 --streams=3\ntrtexec --loadEngine=g1.trt --batch=1 --streams=4\ntrtexec --loadEngine=g2.trt --batch=2 --streams=2<\/code><\/pre>\n\n\n\n<h2>python\u8c03\u7528&nbsp;TensorRT\u6a21\u578b\u7684\u63a8\u7406<\/h2>\n\n\n\n<p>        \u63a8\u7406\u4f9d\u65e7\u5206\u4e3a\u52a8\u6001\u5c3a\u5bf8\u7684\u548c\u56fa\u5b9a\u5c3a\u5bf8\u7684\uff0c\u52a8\u6001\u63a8\u7406\u8fd9\u4e00\u5757C++\u7248\u672c\u7684\u8d44\u6599\u6bd4\u8f83\u591a\uff0cpython\u63a5\u53e3\u7684\u6bd4\u8f83\u5c11\uff0c\u56fa\u5b9a\u5c3a\u5bf8\u7684\u63a8\u7406\u5b98\u65b9\u4e5f\u6709demo\uff0c\u5206\u4e3a\u5f02\u6b65\u540c\u6b65\u63a8\u7406\u3002<\/p>\n\n\n\n<p>python\u63a8\u7406\u63a5\u6536numpy\u683c\u5f0f\u7684\u6570\u636e\u8f93\u5165\u3002<\/p>\n\n\n\n<p><strong>\u52a8\u6001\u63a8\u65ad<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import tensorrt as trt\nimport pycuda.driver as cuda\n#import pycuda.driver as cuda2\nimport pycuda.autoinit\nimport numpy as np\nimport cv2\ndef load_engine(engine_path):\n    #TRT_LOGGER = trt.Logger(trt.Logger.WARNING)  # INFO\n    TRT_LOGGER = trt.Logger(trt.Logger.ERROR)\n    with open(engine_path, 'rb') as f, trt.Runtime(TRT_LOGGER) as runtime:\n        return runtime.deserialize_cuda_engine(f.read())\n \npath ='\/home\/caidou\/trt_python\/model_1_-1_-1_3.engine'\n#\u8fd9\u91cc\u4e0d\u4ee5\u67d0\u4e2a\u5177\u4f53\u6a21\u578b\u505a\u4e3a\u63a8\u65ad\u4f8b\u5b50.\n \n# 1. \u5efa\u7acb\u6a21\u578b\uff0c\u6784\u5efa\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\nengine = load_engine(path)\ncontext = engine.create_execution_context()\ncontext.active_optimization_profile = 0\n \n#2. \u8bfb\u53d6\u6570\u636e\uff0c\u6570\u636e\u5904\u7406\u4e3a\u53ef\u4ee5\u548c\u7f51\u7edc\u7ed3\u6784\u8f93\u5165\u5bf9\u5e94\u8d77\u6765\u7684\u7684shape\uff0c\u6570\u636e\u53ef\u589e\u52a0\u9884\u5904\u7406\nimgpath = '\/home\/caidou\/test\/aaa.jpg'\nimage = cv2.imread(imgpath)\nimage = np.expand_dims(image, 0)  # Add batch dimension.  \n \n \n#3.\u5206\u914d\u5185\u5b58\u7a7a\u95f4\uff0c\u5e76\u8fdb\u884c\u6570\u636ecpu\u5230gpu\u7684\u62f7\u8d1d\n#\u52a8\u6001\u5c3a\u5bf8\uff0c\u6bcf\u6b21\u90fd\u8981set\u4e00\u4e0b\u6a21\u578b\u8f93\u5165\u7684shape\uff0c0\u4ee3\u8868\u7684\u5c31\u662f\u8f93\u5165\uff0c\u8f93\u51fa\u6839\u636e\u5177\u4f53\u7684\u7f51\u7edc\u7ed3\u6784\u800c\u5b9a\uff0c\u53ef\u4ee5\u662f0,1,2,3...\u5176\u4e2d\u7684\u67d0\u4e2a\u5934\u3002\ncontext.set_binding_shape(0, image.shape)\nd_input = cuda.mem_alloc(image.nbytes)  #\u5206\u914d\u8f93\u5165\u7684\u5185\u5b58\u3002\n \n \noutput_shape = context.get_binding_shape(1) \nbuffer = np.empty(output_shape, dtype=np.float32)\nd_output = cuda.mem_alloc(buffer.nbytes)    #\u5206\u914d\u8f93\u51fa\u5185\u5b58\u3002\ncuda.memcpy_htod(d_input,image)\nbindings = &#091;d_input ,d_output]\n \n#4.\u8fdb\u884c\u63a8\u7406\uff0c\u5e76\u5c06\u7ed3\u679c\u4ecegpu\u62f7\u8d1d\u5230cpu\u3002\ncontext.execute_v2(bindings)  #\u53ef\u5f02\u6b65\u548c\u540c\u6b65\ncuda.memcpy_dtoh(buffer,d_output)  \noutput = buffer.reshape(output_shape)\n \n#5.\u5bf9\u63a8\u7406\u7ed3\u679c\u8fdb\u884c\u540e\u5904\u7406\u3002\u8fd9\u91cc\u53ea\u662f\u4e3e\u4e86\u4e00\u4e2a\u7b80\u5355\u4f8b\u5b50\uff0c\u53ef\u4ee5\u7ed3\u5408\u5b98\u65b9\u9759\u6001\u7684yolov3\u6848\u4f8b\u5b8c\u5584\u3002<\/code><\/pre>\n\n\n\n<p><strong>\u9759\u6001\u63a8\u65ad<\/strong>:<\/p>\n\n\n\n<p>\u9759\u6001\u63a8\u65ad\u548c\u52a8\u6001\u63a8\u65ad\u5dee\u4e0d\u591a\uff0c\u53ea\u4e0d\u8fc7\u4e0d\u9700\u8981\u6bcf\u6b21\u90fd\u5206\u914d\u8f93\u5165\u548c\u8f93\u51fa\u7684\u5185\u5b58\u7a7a\u95f4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import tensorrt as trt\nimport pycuda.driver as cuda\n#import pycuda.driver as cuda2\nimport pycuda.autoinit\nimport numpy as np\nimport cv2\npath ='\/home\/caidou\/trt_python\/model_1_4_256_256.engine'\nengine = load_engine(path)\nimgpath = 'aaa.jpg'\ncontext = engine.create_execution_context()\nimage1 = cv2.write(imgpath)\nimage1 = cv2.resize(image1,(256,256))\nimage2 = image1.copy()\nimage3 = image1.copy()\nimage4 = image1.copy()\nimage = np.concatenate((image1,image2,image3,image4))\nimage = image.reshape(-1,256,256)\n \n# image = np.expand_dims(image, axis=1)\nimage = image.astype(np.float32)\n \nimage = image.ravel()#\u6570\u636e\u5e73\u94fa\noutshape= context.get_binding_shape(1) \noutput = np.empty((outshape), dtype=np.float32)\nd_input = cuda.mem_alloc(1 * image.size * image.dtype.itemsize)\nd_output = cuda.mem_alloc(1*output.size * output.dtype.itemsize)\nbindings = &#091;int(d_input), int(d_output)]\nstream = cuda.Stream()\nfor i in tqdm.tqdm(range(600)):\n    cuda.memcpy_htod(d_input,image)\n    context.execute_v2(bindings)\n    cuda.memcpy_dtoh(output, d_output)<\/code><\/pre>\n\n\n\n<p>\u66f4\u65b0\uff1a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u6362\u6a21\u578b\u5c06onnx\u8f6c\u6362\u4e3aTensorRT: \u65b9\u6cd5\u4e00\u3001trtexec trtexec\u662f\u5728tensorrt\u5305\u4e2d\u81ea\u5e26 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2023\/02\/17\/tensorrt-1\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">TensorRT &#8211; \u4f7f\u7528trtexec\u5de5\u5177\u8f6c\u6362\u6a21\u578b\u3001\u8fd0\u884c\u6a21\u578b\u3001\u6d4b\u8bd5\u7f51\u7edc\u6027\u80fd<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,11,26],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/14153"}],"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=14153"}],"version-history":[{"count":82,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/14153\/revisions"}],"predecessor-version":[{"id":15220,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/14153\/revisions\/15220"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=14153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=14153"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=14153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}