__init__.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from modulefinder import Module
  2. import torch
  3. # Don't re-order these, we need to load the _C extension (done when importing
  4. # .extension) before entering _meta_registrations.
  5. from . import extension # usort:skip # noqa: F401
  6. from torchvision import _meta_registrations, datasets, io, models, ops, transforms, utils # usort:skip
  7. try:
  8. from .version import __version__ # noqa: F401
  9. except ImportError:
  10. pass
  11. _image_backend = "PIL"
  12. _video_backend = "pyav"
  13. def set_image_backend(backend):
  14. """
  15. Specifies the package used to load images.
  16. Args:
  17. backend (string): Name of the image backend. one of {'PIL', 'accimage'}.
  18. The :mod:`accimage` package uses the Intel IPP library. It is
  19. generally faster than PIL, but does not support as many operations.
  20. """
  21. global _image_backend
  22. if backend not in ["PIL", "accimage"]:
  23. raise ValueError(f"Invalid backend '{backend}'. Options are 'PIL' and 'accimage'")
  24. _image_backend = backend
  25. def get_image_backend():
  26. """
  27. Gets the name of the package used to load images
  28. """
  29. return _image_backend
  30. def set_video_backend(backend):
  31. """
  32. Specifies the package used to decode videos.
  33. Args:
  34. backend (string): Name of the video backend. Only 'pyav' is supported.
  35. The :mod:`pyav` package uses the 3rd party PyAv library. It is a Pythonic
  36. binding for the FFmpeg libraries.
  37. """
  38. pass
  39. def get_video_backend():
  40. """
  41. Returns the currently active video backend used to decode videos.
  42. Returns:
  43. str: Name of the video backend. Currently only 'pyav' is supported.
  44. """
  45. return _video_backend
  46. def _is_tracing():
  47. return torch._C._get_tracing_state()
  48. def disable_beta_transforms_warning():
  49. # Noop, only exists to avoid breaking existing code.
  50. # See https://github.com/pytorch/vision/issues/7896
  51. pass