leon 5 mesi fa
parent
commit
7fc39c1f6b
1 ha cambiato i file con 34 aggiunte e 0 eliminazioni
  1. 34 0
      README.md

+ 34 - 0
README.md

@@ -0,0 +1,34 @@
+## Tensorrt 推理 resnet 分类模型
+
+### 使用tensorrt推理resnet模型流程
+#### 模型转换
+```shell
+trtexec --onnx=resnet.onnx --saveEngine=resnet.engine --fp16 --verbose
+```
+#### 代码使用
+1. 直接推理
+    ```C++
+    cv::Mat image = cv::imread("inference/car.jpg");
+    auto resnet = resnet::load("resnet.engine");
+    if (resnet == nullptr) return;
+    auto attr = resnet->forward(cvimg(image));
+    printf("score : %lf, label : %d\n", attr.confidence, attr.class_label);
+    /*
+    [infer.cu:393]: Infer 0x564a443b3440 [StaticShape]
+    [infer.cu:405]: Inputs: 1
+    [infer.cu:409]: 	0.input.1 : shape {1x3x224x224}
+    [infer.cu:412]: Outputs: 1
+    [infer.cu:416]: 	0.343 : shape {1x3}
+    score : 0.997001, label : 2
+    */
+    ```
+
+2. cpm模式
+    ```C++
+    cv::Mat image = cv::imread("inference/car.jpg");
+
+    cpm::Instance<resnet::Attribute, resnet::Image, resnet::Infer> cpmi;
+    bool ok = cpmi.start([] { return resnet::load("resnet.engine"); }, max_infer_batch);
+
+    cpmi.commit(cvimg(image)).get();
+    ```