Skip to content

Commit c402346

Browse files
authored
AC: fix segmentation masks in postprocessing (#2921)
1 parent 3be5d55 commit c402346

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
"""
16-
16+
from pathlib import Path
1717
from ..config import PathField, BoolField
1818
from ..representation import DetectionAnnotation, SegmentationAnnotation
1919
from ..representation.segmentation_representation import GTMaskLoader
@@ -169,16 +169,16 @@ def find_images(self, image_id):
169169
else:
170170
image_root = self.image_dir
171171
mask_root = self.mask_dir
172-
images = list(image_root.glob('{}.*'.format(image_id)))
172+
images = list(Path(image_root).glob('{}.*'.format(image_id)))
173173
if not images:
174174
image_file = '{}.jpg'.format(relative_image_subdir + '/' + image_id if relative_image_subdir else image_id)
175175
else:
176176
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)))
177+
masks = list(Path(mask_root).glob('{}.*'.format(image_id)))
178178
if not masks:
179179
mask_file = '{}.png'.format(relative_image_subdir + '/' + image_id if relative_image_subdir else image_id)
180180
else:
181-
mask_file = images[0].name if not relative_image_subdir else relative_image_subdir + '/' + images[0].name
181+
mask_file = masks[0].name if not relative_image_subdir else relative_image_subdir + '/' + masks[0].name
182182
return image_file, mask_file
183183

184184

tools/accuracy_checker/openvino/tools/accuracy_checker/postprocessor/extend_segmentation_mask.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ def process_image(self, annotation, prediction):
6060
height, width = annotation_mask.shape[-2:]
6161
if dst_width < width or dst_height < height:
6262
warning('size for extending should be not less current mask size. resize operation will be applied')
63-
annotation_.mask = self._resize(annotation_.mask, dst_height, dst_width, False)
63+
pad_width = min(dst_width, width)
64+
pad_height = min(dst_height, height)
65+
pad = self.pad_func(dst_width, dst_height, pad_width, pad_height)
66+
extended_mask = cv2.copyMakeBorder(
67+
annotation_mask, pad[0], pad[2], pad[1], pad[3], cv2.BORDER_CONSTANT, value=self.filling_label
68+
)
69+
annotation_.mask = self._resize(extended_mask, dst_height, dst_width, True)
6470
continue
6571

6672

0 commit comments

Comments
 (0)