Skip to content

Commit

Permalink
Fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
qubvel committed May 15, 2024
1 parent e4d8dea commit 6682c34
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1322,8 +1322,8 @@ def preprocess(
image_std (`float` or `List[float]`, *optional*, defaults to self.image_std):
Standard deviation to use when normalizing the image.
do_pad (`bool`, *optional*, defaults to self.do_pad):
Whether to pad the image. If `True`, padding will be applied to the bottom and right of
the image with zeros. If `pad_size` is provided, the image will be padded to the specified
Whether to pad the image. If `True`, padding will be applied to the bottom and right of
the image with zeros. If `pad_size` is provided, the image will be padded to the specified
dimensions. Otherwise, the image will be padded to the maximum height and width of the batch.
format (`str` or `AnnotationFormat`, *optional*, defaults to self.format):
Format of the annotations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def get_resize_output_image_size(
return get_size_with_aspect_ratio(image_size, size, max_size)



# Copied from transformers.models.detr.image_processing_detr.get_image_size_for_max_height_width
def get_image_size_for_max_height_width(
input_image: np.ndarray,
Expand Down Expand Up @@ -832,7 +831,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
If `pad_size` is provided, the image will be padded to the specified dimensions.
Otherwise, the image will be padded to the maximum height and width of the batch.
pad_size (`Dict[str, int]`, *optional*):
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
image in `images`. If not provided, the images will be padded to the largest height and width in the batch.
"""

Expand Down Expand Up @@ -1325,8 +1324,8 @@ def preprocess(
image_std (`float` or `List[float]`, *optional*, defaults to self.image_std):
Standard deviation to use when normalizing the image.
do_pad (`bool`, *optional*, defaults to self.do_pad):
Whether to pad the image. If `True`, padding will be applied to the bottom and right of
the image with zeros. If `pad_size` is provided, the image will be padded to the specified
Whether to pad the image. If `True`, padding will be applied to the bottom and right of
the image with zeros. If `pad_size` is provided, the image will be padded to the specified
dimensions. Otherwise, the image will be padded to the maximum height and width of the batch.
format (`str` or `AnnotationFormat`, *optional*, defaults to self.format):
Format of the annotations.
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/deta/image_processing_deta.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def get_resize_output_image_size(
return get_size_with_aspect_ratio(image_size, size, max_size)



# Copied from transformers.models.detr.image_processing_detr.get_image_size_for_max_height_width
def get_image_size_for_max_height_width(
input_image: np.ndarray,
Expand Down Expand Up @@ -541,7 +540,7 @@ class DetaImageProcessor(BaseImageProcessor):
If `pad_size` is provided, the image will be padded to the specified dimensions.
Otherwise, the image will be padded to the maximum height and width of the batch.
pad_size (`Dict[str, int]`, *optional*):
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
image in `images`. If not provided, the images will be padded to the largest height and width in the batch.
"""

Expand Down Expand Up @@ -972,8 +971,8 @@ def preprocess(
boxes from the format `(top_left_x, top_left_y, width, height)` to `(center_x, center_y, width, height)`
and in relative coordinates.
do_pad (`bool`, *optional*, defaults to self.do_pad):
Whether to pad the image. If `True`, padding will be applied to the bottom and right of
the image with zeros. If `pad_size` is provided, the image will be padded to the specified
Whether to pad the image. If `True`, padding will be applied to the bottom and right of
the image with zeros. If `pad_size` is provided, the image will be padded to the specified
dimensions. Otherwise, the image will be padded to the maximum height and width of the batch.
format (`str` or `AnnotationFormat`, *optional*, defaults to self.format):
Format of the annotations.
Expand All @@ -991,7 +990,7 @@ def preprocess(
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
pad_size (`Dict[str, int]`, *optional*):
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
image in `images`. If not provided, the images will be padded to the largest height and width in the batch.
"""
if "pad_and_return_pixel_mask" in kwargs:
Expand Down
10 changes: 5 additions & 5 deletions src/transformers/models/detr/image_processing_detr.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ class DetrImageProcessor(BaseImageProcessor):
If `pad_size` is provided, the image will be padded to the specified dimensions.
Otherwise, the image will be padded to the maximum height and width of the batch.
pad_size (`Dict[str, int]`, *optional*):
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
image in `images`. If not provided, the images will be padded to the largest height and width in the batch.
"""

Expand Down Expand Up @@ -1194,7 +1194,7 @@ def pad(
bounding boxes have not been converted to relative coordinates and `(centre_x, centre_y, width, height)`
format, the bounding boxes will not be updated.
pad_size (`Dict[str, int]`, *optional*):
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
image in `images`. If not provided, the images will be padded to the largest height and width in the batch.
"""
pad_size = pad_size if pad_size is not None else self.pad_size
Expand Down Expand Up @@ -1303,8 +1303,8 @@ def preprocess(
image_std (`float` or `List[float]`, *optional*, defaults to self.image_std):
Standard deviation to use when normalizing the image.
do_pad (`bool`, *optional*, defaults to self.do_pad):
Whether to pad the image. If `True`, padding will be applied to the bottom and right of
the image with zeros. If `pad_size` is provided, the image will be padded to the specified
Whether to pad the image. If `True`, padding will be applied to the bottom and right of
the image with zeros. If `pad_size` is provided, the image will be padded to the specified
dimensions. Otherwise, the image will be padded to the maximum height and width of the batch.
format (`str` or `AnnotationFormat`, *optional*, defaults to self.format):
Format of the annotations.
Expand All @@ -1322,7 +1322,7 @@ def preprocess(
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
pad_size (`Dict[str, int]`, *optional*):
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
image in `images`. If not provided, the images will be padded to the largest height and width in the batch.
"""
if "pad_and_return_pixel_mask" in kwargs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ class GroundingDinoImageProcessor(BaseImageProcessor):
If `pad_size` is provided, the image will be padded to the specified dimensions.
Otherwise, the image will be padded to the maximum height and width of the batch.
pad_size (`Dict[str, int]`, *optional*):
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
image in `images`. If not provided, the images will be padded to the largest height and width in the batch.
"""

Expand Down Expand Up @@ -1332,8 +1332,8 @@ def preprocess(
image_std (`float` or `List[float]`, *optional*, defaults to self.image_std):
Standard deviation to use when normalizing the image.
do_pad (`bool`, *optional*, defaults to self.do_pad):
Whether to pad the image. If `True`, padding will be applied to the bottom and right of
the image with zeros. If `pad_size` is provided, the image will be padded to the specified
Whether to pad the image. If `True`, padding will be applied to the bottom and right of
the image with zeros. If `pad_size` is provided, the image will be padded to the specified
dimensions. Otherwise, the image will be padded to the maximum height and width of the batch.
format (`str` or `AnnotationFormat`, *optional*, defaults to self.format):
Format of the annotations.
Expand Down
10 changes: 5 additions & 5 deletions src/transformers/models/yolos/image_processing_yolos.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ class YolosImageProcessor(BaseImageProcessor):
If `pad_size` is provided, the image will be padded to the specified dimensions.
Otherwise, the image will be padded to the maximum height and width of the batch.
pad_size (`Dict[str, int]`, *optional*):
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
image in `images`. If not provided, the images will be padded to the largest height and width in the batch.
"""

Expand Down Expand Up @@ -1121,7 +1121,7 @@ def pad(
bounding boxes have not been converted to relative coordinates and `(centre_x, centre_y, width, height)`
format, the bounding boxes will not be updated.
pad_size (`Dict[str, int]`, *optional*):
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
image in `images`. If not provided, the images will be padded to the largest height and width in the batch.
"""
pad_size = pad_size if pad_size is not None else self.pad_size
Expand Down Expand Up @@ -1230,8 +1230,8 @@ def preprocess(
boxes from the format `(top_left_x, top_left_y, width, height)` to `(center_x, center_y, width, height)`
and in relative coordinates.
do_pad (`bool`, *optional*, defaults to self.do_pad):
Whether to pad the image. If `True`, padding will be applied to the bottom and right of
the image with zeros. If `pad_size` is provided, the image will be padded to the specified
Whether to pad the image. If `True`, padding will be applied to the bottom and right of
the image with zeros. If `pad_size` is provided, the image will be padded to the specified
dimensions. Otherwise, the image will be padded to the maximum height and width of the batch.
format (`str` or `AnnotationFormat`, *optional*, defaults to self.format):
Format of the annotations.
Expand All @@ -1246,7 +1246,7 @@ def preprocess(
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
pad_size (`Dict[str, int]`, *optional*):
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
The size `{"height": int, "width" int}` to pad the images to. Must be larger than any
image in `images`. If not provided, the images will be padded to the largest height and width in the batch.
"""
if "pad_and_return_pixel_mask" in kwargs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,7 @@ def test_max_width_max_height_resizing_and_pad_strategy(self):

# do_pad=True, max_height=100, max_width=100, image=200x100 -> 100x100
image_processor = ConditionalDetrImageProcessor(
size={"max_height": 100, "max_width": 100},
do_pad=True,
pad_size={"height": 100, "width": 100}
size={"max_height": 100, "max_width": 100}, do_pad=True, pad_size={"height": 100, "width": 100}
)
inputs = image_processor(images=[image_1], return_tensors="pt")
self.assertEqual(inputs["pixel_values"].shape, torch.Size([1, 3, 100, 100]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,7 @@ def test_max_width_max_height_resizing_and_pad_strategy(self):

# do_pad=True, max_height=100, max_width=100, image=200x100 -> 100x100
image_processor = DeformableDetrImageProcessor(
size={"max_height": 100, "max_width": 100},
do_pad=True,
pad_size={"height": 100, "width": 100}
size={"max_height": 100, "max_width": 100}, do_pad=True, pad_size={"height": 100, "width": 100}
)
inputs = image_processor(images=[image_1], return_tensors="pt")
self.assertEqual(inputs["pixel_values"].shape, torch.Size([1, 3, 100, 100]))
Expand Down
4 changes: 1 addition & 3 deletions tests/models/deta/test_image_processing_deta.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,7 @@ def test_max_width_max_height_resizing_and_pad_strategy(self):

# do_pad=True, max_height=100, max_width=100, image=200x100 -> 100x100
image_processor = DetaImageProcessor(
size={"max_height": 100, "max_width": 100},
do_pad=True,
pad_size={"height": 100, "width": 100}
size={"max_height": 100, "max_width": 100}, do_pad=True, pad_size={"height": 100, "width": 100}
)
inputs = image_processor(images=[image_1], return_tensors="pt")
self.assertEqual(inputs["pixel_values"].shape, torch.Size([1, 3, 100, 100]))
Expand Down
4 changes: 1 addition & 3 deletions tests/models/detr/test_image_processing_detr.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,7 @@ def test_max_width_max_height_resizing_and_pad_strategy(self):

# do_pad=True, max_height=100, max_width=100, image=200x100 -> 100x100
image_processor = DetrImageProcessor(
size={"max_height": 100, "max_width": 100},
do_pad=True,
pad_size={"height": 100, "width": 100}
size={"max_height": 100, "max_width": 100}, do_pad=True, pad_size={"height": 100, "width": 100}
)
inputs = image_processor(images=[image_1], return_tensors="pt")
self.assertEqual(inputs["pixel_values"].shape, torch.Size([1, 3, 100, 100]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,7 @@ def test_max_width_max_height_resizing_and_pad_strategy(self):

# do_pad=True, max_height=100, max_width=100, image=200x100 -> 100x100
image_processor = GroundingDinoImageProcessor(
size={"max_height": 100, "max_width": 100},
do_pad=True,
pad_size={"height": 100, "width": 100}
size={"max_height": 100, "max_width": 100}, do_pad=True, pad_size={"height": 100, "width": 100}
)
inputs = image_processor(images=[image_1], return_tensors="pt")
self.assertEqual(inputs["pixel_values"].shape, torch.Size([1, 3, 100, 100]))
Expand Down
4 changes: 1 addition & 3 deletions tests/models/yolos/test_image_processing_yolos.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,7 @@ def test_max_width_max_height_resizing_and_pad_strategy(self):

# do_pad=True, max_height=100, max_width=100, image=200x100 -> 100x100
image_processor = YolosImageProcessor(
size={"max_height": 100, "max_width": 100},
do_pad=True,
pad_size={"height": 100, "width": 100}
size={"max_height": 100, "max_width": 100}, do_pad=True, pad_size={"height": 100, "width": 100}
)
inputs = image_processor(images=[image_1], return_tensors="pt")
self.assertEqual(inputs["pixel_values"].shape, torch.Size([1, 3, 100, 100]))
Expand Down

0 comments on commit 6682c34

Please sign in to comment.