Some further optimizations.

This commit is contained in:
Daniel
2024-11-29 18:22:48 +01:00
parent ad1ef42b99
commit d50364cda7
3 changed files with 63 additions and 11 deletions
+4 -5
View File
@@ -2,7 +2,7 @@ import numpy as np
from typing import List
from .base_model import BaseModel
from .utils import letterbox, nms, xywh2xyxy
from .utils import letterbox, nms_optimized, xywh2xyxy
class RTMDet(BaseModel):
@@ -21,11 +21,10 @@ class RTMDet(BaseModel):
def preprocess(self, image: np.ndarray):
th, tw = self.input_shape[2:]
tensor, self.dx, self.dy, self.scale = letterbox(
image, self.dx, self.dy, self.scale = letterbox(
image, (tw, th), fill_value=114
)
tensor = tensor.astype(self.input_type, copy=False)
tensor = tensor[..., ::-1]
tensor = np.asarray(image).astype(self.input_type, copy=False)[..., ::-1]
tensor = np.expand_dims(tensor, axis=0).transpose((0, 3, 1, 2))
return tensor
@@ -34,7 +33,7 @@ class RTMDet(BaseModel):
classes = np.expand_dims(np.squeeze(tensor[1], axis=0), axis=-1)
boxes = np.concatenate([boxes, classes], axis=-1)
boxes = nms(boxes, self.iou_threshold, self.conf_threshold)
boxes = nms_optimized(boxes, self.iou_threshold, self.conf_threshold)
if boxes.shape[0] == 0:
return boxes