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

io.rst 2.8 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
  1. Decoding / Encoding images and videos
  2. =====================================
  3. .. currentmodule:: torchvision.io
  4. The :mod:`torchvision.io` module provides utilities for decoding and encoding
  5. images and videos.
  6. Image Decoding
  7. --------------
  8. Torchvision currently supports decoding JPEG, PNG, WEBP, GIF, AVIF, and HEIC
  9. images. JPEG decoding can also be done on CUDA GPUs.
  10. The main entry point is the :func:`~torchvision.io.decode_image` function, which
  11. you can use as an alternative to ``PIL.Image.open()``. It will decode images
  12. straight into image Tensors, thus saving you the conversion and allowing you to
  13. run transforms/preproc natively on tensors.
  14. .. code::
  15. from torchvision.io import decode_image
  16. img = decode_image("path_to_image", mode="RGB")
  17. img.dtype # torch.uint8
  18. # Or
  19. raw_encoded_bytes = ... # read encoded bytes from your file system
  20. img = decode_image(raw_encoded_bytes, mode="RGB")
  21. :func:`~torchvision.io.decode_image` will automatically detect the image format,
  22. and call the corresponding decoder (except for HEIC and AVIF images, see details
  23. in :func:`~torchvision.io.decode_avif` and :func:`~torchvision.io.decode_heic`).
  24. You can also use the lower-level format-specific decoders which can be more
  25. powerful, e.g. if you want to encode/decode JPEGs on CUDA.
  26. .. autosummary::
  27. :toctree: generated/
  28. :template: function.rst
  29. decode_image
  30. decode_jpeg
  31. encode_png
  32. decode_webp
  33. decode_avif
  34. decode_heic
  35. decode_gif
  36. .. autosummary::
  37. :toctree: generated/
  38. :template: class.rst
  39. ImageReadMode
  40. Obsolete decoding function:
  41. .. autosummary::
  42. :toctree: generated/
  43. :template: function.rst
  44. read_image
  45. Image Encoding
  46. --------------
  47. For encoding, JPEG (cpu and CUDA) and PNG are supported.
  48. .. autosummary::
  49. :toctree: generated/
  50. :template: function.rst
  51. encode_jpeg
  52. write_jpeg
  53. encode_png
  54. write_png
  55. IO operations
  56. -------------
  57. .. autosummary::
  58. :toctree: generated/
  59. :template: function.rst
  60. read_file
  61. write_file
  62. Video - DEPREACTED
  63. ------------------
  64. .. warning::
  65. DEPRECATED: All the video decoding and encoding capabilities of torchvision
  66. are deprecated from version 0.22 and will be removed in version 0.24. We
  67. recommend that you migrate to
  68. `TorchCodec <https://github.com/pytorch/torchcodec>`__, where we'll
  69. consolidate the future decoding/encoding capabilities of PyTorch
  70. .. autosummary::
  71. :toctree: generated/
  72. :template: function.rst
  73. read_video
  74. read_video_timestamps
  75. write_video
  76. **Fine-grained video API**
  77. In addition to the :mod:`read_video` function, we provide a high-performance
  78. lower-level API for more fine-grained control compared to the :mod:`read_video` function.
  79. It does all this whilst fully supporting torchscript.
  80. .. autosummary::
  81. :toctree: generated/
  82. :template: class.rst
  83. VideoReader
Tip!

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

Comments

Loading...