importosimportwarningsfrommodulefinderimportModuleimporttorch# Don't re-order these, we need to load the _C extension (done when importing# .extensions) before entering _meta_registrations.from.extensionimport_HAS_OPS# usort:skipfromtorchvisionimport_meta_registrations,datasets,io,models,ops,transforms,utils# usort:skiptry:from.versionimport__version__# noqa: F401exceptImportError:pass# Check if torchvision is being imported within the root folderifnot_HAS_OPSandos.path.dirname(os.path.realpath(__file__))==os.path.join(os.path.realpath(os.getcwd()),"torchvision"):message=("You are importing torchvision within its own root folder ({}). ""This is not expected to work and may give errors. Please exit the ""torchvision project source and relaunch your python interpreter.")warnings.warn(message.format(os.getcwd()))_image_backend="PIL"_video_backend="pyav"
[docs]defset_image_backend(backend):""" Specifies the package used to load images. Args: backend (string): Name of the image backend. one of {'PIL', 'accimage'}. The :mod:`accimage` package uses the Intel IPP library. It is generally faster than PIL, but does not support as many operations. """global_image_backendifbackendnotin["PIL","accimage"]:raiseValueError(f"Invalid backend '{backend}'. Options are 'PIL' and 'accimage'")_image_backend=backend
[docs]defget_image_backend():""" Gets the name of the package used to load images """return_image_backend
[docs]defset_video_backend(backend):""" Specifies the package used to decode videos. Args: backend (string): Name of the video backend. one of {'pyav', 'video_reader'}. The :mod:`pyav` package uses the 3rd party PyAv library. It is a Pythonic binding for the FFmpeg libraries. The :mod:`video_reader` package includes a native C++ implementation on top of FFMPEG libraries, and a python API of TorchScript custom operator. It generally decodes faster than :mod:`pyav`, but is perhaps less robust. .. note:: Building with FFMPEG is disabled by default in the latest `main`. If you want to use the 'video_reader' backend, please compile torchvision from source. """global_video_backendifbackendnotin["pyav","video_reader","cuda"]:raiseValueError("Invalid video backend '%s'. Options are 'pyav', 'video_reader' and 'cuda'"%backend)ifbackend=="video_reader"andnotio._HAS_CPU_VIDEO_DECODER:# TODO: better messagesmessage="video_reader video backend is not available. Please compile torchvision from source and try again"raiseRuntimeError(message)elifbackend=="cuda"andnotio._HAS_GPU_VIDEO_DECODER:# TODO: better messagesmessage="cuda video backend is not available."raiseRuntimeError(message)else:_video_backend=backend
[docs]defget_video_backend():""" Returns the currently active video backend used to decode videos. Returns: str: Name of the video backend. one of {'pyav', 'video_reader'}. """return_video_backend
def_is_tracing():returntorch._C._get_tracing_state()defdisable_beta_transforms_warning():# Noop, only exists to avoid breaking existing code.# See https://github.com/pytorch/vision/issues/7896pass
Docs
Access comprehensive developer documentation for PyTorch
To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.