diff --git a/torchvision/ops/boxes.py b/torchvision/ops/boxes.py index 38cb4c1a836..7047db7096e 100644 --- a/torchvision/ops/boxes.py +++ b/torchvision/ops/boxes.py @@ -5,7 +5,7 @@ from torch import Tensor from torchvision.extension import _assert_has_ops -from ..utils import _log_api_usage_once +from ..utils import _log_api_usage_once, log_api_usage_once_dec from ._box_convert import _box_cxcywh_to_xyxy, _box_xyxy_to_cxcywh, _box_xywh_to_xyxy, _box_xyxy_to_xywh @@ -223,6 +223,7 @@ def _upcast(t: Tensor) -> Tensor: return t if t.dtype in (torch.int32, torch.int64) else t.int() +@log_api_usage_once_dec def box_area(boxes: Tensor) -> Tensor: """ Computes the area of a set of bounding boxes, which are specified by their @@ -259,6 +260,7 @@ def _box_inter_union(boxes1: Tensor, boxes2: Tensor) -> Tuple[Tensor, Tensor]: return inter, union +@log_api_usage_once_dec def box_iou(boxes1: Tensor, boxes2: Tensor) -> Tensor: """ Return intersection-over-union (Jaccard index) between two sets of boxes. diff --git a/torchvision/utils.py b/torchvision/utils.py index 6d3293d103d..fa727307566 100644 --- a/torchvision/utils.py +++ b/torchvision/utils.py @@ -1,8 +1,9 @@ import math import pathlib import warnings +from functools import wraps from types import FunctionType -from typing import Any, BinaryIO, List, Optional, Tuple, Union +from typing import Any, BinaryIO, List, Optional, Tuple, Union, TypeVar, Callable, cast import numpy as np import torch @@ -547,3 +548,15 @@ def _log_api_usage_once(obj: Any) -> None: if isinstance(obj, FunctionType): name = obj.__name__ torch._C._log_api_usage_once(f"{obj.__module__}.{name}") + + +F = TypeVar("F", bound=Callable[..., Any]) + + +def log_api_usage_once_dec(fn: F) -> F: + @wraps(fn) + def wrapper(*args, **kwargs): + _log_api_usage_once(fn) + return fn(*args, **kwargs) + + return cast(F, wrapper)