@@ -223,27 +223,6 @@ class _PillowResizer(_Resizer):
223
223
__provider__ = 'pillow'
224
224
default_interpolation = 'BILINEAR'
225
225
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
-
247
226
def resize (self , data , new_height , new_width ):
248
227
data = Image .fromarray (data )
249
228
data = data .resize ((new_width , new_height ), self .interpolation )
@@ -255,20 +234,22 @@ def resize(self, data, new_height, new_width):
255
234
def supported_interpolations (cls ):
256
235
if Image is None :
257
236
return {}
237
+ resampling = Image .Resampling if hasattr (Image , 'Resampling' ) else Image
238
+ dither = Image .Dither if hasattr (Image , 'Dither' ) else Image
258
239
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 ,
266
246
}
267
247
try :
268
248
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 ,
272
253
}
273
254
intrp .update (optional_interpolations )
274
255
except AttributeError :
@@ -290,11 +271,6 @@ def __init__(self, interpolation):
290
271
self ._resize = tf .image .resize_images
291
272
else :
292
273
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
- }
298
274
self .default_interpolation = 'BILINEAR'
299
275
super ().__init__ (interpolation )
300
276
@@ -304,7 +280,17 @@ def resize(self, data, new_height, new_width):
304
280
305
281
@classmethod
306
282
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
+ }
308
294
309
295
310
296
def create_resizer (config ):
0 commit comments