Unverified Commit ce06e478 authored by NielsRogge's avatar NielsRogge Committed by GitHub
Browse files

Update warning levels (#22727)

* Use different level

* Remove futurewarning

* Use warning_once

* Update copies
parent 98581954
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
import io import io
import pathlib import pathlib
import warnings
from collections import defaultdict from collections import defaultdict
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union
...@@ -61,6 +60,7 @@ from ...utils import ( ...@@ -61,6 +60,7 @@ from ...utils import (
is_torch_available, is_torch_available,
is_torch_tensor, is_torch_tensor,
is_vision_available, is_vision_available,
logging,
) )
...@@ -78,6 +78,8 @@ if is_scipy_available(): ...@@ -78,6 +78,8 @@ if is_scipy_available():
import scipy.stats import scipy.stats
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
AnnotationType = Dict[str, Union[int, str, List[Dict]]] AnnotationType = Dict[str, Union[int, str, List[Dict]]]
...@@ -795,10 +797,9 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -795,10 +797,9 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
do_pad = kwargs.pop("pad_and_return_pixel_mask") do_pad = kwargs.pop("pad_and_return_pixel_mask")
if "max_size" in kwargs: if "max_size" in kwargs:
warnings.warn( logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. " "The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.", "Please specify in `size['longest_edge'] instead`.",
FutureWarning,
) )
max_size = kwargs.pop("max_size") max_size = kwargs.pop("max_size")
else: else:
...@@ -822,10 +823,9 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -822,10 +823,9 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
@property @property
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.max_size # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.max_size
def max_size(self): def max_size(self):
warnings.warn( logger.warning(
"The `max_size` parameter is deprecated and will be removed in v4.27. " "The `max_size` parameter is deprecated and will be removed in v4.27. "
"Please specify in `size['longest_edge'] instead`.", "Please specify in `size['longest_edge'] instead`.",
FutureWarning,
) )
return self.size["longest_edge"] return self.size["longest_edge"]
...@@ -872,7 +872,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -872,7 +872,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare
def prepare(self, image, target, return_segmentation_masks=False, masks_path=None): 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. " "The `prepare` method is deprecated and will be removed in a future version. "
"Please use `prepare_annotation` instead. Note: the `prepare_annotation` method " "Please use `prepare_annotation` instead. Note: the `prepare_annotation` method "
"does not return the image anymore.", "does not return the image anymore.",
...@@ -882,17 +882,23 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -882,17 +882,23 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.convert_coco_poly_to_mask # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.convert_coco_poly_to_mask
def convert_coco_poly_to_mask(self, *args, **kwargs): 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) return convert_coco_poly_to_mask(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_detection with DETR->ConditionalDetr # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_detection with DETR->ConditionalDetr
def prepare_coco_detection(self, *args, **kwargs): 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) return prepare_coco_detection_annotation(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_panoptic # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_panoptic
def prepare_coco_panoptic(self, *args, **kwargs): 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) return prepare_coco_panoptic_annotation(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.resize # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.resize
...@@ -909,10 +915,9 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -909,10 +915,9 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
int, smaller edge of the image will be matched to this number. int, smaller edge of the image will be matched to this number.
""" """
if "max_size" in kwargs: if "max_size" in kwargs:
warnings.warn( logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. " "The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.", "Please specify in `size['longest_edge'] instead`.",
FutureWarning,
) )
max_size = kwargs.pop("max_size") max_size = kwargs.pop("max_size")
else: else:
...@@ -998,9 +1003,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -998,9 +1003,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
data_format (`str` or `ChannelDimension`, *optional*): 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. The channel dimension format of the image. If not provided, it will be the same as the input image.
""" """
warnings.warn( logger.warning_once("This method is deprecated and will be removed in v4.27.0. Please use pad instead.")
"This method is deprecated and will be removed in v4.27.0. Please use pad instead.", FutureWarning
)
# pad expects a list of np.ndarray, but the previous feature extractors expected torch tensors # 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] images = [to_numpy_array(image) for image in pixel_values_list]
return self.pad( return self.pad(
...@@ -1139,19 +1142,17 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -1139,19 +1142,17 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
The channel dimension format of the image. If not provided, it will be the same as the input image. 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: 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, " "The `pad_and_return_pixel_mask` argument is deprecated and will be removed in a future version, "
"use `do_pad` instead.", "use `do_pad` instead."
FutureWarning,
) )
do_pad = kwargs.pop("pad_and_return_pixel_mask") do_pad = kwargs.pop("pad_and_return_pixel_mask")
max_size = None max_size = None
if "max_size" in kwargs: 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" "The `max_size` argument is deprecated and will be removed in a future version, use"
" `size['longest_edge']` instead.", " `size['longest_edge']` instead."
FutureWarning,
) )
size = kwargs.pop("max_size") size = kwargs.pop("max_size")
...@@ -1296,10 +1297,9 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -1296,10 +1297,9 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image `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. 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` is deprecated and will be removed in v5 of Transformers, please use"
" `post_process_object_detection`", " `post_process_object_detection`",
FutureWarning,
) )
out_logits, out_bbox = outputs.logits, outputs.pred_boxes out_logits, out_bbox = outputs.logits, outputs.pred_boxes
...@@ -1560,7 +1560,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -1560,7 +1560,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
""" """
if label_ids_to_fuse is None: 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() label_ids_to_fuse = set()
class_queries_logits = outputs.logits # [batch_size, num_queries, num_classes+1] class_queries_logits = outputs.logits # [batch_size, num_queries, num_classes+1]
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
import io import io
import pathlib import pathlib
import warnings
from collections import defaultdict from collections import defaultdict
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union
...@@ -61,6 +60,7 @@ from ...utils import ( ...@@ -61,6 +60,7 @@ from ...utils import (
is_torch_available, is_torch_available,
is_torch_tensor, is_torch_tensor,
is_vision_available, is_vision_available,
logging,
) )
...@@ -77,6 +77,8 @@ if is_scipy_available(): ...@@ -77,6 +77,8 @@ if is_scipy_available():
import scipy.stats import scipy.stats
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
AnnotationType = Dict[str, Union[int, str, List[Dict]]] AnnotationType = Dict[str, Union[int, str, List[Dict]]]
...@@ -793,10 +795,9 @@ class DeformableDetrImageProcessor(BaseImageProcessor): ...@@ -793,10 +795,9 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
do_pad = kwargs.pop("pad_and_return_pixel_mask") do_pad = kwargs.pop("pad_and_return_pixel_mask")
if "max_size" in kwargs: if "max_size" in kwargs:
warnings.warn( logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. " "The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.", "Please specify in `size['longest_edge'] instead`.",
FutureWarning,
) )
max_size = kwargs.pop("max_size") max_size = kwargs.pop("max_size")
else: else:
...@@ -820,10 +821,9 @@ class DeformableDetrImageProcessor(BaseImageProcessor): ...@@ -820,10 +821,9 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
@property @property
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.max_size # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.max_size
def max_size(self): def max_size(self):
warnings.warn( logger.warning(
"The `max_size` parameter is deprecated and will be removed in v4.27. " "The `max_size` parameter is deprecated and will be removed in v4.27. "
"Please specify in `size['longest_edge'] instead`.", "Please specify in `size['longest_edge'] instead`.",
FutureWarning,
) )
return self.size["longest_edge"] return self.size["longest_edge"]
...@@ -870,7 +870,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor): ...@@ -870,7 +870,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare
def prepare(self, image, target, return_segmentation_masks=None, masks_path=None): 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. " "The `prepare` method is deprecated and will be removed in a future version. "
"Please use `prepare_annotation` instead. Note: the `prepare_annotation` method " "Please use `prepare_annotation` instead. Note: the `prepare_annotation` method "
"does not return the image anymore.", "does not return the image anymore.",
...@@ -880,17 +880,23 @@ class DeformableDetrImageProcessor(BaseImageProcessor): ...@@ -880,17 +880,23 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.convert_coco_poly_to_mask # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.convert_coco_poly_to_mask
def convert_coco_poly_to_mask(self, *args, **kwargs): 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) return convert_coco_poly_to_mask(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_detection # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_detection
def prepare_coco_detection(self, *args, **kwargs): 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) return prepare_coco_detection_annotation(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_panoptic # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_panoptic
def prepare_coco_panoptic(self, *args, **kwargs): 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) return prepare_coco_panoptic_annotation(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.resize # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.resize
...@@ -907,10 +913,9 @@ class DeformableDetrImageProcessor(BaseImageProcessor): ...@@ -907,10 +913,9 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
int, smaller edge of the image will be matched to this number. int, smaller edge of the image will be matched to this number.
""" """
if "max_size" in kwargs: if "max_size" in kwargs:
warnings.warn( logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. " "The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.", "Please specify in `size['longest_edge'] instead`.",
FutureWarning,
) )
max_size = kwargs.pop("max_size") max_size = kwargs.pop("max_size")
else: else:
...@@ -996,9 +1001,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor): ...@@ -996,9 +1001,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
data_format (`str` or `ChannelDimension`, *optional*): 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. The channel dimension format of the image. If not provided, it will be the same as the input image.
""" """
warnings.warn( logger.warning_once("This method is deprecated and will be removed in v4.27.0. Please use pad instead.")
"This method is deprecated and will be removed in v4.27.0. Please use pad instead.", FutureWarning
)
# pad expects a list of np.ndarray, but the previous feature extractors expected torch tensors # 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] images = [to_numpy_array(image) for image in pixel_values_list]
return self.pad( return self.pad(
...@@ -1137,19 +1140,17 @@ class DeformableDetrImageProcessor(BaseImageProcessor): ...@@ -1137,19 +1140,17 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
The channel dimension format of the image. If not provided, it will be the same as the input image. 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: 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, " "The `pad_and_return_pixel_mask` argument is deprecated and will be removed in a future version, "
"use `do_pad` instead.", "use `do_pad` instead."
FutureWarning,
) )
do_pad = kwargs.pop("pad_and_return_pixel_mask") do_pad = kwargs.pop("pad_and_return_pixel_mask")
max_size = None max_size = None
if "max_size" in kwargs: 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" "The `max_size` argument is deprecated and will be removed in a future version, use"
" `size['longest_edge']` instead.", " `size['longest_edge']` instead."
FutureWarning,
) )
size = kwargs.pop("max_size") size = kwargs.pop("max_size")
...@@ -1294,10 +1295,9 @@ class DeformableDetrImageProcessor(BaseImageProcessor): ...@@ -1294,10 +1295,9 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image `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. 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` is deprecated and will be removed in v5 of Transformers, please use"
" `post_process_object_detection`.", " `post_process_object_detection`.",
FutureWarning,
) )
out_logits, out_bbox = outputs.logits, outputs.pred_boxes out_logits, out_bbox = outputs.logits, outputs.pred_boxes
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
"""Image processor class for Deformable DETR.""" """Image processor class for Deformable DETR."""
import pathlib import pathlib
import warnings
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
import numpy as np import numpy as np
...@@ -56,6 +55,7 @@ from ...utils import ( ...@@ -56,6 +55,7 @@ from ...utils import (
is_torch_tensor, is_torch_tensor,
is_torchvision_available, is_torchvision_available,
is_vision_available, is_vision_available,
logging,
) )
from ...utils.generic import ExplicitEnum, TensorType from ...utils.generic import ExplicitEnum, TensorType
...@@ -71,6 +71,9 @@ if is_vision_available(): ...@@ -71,6 +71,9 @@ if is_vision_available():
import PIL import PIL
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
class AnnotionFormat(ExplicitEnum): class AnnotionFormat(ExplicitEnum):
COCO_DETECTION = "coco_detection" COCO_DETECTION = "coco_detection"
COCO_PANOPTIC = "coco_panoptic" COCO_PANOPTIC = "coco_panoptic"
...@@ -540,7 +543,7 @@ class DetaImageProcessor(BaseImageProcessor): ...@@ -540,7 +543,7 @@ class DetaImageProcessor(BaseImageProcessor):
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare
def prepare(self, image, target, return_segmentation_masks=None, masks_path=None): 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. " "The `prepare` method is deprecated and will be removed in a future version. "
"Please use `prepare_annotation` instead. Note: the `prepare_annotation` method " "Please use `prepare_annotation` instead. Note: the `prepare_annotation` method "
"does not return the image anymore.", "does not return the image anymore.",
...@@ -550,17 +553,23 @@ class DetaImageProcessor(BaseImageProcessor): ...@@ -550,17 +553,23 @@ class DetaImageProcessor(BaseImageProcessor):
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.convert_coco_poly_to_mask # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.convert_coco_poly_to_mask
def convert_coco_poly_to_mask(self, *args, **kwargs): 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) return convert_coco_poly_to_mask(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_detection # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_detection
def prepare_coco_detection(self, *args, **kwargs): 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) return prepare_coco_detection_annotation(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_panoptic # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_panoptic
def prepare_coco_panoptic(self, *args, **kwargs): 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) return prepare_coco_panoptic_annotation(*args, **kwargs)
def resize( def resize(
...@@ -656,9 +665,7 @@ class DetaImageProcessor(BaseImageProcessor): ...@@ -656,9 +665,7 @@ class DetaImageProcessor(BaseImageProcessor):
data_format (`str` or `ChannelDimension`, *optional*): 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. The channel dimension format of the image. If not provided, it will be the same as the input image.
""" """
warnings.warn( logger.warning_once("This method is deprecated and will be removed in v4.27.0. Please use pad instead.")
"This method is deprecated and will be removed in v4.27.0. Please use pad instead.", FutureWarning
)
# pad expects a list of np.ndarray, but the previous feature extractors expected torch tensors # 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] images = [to_numpy_array(image) for image in pixel_values_list]
return self.pad( return self.pad(
...@@ -796,10 +803,9 @@ class DetaImageProcessor(BaseImageProcessor): ...@@ -796,10 +803,9 @@ class DetaImageProcessor(BaseImageProcessor):
The channel dimension format of the image. If not provided, it will be the same as the input image. 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: 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, " "The `pad_and_return_pixel_mask` argument is deprecated and will be removed in a future version, "
"use `do_pad` instead.", "use `do_pad` instead.",
FutureWarning,
) )
do_pad = kwargs.pop("pad_and_return_pixel_mask") do_pad = kwargs.pop("pad_and_return_pixel_mask")
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
import io import io
import pathlib import pathlib
import warnings
from collections import defaultdict from collections import defaultdict
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union
...@@ -60,6 +59,7 @@ from ...utils import ( ...@@ -60,6 +59,7 @@ from ...utils import (
is_torch_available, is_torch_available,
is_torch_tensor, is_torch_tensor,
is_vision_available, is_vision_available,
logging,
) )
...@@ -77,6 +77,8 @@ if is_scipy_available(): ...@@ -77,6 +77,8 @@ if is_scipy_available():
import scipy.stats import scipy.stats
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
AnnotationType = Dict[str, Union[int, str, List[Dict]]] AnnotationType = Dict[str, Union[int, str, List[Dict]]]
...@@ -777,10 +779,9 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -777,10 +779,9 @@ class DetrImageProcessor(BaseImageProcessor):
do_pad = kwargs.pop("pad_and_return_pixel_mask") do_pad = kwargs.pop("pad_and_return_pixel_mask")
if "max_size" in kwargs: if "max_size" in kwargs:
warnings.warn( logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. " "The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.", "Please specify in `size['longest_edge'] instead`.",
FutureWarning,
) )
max_size = kwargs.pop("max_size") max_size = kwargs.pop("max_size")
else: else:
...@@ -803,10 +804,9 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -803,10 +804,9 @@ class DetrImageProcessor(BaseImageProcessor):
@property @property
def max_size(self): def max_size(self):
warnings.warn( logger.warning(
"The `max_size` parameter is deprecated and will be removed in v4.27. " "The `max_size` parameter is deprecated and will be removed in v4.27. "
"Please specify in `size['longest_edge'] instead`.", "Please specify in `size['longest_edge'] instead`.",
FutureWarning,
) )
return self.size["longest_edge"] return self.size["longest_edge"]
...@@ -850,7 +850,7 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -850,7 +850,7 @@ class DetrImageProcessor(BaseImageProcessor):
return target return target
def prepare(self, image, target, return_segmentation_masks=None, masks_path=None): 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. " "The `prepare` method is deprecated and will be removed in a future version. "
"Please use `prepare_annotation` instead. Note: the `prepare_annotation` method " "Please use `prepare_annotation` instead. Note: the `prepare_annotation` method "
"does not return the image anymore.", "does not return the image anymore.",
...@@ -859,15 +859,21 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -859,15 +859,21 @@ class DetrImageProcessor(BaseImageProcessor):
return image, target return image, target
def convert_coco_poly_to_mask(self, *args, **kwargs): 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) return convert_coco_poly_to_mask(*args, **kwargs)
def prepare_coco_detection(self, *args, **kwargs): 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) return prepare_coco_detection_annotation(*args, **kwargs)
def prepare_coco_panoptic(self, *args, **kwargs): 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) return prepare_coco_panoptic_annotation(*args, **kwargs)
def resize( def resize(
...@@ -883,10 +889,9 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -883,10 +889,9 @@ class DetrImageProcessor(BaseImageProcessor):
int, smaller edge of the image will be matched to this number. int, smaller edge of the image will be matched to this number.
""" """
if "max_size" in kwargs: if "max_size" in kwargs:
warnings.warn( logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. " "The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.", "Please specify in `size['longest_edge'] instead`.",
FutureWarning,
) )
max_size = kwargs.pop("max_size") max_size = kwargs.pop("max_size")
else: else:
...@@ -967,9 +972,7 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -967,9 +972,7 @@ class DetrImageProcessor(BaseImageProcessor):
data_format (`str` or `ChannelDimension`, *optional*): 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. The channel dimension format of the image. If not provided, it will be the same as the input image.
""" """
warnings.warn( logger.warning_once("This method is deprecated and will be removed in v4.27.0. Please use pad instead.")
"This method is deprecated and will be removed in v4.27.0. Please use pad instead.", FutureWarning
)
# pad expects a list of np.ndarray, but the previous feature extractors expected torch tensors # 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] images = [to_numpy_array(image) for image in pixel_values_list]
return self.pad( return self.pad(
...@@ -1105,19 +1108,17 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -1105,19 +1108,17 @@ class DetrImageProcessor(BaseImageProcessor):
The channel dimension format of the image. If not provided, it will be the same as the input image. 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: 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, " "The `pad_and_return_pixel_mask` argument is deprecated and will be removed in a future version, "
"use `do_pad` instead.", "use `do_pad` instead."
FutureWarning,
) )
do_pad = kwargs.pop("pad_and_return_pixel_mask") do_pad = kwargs.pop("pad_and_return_pixel_mask")
max_size = None max_size = None
if "max_size" in kwargs: 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" "The `max_size` argument is deprecated and will be removed in a future version, use"
" `size['longest_edge']` instead.", " `size['longest_edge']` instead."
FutureWarning,
) )
size = kwargs.pop("max_size") size = kwargs.pop("max_size")
...@@ -1263,10 +1264,9 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -1263,10 +1264,9 @@ class DetrImageProcessor(BaseImageProcessor):
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image `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. 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` is deprecated and will be removed in v5 of Transformers, please use"
" `post_process_object_detection`", " `post_process_object_detection`",
FutureWarning,
) )
out_logits, out_bbox = outputs.logits, outputs.pred_boxes out_logits, out_bbox = outputs.logits, outputs.pred_boxes
...@@ -1306,10 +1306,9 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -1306,10 +1306,9 @@ class DetrImageProcessor(BaseImageProcessor):
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels, and masks for an image `List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels, and masks for an image
in the batch as predicted by the model. in the batch as predicted by the model.
""" """
warnings.warn( logger.warning_once(
"`post_process_segmentation` is deprecated and will be removed in v5 of Transformers, please use" "`post_process_segmentation` is deprecated and will be removed in v5 of Transformers, please use"
" `post_process_semantic_segmentation`.", " `post_process_semantic_segmentation`.",
FutureWarning,
) )
out_logits, raw_masks = outputs.logits, outputs.pred_masks out_logits, raw_masks = outputs.logits, outputs.pred_masks
empty_label = out_logits.shape[-1] - 1 empty_label = out_logits.shape[-1] - 1
...@@ -1358,10 +1357,9 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -1358,10 +1357,9 @@ class DetrImageProcessor(BaseImageProcessor):
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels, boxes and masks for an `List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels, boxes and masks for an
image in the batch as predicted by the model. image in the batch as predicted by the model.
""" """
warnings.warn( logger.warning_once(
"`post_process_instance` is deprecated and will be removed in v5 of Transformers, please use" "`post_process_instance` is deprecated and will be removed in v5 of Transformers, please use"
" `post_process_instance_segmentation`.", " `post_process_instance_segmentation`.",
FutureWarning,
) )
if len(orig_target_sizes) != len(max_target_sizes): if len(orig_target_sizes) != len(max_target_sizes):
...@@ -1405,10 +1403,9 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -1405,10 +1403,9 @@ class DetrImageProcessor(BaseImageProcessor):
`List[Dict]`: A list of dictionaries, each dictionary containing a PNG string and segments_info values for `List[Dict]`: A list of dictionaries, each dictionary containing a PNG string and segments_info values for
an image in the batch as predicted by the model. an image in the batch as predicted by the model.
""" """
warnings.warn( logger.warning_once(
"`post_process_panoptic is deprecated and will be removed in v5 of Transformers, please use" "`post_process_panoptic is deprecated and will be removed in v5 of Transformers, please use"
" `post_process_panoptic_segmentation`.", " `post_process_panoptic_segmentation`.",
FutureWarning,
) )
if target_sizes is None: if target_sizes is None:
target_sizes = processed_sizes target_sizes = processed_sizes
...@@ -1751,7 +1748,7 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -1751,7 +1748,7 @@ class DetrImageProcessor(BaseImageProcessor):
""" """
if label_ids_to_fuse is None: 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() label_ids_to_fuse = set()
class_queries_logits = outputs.logits # [batch_size, num_queries, num_classes+1] class_queries_logits = outputs.logits # [batch_size, num_queries, num_classes+1]
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
"""Image processor class for YOLOS.""" """Image processor class for YOLOS."""
import pathlib import pathlib
import warnings
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union
import numpy as np import numpy as np
...@@ -707,10 +706,9 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -707,10 +706,9 @@ class YolosImageProcessor(BaseImageProcessor):
do_pad = kwargs.pop("pad_and_return_pixel_mask") do_pad = kwargs.pop("pad_and_return_pixel_mask")
if "max_size" in kwargs: if "max_size" in kwargs:
warnings.warn( logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. " "The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.", "Please specify in `size['longest_edge'] instead`.",
FutureWarning,
) )
max_size = kwargs.pop("max_size") max_size = kwargs.pop("max_size")
else: else:
...@@ -734,10 +732,9 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -734,10 +732,9 @@ class YolosImageProcessor(BaseImageProcessor):
@property @property
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.max_size # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.max_size
def max_size(self): def max_size(self):
warnings.warn( logger.warning(
"The `max_size` parameter is deprecated and will be removed in v4.27. " "The `max_size` parameter is deprecated and will be removed in v4.27. "
"Please specify in `size['longest_edge'] instead`.", "Please specify in `size['longest_edge'] instead`.",
FutureWarning,
) )
return self.size["longest_edge"] return self.size["longest_edge"]
...@@ -784,7 +781,7 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -784,7 +781,7 @@ class YolosImageProcessor(BaseImageProcessor):
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare
def prepare(self, image, target, return_segmentation_masks=False, masks_path=None): 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. " "The `prepare` method is deprecated and will be removed in a future version. "
"Please use `prepare_annotation` instead. Note: the `prepare_annotation` method " "Please use `prepare_annotation` instead. Note: the `prepare_annotation` method "
"does not return the image anymore.", "does not return the image anymore.",
...@@ -794,17 +791,23 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -794,17 +791,23 @@ class YolosImageProcessor(BaseImageProcessor):
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.convert_coco_poly_to_mask # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.convert_coco_poly_to_mask
def convert_coco_poly_to_mask(self, *args, **kwargs): 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) return convert_coco_poly_to_mask(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_detection with DETR->Yolos # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_detection with DETR->Yolos
def prepare_coco_detection(self, *args, **kwargs): 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) return prepare_coco_detection_annotation(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_panoptic # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.prepare_coco_panoptic
def prepare_coco_panoptic(self, *args, **kwargs): 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) return prepare_coco_panoptic_annotation(*args, **kwargs)
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.resize # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.resize
...@@ -821,10 +824,9 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -821,10 +824,9 @@ class YolosImageProcessor(BaseImageProcessor):
int, smaller edge of the image will be matched to this number. int, smaller edge of the image will be matched to this number.
""" """
if "max_size" in kwargs: if "max_size" in kwargs:
warnings.warn( logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. " "The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.", "Please specify in `size['longest_edge'] instead`.",
FutureWarning,
) )
max_size = kwargs.pop("max_size") max_size = kwargs.pop("max_size")
else: else:
...@@ -1007,19 +1009,17 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -1007,19 +1009,17 @@ class YolosImageProcessor(BaseImageProcessor):
The channel dimension format of the image. If not provided, it will be the same as the input image. 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: 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, " "The `pad_and_return_pixel_mask` argument is deprecated and will be removed in a future version, "
"use `do_pad` instead.", "use `do_pad` instead.",
FutureWarning,
) )
do_pad = kwargs.pop("pad_and_return_pixel_mask") do_pad = kwargs.pop("pad_and_return_pixel_mask")
max_size = None max_size = None
if "max_size" in kwargs: 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" "The `max_size` argument is deprecated and will be removed in a future version, use"
" `size['longest_edge']` instead.", " `size['longest_edge']` instead.",
FutureWarning,
) )
size = kwargs.pop("max_size") size = kwargs.pop("max_size")
...@@ -1164,10 +1164,9 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -1164,10 +1164,9 @@ class YolosImageProcessor(BaseImageProcessor):
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image `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. 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` is deprecated and will be removed in v5 of Transformers, please use"
" `post_process_object_detection`", " `post_process_object_detection`",
FutureWarning,
) )
out_logits, out_bbox = outputs.logits, outputs.pred_boxes out_logits, out_bbox = outputs.logits, outputs.pred_boxes
......
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