|  | 
| 8 | 8 | import torch | 
| 9 | 9 | import torch.nn as nn | 
| 10 | 10 | from PIL import Image | 
|  | 11 | +from torch.cuda import amp | 
| 11 | 12 | 
 | 
| 12 | 13 | from utils.datasets import letterbox | 
| 13 | 14 | from utils.general import non_max_suppression, make_divisible, scale_coords, xyxy2xywh | 
| @@ -219,17 +220,17 @@ def forward(self, imgs, size=640, augment=False, profile=False): | 
| 219 | 220 |         x = torch.from_numpy(x).to(p.device).type_as(p) / 255.  # uint8 to fp16/32 | 
| 220 | 221 |         t.append(time_synchronized()) | 
| 221 | 222 | 
 | 
| 222 |  | -        # Inference | 
| 223 |  | -        with torch.no_grad(): | 
|  | 223 | +        with torch.no_grad(), amp.autocast(enabled=p.device.type != 'cpu'): | 
|  | 224 | +            # Inference | 
| 224 | 225 |             y = self.model(x, augment, profile)[0]  # forward | 
| 225 |  | -        t.append(time_synchronized()) | 
|  | 226 | +            t.append(time_synchronized()) | 
| 226 | 227 | 
 | 
| 227 |  | -        # Post-process | 
| 228 |  | -        y = non_max_suppression(y, conf_thres=self.conf, iou_thres=self.iou, classes=self.classes)  # NMS | 
| 229 |  | -        for i in range(n): | 
| 230 |  | -            scale_coords(shape1, y[i][:, :4], shape0[i]) | 
| 231 |  | -        t.append(time_synchronized()) | 
|  | 228 | +            # Post-process | 
|  | 229 | +            y = non_max_suppression(y, conf_thres=self.conf, iou_thres=self.iou, classes=self.classes)  # NMS | 
|  | 230 | +            for i in range(n): | 
|  | 231 | +                scale_coords(shape1, y[i][:, :4], shape0[i]) | 
| 232 | 232 | 
 | 
|  | 233 | +        t.append(time_synchronized()) | 
| 233 | 234 |         return Detections(imgs, y, files, t, self.names, x.shape) | 
| 234 | 235 | 
 | 
| 235 | 236 | 
 | 
|  | 
0 commit comments