Moved image normalization into onnx models.

This commit is contained in:
Daniel
2024-11-29 17:05:43 +01:00
parent 1b5e0c44e3
commit 7b9505ca02
6 changed files with 95 additions and 18 deletions

View File

@ -19,19 +19,12 @@ class RTMDet(BaseModel):
self.dy = 0
self.scale = 0
norm_mean = -1 * np.array([123.675, 116.28, 103.53])
norm_std = 1.0 / np.array([58.395, 57.12, 57.375])
self.norm_mean = np.reshape(norm_mean, (1, 1, 3)).astype(np.float32)
self.norm_std = np.reshape(norm_std, (1, 1, 3)).astype(np.float32)
def preprocess(self, image: np.ndarray):
th, tw = self.input_shape[2:]
tensor, self.dx, self.dy, self.scale = letterbox(
image, (tw, th), fill_value=114
)
tensor = tensor.astype(np.float32, copy=False)
tensor += self.norm_mean
tensor *= self.norm_std
tensor = tensor[..., ::-1]
tensor = np.expand_dims(tensor, axis=0).transpose((0, 3, 1, 2))
return tensor