-
Notifications
You must be signed in to change notification settings - Fork 3
/
post_processing_model.py
42 lines (33 loc) · 1.38 KB
/
post_processing_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#
# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
# SPDX-License-Identifier: MIT
#
import numpy as np
class PostProcessingModel:
def __init__(self, input_shape, stride=16, scale=35.0, offset=0.5):
self.stride = stride
self.scale = scale
self.offset = offset
self.centers_x = np.arange(input_shape[1]) * stride + offset
self.centers_y = np.arange(input_shape[0]) * stride + offset
self.centers_x = self.centers_x[:, np.newaxis]
self.centers_y = self.centers_y[:, np.newaxis, np.newaxis]
def predict(self, cov, bbox):
bbox = np.reshape(
bbox, [cov.shape[0], cov.shape[1], cov.shape[2], cov.shape[3], 4]
)
bbox[:, :, :, :, 0] = self.centers_x - self.scale * bbox[:, :, :, :, 0]
bbox[:, :, :, :, 1] = self.centers_y - self.scale * bbox[:, :, :, :, 1]
bbox[:, :, :, :, 2] = self.centers_x + self.scale * bbox[:, :, :, :, 2]
bbox[:, :, :, :, 3] = self.centers_y + self.scale * bbox[:, :, :, :, 3]
cov = np.reshape(cov, [cov.shape[0], cov.shape[1] * cov.shape[2], cov.shape[3]])
bbox = np.reshape(
bbox,
[
bbox.shape[0],
bbox.shape[1] * bbox.shape[2],
bbox.shape[3],
bbox.shape[4],
],
)
return cov, bbox