diff --git a/src/transformers/image_utils.py b/src/transformers/image_utils.py index 5d280bf5e2b49a..99eac953bc3208 100644 --- a/src/transformers/image_utils.py +++ b/src/transformers/image_utils.py @@ -15,7 +15,6 @@ import base64 import os -from enum import EnumMeta from io import BytesIO from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Tuple, Union @@ -76,16 +75,7 @@ class AnnotationFormat(ExplicitEnum): COCO_PANOPTIC = "coco_panoptic" -class DeprecatedEnumMeta(EnumMeta): - def __init__(cls, *args, **kwargs): - super().__init__(*args, **kwargs) - logger.warning_once( - f"`{cls.__name__}` is deprecated and will be removed in v4.38. " - f"Please use `transformers.image_utils.AnnotationFormat` instead." - ) - - -class AnnotionFormat(ExplicitEnum, metaclass=DeprecatedEnumMeta): +class AnnotionFormat(ExplicitEnum): COCO_DETECTION = AnnotationFormat.COCO_DETECTION.value COCO_PANOPTIC = AnnotationFormat.COCO_PANOPTIC.value @@ -703,10 +693,17 @@ def validate_annotations( supported_annotation_formats: Tuple[AnnotationFormat, ...], annotations: List[Dict], ) -> None: - if promote_annotation_format(annotation_format) not in supported_annotation_formats: + if isinstance(annotation_format, AnnotionFormat): + logger.warning_once( + f"`{annotation_format.__class__.__name__}` is deprecated and will be removed in v4.38. " + f"Please use `{AnnotationFormat.__name__}` instead." + ) + annotation_format = promote_annotation_format(annotation_format) + + if annotation_format not in supported_annotation_formats: raise ValueError(f"Unsupported annotation format: {format} must be one of {supported_annotation_formats}") - if promote_annotation_format(annotation_format) is AnnotationFormat.COCO_DETECTION: + if annotation_format is AnnotationFormat.COCO_DETECTION: if not valid_coco_detection_annotations(annotations): raise ValueError( "Invalid COCO detection annotations. Annotations must a dict (single image) or list of dicts " @@ -714,7 +711,7 @@ def validate_annotations( "being a list of annotations in the COCO format." ) - if promote_annotation_format(annotation_format) is AnnotationFormat.COCO_PANOPTIC: + if annotation_format is AnnotationFormat.COCO_PANOPTIC: if not valid_coco_panoptic_annotations(annotations): raise ValueError( "Invalid COCO panoptic annotations. Annotations must a dict (single image) or list of dicts " diff --git a/src/transformers/models/conditional_detr/image_processing_conditional_detr.py b/src/transformers/models/conditional_detr/image_processing_conditional_detr.py index 23e493e08bf105..2fe33db810890a 100644 --- a/src/transformers/models/conditional_detr/image_processing_conditional_detr.py +++ b/src/transformers/models/conditional_detr/image_processing_conditional_detr.py @@ -39,7 +39,6 @@ IMAGENET_DEFAULT_STD, AnnotationFormat, AnnotationType, - AnnotionFormat, # noqa: F401 ChannelDimension, ImageInput, PILImageResampling, diff --git a/src/transformers/models/deformable_detr/image_processing_deformable_detr.py b/src/transformers/models/deformable_detr/image_processing_deformable_detr.py index 00cf8eaecfa308..8c40d20c816ad3 100644 --- a/src/transformers/models/deformable_detr/image_processing_deformable_detr.py +++ b/src/transformers/models/deformable_detr/image_processing_deformable_detr.py @@ -39,7 +39,6 @@ IMAGENET_DEFAULT_STD, AnnotationFormat, AnnotationType, - AnnotionFormat, # noqa: F401 ChannelDimension, ImageInput, PILImageResampling, diff --git a/src/transformers/models/deta/image_processing_deta.py b/src/transformers/models/deta/image_processing_deta.py index 1e3ece8e324ad0..bdd7ab11182ee6 100644 --- a/src/transformers/models/deta/image_processing_deta.py +++ b/src/transformers/models/deta/image_processing_deta.py @@ -35,7 +35,6 @@ IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, AnnotationFormat, - AnnotionFormat, # noqa: F401 ChannelDimension, ImageInput, PILImageResampling, diff --git a/src/transformers/models/detr/image_processing_detr.py b/src/transformers/models/detr/image_processing_detr.py index 8b64b9c4d9a46b..24c36c5d102273 100644 --- a/src/transformers/models/detr/image_processing_detr.py +++ b/src/transformers/models/detr/image_processing_detr.py @@ -38,7 +38,6 @@ IMAGENET_DEFAULT_STD, AnnotationFormat, AnnotationType, - AnnotionFormat, # noqa: F401 ChannelDimension, ImageInput, PILImageResampling, diff --git a/src/transformers/models/yolos/image_processing_yolos.py b/src/transformers/models/yolos/image_processing_yolos.py index 4b59fd5ef04905..3b0c635c0ee4d6 100644 --- a/src/transformers/models/yolos/image_processing_yolos.py +++ b/src/transformers/models/yolos/image_processing_yolos.py @@ -37,7 +37,6 @@ IMAGENET_DEFAULT_STD, AnnotationFormat, AnnotationType, - AnnotionFormat, # noqa: F401 ChannelDimension, ImageInput, PILImageResampling,