Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clean-up] Planned removal of the max_size argument #35090

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -877,16 +877,14 @@ def __init__(
do_pad = kwargs.pop("pad_and_return_pixel_mask")

if "max_size" in kwargs:
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
logger.error(
"The `max_size` parameter is deprecated. " "Please specify in `size['longest_edge'] instead`.",
)
max_size = kwargs.pop("max_size")
else:
max_size = None if size is None else 1333

size = size if size is not None else {"shortest_edge": 800, "longest_edge": 1333}
size = get_size_dict(size, max_size=max_size, default_to_square=False)
# Backwards compatibility
size = {"shortest_edge": size, "longest_edge": 1333} if isinstance(size, int) else size
size = get_size_dict(size, default_to_square=False)

# Backwards compatibility
if do_convert_annotations is None:
Expand Down Expand Up @@ -1011,14 +1009,11 @@ def resize(
The channel dimension format of the input image. If not provided, it will be inferred.
"""
if "max_size" in kwargs:
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
logger.error(
"The `max_size` parameter is deprecated. " "Please specify in `size['longest_edge'] instead`.",
)
max_size = kwargs.pop("max_size")
else:
max_size = None
size = get_size_dict(size, max_size=max_size, default_to_square=False)

size = get_size_dict(size, default_to_square=False)
if "shortest_edge" in size and "longest_edge" in size:
new_size = get_resize_output_image_size(
image, size["shortest_edge"], size["longest_edge"], input_data_format=input_data_format
Expand Down Expand Up @@ -1364,17 +1359,12 @@ def preprocess(
)
do_pad = kwargs.pop("pad_and_return_pixel_mask")

max_size = None
if "max_size" in kwargs:
logger.warning_once(
"The `max_size` argument is deprecated and will be removed in a future version, use"
" `size['longest_edge']` instead."
)
size = kwargs.pop("max_size")
logger.error("The `max_size` argument is deprecated, use" " `size['longest_edge']` instead.")

do_resize = self.do_resize if do_resize is None else do_resize
size = self.size if size is None else size
size = get_size_dict(size=size, max_size=max_size, default_to_square=False)
size = get_size_dict(size=size, default_to_square=False)
resample = self.resample if resample is None else resample
do_rescale = self.do_rescale if do_rescale is None else do_rescale
rescale_factor = self.rescale_factor if rescale_factor is None else rescale_factor
Expand Down Expand Up @@ -1470,7 +1460,7 @@ def preprocess(
for image, target in zip(images, annotations):
orig_size = get_image_size(image, input_data_format)
resized_image = self.resize(
image, size=size, max_size=max_size, resample=resample, input_data_format=input_data_format
image, size=size, resample=resample, input_data_format=input_data_format
)
resized_annotation = self.resize_annotation(
target, orig_size, get_image_size(resized_image, input_data_format)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,16 +875,14 @@ def __init__(
do_pad = kwargs.pop("pad_and_return_pixel_mask")

if "max_size" in kwargs:
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
logger.error(
"The `max_size` parameter is deprecated. " "Please specify in `size['longest_edge'] instead`.",
)
max_size = kwargs.pop("max_size")
else:
max_size = None if size is None else 1333

size = size if size is not None else {"shortest_edge": 800, "longest_edge": 1333}
size = get_size_dict(size, max_size=max_size, default_to_square=False)
# Backwards compatibility
size = {"shortest_edge": size, "longest_edge": 1333} if isinstance(size, int) else size
size = get_size_dict(size, default_to_square=False)

# Backwards compatibility
if do_convert_annotations is None:
Expand Down Expand Up @@ -1009,14 +1007,11 @@ def resize(
The channel dimension format of the input image. If not provided, it will be inferred.
"""
if "max_size" in kwargs:
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
logger.error(
"The `max_size` parameter is deprecated. " "Please specify in `size['longest_edge'] instead`.",
)
max_size = kwargs.pop("max_size")
else:
max_size = None
size = get_size_dict(size, max_size=max_size, default_to_square=False)

size = get_size_dict(size, default_to_square=False)
if "shortest_edge" in size and "longest_edge" in size:
new_size = get_resize_output_image_size(
image, size["shortest_edge"], size["longest_edge"], input_data_format=input_data_format
Expand Down Expand Up @@ -1362,17 +1357,12 @@ def preprocess(
)
do_pad = kwargs.pop("pad_and_return_pixel_mask")

max_size = None
if "max_size" in kwargs:
logger.warning_once(
"The `max_size` argument is deprecated and will be removed in a future version, use"
" `size['longest_edge']` instead."
)
size = kwargs.pop("max_size")
logger.error("The `max_size` argument is deprecated, use" " `size['longest_edge']` instead.")

do_resize = self.do_resize if do_resize is None else do_resize
size = self.size if size is None else size
size = get_size_dict(size=size, max_size=max_size, default_to_square=False)
size = get_size_dict(size=size, default_to_square=False)
resample = self.resample if resample is None else resample
do_rescale = self.do_rescale if do_rescale is None else do_rescale
rescale_factor = self.rescale_factor if rescale_factor is None else rescale_factor
Expand Down Expand Up @@ -1468,7 +1458,7 @@ def preprocess(
for image, target in zip(images, annotations):
orig_size = get_image_size(image, input_data_format)
resized_image = self.resize(
image, size=size, max_size=max_size, resample=resample, input_data_format=input_data_format
image, size=size, resample=resample, input_data_format=input_data_format
)
resized_annotation = self.resize_annotation(
target, orig_size, get_image_size(resized_image, input_data_format)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,14 @@ def __init__(
do_pad = kwargs.pop("pad_and_return_pixel_mask")

if "max_size" in kwargs:
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
logger.error(
"The `max_size` parameter is deprecated. " "Please specify in `size['longest_edge'] instead`.",
)
max_size = kwargs.pop("max_size")
else:
max_size = None if size is None else 1333

size = size if size is not None else {"shortest_edge": 800, "longest_edge": 1333}
size = get_size_dict(size, max_size=max_size, default_to_square=False)
# Backwards compatibility
size = {"shortest_edge": size, "longest_edge": 1333} if isinstance(size, int) else size
size = get_size_dict(size, default_to_square=False)

# Backwards compatibility
if do_convert_annotations is None:
Expand Down Expand Up @@ -779,11 +777,8 @@ def preprocess(
do_pad = kwargs.pop("pad_and_return_pixel_mask")

if "max_size" in kwargs:
logger.warning_once(
"The `max_size` argument is deprecated and will be removed in a future version, use"
" `size['longest_edge']` instead."
)
size = kwargs.pop("max_size")
logger.error("The `max_size` argument is deprecated, use" " `size['longest_edge']` instead.")

do_resize = self.do_resize if do_resize is None else do_resize
size = self.size if size is None else size
size = get_size_dict(size=size, default_to_square=False)
Expand Down
34 changes: 12 additions & 22 deletions src/transformers/models/detr/image_processing_detr.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,16 +859,14 @@ def __init__(
do_pad = kwargs.pop("pad_and_return_pixel_mask")

if "max_size" in kwargs:
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
logger.error(
"The `max_size` parameter is deprecated. " "Please specify in `size['longest_edge'] instead`.",
)
max_size = kwargs.pop("max_size")
else:
max_size = None if size is None else 1333

size = size if size is not None else {"shortest_edge": 800, "longest_edge": 1333}
size = get_size_dict(size, max_size=max_size, default_to_square=False)
# Backwards compatibility
size = {"shortest_edge": size, "longest_edge": 1333} if isinstance(size, int) else size
size = get_size_dict(size, default_to_square=False)

# Backwards compatibility
if do_convert_annotations is None:
Expand Down Expand Up @@ -990,14 +988,11 @@ def resize(
The channel dimension format of the input image. If not provided, it will be inferred.
"""
if "max_size" in kwargs:
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
logger.error(
"The `max_size` parameter is deprecated. " "Please specify in `size['longest_edge'] instead`.",
)
max_size = kwargs.pop("max_size")
else:
max_size = None
size = get_size_dict(size, max_size=max_size, default_to_square=False)

size = get_size_dict(size, default_to_square=False)
if "shortest_edge" in size and "longest_edge" in size:
new_size = get_resize_output_image_size(
image, size["shortest_edge"], size["longest_edge"], input_data_format=input_data_format
Expand Down Expand Up @@ -1337,17 +1332,12 @@ def preprocess(
)
do_pad = kwargs.pop("pad_and_return_pixel_mask")

max_size = None
if "max_size" in kwargs:
logger.warning_once(
"The `max_size` argument is deprecated and will be removed in a future version, use"
" `size['longest_edge']` instead."
)
size = kwargs.pop("max_size")
logger.error("The `max_size` argument is deprecated, use" " `size['longest_edge']` instead.")

do_resize = self.do_resize if do_resize is None else do_resize
size = self.size if size is None else size
size = get_size_dict(size=size, max_size=max_size, default_to_square=False)
size = get_size_dict(size=size, default_to_square=False)
resample = self.resample if resample is None else resample
do_rescale = self.do_rescale if do_rescale is None else do_rescale
rescale_factor = self.rescale_factor if rescale_factor is None else rescale_factor
Expand Down Expand Up @@ -1443,7 +1433,7 @@ def preprocess(
for image, target in zip(images, annotations):
orig_size = get_image_size(image, input_data_format)
resized_image = self.resize(
image, size=size, max_size=max_size, resample=resample, input_data_format=input_data_format
image, size=size, resample=resample, input_data_format=input_data_format
)
resized_annotation = self.resize_annotation(
target, orig_size, get_image_size(resized_image, input_data_format)
Expand Down
19 changes: 7 additions & 12 deletions src/transformers/models/detr/image_processing_detr_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,14 @@ def __init__(
do_pad = kwargs.pop("pad_and_return_pixel_mask")

if "max_size" in kwargs:
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
logger.error(
"The `max_size` parameter is deprecated. " "Please specify in `size['longest_edge'] instead`.",
)
max_size = kwargs.pop("max_size")
else:
max_size = None if size is None else 1333

size = size if size is not None else {"shortest_edge": 800, "longest_edge": 1333}
size = get_size_dict(size, max_size=max_size, default_to_square=False)
# Backwards compatibility
size = {"shortest_edge": size, "longest_edge": 1333} if isinstance(size, int) else size
size = get_size_dict(size, default_to_square=False)

# Backwards compatibility
if do_convert_annotations is None:
Expand Down Expand Up @@ -779,11 +777,8 @@ def preprocess(
do_pad = kwargs.pop("pad_and_return_pixel_mask")

if "max_size" in kwargs:
logger.warning_once(
"The `max_size` argument is deprecated and will be removed in a future version, use"
" `size['longest_edge']` instead."
)
size = kwargs.pop("max_size")
logger.error("The `max_size` argument is deprecated, use" " `size['longest_edge']` instead.")

do_resize = self.do_resize if do_resize is None else do_resize
size = self.size if size is None else size
size = get_size_dict(size=size, default_to_square=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,16 +883,14 @@ def __init__(
do_pad = kwargs.pop("pad_and_return_pixel_mask")

if "max_size" in kwargs:
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
logger.error(
"The `max_size` parameter is deprecated. " "Please specify in `size['longest_edge'] instead`.",
)
max_size = kwargs.pop("max_size")
else:
max_size = None if size is None else 1333

size = size if size is not None else {"shortest_edge": 800, "longest_edge": 1333}
size = get_size_dict(size, max_size=max_size, default_to_square=False)
# Backwards compatibility
size = {"shortest_edge": size, "longest_edge": 1333} if isinstance(size, int) else size
size = get_size_dict(size, default_to_square=False)

# Backwards compatibility
if do_convert_annotations is None:
Expand Down Expand Up @@ -1017,14 +1015,11 @@ def resize(
The channel dimension format of the input image. If not provided, it will be inferred.
"""
if "max_size" in kwargs:
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
logger.error(
"The `max_size` parameter is deprecated. " "Please specify in `size['longest_edge'] instead`.",
)
max_size = kwargs.pop("max_size")
else:
max_size = None
size = get_size_dict(size, max_size=max_size, default_to_square=False)

size = get_size_dict(size, default_to_square=False)
if "shortest_edge" in size and "longest_edge" in size:
new_size = get_resize_output_image_size(
image, size["shortest_edge"], size["longest_edge"], input_data_format=input_data_format
Expand Down Expand Up @@ -1370,17 +1365,12 @@ def preprocess(
)
do_pad = kwargs.pop("pad_and_return_pixel_mask")

max_size = None
if "max_size" in kwargs:
logger.warning_once(
"The `max_size` argument is deprecated and will be removed in a future version, use"
" `size['longest_edge']` instead."
)
size = kwargs.pop("max_size")
logger.error("The `max_size` argument is deprecated, use" " `size['longest_edge']` instead.")

do_resize = self.do_resize if do_resize is None else do_resize
size = self.size if size is None else size
size = get_size_dict(size=size, max_size=max_size, default_to_square=False)
size = get_size_dict(size=size, default_to_square=False)
resample = self.resample if resample is None else resample
do_rescale = self.do_rescale if do_rescale is None else do_rescale
rescale_factor = self.rescale_factor if rescale_factor is None else rescale_factor
Expand Down Expand Up @@ -1476,7 +1466,7 @@ def preprocess(
for image, target in zip(images, annotations):
orig_size = get_image_size(image, input_data_format)
resized_image = self.resize(
image, size=size, max_size=max_size, resample=resample, input_data_format=input_data_format
image, size=size, resample=resample, input_data_format=input_data_format
)
resized_annotation = self.resize_annotation(
target, orig_size, get_image_size(resized_image, input_data_format)
Expand Down
13 changes: 6 additions & 7 deletions src/transformers/models/rt_detr/image_processing_rt_detr.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ def __init__(
**kwargs,
) -> None:
size = size if size is not None else {"height": 640, "width": 640}
# Backwards compatibility
size = {"shortest_edge": size, "longest_edge": 1333} if isinstance(size, int) else size
size = get_size_dict(size, default_to_square=False)

if do_convert_annotations is None:
Expand Down Expand Up @@ -531,14 +533,11 @@ def resize(
The channel dimension format of the input image. If not provided, it will be inferred.
"""
if "max_size" in kwargs:
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
logger.error(
"The `max_size` parameter is deprecated. " "Please specify in `size['longest_edge'] instead`.",
)
max_size = kwargs.pop("max_size")
else:
max_size = None
size = get_size_dict(size, max_size=max_size, default_to_square=False)

size = get_size_dict(size, default_to_square=False)
if "shortest_edge" in size and "longest_edge" in size:
new_size = get_resize_output_image_size(
image, size["shortest_edge"], size["longest_edge"], input_data_format=input_data_format
Expand Down
Loading