From d94b4705a65e751a8238696704a6300df4ac33db Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 1 Jul 2022 15:41:14 +0200 Subject: [PATCH] TRT `--half` fix autocast images to FP16 (#8435) * TRT `--half` fix autocast images to FP16 Resolves bug raised in https://github.com/ultralytics/yolov5/issues/7822 * Update common.py --- models/common.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/models/common.py b/models/common.py index 7690f714def8..a6488dd85648 100644 --- a/models/common.py +++ b/models/common.py @@ -441,6 +441,9 @@ def wrap_frozen_graph(gd, inputs, outputs): def forward(self, im, augment=False, visualize=False, val=False): # YOLOv5 MultiBackend inference b, ch, h, w = im.shape # batch, channel, height, width + if self.fp16 and im.dtype != torch.float16: + im = im.half() # to FP16 + if self.pt: # PyTorch y = self.model(im, augment=augment, visualize=visualize)[0] elif self.jit: # TorchScript