Publishing 2019 R1 content
[platform/upstream/dldt.git] / tools / accuracy_checker / accuracy_checker / annotation_converters / super_resolution_converter.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 from ..config import PathField, StringField, BoolField
17 from ..representation import SuperResolutionAnnotation
18 from .format_converter import BaseFormatConverter, BaseFormatConverterConfig
19
20
21 class SRConverterConfig(BaseFormatConverterConfig):
22     data_dir = PathField(is_directory=True)
23     lr_suffix = StringField(optional=True)
24     hr_suffix = StringField(optional=True)
25     two_streams = BoolField(optional=True)
26
27
28 class SRConverter(BaseFormatConverter):
29     __provider__ = 'super_resolution'
30
31     _config_validator_type = SRConverterConfig
32
33     def configure(self):
34         self.data_dir = self.config['data_dir']
35         self.lr_suffix = self.config.get('lr_suffix', 'lr')
36         self.hr_suffix = self.config.get('hr_suffix', 'hr')
37         self.two_streams = self.config.get('two_streams', False)
38
39     def convert(self):
40         file_list_lr = []
41         for file_in_dir in self.data_dir.iterdir():
42             if self.lr_suffix in file_in_dir.parts[-1]:
43                 file_list_lr.append(file_in_dir)
44
45         annotation = []
46         for lr_file in file_list_lr:
47             lr_file_name = lr_file.parts[-1]
48             hr_file_name = self.hr_suffix.join(lr_file_name.split(self.lr_suffix))
49             identifier = [lr_file_name, hr_file_name] if self.two_streams else lr_file_name
50             annotation.append(SuperResolutionAnnotation(identifier, hr_file_name))
51
52         return annotation, None