Publishing 2019 R1 content
[platform/upstream/dldt.git] / tools / accuracy_checker / accuracy_checker / representation / pose_estimation_representation.py
1 """
2 Copyright (c) 2019 Intel Corporation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 """
16
17 import numpy as np
18 from .base_representation import BaseRepresentation
19
20
21 class PoseEstimationRepresentation(BaseRepresentation):
22     def __init__(self, identifier='', x_values=None, y_values=None, visibility=None, labels=None):
23         super().__init__(identifier)
24         self.x_values = x_values if np.size(x_values) > 0 else []
25         self.y_values = y_values if np.size(y_values) > 0 else []
26         self.visibility = visibility if np.size(visibility) > 0 else [2] * len(x_values)
27         self.labels = labels if labels is not None else np.array([1]*len(x_values))
28
29     @property
30     def areas(self):
31         areas = self.metadata.get('areas')
32         if areas:
33             return areas
34         x_mins = np.min(self.x_values, axis=1)
35         x_maxs = np.max(self.x_values, axis=1)
36         y_mins = np.min(self.y_values, axis=1)
37         y_maxs = np.max(self.y_values, axis=1)
38         return (x_maxs - x_mins) * (y_maxs - y_mins)
39
40     @property
41     def bboxes(self):
42         rects = self.metadata.get('rects')
43         if rects:
44             return rects
45         x_mins = np.min(self.x_values, axis=1)
46         x_maxs = np.max(self.x_values, axis=1)
47         y_mins = np.min(self.y_values, axis=1)
48         y_maxs = np.max(self.y_values, axis=1)
49         return [[x_min, y_min, x_max, y_max] for x_min, y_min, x_max, y_max in zip(x_mins, y_mins, x_maxs, y_maxs)]
50
51     @property
52     def size(self):
53         return len(self.x_values)
54
55
56 class PoseEstimationAnnotation(PoseEstimationRepresentation):
57     pass
58
59
60 class PoseEstimationPrediction(PoseEstimationRepresentation):
61     def __init__(self, identifier='', x_values=None, y_values=None, visibility=None, scores=None, labels=None):
62         super().__init__(identifier, x_values, y_values, visibility, labels)
63         self.scores = scores if scores.any() else []