Open jade-tenon opened 1 year ago
安装tensorrt可以参照Nvidia官网的Guide 你已经下载好zip,那么你现在应该按照guide里面配置环境变量。
感谢!但是安装并运行之后 utils.py line 30有报错 AttributeError: 'NoneType' object has no attribute 'get_binding_shape'
可能原因是我们的环境存在一定差异,而trt模型的运行需要环境极其相似才能运行,所以需要你自己生成trt模型,可以参照我在readme中给出的repo链接,里面有pt模型转trt模型的方法。
配置trt环境以及转换模型是比较麻烦的,如果你的配置能够足够快得用.pt模型推理,也可以直接使用.pt模型
好的,谢谢!
官方文档:yolo export model=path/to/best.pt format=onnx # export custom trained model
Available YOLOv8 export formats are in the table below. You can export to any format using the format argument, i.e. format='onnx' or format='engine'.
所以我用了这个命令来导出trt:yolo export model=G:\AI\Yolo-v8-Apex-Aim-assist\Model\apex_8s.pt format=engine half device=0
,导出后加载还是有错误:
G:\ailearning\anaconda\envs\Yolo-v8-Apex-Aim-assist\python.exe G:\AI\Yolo-v8-Apex-Aim-assist\main.py
listener start
[05/06/2023-17:26:05] [TRT] [E] 1: [stdArchiveReader.cpp::nvinfer1::rt::StdArchiveReader::StdArchiveReader::32] Error Code 1: Serialization (Serialization assertion magicTagRead == kMAGIC_TAG failed.Magic tag does not match)
[05/06/2023-17:26:05] [TRT] [E] 4: [runtime.cpp::nvinfer1::Runtime::deserializeCudaEngine::66] Error Code 4: Internal Error (Engine deserialization failed.)
Traceback (most recent call last):
File "G:\AI\Yolo-v8-Apex-Aim-assist\main.py", line 46, in <module>
predict_init(args)
File "G:\AI\Yolo-v8-Apex-Aim-assist\trt.py", line 41, in predict_init
pred = Predictor(engine_path=args.model_dir + args.model)
File "G:\AI\Yolo-v8-Apex-Aim-assist\trt.py", line 12, in __init__
super(Predictor, self).__init__(engine_path)
File "G:\AI\Yolo-v8-Apex-Aim-assist\utils\utils.py", line 30, in __init__
self.imgsz = engine.get_binding_shape(0)[2:] # get the read shape of model, in case user input it wrong
AttributeError: 'NoneType' object has no attribute 'get_binding_shape'
我又去查了下最上面的两条报错,发现在英伟达的论坛里面有人提出来过:deserializeCudaEngine failed. Serialization assertion magicTagRead == kMAGIC_TAG failed.Magic tag does not match,并给出了一个解决方案:
ifstream file(trtFile, ios_base::in |ios_base::binary);
assert(file.good());
file.seekg(0, ios::end);
auto size = file.tellg();
cout << size << endl;
char *engineString = new char[size];
assert(engineString);
file.seekg(0, file.beg); // just add this line
file.read(engineString, size);
file.close();
但我看不懂.jpg,能麻烦下您看下吗?
yolo export只能导出onnx,要再转化成trt需先下载这个repo,然后使用这个repo 里面的export.py吧onnx模型转化为trt。 命令:
python export.py -o yolov8n.onnx -e yolov8n.trt --end2end --v8
我的问题解决了。
我的问题解决了。
Hi, I have the same problem, how did you solve it?
你好,能请教一下如何安装tensorrt库么,我在搜索引擎里没有找到合适的教程。 本地是windows10,已经从nv官网下载了8.5.1.7的tensorrt文件