".circleci/vscode:/vscode.git/clone" did not exist on "39e4057c77ced6e027f32b862ffe21ad9f950e7a"
Unverified Commit f762f373 authored by Alara Dirik's avatar Alara Dirik Committed by GitHub
Browse files

Fix resizing bug in OWL-ViT (#18573)

* Fixes resizing bug in OWL-ViT
* Defaults to square resize if size is set to an int
* Sets do_center_crop default value to False
parent 76568d24
...@@ -50,13 +50,15 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin ...@@ -50,13 +50,15 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin
Args: Args:
do_resize (`bool`, *optional*, defaults to `True`): do_resize (`bool`, *optional*, defaults to `True`):
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 768): size (`int` or `Tuple[int, int]`, *optional*, defaults to (768, 768)):
Resize the shorter edge of the input to the given size. Only has an effect if `do_resize` is set to `True`. 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
to (size, size).
resample (`int`, *optional*, defaults to `PIL.Image.BICUBIC`): resample (`int`, *optional*, defaults to `PIL.Image.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.NEAREST`, `PIL.Image.BOX`,
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect `PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect
if `do_resize` is set to `True`. if `do_resize` is set to `True`.
do_center_crop (`bool`, *optional*, defaults to `True`): 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.
crop_size (`int`, *optional*, defaults to 768): crop_size (`int`, *optional*, defaults to 768):
...@@ -74,10 +76,10 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin ...@@ -74,10 +76,10 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin
def __init__( def __init__(
self, self,
do_resize=True, do_resize=True,
size=768, size=(768, 768),
resample=Image.BICUBIC, resample=Image.BICUBIC,
crop_size=768, crop_size=768,
do_center_crop=True, do_center_crop=False,
do_normalize=True, do_normalize=True,
image_mean=None, image_mean=None,
image_std=None, image_std=None,
...@@ -195,7 +197,7 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin ...@@ -195,7 +197,7 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin
# transformations (resizing + center cropping + normalization) # transformations (resizing + center cropping + normalization)
if self.do_resize and self.size is not None and self.resample is not None: if self.do_resize and self.size is not None and self.resample is not None:
images = [ images = [
self.resize(image=image, size=self.size, resample=self.resample, default_to_square=False) self.resize(image=image, size=self.size, resample=self.resample, default_to_square=True)
for image in images for image in images
] ]
if self.do_center_crop and self.crop_size is not None: if self.do_center_crop and self.crop_size is not None:
......
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