How to export castom yolo5.pt to tensorrt?

How can I convert my YOLOv5 model (exported as ONNX) to TensorRT? I followed the export.py script, and the ONNX file was generated successfully (crowdhuman_yolov5m.onnx), but I’m unsure about the next steps for TensorRT integration. Are there specific tools or steps required for this?

Additional context:

  • ONNX export completed with warnings about tensor-to-boolean conversion (TracerWarning).
  • Need guidance on optimizing the ONNX model for TensorRT (e.g., using trtexec or Python API).
  • Any tips to avoid errors during TensorRT conversion?
(venv) shakir@laptop:~/Downloads/yolov5$ python export.py --weights ../traffic_analyzer/weights/crowdhuman_yolov5m.pt --include onnx
   
/home/shakir/Downloads/yolov5/venv/lib/python3.10/site-packages/numpy/core/getlimits.py:518: UserWarning: The value of the smallest subnormal for <class 'numpy.float64'> type is zero.
  setattr(self, word, getattr(machar, word).flat[0])
/home/shakir/Downloads/yolov5/venv/lib/python3.10/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for <class 'numpy.float64'> type is zero.
  return self._float_to_str(self.smallest_subnormal)
/home/shakir/Downloads/yolov5/venv/lib/python3.10/site-packages/numpy/core/getlimits.py:518: UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero.
  setattr(self, word, getattr(machar, word).flat[0])
/home/shakir/Downloads/yolov5/venv/lib/python3.10/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero.
  return self._float_to_str(self.smallest_subnormal)
export: data=data/coco128.yaml, weights=../traffic_analyzer/weights/crowdhuman_yolov5m.pt, imgsz=[640, 640], batch_size=1, device=cpu, half=False, inplace=False, train=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=13, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['onnx']
YOLOv5 🚀 v6.0-0-g956be8e6 torch 2.7.0+cu126 CPU

Fusing layers... 
Model Summary: 308 layers, 21041679 parameters, 0 gradients

PyTorch: starting from ../traffic_analyzer/weights/crowdhuman_yolov5m.pt (169.0 MB)

ONNX: starting export with onnx 1.18.0...
/home/shakir/Downloads/yolov5/models/yolo.py:124: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  if augment:
/home/shakir/Downloads/yolov5/models/yolo.py:147: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  if profile:
/home/shakir/Downloads/yolov5/models/yolo.py:151: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  if visualize:
/home/shakir/Downloads/yolov5/models/yolo.py:151: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  if visualize:
/home/shakir/Downloads/yolov5/models/yolo.py:147: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  if profile:
/home/shakir/Downloads/yolov5/models/yolo.py:60: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  if self.grid[i].shape[2:4] != x[i].shape[2:4] or self.onnx_dynamic:
ONNX: export success, saved as ../traffic_analyzer/weights/crowdhuman_yolov5m.onnx (84.6 MB)
ONNX: run --dynamic ONNX model inference with: 'python detect.py --weights ../traffic_analyzer/weights/crowdhuman_yolov5m.onnx'

Export complete (2.74s)
Results saved to /home/shakir/Downloads/traffic_analyzer/weights
Visualize with https://netron.app
(venv) shakir@laptop:~/Downloads/yolov5$