Skip to content

Commit

Permalink
Remove warning when Annotion enum is created (#28048)
Browse files Browse the repository at this point in the history
Remove warning when enum is created
  • Loading branch information
amyeroberts authored Dec 14, 2023
1 parent 3060899 commit 1a585c1
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 19 deletions.
25 changes: 11 additions & 14 deletions src/transformers/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -703,18 +693,25 @@ 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 "
"(batch of images) with the following keys: `image_id` and `annotations`, with the latter "
"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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
IMAGENET_DEFAULT_STD,
AnnotationFormat,
AnnotationType,
AnnotionFormat, # noqa: F401
ChannelDimension,
ImageInput,
PILImageResampling,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
IMAGENET_DEFAULT_STD,
AnnotationFormat,
AnnotationType,
AnnotionFormat, # noqa: F401
ChannelDimension,
ImageInput,
PILImageResampling,
Expand Down
1 change: 0 additions & 1 deletion src/transformers/models/deta/image_processing_deta.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
IMAGENET_DEFAULT_MEAN,
IMAGENET_DEFAULT_STD,
AnnotationFormat,
AnnotionFormat, # noqa: F401
ChannelDimension,
ImageInput,
PILImageResampling,
Expand Down
1 change: 0 additions & 1 deletion src/transformers/models/detr/image_processing_detr.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
IMAGENET_DEFAULT_STD,
AnnotationFormat,
AnnotationType,
AnnotionFormat, # noqa: F401
ChannelDimension,
ImageInput,
PILImageResampling,
Expand Down
1 change: 0 additions & 1 deletion src/transformers/models/yolos/image_processing_yolos.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
IMAGENET_DEFAULT_STD,
AnnotationFormat,
AnnotationType,
AnnotionFormat, # noqa: F401
ChannelDimension,
ImageInput,
PILImageResampling,
Expand Down

0 comments on commit 1a585c1

Please sign in to comment.