Skip to content

Commit 143d778

Browse files
eaidovaekaterina.aidova
andauthored
AC: support mask concat for inpainting (#3514)
Co-authored-by: ekaterina.aidova <[email protected]>
1 parent 5450940 commit 143d778

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

tools/accuracy_checker/openvino/tools/accuracy_checker/preprocessor/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,15 @@ Accuracy Checker supports following set of preprocessors:
160160
* `max_length` - Maximum line length to draw mask.
161161
* `max_vertex` - Maximum number vertex to draw mask.
162162
* `inverse_mask` - Allows mask inversion (1 - real image, 0 - masked area). Optional, default `False` (0 - real image, 1- masked area).
163+
* `concat_mask` - Allows concatenate generated mask and image to one tensor by channels. Optional, default `False`.
163164
* `rect_mask` - Applies rectangle mask to the image.
164165
* `dst_width` and `dst_height` are width, and height of mask. You can also use `size` instead in case when destination sizes are equal.
165-
* `inverse_mask` - Allows mask inversion (1 - real image, 0 - masked area). Optional, default `False` (0 - real image, 1- masked areaa).
166+
* `inverse_mask` - Allows mask inversion (1 - real image, 0 - masked area). Optional, default `False` (0 - real image, 1- masked area).
167+
* `concat_mask` - Allows concatenate generated mask and image to one tensor by channels. Optional, default `False`.
166168
* `custom_mask` - Applies masks from custom mask dataset.
167169
* `mask_dir` - path to mask dataset to be used for inpainting.
168170
* `inverse_mask` - inverse mask before apply
171+
* `concat_mask` - Allows concatenate generated mask and image to one tensor by channels. Optional, default `False`.
169172
* `mask_loader` - which reader to use to load masks. The following readers can be used:
170173
* `opencv_imread` - read images using OpenCV library. Default color space is BGR.
171174
* `pillow_imread` - read images using Pillow library. Default color space is RGB.

tools/accuracy_checker/openvino/tools/accuracy_checker/preprocessor/inpainting_preprocessor.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def parameters(cls):
4141
optional=True, default=20, description="Maximum number vertex to draw mask.", value_type=int
4242
),
4343
'inverse_mask': BoolField(optional=True, default=False, description="Inverse mask"),
44+
'concat_mask': BoolField(
45+
optional=True, default=False, description='concatenate masked image and mask to one tensor')
4446
})
4547
return parameters
4648

@@ -50,6 +52,7 @@ def configure(self):
5052
self.max_length = self.get_value_from_config('max_length')
5153
self.max_vertex = self.get_value_from_config('max_vertex')
5254
self.inverse_mask = self.get_value_from_config('inverse_mask')
55+
self.concat_mask = self.get_value_from_config('concat_mask')
5356

5457
@staticmethod
5558
def _free_form_mask(mask, max_vertex, max_length, max_brush_width, h, w, max_angle=360):
@@ -87,6 +90,10 @@ def process(self, image, annotation_meta=None):
8790
img = img * (1 - mask) + 255 * mask
8891
if self.inverse_mask:
8992
mask = 1 - mask
93+
if self.concat_mask:
94+
image.identifier = image.identifier[0]
95+
image.data = np.concatenate([img, mask], axis=2)
96+
return image
9097
image.data = [img, mask]
9198
identifier = image.identifier[0]
9299
image.identifier = ['{}_image'.format(identifier), '{}_mask'.format(identifier)]
@@ -110,7 +117,9 @@ def parameters(cls):
110117
optional=True, default=128,
111118
description="Size of mask, used if both dimensions are equal", value_type=int
112119
),
113-
'inverse_mask': BoolField(optional=True, default=False, description="Inverse mask")
120+
'inverse_mask': BoolField(optional=True, default=False, description="Inverse mask"),
121+
'concat_mask': BoolField(
122+
optional=True, default=False, description='concatenate masked image and mask to one tensor')
114123

115124
})
116125
return parameters
@@ -122,6 +131,7 @@ def configure(self):
122131
if self.mask_width is None:
123132
self.mask_width = 128
124133
self.inverse_mask = self.get_value_from_config('inverse_mask')
134+
self.concat_mask = self.get_value_from_config('concat_mask')
125135

126136
def process(self, image, annotation_meta=None):
127137
if len(image.data) == 2:
@@ -139,6 +149,10 @@ def process(self, image, annotation_meta=None):
139149
img = img * (1 - mask) + 255 * mask
140150
if self.inverse_mask:
141151
mask = 1 - mask
152+
if self.concat_mask:
153+
image.identifier = image.identifier[0]
154+
image.data = np.concatenate([img, mask], axis=2)
155+
return image
142156
image.data = [img, mask]
143157
identifier = image.identifier[0]
144158
image.identifier = ['{}_image'.format(identifier), '{}_mask'.format(identifier)]
@@ -154,14 +168,17 @@ def parameters(cls):
154168
parameters.update({
155169
'mask_dir': PathField(is_directory=True, optional=False, description="Path to mask dataset directory"),
156170
'inverse_mask': BoolField(optional=True, default=False, description="Inverse mask"),
157-
'mask_loader': StringField(optional=True, default='numpy_reader', description="Mask loader")
171+
'mask_loader': StringField(optional=True, default='numpy_reader', description="Mask loader"),
172+
'concat_mask': BoolField(
173+
optional=True, default=False, description='concatenate masked image and mask to one tensor')
158174
})
159175
return parameters
160176

161177
def configure(self):
162178
self.mask_dir = self.get_value_from_config('mask_dir')
163179
self.inverse_mask = self.get_value_from_config('inverse_mask')
164180
self.mask_loader = self.get_value_from_config('mask_loader')
181+
self.concat_mask = self.get_value_from_config('concat_mask')
165182

166183
def process(self, image, annotation_meta=None):
167184
if len(image.data) == 2:
@@ -188,6 +205,10 @@ def process(self, image, annotation_meta=None):
188205
mask = np.expand_dims(mask, axis=2)
189206

190207
img = img * (1 - mask) + 255 * mask
208+
if self.concat_mask:
209+
image.identifier = image.identifier[0]
210+
image.data = np.concatenate([img, mask], axis=2)
211+
return image
191212
image.data = [img, mask]
192213
identifier = image.identifier[0]
193214
image.identifier = ['{}_image'.format(identifier), '{}_mask'.format(identifier)]

0 commit comments

Comments
 (0)