From 067a6ed3104d017f25d60fdde4aec68261afbae2 Mon Sep 17 00:00:00 2001 From: Kai Zhang Date: Mon, 29 Nov 2021 23:42:26 +0000 Subject: [PATCH 01/11] add api usage log for io --- torchvision/io/image.py | 11 +++++++++++ torchvision/io/video.py | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/torchvision/io/image.py b/torchvision/io/image.py index f835565016c..dd1801d6bd6 100644 --- a/torchvision/io/image.py +++ b/torchvision/io/image.py @@ -3,6 +3,7 @@ import torch from .._internally_replaced_utils import _get_extension_path +from ..utils import _log_api_usage_once try: @@ -41,6 +42,7 @@ def read_file(path: str) -> torch.Tensor: Returns: data (Tensor) """ + _log_api_usage_once("torchvision.io.read_file") data = torch.ops.image.read_file(path) return data @@ -54,6 +56,7 @@ 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 """ + _log_api_usage_once("torchvision.io.write_file") torch.ops.image.write_file(filename, data) @@ -74,6 +77,7 @@ def decode_png(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGE Returns: output (Tensor[image_channels, image_height, image_width]) """ + _log_api_usage_once("torchvision.io.decode_png") output = torch.ops.image.decode_png(input, mode.value, False) return output @@ -93,6 +97,7 @@ 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. """ + _log_api_usage_once("torchvision.io.encode_png") output = torch.ops.image.encode_png(input, compression_level) return output @@ -109,6 +114,7 @@ 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 """ + _log_api_usage_once("torchvision.io.write_png") output = encode_png(input, compression_level) write_file(filename, output) @@ -137,6 +143,7 @@ def decode_jpeg( Returns: output (Tensor[image_channels, image_height, image_width]) """ + _log_api_usage_once("torchvision.io.decode_jpeg") device = torch.device(device) if device.type == "cuda": output = torch.ops.image.decode_jpeg_cuda(input, mode.value, device) @@ -160,6 +167,7 @@ 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. """ + _log_api_usage_once("torchvision.io.encode_jpeg") if quality < 1 or quality > 100: raise ValueError("Image quality should be a positive number between 1 and 100") @@ -178,6 +186,7 @@ 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 """ + _log_api_usage_once("torchvision.io.write_jpeg") output = encode_jpeg(input, quality) write_file(filename, output) @@ -201,6 +210,7 @@ def decode_image(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHAN Returns: output (Tensor[image_channels, image_height, image_width]) """ + _log_api_usage_once("torchvision.io.decode_image") output = torch.ops.image.decode_image(input, mode.value) return output @@ -221,6 +231,7 @@ def read_image(path: str, mode: ImageReadMode = ImageReadMode.UNCHANGED) -> torc Returns: output (Tensor[image_channels, image_height, image_width]) """ + _log_api_usage_once("torchvision.io.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..cdb426d6d09 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,7 @@ 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 """ + _log_api_usage_once("torchvision.io.write_video") _check_av_available() video_array = torch.as_tensor(video_array, dtype=torch.uint8).numpy() @@ -256,6 +258,7 @@ 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) """ + _log_api_usage_once("torchvision.io.read_video") from torchvision import get_video_backend @@ -374,6 +377,7 @@ def read_video_timestamps(filename: str, pts_unit: str = "pts") -> Tuple[List[in video_fps (float, optional): the frame rate for the video """ + _log_api_usage_once("torchvision.io.read_video_timestamps") from torchvision import get_video_backend if get_video_backend() != "pyav": From 51f015a7708ae20e672b795a5605b2550a090363 Mon Sep 17 00:00:00 2001 From: Kai Zhang Date: Tue, 30 Nov 2021 23:59:16 +0000 Subject: [PATCH 02/11] cover VideoReader --- torchvision/io/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torchvision/io/__init__.py b/torchvision/io/__init__.py index 382e06fb4f2..1c91bbfb523 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, " From dedf489d35b7f91bef2e87e2d0638793a2c08c39 Mon Sep 17 00:00:00 2001 From: Kai Zhang Date: Wed, 1 Dec 2021 00:46:32 +0000 Subject: [PATCH 03/11] cover c++ APIs --- torchvision/csrc/io/image/cpu/decode_jpeg.cpp | 1 + torchvision/csrc/io/image/cpu/decode_png.cpp | 1 + torchvision/csrc/io/image/cpu/encode_jpeg.cpp | 1 + torchvision/csrc/io/image/cpu/encode_png.cpp | 1 + torchvision/csrc/io/image/cpu/read_write_file.cpp | 2 ++ torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp | 1 + torchvision/csrc/io/video/video.cpp | 1 + torchvision/csrc/io/video_reader/video_reader.cpp | 4 ++++ 8 files changed, 12 insertions(+) diff --git a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp index c6e971c3b12..dc60f5e8f71 100644 --- a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp @@ -70,6 +70,7 @@ static void torch_jpeg_set_source_mgr( } // namespace torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) { + C10_LOG_API_USAGE_ONCE("torchvision.io.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..0c33cbfadb2 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.io.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..be09694b28e 100644 --- a/torchvision/csrc/io/image/cpu/encode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp @@ -25,6 +25,7 @@ using JpegSizeType = size_t; using namespace detail; torch::Tensor encode_jpeg(const torch::Tensor& data, int64_t quality) { + C10_LOG_API_USAGE_ONCE("torchvision.io.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..655cf38ae26 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.io.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..120ba34b65f 100644 --- a/torchvision/csrc/io/image/cpu/read_write_file.cpp +++ b/torchvision/csrc/io/image/cpu/read_write_file.cpp @@ -33,6 +33,7 @@ std::wstring utf8_decode(const std::string& str) { #endif torch::Tensor read_file(const std::string& filename) { + C10_LOG_API_USAGE_ONCE("torchvision.io.read_file"); #ifdef _WIN32 // According to // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=vs-2019, @@ -76,6 +77,7 @@ torch::Tensor read_file(const std::string& filename) { } void write_file(const std::string& filename, torch::Tensor& data) { + C10_LOG_API_USAGE_ONCE("torchvision.io.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..017fdebc9ef 100644 --- a/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp +++ b/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp @@ -33,6 +33,7 @@ torch::Tensor decode_jpeg_cuda( const torch::Tensor& data, ImageReadMode mode, torch::Device device) { + C10_LOG_API_USAGE_ONCE("torchvision.io.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 d5a24398694..de7b557f7ae 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.io.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..3580387718d 100644 --- a/torchvision/csrc/io/video_reader/video_reader.cpp +++ b/torchvision/csrc/io/video_reader/video_reader.cpp @@ -583,6 +583,7 @@ torch::List read_video_from_memory( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { + C10_LOG_API_USAGE_ONCE("torchvision.io.read_video_from_memory"); return readVideo( false, input_video, @@ -627,6 +628,7 @@ torch::List read_video_from_file( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { + C10_LOG_API_USAGE_ONCE("torchvision.io.read_video_from_file"); torch::Tensor dummy_input_video = torch::ones({0}); return readVideo( true, @@ -653,10 +655,12 @@ torch::List read_video_from_file( } torch::List probe_video_from_memory(torch::Tensor input_video) { + C10_LOG_API_USAGE_ONCE("torchvision.io.probe_video_from_memory"); return probeVideo(false, input_video, ""); } torch::List probe_video_from_file(std::string videoPath) { + C10_LOG_API_USAGE_ONCE("torchvision.io.probe_video_from_file"); torch::Tensor dummy_input_video = torch::ones({0}); return probeVideo(true, dummy_input_video, videoPath); } From c610fbd760d345c96729441240c6d00fa5ad8f24 Mon Sep 17 00:00:00 2001 From: Kai Zhang Date: Mon, 29 Nov 2021 23:42:26 +0000 Subject: [PATCH 04/11] add api usage log for io --- torchvision/io/image.py | 11 +++++++++++ torchvision/io/video.py | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/torchvision/io/image.py b/torchvision/io/image.py index f835565016c..dd1801d6bd6 100644 --- a/torchvision/io/image.py +++ b/torchvision/io/image.py @@ -3,6 +3,7 @@ import torch from .._internally_replaced_utils import _get_extension_path +from ..utils import _log_api_usage_once try: @@ -41,6 +42,7 @@ def read_file(path: str) -> torch.Tensor: Returns: data (Tensor) """ + _log_api_usage_once("torchvision.io.read_file") data = torch.ops.image.read_file(path) return data @@ -54,6 +56,7 @@ 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 """ + _log_api_usage_once("torchvision.io.write_file") torch.ops.image.write_file(filename, data) @@ -74,6 +77,7 @@ def decode_png(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGE Returns: output (Tensor[image_channels, image_height, image_width]) """ + _log_api_usage_once("torchvision.io.decode_png") output = torch.ops.image.decode_png(input, mode.value, False) return output @@ -93,6 +97,7 @@ 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. """ + _log_api_usage_once("torchvision.io.encode_png") output = torch.ops.image.encode_png(input, compression_level) return output @@ -109,6 +114,7 @@ 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 """ + _log_api_usage_once("torchvision.io.write_png") output = encode_png(input, compression_level) write_file(filename, output) @@ -137,6 +143,7 @@ def decode_jpeg( Returns: output (Tensor[image_channels, image_height, image_width]) """ + _log_api_usage_once("torchvision.io.decode_jpeg") device = torch.device(device) if device.type == "cuda": output = torch.ops.image.decode_jpeg_cuda(input, mode.value, device) @@ -160,6 +167,7 @@ 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. """ + _log_api_usage_once("torchvision.io.encode_jpeg") if quality < 1 or quality > 100: raise ValueError("Image quality should be a positive number between 1 and 100") @@ -178,6 +186,7 @@ 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 """ + _log_api_usage_once("torchvision.io.write_jpeg") output = encode_jpeg(input, quality) write_file(filename, output) @@ -201,6 +210,7 @@ def decode_image(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHAN Returns: output (Tensor[image_channels, image_height, image_width]) """ + _log_api_usage_once("torchvision.io.decode_image") output = torch.ops.image.decode_image(input, mode.value) return output @@ -221,6 +231,7 @@ def read_image(path: str, mode: ImageReadMode = ImageReadMode.UNCHANGED) -> torc Returns: output (Tensor[image_channels, image_height, image_width]) """ + _log_api_usage_once("torchvision.io.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..cdb426d6d09 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,7 @@ 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 """ + _log_api_usage_once("torchvision.io.write_video") _check_av_available() video_array = torch.as_tensor(video_array, dtype=torch.uint8).numpy() @@ -256,6 +258,7 @@ 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) """ + _log_api_usage_once("torchvision.io.read_video") from torchvision import get_video_backend @@ -374,6 +377,7 @@ def read_video_timestamps(filename: str, pts_unit: str = "pts") -> Tuple[List[in video_fps (float, optional): the frame rate for the video """ + _log_api_usage_once("torchvision.io.read_video_timestamps") from torchvision import get_video_backend if get_video_backend() != "pyav": From d227affadd1add0c61ce11fe395ae0b0303d3ff3 Mon Sep 17 00:00:00 2001 From: Kai Zhang Date: Tue, 30 Nov 2021 23:59:16 +0000 Subject: [PATCH 05/11] cover VideoReader --- torchvision/io/__init__.py | 2 ++ 1 file changed, 2 insertions(+) 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, " From ed7513d25308340c0f25d7f8ea8212eecc08841b Mon Sep 17 00:00:00 2001 From: Kai Zhang Date: Wed, 1 Dec 2021 00:46:32 +0000 Subject: [PATCH 06/11] cover c++ APIs --- torchvision/csrc/io/image/cpu/decode_jpeg.cpp | 1 + torchvision/csrc/io/image/cpu/decode_png.cpp | 1 + torchvision/csrc/io/image/cpu/encode_jpeg.cpp | 1 + torchvision/csrc/io/image/cpu/encode_png.cpp | 1 + torchvision/csrc/io/image/cpu/read_write_file.cpp | 2 ++ torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp | 1 + torchvision/csrc/io/video/video.cpp | 1 + torchvision/csrc/io/video_reader/video_reader.cpp | 4 ++++ 8 files changed, 12 insertions(+) diff --git a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp index c6e971c3b12..dc60f5e8f71 100644 --- a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp @@ -70,6 +70,7 @@ static void torch_jpeg_set_source_mgr( } // namespace torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) { + C10_LOG_API_USAGE_ONCE("torchvision.io.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..0c33cbfadb2 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.io.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..be09694b28e 100644 --- a/torchvision/csrc/io/image/cpu/encode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp @@ -25,6 +25,7 @@ using JpegSizeType = size_t; using namespace detail; torch::Tensor encode_jpeg(const torch::Tensor& data, int64_t quality) { + C10_LOG_API_USAGE_ONCE("torchvision.io.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..655cf38ae26 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.io.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..120ba34b65f 100644 --- a/torchvision/csrc/io/image/cpu/read_write_file.cpp +++ b/torchvision/csrc/io/image/cpu/read_write_file.cpp @@ -33,6 +33,7 @@ std::wstring utf8_decode(const std::string& str) { #endif torch::Tensor read_file(const std::string& filename) { + C10_LOG_API_USAGE_ONCE("torchvision.io.read_file"); #ifdef _WIN32 // According to // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=vs-2019, @@ -76,6 +77,7 @@ torch::Tensor read_file(const std::string& filename) { } void write_file(const std::string& filename, torch::Tensor& data) { + C10_LOG_API_USAGE_ONCE("torchvision.io.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..017fdebc9ef 100644 --- a/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp +++ b/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp @@ -33,6 +33,7 @@ torch::Tensor decode_jpeg_cuda( const torch::Tensor& data, ImageReadMode mode, torch::Device device) { + C10_LOG_API_USAGE_ONCE("torchvision.io.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 d5a24398694..de7b557f7ae 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.io.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..3580387718d 100644 --- a/torchvision/csrc/io/video_reader/video_reader.cpp +++ b/torchvision/csrc/io/video_reader/video_reader.cpp @@ -583,6 +583,7 @@ torch::List read_video_from_memory( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { + C10_LOG_API_USAGE_ONCE("torchvision.io.read_video_from_memory"); return readVideo( false, input_video, @@ -627,6 +628,7 @@ torch::List read_video_from_file( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { + C10_LOG_API_USAGE_ONCE("torchvision.io.read_video_from_file"); torch::Tensor dummy_input_video = torch::ones({0}); return readVideo( true, @@ -653,10 +655,12 @@ torch::List read_video_from_file( } torch::List probe_video_from_memory(torch::Tensor input_video) { + C10_LOG_API_USAGE_ONCE("torchvision.io.probe_video_from_memory"); return probeVideo(false, input_video, ""); } torch::List probe_video_from_file(std::string videoPath) { + C10_LOG_API_USAGE_ONCE("torchvision.io.probe_video_from_file"); torch::Tensor dummy_input_video = torch::ones({0}); return probeVideo(true, dummy_input_video, videoPath); } From f3aba201c2dedc1f608a9b108467e510e1f23a32 Mon Sep 17 00:00:00 2001 From: Kai Zhang Date: Mon, 6 Dec 2021 22:48:01 +0000 Subject: [PATCH 07/11] add _cpp suffix to c++ APIs --- torchvision/csrc/io/image/cpu/decode_jpeg.cpp | 2 +- torchvision/csrc/io/image/cpu/decode_png.cpp | 2 +- torchvision/csrc/io/image/cpu/encode_jpeg.cpp | 2 +- torchvision/csrc/io/image/cpu/encode_png.cpp | 2 +- torchvision/csrc/io/image/cpu/read_write_file.cpp | 4 ++-- torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp | 2 +- torchvision/csrc/io/video/video.cpp | 2 +- torchvision/csrc/io/video_reader/video_reader.cpp | 8 ++++---- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp index dc60f5e8f71..0167ed70a64 100644 --- a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp @@ -70,7 +70,7 @@ static void torch_jpeg_set_source_mgr( } // namespace torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) { - C10_LOG_API_USAGE_ONCE("torchvision.io.decode_jpeg"); + C10_LOG_API_USAGE_ONCE("torchvision.io.decode_jpeg_cpp"); // 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 0c33cbfadb2..8ab0fed205c 100644 --- a/torchvision/csrc/io/image/cpu/decode_png.cpp +++ b/torchvision/csrc/io/image/cpu/decode_png.cpp @@ -23,7 +23,7 @@ torch::Tensor decode_png( const torch::Tensor& data, ImageReadMode mode, bool allow_16_bits) { - C10_LOG_API_USAGE_ONCE("torchvision.io.decode_png"); + C10_LOG_API_USAGE_ONCE("torchvision.io.decode_png_cpp"); // 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 be09694b28e..739783919ae 100644 --- a/torchvision/csrc/io/image/cpu/encode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp @@ -25,7 +25,7 @@ using JpegSizeType = size_t; using namespace detail; torch::Tensor encode_jpeg(const torch::Tensor& data, int64_t quality) { - C10_LOG_API_USAGE_ONCE("torchvision.io.encode_jpeg"); + C10_LOG_API_USAGE_ONCE("torchvision.io.encode_jpeg_cpp"); // 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 655cf38ae26..ca308f357ff 100644 --- a/torchvision/csrc/io/image/cpu/encode_png.cpp +++ b/torchvision/csrc/io/image/cpu/encode_png.cpp @@ -63,7 +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.io.encode_png"); + C10_LOG_API_USAGE_ONCE("torchvision.io.encode_png_cpp"); // 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 120ba34b65f..b1d1a48c4b9 100644 --- a/torchvision/csrc/io/image/cpu/read_write_file.cpp +++ b/torchvision/csrc/io/image/cpu/read_write_file.cpp @@ -33,7 +33,7 @@ std::wstring utf8_decode(const std::string& str) { #endif torch::Tensor read_file(const std::string& filename) { - C10_LOG_API_USAGE_ONCE("torchvision.io.read_file"); + C10_LOG_API_USAGE_ONCE("torchvision.io.read_file_cpp"); #ifdef _WIN32 // According to // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=vs-2019, @@ -77,7 +77,7 @@ torch::Tensor read_file(const std::string& filename) { } void write_file(const std::string& filename, torch::Tensor& data) { - C10_LOG_API_USAGE_ONCE("torchvision.io.write_file"); + C10_LOG_API_USAGE_ONCE("torchvision.io.write_file_cpp"); // 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 017fdebc9ef..37674d2b44d 100644 --- a/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp +++ b/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp @@ -33,7 +33,7 @@ torch::Tensor decode_jpeg_cuda( const torch::Tensor& data, ImageReadMode mode, torch::Device device) { - C10_LOG_API_USAGE_ONCE("torchvision.io.decode_jpeg_cuda"); + C10_LOG_API_USAGE_ONCE("torchvision.io.decode_jpeg_cuda_cpp"); 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 de7b557f7ae..ea4d31628e6 100644 --- a/torchvision/csrc/io/video/video.cpp +++ b/torchvision/csrc/io/video/video.cpp @@ -157,7 +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.io.Video"); + C10_LOG_API_USAGE_ONCE("torchvision.io.Video_cpp"); // 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 3580387718d..6b1c70d0bed 100644 --- a/torchvision/csrc/io/video_reader/video_reader.cpp +++ b/torchvision/csrc/io/video_reader/video_reader.cpp @@ -583,7 +583,7 @@ torch::List read_video_from_memory( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { - C10_LOG_API_USAGE_ONCE("torchvision.io.read_video_from_memory"); + C10_LOG_API_USAGE_ONCE("torchvision.io.read_video_from_memory_cpp"); return readVideo( false, input_video, @@ -628,7 +628,7 @@ torch::List read_video_from_file( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { - C10_LOG_API_USAGE_ONCE("torchvision.io.read_video_from_file"); + C10_LOG_API_USAGE_ONCE("torchvision.io.read_video_from_file_cpp"); torch::Tensor dummy_input_video = torch::ones({0}); return readVideo( true, @@ -655,12 +655,12 @@ torch::List read_video_from_file( } torch::List probe_video_from_memory(torch::Tensor input_video) { - C10_LOG_API_USAGE_ONCE("torchvision.io.probe_video_from_memory"); + C10_LOG_API_USAGE_ONCE("torchvision.io.probe_video_from_memory_cpp"); return probeVideo(false, input_video, ""); } torch::List probe_video_from_file(std::string videoPath) { - C10_LOG_API_USAGE_ONCE("torchvision.io.probe_video_from_file"); + C10_LOG_API_USAGE_ONCE("torchvision.io.probe_video_from_file_cpp"); torch::Tensor dummy_input_video = torch::ones({0}); return probeVideo(true, dummy_input_video, videoPath); } From 8e8a87faf325f334fe60dcc8591aba63ff6851cb Mon Sep 17 00:00:00 2001 From: Kai Zhang Date: Thu, 9 Dec 2021 23:24:50 +0000 Subject: [PATCH 08/11] use new API and change cpp format --- torchvision/csrc/io/image/cpu/decode_jpeg.cpp | 2 +- torchvision/csrc/io/image/cpu/decode_png.cpp | 2 +- torchvision/csrc/io/image/cpu/encode_jpeg.cpp | 2 +- torchvision/csrc/io/image/cpu/encode_png.cpp | 2 +- .../csrc/io/image/cpu/read_write_file.cpp | 4 ++-- .../csrc/io/image/cuda/decode_jpeg_cuda.cpp | 2 +- torchvision/csrc/io/video/video.cpp | 2 +- .../csrc/io/video_reader/video_reader.cpp | 8 ++++---- torchvision/io/__init__.py | 2 +- torchvision/io/image.py | 20 +++++++++---------- torchvision/io/video.py | 6 +++--- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp index 0167ed70a64..a8cc2e217df 100644 --- a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp @@ -70,7 +70,7 @@ static void torch_jpeg_set_source_mgr( } // namespace torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) { - C10_LOG_API_USAGE_ONCE("torchvision.io.decode_jpeg_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.decode_jpeg_cpp"); // 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 8ab0fed205c..dd0304b1ae9 100644 --- a/torchvision/csrc/io/image/cpu/decode_png.cpp +++ b/torchvision/csrc/io/image/cpu/decode_png.cpp @@ -23,7 +23,7 @@ torch::Tensor decode_png( const torch::Tensor& data, ImageReadMode mode, bool allow_16_bits) { - C10_LOG_API_USAGE_ONCE("torchvision.io.decode_png_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.decode_png_cpp"); // 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 739783919ae..6f65e37264b 100644 --- a/torchvision/csrc/io/image/cpu/encode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp @@ -25,7 +25,7 @@ using JpegSizeType = size_t; using namespace detail; torch::Tensor encode_jpeg(const torch::Tensor& data, int64_t quality) { - C10_LOG_API_USAGE_ONCE("torchvision.io.encode_jpeg_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.encode_jpeg_cpp"); // 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 ca308f357ff..e8e39dc7f53 100644 --- a/torchvision/csrc/io/image/cpu/encode_png.cpp +++ b/torchvision/csrc/io/image/cpu/encode_png.cpp @@ -63,7 +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.io.encode_png_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.encode_png_cpp"); // 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 b1d1a48c4b9..565a1da5ba2 100644 --- a/torchvision/csrc/io/image/cpu/read_write_file.cpp +++ b/torchvision/csrc/io/image/cpu/read_write_file.cpp @@ -33,7 +33,7 @@ std::wstring utf8_decode(const std::string& str) { #endif torch::Tensor read_file(const std::string& filename) { - C10_LOG_API_USAGE_ONCE("torchvision.io.read_file_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.read_file_cpp"); #ifdef _WIN32 // According to // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=vs-2019, @@ -77,7 +77,7 @@ torch::Tensor read_file(const std::string& filename) { } void write_file(const std::string& filename, torch::Tensor& data) { - C10_LOG_API_USAGE_ONCE("torchvision.io.write_file_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.write_file_cpp"); // 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 37674d2b44d..8333b00b08d 100644 --- a/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp +++ b/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp @@ -33,7 +33,7 @@ torch::Tensor decode_jpeg_cuda( const torch::Tensor& data, ImageReadMode mode, torch::Device device) { - C10_LOG_API_USAGE_ONCE("torchvision.io.decode_jpeg_cuda_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.decode_jpeg_cuda_cpp"); 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 ea4d31628e6..62f175f29c3 100644 --- a/torchvision/csrc/io/video/video.cpp +++ b/torchvision/csrc/io/video/video.cpp @@ -157,7 +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.io.Video_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.Video_cpp"); // 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 6b1c70d0bed..e83f99facb8 100644 --- a/torchvision/csrc/io/video_reader/video_reader.cpp +++ b/torchvision/csrc/io/video_reader/video_reader.cpp @@ -583,7 +583,7 @@ torch::List read_video_from_memory( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { - C10_LOG_API_USAGE_ONCE("torchvision.io.read_video_from_memory_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.read_video_from_memory_cpp"); return readVideo( false, input_video, @@ -628,7 +628,7 @@ torch::List read_video_from_file( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { - C10_LOG_API_USAGE_ONCE("torchvision.io.read_video_from_file_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.read_video_from_file_cpp"); torch::Tensor dummy_input_video = torch::ones({0}); return readVideo( true, @@ -655,12 +655,12 @@ torch::List read_video_from_file( } torch::List probe_video_from_memory(torch::Tensor input_video) { - C10_LOG_API_USAGE_ONCE("torchvision.io.probe_video_from_memory_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.probe_video_from_memory_cpp"); return probeVideo(false, input_video, ""); } torch::List probe_video_from_file(std::string videoPath) { - C10_LOG_API_USAGE_ONCE("torchvision.io.probe_video_from_file_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.probe_video_from_file_cpp"); 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 f2ae6dff51e..4628d426ab3 100644 --- a/torchvision/io/__init__.py +++ b/torchvision/io/__init__.py @@ -107,7 +107,7 @@ class VideoReader: """ def __init__(self, path: str, stream: str = "video", num_threads: int = 0) -> None: - _log_api_usage_once(self) + _log_api_usage_once("io", self.__class__.__name__) 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 dd1801d6bd6..1fd8b2feb09 100644 --- a/torchvision/io/image.py +++ b/torchvision/io/image.py @@ -42,7 +42,7 @@ def read_file(path: str) -> torch.Tensor: Returns: data (Tensor) """ - _log_api_usage_once("torchvision.io.read_file") + _log_api_usage_once("io", "read_file") data = torch.ops.image.read_file(path) return data @@ -56,7 +56,7 @@ 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 """ - _log_api_usage_once("torchvision.io.write_file") + _log_api_usage_once("io", "write_file") torch.ops.image.write_file(filename, data) @@ -77,7 +77,7 @@ def decode_png(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGE Returns: output (Tensor[image_channels, image_height, image_width]) """ - _log_api_usage_once("torchvision.io.decode_png") + _log_api_usage_once("io", "decode_png") output = torch.ops.image.decode_png(input, mode.value, False) return output @@ -97,7 +97,7 @@ 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. """ - _log_api_usage_once("torchvision.io.encode_png") + _log_api_usage_once("io", "encode_png") output = torch.ops.image.encode_png(input, compression_level) return output @@ -114,7 +114,7 @@ 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 """ - _log_api_usage_once("torchvision.io.write_png") + _log_api_usage_once("io", "write_png") output = encode_png(input, compression_level) write_file(filename, output) @@ -143,7 +143,7 @@ def decode_jpeg( Returns: output (Tensor[image_channels, image_height, image_width]) """ - _log_api_usage_once("torchvision.io.decode_jpeg") + _log_api_usage_once("io", "decode_jpeg") device = torch.device(device) if device.type == "cuda": output = torch.ops.image.decode_jpeg_cuda(input, mode.value, device) @@ -167,7 +167,7 @@ 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. """ - _log_api_usage_once("torchvision.io.encode_jpeg") + _log_api_usage_once("io", "encode_jpeg") if quality < 1 or quality > 100: raise ValueError("Image quality should be a positive number between 1 and 100") @@ -186,7 +186,7 @@ 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 """ - _log_api_usage_once("torchvision.io.write_jpeg") + _log_api_usage_once("io", "write_jpeg") output = encode_jpeg(input, quality) write_file(filename, output) @@ -210,7 +210,7 @@ def decode_image(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHAN Returns: output (Tensor[image_channels, image_height, image_width]) """ - _log_api_usage_once("torchvision.io.decode_image") + _log_api_usage_once("io", "decode_image") output = torch.ops.image.decode_image(input, mode.value) return output @@ -231,7 +231,7 @@ def read_image(path: str, mode: ImageReadMode = ImageReadMode.UNCHANGED) -> torc Returns: output (Tensor[image_channels, image_height, image_width]) """ - _log_api_usage_once("torchvision.io.read_image") + _log_api_usage_once("io", "read_image") data = read_file(path) return decode_image(data, mode) diff --git a/torchvision/io/video.py b/torchvision/io/video.py index cdb426d6d09..4d9a64b4a71 100644 --- a/torchvision/io/video.py +++ b/torchvision/io/video.py @@ -78,7 +78,7 @@ 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 """ - _log_api_usage_once("torchvision.io.write_video") + _log_api_usage_once("io", "write_video") _check_av_available() video_array = torch.as_tensor(video_array, dtype=torch.uint8).numpy() @@ -258,7 +258,7 @@ 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) """ - _log_api_usage_once("torchvision.io.read_video") + _log_api_usage_once("io", "read_video") from torchvision import get_video_backend @@ -377,7 +377,7 @@ def read_video_timestamps(filename: str, pts_unit: str = "pts") -> Tuple[List[in video_fps (float, optional): the frame rate for the video """ - _log_api_usage_once("torchvision.io.read_video_timestamps") + _log_api_usage_once("io", "read_video_timestamps") from torchvision import get_video_backend if get_video_backend() != "pyav": From ad474141ff08c915200b97cef90c82d9ac6808c3 Mon Sep 17 00:00:00 2001 From: Kai Zhang Date: Fri, 10 Dec 2021 07:16:24 +0000 Subject: [PATCH 09/11] remove _cpp suffix --- torchvision/csrc/io/image/cpu/decode_jpeg.cpp | 2 +- torchvision/csrc/io/image/cpu/decode_png.cpp | 2 +- torchvision/csrc/io/image/cpu/encode_jpeg.cpp | 2 +- torchvision/csrc/io/image/cpu/encode_png.cpp | 2 +- torchvision/csrc/io/image/cpu/read_write_file.cpp | 4 ++-- torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp | 2 +- torchvision/csrc/io/video/video.cpp | 2 +- torchvision/csrc/io/video_reader/video_reader.cpp | 8 ++++---- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp index a8cc2e217df..b64b2db5f76 100644 --- a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp @@ -70,7 +70,7 @@ 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.decode_jpeg_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.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 dd0304b1ae9..74f2be2a6ac 100644 --- a/torchvision/csrc/io/image/cpu/decode_png.cpp +++ b/torchvision/csrc/io/image/cpu/decode_png.cpp @@ -23,7 +23,7 @@ torch::Tensor decode_png( const torch::Tensor& data, ImageReadMode mode, bool allow_16_bits) { - C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.decode_png_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.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 6f65e37264b..57d3297c4fa 100644 --- a/torchvision/csrc/io/image/cpu/encode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp @@ -25,7 +25,7 @@ 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.encode_jpeg_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.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 e8e39dc7f53..7e51762561a 100644 --- a/torchvision/csrc/io/image/cpu/encode_png.cpp +++ b/torchvision/csrc/io/image/cpu/encode_png.cpp @@ -63,7 +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.encode_png_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.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 565a1da5ba2..ab193dd1c1d 100644 --- a/torchvision/csrc/io/image/cpu/read_write_file.cpp +++ b/torchvision/csrc/io/image/cpu/read_write_file.cpp @@ -33,7 +33,7 @@ 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.read_file_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.read_file"); #ifdef _WIN32 // According to // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=vs-2019, @@ -77,7 +77,7 @@ 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.write_file_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.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 8333b00b08d..6df3b1a4a1a 100644 --- a/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp +++ b/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp @@ -33,7 +33,7 @@ torch::Tensor decode_jpeg_cuda( const torch::Tensor& data, ImageReadMode mode, torch::Device device) { - C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.decode_jpeg_cuda_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.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 62f175f29c3..06fce9a7c45 100644 --- a/torchvision/csrc/io/video/video.cpp +++ b/torchvision/csrc/io/video/video.cpp @@ -157,7 +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_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.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 e83f99facb8..37e4e963926 100644 --- a/torchvision/csrc/io/video_reader/video_reader.cpp +++ b/torchvision/csrc/io/video_reader/video_reader.cpp @@ -583,7 +583,7 @@ torch::List read_video_from_memory( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { - C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.read_video_from_memory_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.read_video_from_memory"); return readVideo( false, input_video, @@ -628,7 +628,7 @@ torch::List read_video_from_file( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { - C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.read_video_from_file_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.read_video_from_file"); torch::Tensor dummy_input_video = torch::ones({0}); return readVideo( true, @@ -655,12 +655,12 @@ torch::List read_video_from_file( } torch::List probe_video_from_memory(torch::Tensor input_video) { - C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.probe_video_from_memory_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.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.probe_video_from_file_cpp"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.probe_video_from_file"); torch::Tensor dummy_input_video = torch::ones({0}); return probeVideo(true, dummy_input_video, videoPath); } From c106b8aba43e4df6ba24c7502f1e5645853318da Mon Sep 17 00:00:00 2001 From: Kai Zhang Date: Mon, 20 Dec 2021 19:06:50 +0000 Subject: [PATCH 10/11] adopt new API --- torchvision/csrc/io/image/cpu/decode_jpeg.cpp | 2 +- torchvision/csrc/io/image/cpu/decode_png.cpp | 2 +- torchvision/csrc/io/image/cpu/encode_jpeg.cpp | 2 +- torchvision/csrc/io/image/cpu/encode_png.cpp | 2 +- .../csrc/io/image/cpu/read_write_file.cpp | 4 +-- .../csrc/io/image/cuda/decode_jpeg_cuda.cpp | 2 +- torchvision/csrc/io/video/video.cpp | 2 +- .../csrc/io/video_reader/video_reader.cpp | 8 ++--- torchvision/io/__init__.py | 2 +- torchvision/io/image.py | 30 ++++++++++++------- torchvision/io/video.py | 9 ++++-- 11 files changed, 39 insertions(+), 26 deletions(-) diff --git a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp index b64b2db5f76..137f267076b 100644 --- a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp @@ -70,7 +70,7 @@ 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.decode_jpeg"); + 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 74f2be2a6ac..fc065e9b839 100644 --- a/torchvision/csrc/io/image/cpu/decode_png.cpp +++ b/torchvision/csrc/io/image/cpu/decode_png.cpp @@ -23,7 +23,7 @@ torch::Tensor decode_png( const torch::Tensor& data, ImageReadMode mode, bool allow_16_bits) { - C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.decode_png"); + 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 57d3297c4fa..59eb272ee63 100644 --- a/torchvision/csrc/io/image/cpu/encode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp @@ -25,7 +25,7 @@ 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.encode_jpeg"); + 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 7e51762561a..a9b7d76ff61 100644 --- a/torchvision/csrc/io/image/cpu/encode_png.cpp +++ b/torchvision/csrc/io/image/cpu/encode_png.cpp @@ -63,7 +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.encode_png"); + 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 ab193dd1c1d..12a78b7b131 100644 --- a/torchvision/csrc/io/image/cpu/read_write_file.cpp +++ b/torchvision/csrc/io/image/cpu/read_write_file.cpp @@ -33,7 +33,7 @@ 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.read_file"); + 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, @@ -77,7 +77,7 @@ 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.write_file"); + 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 6df3b1a4a1a..4e9ae10f530 100644 --- a/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp +++ b/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp @@ -33,7 +33,7 @@ torch::Tensor decode_jpeg_cuda( const torch::Tensor& data, ImageReadMode mode, torch::Device device) { - C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.decode_jpeg_cuda"); + 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 785e0c5bccf..e23ecacf075 100644 --- a/torchvision/csrc/io/video/video.cpp +++ b/torchvision/csrc/io/video/video.cpp @@ -157,7 +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"); + 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 37e4e963926..484dc0b2f37 100644 --- a/torchvision/csrc/io/video_reader/video_reader.cpp +++ b/torchvision/csrc/io/video_reader/video_reader.cpp @@ -583,7 +583,7 @@ torch::List read_video_from_memory( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { - C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.read_video_from_memory"); + C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.video_reader.video_reader.read_video_from_memory"); return readVideo( false, input_video, @@ -628,7 +628,7 @@ torch::List read_video_from_file( int64_t audioEndPts, int64_t audioTimeBaseNum, int64_t audioTimeBaseDen) { - C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.read_video_from_file"); + 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, @@ -655,12 +655,12 @@ torch::List read_video_from_file( } torch::List probe_video_from_memory(torch::Tensor input_video) { - C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.probe_video_from_memory"); + 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.probe_video_from_file"); + 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 4628d426ab3..f2ae6dff51e 100644 --- a/torchvision/io/__init__.py +++ b/torchvision/io/__init__.py @@ -107,7 +107,7 @@ class VideoReader: """ def __init__(self, path: str, stream: str = "video", num_threads: int = 0) -> None: - _log_api_usage_once("io", self.__class__.__name__) + _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 c79bd2a963c..7f5aa78880d 100644 --- a/torchvision/io/image.py +++ b/torchvision/io/image.py @@ -42,7 +42,8 @@ def read_file(path: str) -> torch.Tensor: Returns: data (Tensor) """ - _log_api_usage_once("io", "read_file") + 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 @@ -56,7 +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 """ - _log_api_usage_once("io", "write_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) @@ -77,7 +79,8 @@ def decode_png(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGE Returns: output (Tensor[image_channels, image_height, image_width]) """ - _log_api_usage_once("io", "decode_png") + 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 @@ -97,7 +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. """ - _log_api_usage_once("io", "encode_png") + 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 @@ -114,7 +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 """ - _log_api_usage_once("io", "write_png") + 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) @@ -143,7 +148,8 @@ def decode_jpeg( Returns: output (Tensor[image_channels, image_height, image_width]) """ - _log_api_usage_once("io", "decode_jpeg") + 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) @@ -167,7 +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. """ - _log_api_usage_once("io", "encode_jpeg") + 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") @@ -186,7 +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 """ - _log_api_usage_once("io", "write_jpeg") + 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) @@ -210,7 +218,8 @@ def decode_image(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHAN Returns: output (Tensor[image_channels, image_height, image_width]) """ - _log_api_usage_once("io", "decode_image") + 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 @@ -231,7 +240,8 @@ def read_image(path: str, mode: ImageReadMode = ImageReadMode.UNCHANGED) -> torc Returns: output (Tensor[image_channels, image_height, image_width]) """ - _log_api_usage_once("io", "read_image") + 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 4d9a64b4a71..479fdfc1ddf 100644 --- a/torchvision/io/video.py +++ b/torchvision/io/video.py @@ -78,7 +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 """ - _log_api_usage_once("io", "write_video") + 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() @@ -258,7 +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) """ - _log_api_usage_once("io", "read_video") + if not torch.jit.is_scripting() and not torch.jit.is_tracing(): + _log_api_usage_once(read_video) from torchvision import get_video_backend @@ -377,7 +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 """ - _log_api_usage_once("io", "read_video_timestamps") + 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": From 506a285f67b29d2356b16cc853c87baed2a6045b Mon Sep 17 00:00:00 2001 From: Kai Zhang Date: Mon, 20 Dec 2021 19:59:45 +0000 Subject: [PATCH 11/11] lint --- torchvision/csrc/io/image/cpu/decode_jpeg.cpp | 3 ++- torchvision/csrc/io/image/cpu/encode_jpeg.cpp | 3 ++- torchvision/csrc/io/image/cpu/read_write_file.cpp | 6 ++++-- torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp | 3 ++- torchvision/csrc/io/video_reader/video_reader.cpp | 12 ++++++++---- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp index 137f267076b..6ec644d003e 100644 --- a/torchvision/csrc/io/image/cpu/decode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/decode_jpeg.cpp @@ -70,7 +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"); + 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/encode_jpeg.cpp b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp index 59eb272ee63..d2ed73071a2 100644 --- a/torchvision/csrc/io/image/cpu/encode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp @@ -25,7 +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"); + 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/read_write_file.cpp b/torchvision/csrc/io/image/cpu/read_write_file.cpp index 12a78b7b131..def74c6721a 100644 --- a/torchvision/csrc/io/image/cpu/read_write_file.cpp +++ b/torchvision/csrc/io/image/cpu/read_write_file.cpp @@ -33,7 +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"); + 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, @@ -77,7 +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"); + 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 4e9ae10f530..263dadfd51f 100644 --- a/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp +++ b/torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp @@ -33,7 +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"); + 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_reader/video_reader.cpp b/torchvision/csrc/io/video_reader/video_reader.cpp index 484dc0b2f37..cca89483d42 100644 --- a/torchvision/csrc/io/video_reader/video_reader.cpp +++ b/torchvision/csrc/io/video_reader/video_reader.cpp @@ -583,7 +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"); + C10_LOG_API_USAGE_ONCE( + "torchvision.csrc.io.video_reader.video_reader.read_video_from_memory"); return readVideo( false, input_video, @@ -628,7 +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"); + 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, @@ -655,12 +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"); + 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"); + 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); }