Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

__init__.py 3.5 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  1. import os
  2. import warnings
  3. from modulefinder import Module
  4. import torch
  5. # Don't re-order these, we need to load the _C extension (done when importing
  6. # .extensions) before entering _meta_registrations.
  7. from .extension import _HAS_OPS # usort:skip
  8. from torchvision import _meta_registrations, datasets, io, models, ops, transforms, utils # usort:skip
  9. try:
  10. from .version import __version__ # noqa: F401
  11. except ImportError:
  12. pass
  13. # Check if torchvision is being imported within the root folder
  14. if not _HAS_OPS and os.path.dirname(os.path.realpath(__file__)) == os.path.join(
  15. os.path.realpath(os.getcwd()), "torchvision"
  16. ):
  17. message = (
  18. "You are importing torchvision within its own root folder ({}). "
  19. "This is not expected to work and may give errors. Please exit the "
  20. "torchvision project source and relaunch your python interpreter."
  21. )
  22. warnings.warn(message.format(os.getcwd()))
  23. _image_backend = "PIL"
  24. _video_backend = "pyav"
  25. def set_image_backend(backend):
  26. """
  27. Specifies the package used to load images.
  28. Args:
  29. backend (string): Name of the image backend. one of {'PIL', 'accimage'}.
  30. The :mod:`accimage` package uses the Intel IPP library. It is
  31. generally faster than PIL, but does not support as many operations.
  32. """
  33. global _image_backend
  34. if backend not in ["PIL", "accimage"]:
  35. raise ValueError(f"Invalid backend '{backend}'. Options are 'PIL' and 'accimage'")
  36. _image_backend = backend
  37. def get_image_backend():
  38. """
  39. Gets the name of the package used to load images
  40. """
  41. return _image_backend
  42. def set_video_backend(backend):
  43. """
  44. Specifies the package used to decode videos.
  45. Args:
  46. backend (string): Name of the video backend. one of {'pyav', 'video_reader'}.
  47. The :mod:`pyav` package uses the 3rd party PyAv library. It is a Pythonic
  48. binding for the FFmpeg libraries.
  49. The :mod:`video_reader` package includes a native C++ implementation on
  50. top of FFMPEG libraries, and a python API of TorchScript custom operator.
  51. It generally decodes faster than :mod:`pyav`, but is perhaps less robust.
  52. .. note::
  53. Building with FFMPEG is disabled by default in the latest `main`. If you want to use the 'video_reader'
  54. backend, please compile torchvision from source.
  55. """
  56. global _video_backend
  57. if backend not in ["pyav", "video_reader", "cuda"]:
  58. raise ValueError("Invalid video backend '%s'. Options are 'pyav', 'video_reader' and 'cuda'" % backend)
  59. if backend == "video_reader" and not io._HAS_CPU_VIDEO_DECODER:
  60. # TODO: better messages
  61. message = "video_reader video backend is not available. Please compile torchvision from source and try again"
  62. raise RuntimeError(message)
  63. elif backend == "cuda" and not io._HAS_GPU_VIDEO_DECODER:
  64. # TODO: better messages
  65. message = "cuda video backend is not available."
  66. raise RuntimeError(message)
  67. else:
  68. _video_backend = backend
  69. def get_video_backend():
  70. """
  71. Returns the currently active video backend used to decode videos.
  72. Returns:
  73. str: Name of the video backend. one of {'pyav', 'video_reader'}.
  74. """
  75. return _video_backend
  76. def _is_tracing():
  77. return torch._C._get_tracing_state()
  78. def disable_beta_transforms_warning():
  79. # Noop, only exists to avoid breaking existing code.
  80. # See https://github.com/pytorch/vision/issues/7896
  81. pass
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...