Skip to content

Commit 98fdf10

Browse files
authored
Merge pull request #3554 from eaidova/ea/pil_deprecation
AC: fix deprecation warnings for pillow resize
2 parents ce7f28a + 4bb5310 commit 98fdf10

File tree

1 file changed

+23
-37
lines changed
  • tools/accuracy_checker/openvino/tools/accuracy_checker/preprocessor

1 file changed

+23
-37
lines changed

tools/accuracy_checker/openvino/tools/accuracy_checker/preprocessor/resize.py

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -223,27 +223,6 @@ class _PillowResizer(_Resizer):
223223
__provider__ = 'pillow'
224224
default_interpolation = 'BILINEAR'
225225

226-
def __init__(self, interpolation):
227-
self._supported_interpolations = {
228-
'NEAREST': Image.NEAREST,
229-
'NONE': Image.NONE,
230-
'BILINEAR': Image.BILINEAR,
231-
'LINEAR': Image.LINEAR,
232-
'BICUBIC': Image.BICUBIC,
233-
'CUBIC': Image.CUBIC,
234-
'ANTIALIAS': Image.ANTIALIAS,
235-
}
236-
try:
237-
optional_interpolations = {
238-
'BOX': Image.BOX,
239-
'LANCZOS': Image.LANCZOS,
240-
'HAMMING': Image.HAMMING,
241-
}
242-
self._supported_interpolations.update(optional_interpolations)
243-
except AttributeError:
244-
pass
245-
super().__init__(interpolation)
246-
247226
def resize(self, data, new_height, new_width):
248227
data = Image.fromarray(data)
249228
data = data.resize((new_width, new_height), self.interpolation)
@@ -255,20 +234,22 @@ def resize(self, data, new_height, new_width):
255234
def supported_interpolations(cls):
256235
if Image is None:
257236
return {}
237+
resampling = Image.Resampling if hasattr(Image, 'Resampling') else Image
238+
dither = Image.Dither if hasattr(Image, 'Dither') else Image
258239
intrp = {
259-
'NEAREST': Image.NEAREST,
260-
'NONE': Image.NONE,
261-
'BILINEAR': Image.BILINEAR,
262-
'LINEAR': Image.LINEAR,
263-
'BICUBIC': Image.BICUBIC,
264-
'CUBIC': Image.CUBIC,
265-
'ANTIALIAS': Image.ANTIALIAS
240+
'NEAREST': resampling.NEAREST,
241+
'NONE': dither.NONE,
242+
'BILINEAR': resampling.BILINEAR,
243+
'LINEAR': resampling.LINEAR if hasattr(resampling, 'LINEAR') else resampling.BILINEAR,
244+
'BICUBIC': resampling.BICUBIC,
245+
'CUBIC': resampling.CUBIC if hasattr(resampling, 'CUBIC') else resampling.BICUBIC,
266246
}
267247
try:
268248
optional_interpolations = {
269-
'BOX': Image.BOX,
270-
'LANCZOS': Image.LANCZOS,
271-
'HAMMING': Image.HAMMING,
249+
'BOX': resampling.BOX,
250+
'LANCZOS': resampling.LANCZOS,
251+
'ANTIALIAS': resampling.ANTIALIAS if hasattr(resampling, 'ANTIALIAS') else resampling.LANCZOS,
252+
'HAMMING': resampling.HAMMING,
272253
}
273254
intrp.update(optional_interpolations)
274255
except AttributeError:
@@ -290,11 +271,6 @@ def __init__(self, interpolation):
290271
self._resize = tf.image.resize_images
291272
else:
292273
self._resize = tf.image.resize
293-
self._supported_interpolations = {
294-
'BILINEAR': tf.image.ResizeMethod.BILINEAR,
295-
'AREA': tf.image.ResizeMethod.AREA,
296-
'BICUBIC': tf.image.ResizeMethod.BICUBIC,
297-
}
298274
self.default_interpolation = 'BILINEAR'
299275
super().__init__(interpolation)
300276

@@ -304,7 +280,17 @@ def resize(self, data, new_height, new_width):
304280

305281
@classmethod
306282
def supported_interpolations(cls):
307-
return {}
283+
try:
284+
import tensorflow as tf # pylint: disable=C0415
285+
except ImportError as import_error:
286+
return {}
287+
if tf.__version__ < '2.0.0':
288+
tf.enable_eager_execution()
289+
return {
290+
'BILINEAR': tf.image.ResizeMethod.BILINEAR,
291+
'AREA': tf.image.ResizeMethod.AREA,
292+
'BICUBIC': tf.image.ResizeMethod.BICUBIC,
293+
}
308294

309295

310296
def create_resizer(config):

0 commit comments

Comments
 (0)