diff --git a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp index c6e971c3b12..6ec644d003e 100644 --- a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp @@ -70,6 +70,8 @@ static void torch_jpeg_set_source_mgr( } // namespace torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) { + C10_LOG_API_USAGE_ONCE( + "torchvision.csrc.io.image.cpu.decode_jpeg.decode_jpeg"); // Check that the input tensor dtype is uint8 TORCH_CHECK(data.dtype() == torch::kU8, "Expected a torch.uint8 tensor"); // Check that the input tensor is 1-dimensional diff --git a/torchvision/csrc/io/image/cpu/decode_png.cpp b/torchvision/csrc/io/image/cpu/decode_png.cpp index 0df55daed68..fc065e9b839 100644 --- a/torchvision/csrc/io/image/cpu/decode_png.cpp +++ b/torchvision/csrc/io/image/cpu/decode_png.cpp @@ -23,6 +23,7 @@ torch::Tensor decode_png( const torch::Tensor& data, ImageReadMode mode, bool allow_16_bits) { + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.image.cpu.decode_png.decode_png"); // Check that the input tensor dtype is uint8 TORCH_CHECK(data.dtype() == torch::kU8, "Expected a torch.uint8 tensor"); // Check that the input tensor is 1-dimensional diff --git a/torchvision/csrc/io/image/cpu/encode_jpeg.cpp b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp index a8dbc7b2a28..d2ed73071a2 100644 --- a/torchvision/csrc/io/image/cpu/encode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp @@ -25,6 +25,8 @@ using JpegSizeType = size_t; using namespace detail; torch::Tensor encode_jpeg(const torch::Tensor& data, int64_t quality) { + C10_LOG_API_USAGE_ONCE( + "torchvision.csrc.io.image.cpu.encode_jpeg.encode_jpeg"); // Define compression structures and error handling struct jpeg_compress_struct cinfo {}; struct torch_jpeg_error_mgr jerr {}; diff --git a/torchvision/csrc/io/image/cpu/encode_png.cpp b/torchvision/csrc/io/image/cpu/encode_png.cpp index d28bad95890..a9b7d76ff61 100644 --- a/torchvision/csrc/io/image/cpu/encode_png.cpp +++ b/torchvision/csrc/io/image/cpu/encode_png.cpp @@ -63,6 +63,7 @@ void torch_png_write_data( } // namespace torch::Tensor encode_png(const torch::Tensor& data, int64_t compression_level) { + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.image.cpu.encode_png.encode_png"); // Define compression structures and error handling png_structp png_write; png_infop info_ptr; diff --git a/torchvision/csrc/io/image/cpu/read_write_file.cpp b/torchvision/csrc/io/image/cpu/read_write_file.cpp index a0bb7df72d5..def74c6721a 100644 --- a/torchvision/csrc/io/image/cpu/read_write_file.cpp +++ b/torchvision/csrc/io/image/cpu/read_write_file.cpp @@ -33,6 +33,8 @@ std::wstring utf8_decode(const std::string& str) { #endif torch::Tensor read_file(const std::string& filename) { + C10_LOG_API_USAGE_ONCE( + "torchvision.csrc.io.image.cpu.read_write_file.read_file"); #ifdef _WIN32 // According to // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=vs-2019, @@ -76,6 +78,8 @@ torch::Tensor read_file(const std::string& filename) { } void write_file(const std::string& filename, torch::Tensor& data) { + C10_LOG_API_USAGE_ONCE( + "torchvision.csrc.io.image.cpu.read_write_file.write_file"); // Check that the input tensor is on CPU TORCH_CHECK(data.device() == torch::kCPU, "Input tensor should be on CPU"); diff --git a/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp b/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp index 68f63ced427..263dadfd51f 100644 --- a/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp +++ b/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp @@ -33,6 +33,8 @@ torch::Tensor decode_jpeg_cuda( const torch::Tensor& data, ImageReadMode mode, torch::Device device) { + C10_LOG_API_USAGE_ONCE( + "torchvision.csrc.io.image.cuda.decode_jpeg_cuda.decode_jpeg_cuda"); TORCH_CHECK(data.dtype() == torch::kU8, "Expected a torch.uint8 tensor"); TORCH_CHECK( diff --git a/torchvision/csrc/io/video/video.cpp b/torchvision/csrc/io/video/video.cpp index 53a177fdb1e..e23ecacf075 100644 --- a/torchvision/csrc/io/video/video.cpp +++ b/torchvision/csrc/io/video/video.cpp @@ -157,6 +157,7 @@ void Video::_getDecoderParams( } // _get decoder params Video::Video(std::string videoPath, std::string stream, int64_t numThreads) { + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.video.video.Video"); // set number of threads global numThreads_ = numThreads; // parse stream information diff --git a/torchvision/csrc/io/video_reader/video_reader.cpp b/torchvision/csrc/io/video_reader/video_reader.cpp index 51b0750b431..cca89483d42 100644 --- a/torchvision/csrc/io/video_reader/video_reader.cpp +++ b/torchvision/csrc/io/video_reader/video_reader.cpp @@ -583,6 +583,8 @@ torch::List read_video_from_memory( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { + C10_LOG_API_USAGE_ONCE( + "torchvision.csrc.io.video_reader.video_reader.read_video_from_memory"); return readVideo( false, input_video, @@ -627,6 +629,8 @@ torch::List read_video_from_file( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { + C10_LOG_API_USAGE_ONCE( + "torchvision.csrc.io.video_reader.video_reader.read_video_from_file"); torch::Tensor dummy_input_video = torch::ones({0}); return readVideo( true, @@ -653,10 +657,14 @@ torch::List read_video_from_file( } torch::List probe_video_from_memory(torch::Tensor input_video) { + C10_LOG_API_USAGE_ONCE( + "torchvision.csrc.io.video_reader.video_reader.probe_video_from_memory"); return probeVideo(false, input_video, ""); } torch::List probe_video_from_file(std::string videoPath) { + C10_LOG_API_USAGE_ONCE( + "torchvision.csrc.io.video_reader.video_reader.probe_video_from_file"); torch::Tensor dummy_input_video = torch::ones({0}); return probeVideo(true, dummy_input_video, videoPath); } diff --git a/torchvision/io/__init__.py b/torchvision/io/__init__.py index 8ee832f43d7..f2ae6dff51e 100644 --- a/torchvision/io/__init__.py +++ b/torchvision/io/__init__.py @@ -2,6 +2,7 @@ import torch +from ..utils import _log_api_usage_once from ._video_opt import ( Timebase, VideoMetaData, @@ -106,6 +107,7 @@ class VideoReader: """ def __init__(self, path: str, stream: str = "video", num_threads: int = 0) -> None: + _log_api_usage_once(self) if not _has_video_opt(): raise RuntimeError( "Not compiled with video_reader support, " diff --git a/torchvision/io/image.py b/torchvision/io/image.py index 68117c3b7ef..7f5aa78880d 100644 --- a/torchvision/io/image.py +++ b/torchvision/io/image.py @@ -4,6 +4,7 @@ import torch from ..extension import _load_library +from ..utils import _log_api_usage_once try: @@ -41,6 +42,8 @@ def read_file(path: str) -> torch.Tensor: Returns: data (Tensor) """ + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(read_file) data = torch.ops.image.read_file(path) return data @@ -54,6 +57,8 @@ def write_file(filename: str, data: torch.Tensor) -> None: filename (str): the path to the file to be written data (Tensor): the contents to be written to the output file """ + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(write_file) torch.ops.image.write_file(filename, data) @@ -74,6 +79,8 @@ def decode_png(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGE Returns: output (Tensor[image_channels, image_height, image_width]) """ + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(decode_png) output = torch.ops.image.decode_png(input, mode.value, False) return output @@ -93,6 +100,8 @@ def encode_png(input: torch.Tensor, compression_level: int = 6) -> torch.Tensor: Tensor[1]: A one dimensional int8 tensor that contains the raw bytes of the PNG file. """ + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(encode_png) output = torch.ops.image.encode_png(input, compression_level) return output @@ -109,6 +118,8 @@ def write_png(input: torch.Tensor, filename: str, compression_level: int = 6): compression_level (int): Compression factor for the resulting file, it must be a number between 0 and 9. Default: 6 """ + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(write_png) output = encode_png(input, compression_level) write_file(filename, output) @@ -137,6 +148,8 @@ def decode_jpeg( Returns: output (Tensor[image_channels, image_height, image_width]) """ + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(decode_jpeg) device = torch.device(device) if device.type == "cuda": output = torch.ops.image.decode_jpeg_cuda(input, mode.value, device) @@ -160,6 +173,8 @@ def encode_jpeg(input: torch.Tensor, quality: int = 75) -> torch.Tensor: output (Tensor[1]): A one dimensional int8 tensor that contains the raw bytes of the JPEG file. """ + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(encode_jpeg) if quality < 1 or quality > 100: raise ValueError("Image quality should be a positive number between 1 and 100") @@ -178,6 +193,8 @@ def write_jpeg(input: torch.Tensor, filename: str, quality: int = 75): quality (int): Quality of the resulting JPEG file, it must be a number between 1 and 100. Default: 75 """ + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(write_jpeg) output = encode_jpeg(input, quality) write_file(filename, output) @@ -201,6 +218,8 @@ def decode_image(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHAN Returns: output (Tensor[image_channels, image_height, image_width]) """ + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(decode_image) output = torch.ops.image.decode_image(input, mode.value) return output @@ -221,6 +240,8 @@ def read_image(path: str, mode: ImageReadMode = ImageReadMode.UNCHANGED) -> torc Returns: output (Tensor[image_channels, image_height, image_width]) """ + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(read_image) data = read_file(path) return decode_image(data, mode) diff --git a/torchvision/io/video.py b/torchvision/io/video.py index 0ddd60a4586..479fdfc1ddf 100644 --- a/torchvision/io/video.py +++ b/torchvision/io/video.py @@ -9,6 +9,7 @@ import numpy as np import torch +from ..utils import _log_api_usage_once from . import _video_opt @@ -77,6 +78,8 @@ def write_video( audio_codec (str): the name of the audio codec, i.e. "mp3", "aac", etc. audio_options (Dict): dictionary containing options to be passed into the PyAV audio stream """ + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(write_video) _check_av_available() video_array = torch.as_tensor(video_array, dtype=torch.uint8).numpy() @@ -256,6 +259,8 @@ def read_video( aframes (Tensor[K, L]): the audio frames, where `K` is the number of channels and `L` is the number of points info (Dict): metadata for the video and audio. Can contain the fields video_fps (float) and audio_fps (int) """ + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(read_video) from torchvision import get_video_backend @@ -374,6 +379,8 @@ def read_video_timestamps(filename: str, pts_unit: str = "pts") -> Tuple[List[in video_fps (float, optional): the frame rate for the video """ + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(read_video_timestamps) from torchvision import get_video_backend if get_video_backend() != "pyav":