Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion torchvision/ops/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 14 additions & 1 deletion torchvision/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)