"git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "5b45422b58da508dab8b18852609a279517b944d"
Unverified Commit 1a585c12 authored by amyeroberts's avatar amyeroberts Committed by GitHub
Browse files

Remove warning when Annotion enum is created (#28048)

Remove warning when enum is created
parent 3060899b
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
import base64 import base64
import os import os
from enum import EnumMeta
from io import BytesIO from io import BytesIO
from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Tuple, Union from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Tuple, Union
...@@ -76,16 +75,7 @@ class AnnotationFormat(ExplicitEnum): ...@@ -76,16 +75,7 @@ class AnnotationFormat(ExplicitEnum):
COCO_PANOPTIC = "coco_panoptic" COCO_PANOPTIC = "coco_panoptic"
class DeprecatedEnumMeta(EnumMeta): class AnnotionFormat(ExplicitEnum):
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):
COCO_DETECTION = AnnotationFormat.COCO_DETECTION.value COCO_DETECTION = AnnotationFormat.COCO_DETECTION.value
COCO_PANOPTIC = AnnotationFormat.COCO_PANOPTIC.value COCO_PANOPTIC = AnnotationFormat.COCO_PANOPTIC.value
...@@ -703,10 +693,17 @@ def validate_annotations( ...@@ -703,10 +693,17 @@ def validate_annotations(
supported_annotation_formats: Tuple[AnnotationFormat, ...], supported_annotation_formats: Tuple[AnnotationFormat, ...],
annotations: List[Dict], annotations: List[Dict],
) -> None: ) -> 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}") 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): if not valid_coco_detection_annotations(annotations):
raise ValueError( raise ValueError(
"Invalid COCO detection annotations. Annotations must a dict (single image) or list of dicts " "Invalid COCO detection annotations. Annotations must a dict (single image) or list of dicts "
...@@ -714,7 +711,7 @@ def validate_annotations( ...@@ -714,7 +711,7 @@ def validate_annotations(
"being a list of annotations in the COCO format." "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): if not valid_coco_panoptic_annotations(annotations):
raise ValueError( raise ValueError(
"Invalid COCO panoptic annotations. Annotations must a dict (single image) or list of dicts " "Invalid COCO panoptic annotations. Annotations must a dict (single image) or list of dicts "
......
...@@ -39,7 +39,6 @@ from ...image_utils import ( ...@@ -39,7 +39,6 @@ from ...image_utils import (
IMAGENET_DEFAULT_STD, IMAGENET_DEFAULT_STD,
AnnotationFormat, AnnotationFormat,
AnnotationType, AnnotationType,
AnnotionFormat, # noqa: F401
ChannelDimension, ChannelDimension,
ImageInput, ImageInput,
PILImageResampling, PILImageResampling,
......
...@@ -39,7 +39,6 @@ from ...image_utils import ( ...@@ -39,7 +39,6 @@ from ...image_utils import (
IMAGENET_DEFAULT_STD, IMAGENET_DEFAULT_STD,
AnnotationFormat, AnnotationFormat,
AnnotationType, AnnotationType,
AnnotionFormat, # noqa: F401
ChannelDimension, ChannelDimension,
ImageInput, ImageInput,
PILImageResampling, PILImageResampling,
......
...@@ -35,7 +35,6 @@ from ...image_utils import ( ...@@ -35,7 +35,6 @@ from ...image_utils import (
IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_MEAN,
IMAGENET_DEFAULT_STD, IMAGENET_DEFAULT_STD,
AnnotationFormat, AnnotationFormat,
AnnotionFormat, # noqa: F401
ChannelDimension, ChannelDimension,
ImageInput, ImageInput,
PILImageResampling, PILImageResampling,
......
...@@ -38,7 +38,6 @@ from ...image_utils import ( ...@@ -38,7 +38,6 @@ from ...image_utils import (
IMAGENET_DEFAULT_STD, IMAGENET_DEFAULT_STD,
AnnotationFormat, AnnotationFormat,
AnnotationType, AnnotationType,
AnnotionFormat, # noqa: F401
ChannelDimension, ChannelDimension,
ImageInput, ImageInput,
PILImageResampling, PILImageResampling,
......
...@@ -37,7 +37,6 @@ from ...image_utils import ( ...@@ -37,7 +37,6 @@ from ...image_utils import (
IMAGENET_DEFAULT_STD, IMAGENET_DEFAULT_STD,
AnnotationFormat, AnnotationFormat,
AnnotationType, AnnotationType,
AnnotionFormat, # noqa: F401
ChannelDimension, ChannelDimension,
ImageInput, ImageInput,
PILImageResampling, PILImageResampling,
......
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