简体   繁体   English

Libtorch:如何从 tensorRT fp16 半类型指针创建张量?

[英]Libtorch:how to create tensor from tensorRT fp16 half type pointer?

how to create tensor from tensorRT fp16 half type pointer in libtorch?如何从 libtorch 中的 tensorRT fp16 半类型指针创建张量? I am working on a detection model.我正在检测 model。 I change the backbone of it to tensorRT to do FP16 inference, and the detection code such as decode boxes and nms is done in libtorch and torchvisoin, so how to create fp16 tensor from tensorRT half type pointers?我把它的主干改成tensorRT做FP16推理,解码框和nms等检测代码是在libtorch和torchvisoin中完成的,那么如何从tensorRT半型指针创建fp16张量呢? The important code is to illustrate the issue:重要的代码是为了说明问题:

// tensorRT code to get half type outpus
half_float::half* outputs[18];
doInference(*engine, data, outputs, 1);
// to get the final outputs with libtorch
vector<torch::Tensor> output;
//???? how to feed the date in outpus to output????
// get the result with libtorch method detect_trt->forward
 auto res = detect_trt->forward(output); 

Thanks in advance.提前致谢。

I have to do backbone inference in TensorRT, but the post process is using libtorch for convenience.And now I figure it out by using the following code:我必须在 TensorRT 中进行主干推理,但为了方便起见,后期过程使用 libtorch。现在我使用以下代码解决了这个问题:

out = torch::from_blob(outputs[i], {1, num, dim, dim}, torch::kFloat16).to(device_used);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM