Publishing 2019 R1 content
[platform/upstream/dldt.git] / tools / accuracy_checker / accuracy_checker / representation / super_resolution_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 from enum import Enum
18 import numpy as np
19
20 from .base_representation import BaseRepresentation
21 from ..data_readers import BaseReader
22
23
24 class GTLoader(Enum):
25     PILLOW = 0
26     OPENCV = 1
27
28
29 class SuperResolutionRepresentation(BaseRepresentation):
30     pass
31
32
33 class SuperResolutionAnnotation(SuperResolutionRepresentation):
34     LOADERS = {
35         GTLoader.PILLOW: 'pillow_imread',
36         GTLoader.OPENCV: 'opencv_imread'
37     }
38
39     def __init__(self, identifier, path_to_hr, gt_loader=GTLoader.PILLOW):
40         """
41         Args:
42             identifier: object identifier (e.g. image name).
43             path_to_hr: path where height resolution image should be loaded from. The path is relative to data source.
44             gt_loader: back-end, used to load segmentation masks.
45         """
46
47         super().__init__(identifier)
48         self._image_path = path_to_hr
49         self._gt_loader = self.LOADERS.get(gt_loader)
50
51     @property
52     def value(self):
53         loader = BaseReader.provide(self._gt_loader)
54         gt = loader.read(self._image_path, self.metadata['data_source'])
55         return gt.astype(np.uint8)
56
57
58 class SuperResolutionPrediction(SuperResolutionRepresentation):
59     def __init__(self, identifiers, prediction):
60         """
61         Args:
62             identifiers: object identifier (e.g. image name).
63             prediction: array with shape (height, width) contained result image.
64         """
65
66         super().__init__(identifiers)
67         self.value = prediction