!35010 Adapt to the new Resampling APIs of pillow 9.1.0

Merge pull request !35010 from xiaotianci/pillow_api_modification
This commit is contained in:
i-robot 2022-05-31 03:03:26 +00:00 committed by Gitee
commit bb8b479531
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 21 additions and 9 deletions

View File

@ -616,7 +616,7 @@ class Dataset:
... index = 0
... for c in col:
... img = Image.fromarray(c.astype('uint8')).convert('RGB')
... img = img.resize((s, s), Image.ANTIALIAS)
... img = img.resize((s, s))
... output[index] = np.array(img)
... index += 1
... return (output,)

View File

@ -42,10 +42,16 @@ DE_PY_BORDER_TYPE = {Border.CONSTANT: 'constant',
Border.REFLECT: 'reflect',
Border.SYMMETRIC: 'symmetric'}
DE_PY_INTER_MODE = {Inter.NEAREST: Image.NEAREST,
Inter.ANTIALIAS: Image.ANTIALIAS,
Inter.LINEAR: Image.LINEAR,
Inter.CUBIC: Image.CUBIC}
if Image.__version__ >= "9.1.0":
DE_PY_INTER_MODE = {Inter.NEAREST: Image.Resampling.NEAREST,
Inter.ANTIALIAS: Image.Resampling.LANCZOS,
Inter.LINEAR: Image.Resampling.BILINEAR,
Inter.CUBIC: Image.Resampling.BICUBIC}
else:
DE_PY_INTER_MODE = {Inter.NEAREST: Image.NEAREST,
Inter.ANTIALIAS: Image.ANTIALIAS,
Inter.LINEAR: Image.LINEAR,
Inter.CUBIC: Image.CUBIC}
class AdjustGamma(py_transforms.PyTensorOperation):

View File

@ -53,10 +53,16 @@ class Inter(IntEnum):
"""
Function to return Python type for Interpolation Mode.
"""
python_values = {Inter.NEAREST: Image.NEAREST,
Inter.ANTIALIAS: Image.ANTIALIAS,
Inter.LINEAR: Image.LINEAR,
Inter.CUBIC: Image.CUBIC}
if Image.__version__ >= "9.1.0":
python_values = {Inter.NEAREST: Image.Resampling.NEAREST,
Inter.ANTIALIAS: Image.Resampling.LANCZOS,
Inter.LINEAR: Image.Resampling.BILINEAR,
Inter.CUBIC: Image.Resampling.BICUBIC}
else:
python_values = {Inter.NEAREST: Image.NEAREST,
Inter.ANTIALIAS: Image.ANTIALIAS,
Inter.LINEAR: Image.LINEAR,
Inter.CUBIC: Image.CUBIC}
return python_values.get(inter_type)
@staticmethod