Skip to content

Commit 3be5d55

Browse files
authored
AC: support different image types in voc segmentation (#2920)
* AC: support different image types in voc segmentation * Update tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/pascal_voc.py
1 parent d674b9f commit 3be5d55

File tree

1 file changed

+23
-2
lines changed
  • tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters

1 file changed

+23
-2
lines changed

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/pascal_voc.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ def convert(self, check_content=False, progress_callback=None, progress_interval
139139
images_set = read_txt(self.image_set_file)
140140
num_iterations = len(images_set)
141141
for image_id, image in enumerate(images_set):
142-
image_file = '{}.jpg'.format(image)
143-
mask_file = '{}.png'.format(image)
142+
image_file, mask_file = self.find_images(image)
144143
annotation = SegmentationAnnotation(image_file, mask_file, mask_loader=GTMaskLoader.SCIPY)
145144
annotations.append(annotation)
146145
if check_content:
@@ -161,6 +160,28 @@ def convert(self, check_content=False, progress_callback=None, progress_interval
161160

162161
return ConverterReturn(annotations, meta, content_check_errors)
163162

163+
def find_images(self, image_id):
164+
relative_image_subdir = ''
165+
if '/' in image_id:
166+
relative_image_subdir, image_id =image_id.rsplit('/', 1)
167+
image_root = self.image_dir / relative_image_subdir
168+
mask_root = self.mask_dir / relative_image_subdir
169+
else:
170+
image_root = self.image_dir
171+
mask_root = self.mask_dir
172+
images = list(image_root.glob('{}.*'.format(image_id)))
173+
if not images:
174+
image_file = '{}.jpg'.format(relative_image_subdir + '/' + image_id if relative_image_subdir else image_id)
175+
else:
176+
image_file = images[0].name if not relative_image_subdir else relative_image_subdir + '/' + images[0].name
177+
masks = list(mask_root.glob('{}.*'.format(image_id)))
178+
if not masks:
179+
mask_file = '{}.png'.format(relative_image_subdir + '/' + image_id if relative_image_subdir else image_id)
180+
else:
181+
mask_file = images[0].name if not relative_image_subdir else relative_image_subdir + '/' + images[0].name
182+
return image_file, mask_file
183+
184+
164185
@staticmethod
165186
def read_labelmap(input_file):
166187
label_map = {}

0 commit comments

Comments
 (0)