Unverified Commit a23819ed authored by David Yang's avatar David Yang Committed by GitHub
Browse files

Clean up deprecation warnings (#19654)

* Clean up deprecation warnings

Notes:
Changed some strings in tests to raw strings, which will change the literal content of the strings as they are fed into whatever machine handles them.
Test cases for past in the past/past_key_values switch changed/removed due to warning of impending removal

* Add PILImageResampling abstraction for PIL.Image.Resampling
parent af556a09
...@@ -761,7 +761,7 @@ class TFGPTJForCausalLM(TFGPTJPreTrainedModel, TFCausalLanguageModelingLoss): ...@@ -761,7 +761,7 @@ class TFGPTJForCausalLM(TFGPTJPreTrainedModel, TFCausalLanguageModelingLoss):
"input_ids": inputs, "input_ids": inputs,
"attention_mask": attention_mask, "attention_mask": attention_mask,
"position_ids": position_ids, "position_ids": position_ids,
"past": past, "past_key_values": past,
"use_cache": use_cache, "use_cache": use_cache,
"token_type_ids": token_type_ids, "token_type_ids": token_type_ids,
} }
......
...@@ -133,7 +133,7 @@ def _compute_mask_indices( ...@@ -133,7 +133,7 @@ def _compute_mask_indices(
) )
# SpecAugment mask to fill # SpecAugment mask to fill
spec_aug_mask = np.zeros((batch_size, sequence_length), dtype=np.bool) spec_aug_mask = np.zeros((batch_size, sequence_length), dtype=bool)
spec_aug_mask_idxs = [] spec_aug_mask_idxs = []
max_num_masked_span = compute_num_masked_span(sequence_length) max_num_masked_span = compute_num_masked_span(sequence_length)
......
...@@ -19,6 +19,8 @@ from typing import List, Optional, Union ...@@ -19,6 +19,8 @@ from typing import List, Optional, Union
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from transformers.image_utils import PILImageResampling
from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...image_utils import ImageFeatureExtractionMixin, is_torch_tensor from ...image_utils import ImageFeatureExtractionMixin, is_torch_tensor
from ...utils import TensorType, logging from ...utils import TensorType, logging
...@@ -60,17 +62,20 @@ class ImageGPTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMix ...@@ -60,17 +62,20 @@ class ImageGPTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMix
Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an
integer is provided, then the input will be resized to (size, size). Only has an effect if `do_resize` is integer is provided, then the input will be resized to (size, size). Only has an effect if `do_resize` is
set to `True`. set to `True`.
resample (`int`, *optional*, defaults to `PIL.Image.BILINEAR`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
if `do_resize` is set to `True`. `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
to `True`.
do_normalize (`bool`, *optional*, defaults to `True`): do_normalize (`bool`, *optional*, defaults to `True`):
Whether or not to normalize the input to the range between -1 and +1. Whether or not to normalize the input to the range between -1 and +1.
""" """
model_input_names = ["input_ids"] model_input_names = ["input_ids"]
def __init__(self, clusters, do_resize=True, size=32, resample=Image.BILINEAR, do_normalize=True, **kwargs): def __init__(
self, clusters, do_resize=True, size=32, resample=PILImageResampling.BILINEAR, do_normalize=True, **kwargs
):
super().__init__(**kwargs) super().__init__(**kwargs)
self.clusters = np.asarray(clusters) self.clusters = np.asarray(clusters)
self.do_resize = do_resize self.do_resize = do_resize
......
...@@ -21,6 +21,8 @@ from typing import List, Optional, Union ...@@ -21,6 +21,8 @@ from typing import List, Optional, Union
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from transformers.image_utils import PILImageResampling
from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...image_utils import ImageFeatureExtractionMixin, is_torch_tensor from ...image_utils import ImageFeatureExtractionMixin, is_torch_tensor
from ...utils import TensorType, is_pytesseract_available, logging, requires_backends from ...utils import TensorType, is_pytesseract_available, logging, requires_backends
...@@ -94,10 +96,11 @@ class LayoutLMv2FeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM ...@@ -94,10 +96,11 @@ class LayoutLMv2FeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an
integer is provided, then the input will be resized to (size, size). Only has an effect if `do_resize` is integer is provided, then the input will be resized to (size, size). Only has an effect if `do_resize` is
set to `True`. set to `True`.
resample (`int`, *optional*, defaults to `PIL.Image.BILINEAR`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
if `do_resize` is set to `True`. `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
to `True`.
apply_ocr (`bool`, *optional*, defaults to `True`): apply_ocr (`bool`, *optional*, defaults to `True`):
Whether to apply the Tesseract OCR engine to get words + normalized bounding boxes. Whether to apply the Tesseract OCR engine to get words + normalized bounding boxes.
ocr_lang (`str`, *optional*): ocr_lang (`str`, *optional*):
...@@ -119,7 +122,7 @@ class LayoutLMv2FeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM ...@@ -119,7 +122,7 @@ class LayoutLMv2FeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
self, self,
do_resize=True, do_resize=True,
size=224, size=224,
resample=Image.BILINEAR, resample=PILImageResampling.BILINEAR,
apply_ocr=True, apply_ocr=True,
ocr_lang=None, ocr_lang=None,
tesseract_config="", tesseract_config="",
......
...@@ -21,6 +21,8 @@ from typing import List, Optional, Union ...@@ -21,6 +21,8 @@ from typing import List, Optional, Union
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from transformers.image_utils import PILImageResampling
from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...image_utils import IMAGENET_STANDARD_MEAN, IMAGENET_STANDARD_STD, ImageFeatureExtractionMixin, is_torch_tensor from ...image_utils import IMAGENET_STANDARD_MEAN, IMAGENET_STANDARD_STD, ImageFeatureExtractionMixin, is_torch_tensor
from ...utils import TensorType, is_pytesseract_available, logging, requires_backends from ...utils import TensorType, is_pytesseract_available, logging, requires_backends
...@@ -93,10 +95,11 @@ class LayoutLMv3FeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM ...@@ -93,10 +95,11 @@ class LayoutLMv3FeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an
integer is provided, then the input will be resized to (size, size). Only has an effect if `do_resize` is integer is provided, then the input will be resized to (size, size). Only has an effect if `do_resize` is
set to `True`. set to `True`.
resample (`int`, *optional*, defaults to `PIL.Image.BILINEAR`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
if `do_resize` is set to `True`. `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
to `True`.
do_normalize (`bool`, *optional*, defaults to `True`): do_normalize (`bool`, *optional*, defaults to `True`):
Whether or not to normalize the input with mean and standard deviation. Whether or not to normalize the input with mean and standard deviation.
image_mean (`List[int]`, defaults to `[0.5, 0.5, 0.5]`): image_mean (`List[int]`, defaults to `[0.5, 0.5, 0.5]`):
...@@ -124,7 +127,7 @@ class LayoutLMv3FeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM ...@@ -124,7 +127,7 @@ class LayoutLMv3FeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
self, self,
do_resize=True, do_resize=True,
size=224, size=224,
resample=Image.BILINEAR, resample=PILImageResampling.BILINEAR,
do_normalize=True, do_normalize=True,
image_mean=None, image_mean=None,
image_std=None, image_std=None,
......
...@@ -19,6 +19,8 @@ from typing import Optional, Union ...@@ -19,6 +19,8 @@ from typing import Optional, Union
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from transformers.image_utils import PILImageResampling
from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...image_utils import ( from ...image_utils import (
IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_MEAN,
...@@ -46,10 +48,11 @@ class LevitFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin) ...@@ -46,10 +48,11 @@ class LevitFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin)
size (`int` or `Tuple(int)`, *optional*, defaults to 224): size (`int` or `Tuple(int)`, *optional*, defaults to 224):
Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an
integer is provided, then shorter side of input will be resized to 'size'. integer is provided, then shorter side of input will be resized to 'size'.
resample (`int`, *optional*, defaults to `PIL.Image.BICUBIC`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BICUBIC`):
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
if `do_resize` is set to `True`. `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
to `True`.
do_center_crop (`bool`, *optional*, defaults to `True`): do_center_crop (`bool`, *optional*, defaults to `True`):
Whether or not to center crop the input to `size`. Whether or not to center crop the input to `size`.
do_normalize (`bool`, *optional*, defaults to `True`): do_normalize (`bool`, *optional*, defaults to `True`):
...@@ -66,7 +69,7 @@ class LevitFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin) ...@@ -66,7 +69,7 @@ class LevitFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin)
self, self,
do_resize=True, do_resize=True,
size=224, size=224,
resample=Image.BICUBIC, resample=PILImageResampling.BICUBIC,
do_center_crop=True, do_center_crop=True,
do_normalize=True, do_normalize=True,
image_mean=IMAGENET_DEFAULT_MEAN, image_mean=IMAGENET_DEFAULT_MEAN,
......
...@@ -19,6 +19,8 @@ from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, Union ...@@ -19,6 +19,8 @@ from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, Union
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from transformers.image_utils import PILImageResampling
from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...image_utils import ImageFeatureExtractionMixin, ImageInput, is_torch_tensor from ...image_utils import ImageFeatureExtractionMixin, ImageInput, is_torch_tensor
from ...utils import TensorType, is_torch_available, logging from ...utils import TensorType, is_torch_available, logging
...@@ -201,10 +203,11 @@ class MaskFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM ...@@ -201,10 +203,11 @@ class MaskFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
max_size (`int`, *optional*, defaults to 1333): max_size (`int`, *optional*, defaults to 1333):
The largest size an image dimension can have (otherwise it's capped). Only has an effect if `do_resize` is The largest size an image dimension can have (otherwise it's capped). Only has an effect if `do_resize` is
set to `True`. set to `True`.
resample (`int`, *optional*, defaults to `PIL.Image.BILINEAR`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
if `do_resize` is set to `True`. `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
to `True`.
size_divisibility (`int`, *optional*, defaults to 32): size_divisibility (`int`, *optional*, defaults to 32):
Some backbones need images divisible by a certain number. If not passed, it defaults to the value used in Some backbones need images divisible by a certain number. If not passed, it defaults to the value used in
Swin Transformer. Swin Transformer.
...@@ -232,7 +235,7 @@ class MaskFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM ...@@ -232,7 +235,7 @@ class MaskFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
do_resize=True, do_resize=True,
size=800, size=800,
max_size=1333, max_size=1333,
resample=Image.BILINEAR, resample=PILImageResampling.BILINEAR,
size_divisibility=32, size_divisibility=32,
do_normalize=True, do_normalize=True,
image_mean=None, image_mean=None,
......
...@@ -19,6 +19,8 @@ from typing import List, Optional, Tuple, Union ...@@ -19,6 +19,8 @@ from typing import List, Optional, Tuple, Union
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from transformers.image_utils import PILImageResampling
from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...image_utils import ImageFeatureExtractionMixin, ImageInput, is_torch_tensor from ...image_utils import ImageFeatureExtractionMixin, ImageInput, is_torch_tensor
from ...utils import TensorType, is_torch_available, logging from ...utils import TensorType, is_torch_available, logging
...@@ -44,10 +46,11 @@ class MobileViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMi ...@@ -44,10 +46,11 @@ class MobileViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMi
Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an
integer is provided, then the input will be resized to match the shorter side. Only has an effect if integer is provided, then the input will be resized to match the shorter side. Only has an effect if
`do_resize` is set to `True`. `do_resize` is set to `True`.
resample (`int`, *optional*, defaults to `PIL.Image.BILINEAR`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
if `do_resize` is set to `True`. `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
to `True`.
do_center_crop (`bool`, *optional*, defaults to `True`): do_center_crop (`bool`, *optional*, defaults to `True`):
Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the
image is padded with 0's and then center cropped. image is padded with 0's and then center cropped.
...@@ -63,7 +66,7 @@ class MobileViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMi ...@@ -63,7 +66,7 @@ class MobileViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMi
self, self,
do_resize=True, do_resize=True,
size=288, size=288,
resample=Image.BILINEAR, resample=PILImageResampling.BILINEAR,
do_center_crop=True, do_center_crop=True,
crop_size=256, crop_size=256,
do_flip_channel_order=True, do_flip_channel_order=True,
......
...@@ -19,6 +19,8 @@ from typing import List, Optional, Union ...@@ -19,6 +19,8 @@ from typing import List, Optional, Union
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from transformers.image_utils import PILImageResampling
from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...image_utils import ImageFeatureExtractionMixin, is_torch_tensor from ...image_utils import ImageFeatureExtractionMixin, is_torch_tensor
from ...utils import TensorType, is_torch_available, logging from ...utils import TensorType, is_torch_available, logging
...@@ -54,10 +56,11 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin ...@@ -54,10 +56,11 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin
The size to use for resizing the image. Only has an effect if `do_resize` is set to `True`. If `size` is a The size to use for resizing the image. Only has an effect if `do_resize` is set to `True`. If `size` is a
sequence like (h, w), output size will be matched to this. If `size` is an int, then image will be resized sequence like (h, w), output size will be matched to this. If `size` is an int, then image will be resized
to (size, size). to (size, size).
resample (`int`, *optional*, defaults to `PIL.Image.BICUBIC`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BICUBIC`):
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
if `do_resize` is set to `True`. `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
to `True`.
do_center_crop (`bool`, *optional*, defaults to `False`): do_center_crop (`bool`, *optional*, defaults to `False`):
Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the
image is padded with 0's and then center cropped. image is padded with 0's and then center cropped.
...@@ -77,7 +80,7 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin ...@@ -77,7 +80,7 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin
self, self,
do_resize=True, do_resize=True,
size=(768, 768), size=(768, 768),
resample=Image.BICUBIC, resample=PILImageResampling.BICUBIC,
crop_size=768, crop_size=768,
do_center_crop=False, do_center_crop=False,
do_normalize=True, do_normalize=True,
......
...@@ -19,6 +19,8 @@ from typing import Optional, Union ...@@ -19,6 +19,8 @@ from typing import Optional, Union
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from transformers.image_utils import PILImageResampling
from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...image_utils import ( from ...image_utils import (
IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_MEAN,
...@@ -52,10 +54,11 @@ class PerceiverFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMi ...@@ -52,10 +54,11 @@ class PerceiverFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMi
Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an
integer is provided, then the input will be resized to (size, size). Only has an effect if `do_resize` is integer is provided, then the input will be resized to (size, size). Only has an effect if `do_resize` is
set to `True`. set to `True`.
resample (`int`, *optional*, defaults to `PIL.Image.BICUBIC`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BICUBIC`):
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
if `do_resize` is set to `True`. `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
to `True`.
do_normalize (`bool`, *optional*, defaults to `True`): do_normalize (`bool`, *optional*, defaults to `True`):
Whether or not to normalize the input with `image_mean` and `image_std`. Whether or not to normalize the input with `image_mean` and `image_std`.
image_mean (`List[int]`, defaults to `[0.485, 0.456, 0.406]`): image_mean (`List[int]`, defaults to `[0.485, 0.456, 0.406]`):
...@@ -72,7 +75,7 @@ class PerceiverFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMi ...@@ -72,7 +75,7 @@ class PerceiverFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMi
crop_size=256, crop_size=256,
do_resize=True, do_resize=True,
size=224, size=224,
resample=Image.BICUBIC, resample=PILImageResampling.BICUBIC,
do_normalize=True, do_normalize=True,
image_mean=None, image_mean=None,
image_std=None, image_std=None,
......
...@@ -20,6 +20,8 @@ from typing import Optional, Union ...@@ -20,6 +20,8 @@ from typing import Optional, Union
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from transformers.image_utils import PILImageResampling
from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...image_utils import ( from ...image_utils import (
IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_MEAN,
...@@ -48,10 +50,11 @@ class PoolFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM ...@@ -48,10 +50,11 @@ class PoolFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
Center crop the input to the given size. If a tuple is provided, it should be (width, height). If only an Center crop the input to the given size. If a tuple is provided, it should be (width, height). If only an
integer is provided, then the input will be center cropped to (size, size). Only has an effect if integer is provided, then the input will be center cropped to (size, size). Only has an effect if
`do_resize_and_center_crop` is set to `True`. `do_resize_and_center_crop` is set to `True`.
resample (`int`, *optional*, defaults to `PIL.Image.BICUBIC`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BICUBIC`):
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
if `do_resize_and_center_crop` is set to `True`. `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
to `True`.
crop_pct (`float`, *optional*, defaults to `0.9`): crop_pct (`float`, *optional*, defaults to `0.9`):
The percentage of the image to crop from the center. Only has an effect if `do_resize_and_center_crop` is The percentage of the image to crop from the center. Only has an effect if `do_resize_and_center_crop` is
set to `True`. set to `True`.
...@@ -69,7 +72,7 @@ class PoolFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM ...@@ -69,7 +72,7 @@ class PoolFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
self, self,
do_resize_and_center_crop=True, do_resize_and_center_crop=True,
size=224, size=224,
resample=Image.BICUBIC, resample=PILImageResampling.BICUBIC,
crop_pct=0.9, crop_pct=0.9,
do_normalize=True, do_normalize=True,
image_mean=None, image_mean=None,
......
...@@ -19,6 +19,8 @@ from typing import List, Optional, Tuple, Union ...@@ -19,6 +19,8 @@ from typing import List, Optional, Tuple, Union
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from transformers.image_utils import PILImageResampling
from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...image_utils import ( from ...image_utils import (
IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_MEAN,
...@@ -50,10 +52,11 @@ class SegformerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMi ...@@ -50,10 +52,11 @@ class SegformerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMi
Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an
integer is provided, then the input will be resized to (size, size). Only has an effect if `do_resize` is integer is provided, then the input will be resized to (size, size). Only has an effect if `do_resize` is
set to `True`. set to `True`.
resample (`int`, *optional*, defaults to `PIL.Image.BILINEAR`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
if `do_resize` is set to `True`. `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
to `True`.
do_normalize (`bool`, *optional*, defaults to `True`): do_normalize (`bool`, *optional*, defaults to `True`):
Whether or not to normalize the input with mean and standard deviation. Whether or not to normalize the input with mean and standard deviation.
image_mean (`int`, *optional*, defaults to `[0.485, 0.456, 0.406]`): image_mean (`int`, *optional*, defaults to `[0.485, 0.456, 0.406]`):
...@@ -73,7 +76,7 @@ class SegformerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMi ...@@ -73,7 +76,7 @@ class SegformerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMi
self, self,
do_resize=True, do_resize=True,
size=512, size=512,
resample=Image.BILINEAR, resample=PILImageResampling.BILINEAR,
do_normalize=True, do_normalize=True,
image_mean=None, image_mean=None,
image_std=None, image_std=None,
......
...@@ -133,7 +133,7 @@ def _compute_mask_indices( ...@@ -133,7 +133,7 @@ def _compute_mask_indices(
) )
# SpecAugment mask to fill # SpecAugment mask to fill
spec_aug_mask = np.zeros((batch_size, sequence_length), dtype=np.bool) spec_aug_mask = np.zeros((batch_size, sequence_length), dtype=bool)
spec_aug_mask_idxs = [] spec_aug_mask_idxs = []
max_num_masked_span = compute_num_masked_span(sequence_length) max_num_masked_span = compute_num_masked_span(sequence_length)
......
...@@ -134,7 +134,7 @@ def _compute_mask_indices( ...@@ -134,7 +134,7 @@ def _compute_mask_indices(
) )
# SpecAugment mask to fill # SpecAugment mask to fill
spec_aug_mask = np.zeros((batch_size, sequence_length), dtype=np.bool) spec_aug_mask = np.zeros((batch_size, sequence_length), dtype=bool)
spec_aug_mask_idxs = [] spec_aug_mask_idxs = []
max_num_masked_span = compute_num_masked_span(sequence_length) max_num_masked_span = compute_num_masked_span(sequence_length)
......
...@@ -169,7 +169,7 @@ def _compute_mask_indices( ...@@ -169,7 +169,7 @@ def _compute_mask_indices(
) )
# SpecAugment mask to fill # SpecAugment mask to fill
spec_aug_mask = np.zeros((batch_size, sequence_length), dtype=np.bool) spec_aug_mask = np.zeros((batch_size, sequence_length), dtype=bool)
spec_aug_mask_idxs = [] spec_aug_mask_idxs = []
max_num_masked_span = compute_num_masked_span(sequence_length) max_num_masked_span = compute_num_masked_span(sequence_length)
......
...@@ -183,7 +183,7 @@ def _compute_mask_indices( ...@@ -183,7 +183,7 @@ def _compute_mask_indices(
) )
# SpecAugment mask to fill # SpecAugment mask to fill
spec_aug_mask = np.zeros((batch_size, sequence_length), dtype=np.bool) spec_aug_mask = np.zeros((batch_size, sequence_length), dtype=bool)
spec_aug_mask_idxs = [] spec_aug_mask_idxs = []
max_num_masked_span = compute_num_masked_span(sequence_length) max_num_masked_span = compute_num_masked_span(sequence_length)
......
...@@ -19,6 +19,8 @@ from typing import Optional, Union ...@@ -19,6 +19,8 @@ from typing import Optional, Union
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from transformers.image_utils import PILImageResampling
from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...image_utils import ImageFeatureExtractionMixin, ImageInput, is_torch_tensor from ...image_utils import ImageFeatureExtractionMixin, ImageInput, is_torch_tensor
from ...utils import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, TensorType, logging from ...utils import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, TensorType, logging
...@@ -39,10 +41,11 @@ class VideoMAEFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMix ...@@ -39,10 +41,11 @@ class VideoMAEFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMix
Whether to resize the shorter edge of the input to a certain `size`. Whether to resize the shorter edge of the input to a certain `size`.
size (`int`, *optional*, defaults to 224): size (`int`, *optional*, defaults to 224):
Resize the shorter edge of the input to the given size. Only has an effect if `do_resize` is set to `True`. Resize the shorter edge of the input to the given size. Only has an effect if `do_resize` is set to `True`.
resample (`int`, *optional*, defaults to `PIL.Image.BILINEAR`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
if `do_resize` is set to `True`. `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
to `True`.
do_center_crop (`bool`, *optional*, defaults to `True`): do_center_crop (`bool`, *optional*, defaults to `True`):
Whether to center crop the input to a certain `size`. Whether to center crop the input to a certain `size`.
do_normalize (`bool`, *optional*, defaults to `True`): do_normalize (`bool`, *optional*, defaults to `True`):
...@@ -59,7 +62,7 @@ class VideoMAEFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMix ...@@ -59,7 +62,7 @@ class VideoMAEFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMix
self, self,
do_resize=True, do_resize=True,
size=224, size=224,
resample=Image.BILINEAR, resample=PILImageResampling.BILINEAR,
do_center_crop=True, do_center_crop=True,
do_normalize=True, do_normalize=True,
image_mean=None, image_mean=None,
......
...@@ -19,6 +19,8 @@ from typing import List, Optional, Union ...@@ -19,6 +19,8 @@ from typing import List, Optional, Union
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from transformers.image_utils import PILImageResampling
from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...image_utils import ( from ...image_utils import (
IMAGENET_STANDARD_MEAN, IMAGENET_STANDARD_MEAN,
...@@ -53,10 +55,11 @@ class ViltFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin): ...@@ -53,10 +55,11 @@ class ViltFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin):
`do_resize` is set to `True`. `do_resize` is set to `True`.
size_divisor (`int`, *optional*, defaults to 32): size_divisor (`int`, *optional*, defaults to 32):
The size by which to make sure both the height and width can be divided. The size by which to make sure both the height and width can be divided.
resample (`int`, *optional*, defaults to `PIL.Image.BICUBIC`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BICUBIC`):
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
if `do_resize` is set to `True`. `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
to `True`.
do_normalize (`bool`, *optional*, defaults to `True`): do_normalize (`bool`, *optional*, defaults to `True`):
Whether or not to normalize the input with mean and standard deviation. Whether or not to normalize the input with mean and standard deviation.
image_mean (`List[int]`, defaults to `[0.5, 0.5, 0.5]`): image_mean (`List[int]`, defaults to `[0.5, 0.5, 0.5]`):
...@@ -72,7 +75,7 @@ class ViltFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin): ...@@ -72,7 +75,7 @@ class ViltFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin):
do_resize=True, do_resize=True,
size=384, size=384,
size_divisor=32, size_divisor=32,
resample=Image.BICUBIC, resample=PILImageResampling.BICUBIC,
do_normalize=True, do_normalize=True,
image_mean=None, image_mean=None,
image_std=None, image_std=None,
...@@ -87,7 +90,7 @@ class ViltFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin): ...@@ -87,7 +90,7 @@ class ViltFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin):
self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD
def _resize(self, image, shorter=800, longer=1333, size_divisor=32, resample=Image.BICUBIC): def _resize(self, image, shorter=800, longer=1333, size_divisor=32, resample=PILImageResampling.BICUBIC):
""" """
Resizes the shorter edge of `image` to `shorter` and limits the longer edge to under `longer`, while preserving Resizes the shorter edge of `image` to `shorter` and limits the longer edge to under `longer`, while preserving
the aspect ratio. Also makes sure that both the height and width can be divided by `size_divisor`. the aspect ratio. Also makes sure that both the height and width can be divided by `size_divisor`.
...@@ -104,7 +107,7 @@ class ViltFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin): ...@@ -104,7 +107,7 @@ class ViltFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin):
The size by which to limit the longer side of the image, while preserving the aspect ratio. The size by which to limit the longer side of the image, while preserving the aspect ratio.
size_divisor (`int`, *optional*, defaults to `32`): size_divisor (`int`, *optional*, defaults to `32`):
The size by which both the height and the width must be divisible. The size by which both the height and the width must be divisible.
resample (`int`, *optional*, defaults to `PIL.Image.BICUBIC`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BICUBIC`):
An optional resampling filter. An optional resampling filter.
""" """
if not isinstance(image, Image.Image): if not isinstance(image, Image.Image):
......
...@@ -19,6 +19,8 @@ from typing import Optional, Union ...@@ -19,6 +19,8 @@ from typing import Optional, Union
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from transformers.image_utils import PILImageResampling
from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...image_utils import ( from ...image_utils import (
IMAGENET_STANDARD_MEAN, IMAGENET_STANDARD_MEAN,
...@@ -47,10 +49,11 @@ class ViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin): ...@@ -47,10 +49,11 @@ class ViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin):
Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an
integer is provided, then the input will be resized to (size, size). Only has an effect if `do_resize` is integer is provided, then the input will be resized to (size, size). Only has an effect if `do_resize` is
set to `True`. set to `True`.
resample (`int`, *optional*, defaults to `PIL.Image.BILINEAR`): resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
if `do_resize` is set to `True`. `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
to `True`.
do_normalize (`bool`, *optional*, defaults to `True`): do_normalize (`bool`, *optional*, defaults to `True`):
Whether or not to normalize the input with mean and standard deviation. Whether or not to normalize the input with mean and standard deviation.
image_mean (`List[int]`, defaults to `[0.5, 0.5, 0.5]`): image_mean (`List[int]`, defaults to `[0.5, 0.5, 0.5]`):
...@@ -65,7 +68,7 @@ class ViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin): ...@@ -65,7 +68,7 @@ class ViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin):
self, self,
do_resize=True, do_resize=True,
size=224, size=224,
resample=Image.BILINEAR, resample=PILImageResampling.BILINEAR,
do_normalize=True, do_normalize=True,
image_mean=None, image_mean=None,
image_std=None, image_std=None,
......
...@@ -182,7 +182,7 @@ def get_1d_sincos_pos_embed_from_grid(embed_dim, pos): ...@@ -182,7 +182,7 @@ def get_1d_sincos_pos_embed_from_grid(embed_dim, pos):
if embed_dim % 2 != 0: if embed_dim % 2 != 0:
raise ValueError("embed_dim must be even") raise ValueError("embed_dim must be even")
omega = np.arange(embed_dim // 2, dtype=np.float) omega = np.arange(embed_dim // 2, dtype=float)
omega /= embed_dim / 2.0 omega /= embed_dim / 2.0
omega = 1.0 / 10000**omega # (D/2,) omega = 1.0 / 10000**omega # (D/2,)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment