gpt4 book ai didi

c++ - libtorch:如何从tensorRT fp16半类型指针创建张量?

转载 作者:行者123 更新时间:2023-12-02 10:17:43 28 4
gpt4 key购买 nike

如何从libtorch中的tensorRT fp16半类型指针创建张量?
我正在研究检测模型。我将其主干更改为tensorRT以进行FP16推理,并且在libtorch和torchvisoin中完成了诸如解码框和nms之类的检测代码,那么如何从tensorRT半类型指针创建fp16张量?
重要的代码是为了说明问题:

// 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);

提前致谢。

最佳答案

我必须在TensorRT中进行 Backbone 推理,但是后期处理过程中为了方便起见使用libtorch,现在我通过使用以下代码来解决这个问题:

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

关于c++ - libtorch:如何从tensorRT fp16半类型指针创建张量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61400032/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com