Skip to content

Commit 6994142

Browse files
authored
AC: support image generation (#3025)
1 parent 933273f commit 6994142

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ Accuracy Checker supports following list of annotation converters and specific f
181181
* `target_suffix` - target ground truth file name's suffix (default `out`).
182182
* `recursive` - enables acquiring of dataset files from `data_dir` subcatalogs (default False).
183183
* `annotation_loader` - which library will be used for ground truth image reading. Supported: `opencv`, `pillow` (Optional. Default value is pillow). Note, color space of image depends on loader (OpenCV uses BGR, Pillow uses RGB for image reading).
184-
* `parametric_image_processing` - converts dataset for image processing which required variable conditions for getting result, to `ImageProcessingAnnotation. Parameters provided as float value in reference image name using `_` as delimeter.
184+
* `image_generation` - converts dataset for generation images from noise to `ImageProcessingAnnotation`,
185+
* `data_dir` - dataset root directory where pregenerated input sequences are located in subdirectories.
186+
* `input_subdirectories` - list of relative paths for input data. If model have multiple inputs, data for each input should be located in separated directory.
187+
* `reference_dir` - directory with reference data.
188+
annotation_loader - which library will be used for ground truth image reading. Supported: opencv, pillow (Optional. Default value is pillow). Note, color space of image depends on loader (OpenCV uses BGR, Pillow uses RGB for image reading).
189+
* `parametric_image_processing` - converts dataset for image processing which required variable conditions for getting result, to `ImageProcessingAnnotation`. Parameters provided as float value in reference image name using `_` as delimeter.
185190
* `input_dir` - directory with input images.
186191
* `reference_dir` - directory with reference images.
187192
* `annotation_loader` - which library will be used for ground truth image reading. Supported: `opencv`, `pillow` (Optional. Default value is pillow). Note, color space of image depends on loader (OpenCV uses BGR, Pillow uses RGB for image reading).

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
from .coco_facial_landmarks import COCOFacialLandmarksRecognitionConverter
127127
from .speaker_identification import SpeakerReIdentificationDatasetConverter
128128
from .mvtec import MVTecDatasetConverter
129+
from .gan_annotation_converter import GANAnnotationConverter
129130

130131
__all__ = [
131132
'BaseFormatConverter',
@@ -252,4 +253,5 @@
252253
'COCOFacialLandmarksRecognitionConverter',
253254
'SpeakerReIdentificationDatasetConverter',
254255
'MVTecDatasetConverter',
256+
'GANAnnotationConverter'
255257
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""
2+
Copyright (c) 2018-2021 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 .format_converter import ConverterReturn, BaseFormatConverter
17+
from ..config import PathField, ListField, StringField, ConfigError
18+
from ..representation import ImageProcessingAnnotation
19+
from .image_processing import LOADERS_MAPPING
20+
from ..utils import get_path
21+
22+
23+
class GANAnnotationConverter(BaseFormatConverter):
24+
__provider__ = 'image_generation'
25+
26+
@classmethod
27+
def parameters(cls):
28+
params = super().parameters()
29+
params.update({
30+
'data_dir': PathField(description='dataset root directory', is_directory=True),
31+
'input_subdirectories': ListField(value_type=str, allow_empty=False,
32+
description='subdirectories with input data'),
33+
'reference_dir': PathField(
34+
is_directory=True,
35+
description='path to directory with reference relative to dataset root'
36+
),
37+
'annotation_loader': StringField(
38+
optional=True, choices=LOADERS_MAPPING.keys(), default='pillow',
39+
description="Which library will be used for ground truth image reading. "
40+
"Supported: {}".format(', '.join(LOADERS_MAPPING.keys()))
41+
)
42+
})
43+
return params
44+
45+
def configure(self):
46+
self.data_dir = self.get_value_from_config('data_dir')
47+
self.input_subdir = [
48+
get_path(self.data_dir / path, is_directory=True)
49+
for path in self.get_value_from_config('input_subdirectories')
50+
]
51+
self.reference_dir = self.get_value_from_config('reference_dir')
52+
self.annotation_loader = LOADERS_MAPPING.get(self.get_value_from_config('annotation_loader'))
53+
if not self.annotation_loader:
54+
raise ConfigError('provided not existing loader')
55+
56+
def convert(self, check_content=False, progress_callback=None, progress_interval=100, **kwargs):
57+
annotations = []
58+
for ref_file in self.reference_dir.glob('*'):
59+
input_files = []
60+
for input_path in self.input_subdir:
61+
input_candidate = list(input_path.glob('{}.*'.format(ref_file.stem)))
62+
if not input_candidate:
63+
raise ConfigError('Input data for {} is not found'.format(ref_file))
64+
input_files.append(str(input_candidate[0].relative_to(self.data_dir)))
65+
identifier = input_files if len(input_files) > 1 else input_files[0]
66+
ref_path = ref_file.name
67+
annotations.append(ImageProcessingAnnotation(identifier, ref_path, gt_loader=self.annotation_loader))
68+
return ConverterReturn(annotations, None, None)

tools/accuracy_checker/openvino/tools/accuracy_checker/metrics/regression.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ def configure(self):
8080
})
8181
self.magnitude = []
8282

83-
8483
def update(self, annotation, prediction):
8584
diff = self.calculate_diff(annotation, prediction)
8685
if isinstance(diff, dict):

0 commit comments

Comments
 (0)