Fixed running custom onnx models.

This commit is contained in:
Daniel
2024-11-29 15:18:57 +01:00
parent f6d13ea5a7
commit 93d4611a91
6 changed files with 158 additions and 32 deletions
+14 -5
View File
@@ -21,18 +21,27 @@ class RTMDet(BaseModel):
def preprocess(self, image: np.ndarray):
th, tw = self.input_shape[2:]
image, self.dx, self.dy, self.scale = letterbox(image, (tw, th))
tensor = (image - np.array((103.53, 116.28, 123.675))) / np.array((57.375, 57.12, 58.395))
tensor = np.expand_dims(tensor, axis=0).transpose((0, 3, 1, 2)).astype(np.float32)
tensor, self.dx, self.dy, self.scale = letterbox(
image, (tw, th), fill_value=114
)
tensor -= np.array((123.675, 116.28, 103.53))
tensor /= np.array((58.395, 57.12, 57.375))
tensor = tensor[..., ::-1]
tensor = (
np.expand_dims(tensor, axis=0).transpose((0, 3, 1, 2)).astype(np.float32)
)
return tensor
def postprocess(self, tensor: List[np.ndarray]):
boxes = tensor[0]
classes = tensor[1]
boxes = np.squeeze(boxes, axis=0)
boxes[..., [4, 5]] = boxes[..., [5, 4]]
classes = np.squeeze(classes, axis=0)
classes = np.expand_dims(classes, axis=-1)
boxes = np.concatenate([boxes, classes], axis=-1)
boxes = nms(boxes, self.iou_threshold, self.conf_threshold)
if boxes.shape[0] == 0:
return boxes