Skip to content

Commit

Permalink
Update warning levels (#22727)
Browse files Browse the repository at this point in the history
* Use different level

* Remove futurewarning

* Use warning_once

* Update copies
  • Loading branch information
NielsRogge committed Apr 12, 2023
1 parent 9858195 commit ce06e47
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import io
import pathlib
import warnings
from collections import defaultdict
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union

Expand Down Expand Up @@ -61,6 +60,7 @@
is_torch_available,
is_torch_tensor,
is_vision_available,
logging,
)


Expand All @@ -78,6 +78,8 @@
import scipy.stats


logger = logging.get_logger(__name__) # pylint: disable=invalid-name

AnnotationType = Dict[str, Union[int, str, List[Dict]]]


Expand Down Expand Up @@ -795,10 +797,9 @@ def __init__(
do_pad = kwargs.pop("pad_and_return_pixel_mask")

if "max_size" in kwargs:
warnings.warn(
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
FutureWarning,
)
max_size = kwargs.pop("max_size")
else:
Expand All @@ -822,10 +823,9 @@ def __init__(
@property
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.max_size
def max_size(self):
warnings.warn(
logger.warning(
"The `max_size` parameter is deprecated and will be removed in v4.27. "
"Please specify in `size['longest_edge'] instead`.",
FutureWarning,
)
return self.size["longest_edge"]

Expand Down Expand Up @@ -872,7 +872,7 @@ def prepare_annotation(

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare
def prepare(self, image, target, return_segmentation_masks=False, masks_path=None):
warnings.warn(
logger.warning_once(
"The `prepare` method is deprecated and will be removed in a future version. "
"Please use `prepare_annotation` instead. Note: the `prepare_annotation` method "
"does not return the image anymore.",
Expand All @@ -882,17 +882,23 @@ def prepare(self, image, target, return_segmentation_masks=False, masks_path=Non

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.convert_coco_poly_to_mask
def convert_coco_poly_to_mask(self, *args, **kwargs):
warnings.warn("The `convert_coco_poly_to_mask` method is deprecated and will be removed in a future version. ")
logger.warning_once(
"The `convert_coco_poly_to_mask` method is deprecated and will be removed in a future version. "
)
return convert_coco_poly_to_mask(*args, **kwargs)

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_detection with DETR->ConditionalDetr
def prepare_coco_detection(self, *args, **kwargs):
warnings.warn("The `prepare_coco_detection` method is deprecated and will be removed in a future version. ")
logger.warning_once(
"The `prepare_coco_detection` method is deprecated and will be removed in a future version. "
)
return prepare_coco_detection_annotation(*args, **kwargs)

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_panoptic
def prepare_coco_panoptic(self, *args, **kwargs):
warnings.warn("The `prepare_coco_panoptic` method is deprecated and will be removed in a future version. ")
logger.warning_once(
"The `prepare_coco_panoptic` method is deprecated and will be removed in a future version. "
)
return prepare_coco_panoptic_annotation(*args, **kwargs)

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.resize
Expand All @@ -909,10 +915,9 @@ def resize(
int, smaller edge of the image will be matched to this number.
"""
if "max_size" in kwargs:
warnings.warn(
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
FutureWarning,
)
max_size = kwargs.pop("max_size")
else:
Expand Down Expand Up @@ -998,9 +1003,7 @@ def pad_and_create_pixel_mask(
data_format (`str` or `ChannelDimension`, *optional*):
The channel dimension format of the image. If not provided, it will be the same as the input image.
"""
warnings.warn(
"This method is deprecated and will be removed in v4.27.0. Please use pad instead.", FutureWarning
)
logger.warning_once("This method is deprecated and will be removed in v4.27.0. Please use pad instead.")
# pad expects a list of np.ndarray, but the previous feature extractors expected torch tensors
images = [to_numpy_array(image) for image in pixel_values_list]
return self.pad(
Expand Down Expand Up @@ -1139,19 +1142,17 @@ def preprocess(
The channel dimension format of the image. If not provided, it will be the same as the input image.
"""
if "pad_and_return_pixel_mask" in kwargs:
warnings.warn(
logger.warning_once(
"The `pad_and_return_pixel_mask` argument is deprecated and will be removed in a future version, "
"use `do_pad` instead.",
FutureWarning,
"use `do_pad` instead."
)
do_pad = kwargs.pop("pad_and_return_pixel_mask")

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

Expand Down Expand Up @@ -1296,10 +1297,9 @@ def post_process(self, outputs, target_sizes):
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image
in the batch as predicted by the model.
"""
warnings.warn(
logging.warning_once(
"`post_process` is deprecated and will be removed in v5 of Transformers, please use"
" `post_process_object_detection`",
FutureWarning,
)

out_logits, out_bbox = outputs.logits, outputs.pred_boxes
Expand Down Expand Up @@ -1560,7 +1560,7 @@ def post_process_panoptic_segmentation(
"""

if label_ids_to_fuse is None:
warnings.warn("`label_ids_to_fuse` unset. No instance will be fused.")
logger.warning_once("`label_ids_to_fuse` unset. No instance will be fused.")
label_ids_to_fuse = set()

class_queries_logits = outputs.logits # [batch_size, num_queries, num_classes+1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import io
import pathlib
import warnings
from collections import defaultdict
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union

Expand Down Expand Up @@ -61,6 +60,7 @@
is_torch_available,
is_torch_tensor,
is_vision_available,
logging,
)


Expand All @@ -77,6 +77,8 @@
import scipy.stats


logger = logging.get_logger(__name__) # pylint: disable=invalid-name

AnnotationType = Dict[str, Union[int, str, List[Dict]]]


Expand Down Expand Up @@ -793,10 +795,9 @@ def __init__(
do_pad = kwargs.pop("pad_and_return_pixel_mask")

if "max_size" in kwargs:
warnings.warn(
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
FutureWarning,
)
max_size = kwargs.pop("max_size")
else:
Expand All @@ -820,10 +821,9 @@ def __init__(
@property
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.max_size
def max_size(self):
warnings.warn(
logger.warning(
"The `max_size` parameter is deprecated and will be removed in v4.27. "
"Please specify in `size['longest_edge'] instead`.",
FutureWarning,
)
return self.size["longest_edge"]

Expand Down Expand Up @@ -870,7 +870,7 @@ def prepare_annotation(

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare
def prepare(self, image, target, return_segmentation_masks=None, masks_path=None):
warnings.warn(
logger.warning_once(
"The `prepare` method is deprecated and will be removed in a future version. "
"Please use `prepare_annotation` instead. Note: the `prepare_annotation` method "
"does not return the image anymore.",
Expand All @@ -880,17 +880,23 @@ def prepare(self, image, target, return_segmentation_masks=None, masks_path=None

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.convert_coco_poly_to_mask
def convert_coco_poly_to_mask(self, *args, **kwargs):
warnings.warn("The `convert_coco_poly_to_mask` method is deprecated and will be removed in a future version. ")
logger.warning_once(
"The `convert_coco_poly_to_mask` method is deprecated and will be removed in a future version. "
)
return convert_coco_poly_to_mask(*args, **kwargs)

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_detection
def prepare_coco_detection(self, *args, **kwargs):
warnings.warn("The `prepare_coco_detection` method is deprecated and will be removed in a future version. ")
logger.warning_once(
"The `prepare_coco_detection` method is deprecated and will be removed in a future version. "
)
return prepare_coco_detection_annotation(*args, **kwargs)

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_panoptic
def prepare_coco_panoptic(self, *args, **kwargs):
warnings.warn("The `prepare_coco_panoptic` method is deprecated and will be removed in a future version. ")
logger.warning_once(
"The `prepare_coco_panoptic` method is deprecated and will be removed in a future version. "
)
return prepare_coco_panoptic_annotation(*args, **kwargs)

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.resize
Expand All @@ -907,10 +913,9 @@ def resize(
int, smaller edge of the image will be matched to this number.
"""
if "max_size" in kwargs:
warnings.warn(
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
FutureWarning,
)
max_size = kwargs.pop("max_size")
else:
Expand Down Expand Up @@ -996,9 +1001,7 @@ def pad_and_create_pixel_mask(
data_format (`str` or `ChannelDimension`, *optional*):
The channel dimension format of the image. If not provided, it will be the same as the input image.
"""
warnings.warn(
"This method is deprecated and will be removed in v4.27.0. Please use pad instead.", FutureWarning
)
logger.warning_once("This method is deprecated and will be removed in v4.27.0. Please use pad instead.")
# pad expects a list of np.ndarray, but the previous feature extractors expected torch tensors
images = [to_numpy_array(image) for image in pixel_values_list]
return self.pad(
Expand Down Expand Up @@ -1137,19 +1140,17 @@ def preprocess(
The channel dimension format of the image. If not provided, it will be the same as the input image.
"""
if "pad_and_return_pixel_mask" in kwargs:
warnings.warn(
logger.warning_once(
"The `pad_and_return_pixel_mask` argument is deprecated and will be removed in a future version, "
"use `do_pad` instead.",
FutureWarning,
"use `do_pad` instead."
)
do_pad = kwargs.pop("pad_and_return_pixel_mask")

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

Expand Down Expand Up @@ -1294,10 +1295,9 @@ def post_process(self, outputs, target_sizes):
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image
in the batch as predicted by the model.
"""
warnings.warn(
logger.warning_once(
"`post_process` is deprecated and will be removed in v5 of Transformers, please use"
" `post_process_object_detection`.",
FutureWarning,
)

out_logits, out_bbox = outputs.logits, outputs.pred_boxes
Expand Down
26 changes: 16 additions & 10 deletions src/transformers/models/deta/image_processing_deta.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""Image processor class for Deformable DETR."""

import pathlib
import warnings
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union

import numpy as np
Expand Down Expand Up @@ -56,6 +55,7 @@
is_torch_tensor,
is_torchvision_available,
is_vision_available,
logging,
)
from ...utils.generic import ExplicitEnum, TensorType

Expand All @@ -71,6 +71,9 @@
import PIL


logger = logging.get_logger(__name__) # pylint: disable=invalid-name


class AnnotionFormat(ExplicitEnum):
COCO_DETECTION = "coco_detection"
COCO_PANOPTIC = "coco_panoptic"
Expand Down Expand Up @@ -540,7 +543,7 @@ def prepare_annotation(

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare
def prepare(self, image, target, return_segmentation_masks=None, masks_path=None):
warnings.warn(
logger.warning_once(
"The `prepare` method is deprecated and will be removed in a future version. "
"Please use `prepare_annotation` instead. Note: the `prepare_annotation` method "
"does not return the image anymore.",
Expand All @@ -550,17 +553,23 @@ def prepare(self, image, target, return_segmentation_masks=None, masks_path=None

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.convert_coco_poly_to_mask
def convert_coco_poly_to_mask(self, *args, **kwargs):
warnings.warn("The `convert_coco_poly_to_mask` method is deprecated and will be removed in a future version. ")
logger.warning_once(
"The `convert_coco_poly_to_mask` method is deprecated and will be removed in a future version. "
)
return convert_coco_poly_to_mask(*args, **kwargs)

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_detection
def prepare_coco_detection(self, *args, **kwargs):
warnings.warn("The `prepare_coco_detection` method is deprecated and will be removed in a future version. ")
logger.warning_once(
"The `prepare_coco_detection` method is deprecated and will be removed in a future version. "
)
return prepare_coco_detection_annotation(*args, **kwargs)

# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_panoptic
def prepare_coco_panoptic(self, *args, **kwargs):
warnings.warn("The `prepare_coco_panoptic` method is deprecated and will be removed in a future version. ")
logger.warning_once(
"The `prepare_coco_panoptic` method is deprecated and will be removed in a future version. "
)
return prepare_coco_panoptic_annotation(*args, **kwargs)

def resize(
Expand Down Expand Up @@ -656,9 +665,7 @@ def pad_and_create_pixel_mask(
data_format (`str` or `ChannelDimension`, *optional*):
The channel dimension format of the image. If not provided, it will be the same as the input image.
"""
warnings.warn(
"This method is deprecated and will be removed in v4.27.0. Please use pad instead.", FutureWarning
)
logger.warning_once("This method is deprecated and will be removed in v4.27.0. Please use pad instead.")
# pad expects a list of np.ndarray, but the previous feature extractors expected torch tensors
images = [to_numpy_array(image) for image in pixel_values_list]
return self.pad(
Expand Down Expand Up @@ -796,10 +803,9 @@ def preprocess(
The channel dimension format of the image. If not provided, it will be the same as the input image.
"""
if "pad_and_return_pixel_mask" in kwargs:
warnings.warn(
logger.warning_once(
"The `pad_and_return_pixel_mask` argument is deprecated and will be removed in a future version, "
"use `do_pad` instead.",
FutureWarning,
)
do_pad = kwargs.pop("pad_and_return_pixel_mask")

Expand Down
Loading

0 comments on commit ce06e47

Please sign in to comment.