Bytes
docarray.typing.bytes
AudioBytes
Bases: bytes
, AbstractType
Bytes that store an audio and that can be load into an Audio tensor
Source code in docarray/typing/bytes/audio_bytes.py
load()
Load the Audio from the AudioBytes
into an
AudioNdArray
.
from typing import Optional
from docarray import BaseDoc
from docarray.typing import AudioBytes, AudioNdArray, AudioUrl
class MyAudio(BaseDoc):
url: AudioUrl
tensor: Optional[AudioNdArray]
bytes_: Optional[AudioBytes]
frame_rate: Optional[float]
doc = MyAudio(url='https://www.kozco.com/tech/piano2.wav')
doc.bytes_ = doc.url.load_bytes()
doc.tensor, doc.frame_rate = doc.bytes_.load()
# Note this is equivalent to do
doc.tensor, doc.frame_rate = doc.url.load()
assert isinstance(doc.tensor, AudioNdArray)
Returns:
Type | Description |
---|---|
Tuple[AudioNdArray, int]
|
tuple of an |
Source code in docarray/typing/bytes/audio_bytes.py
ImageBytes
Bases: bytes
, AbstractType
Bytes that store an image and that can be load into an image tensor
Source code in docarray/typing/bytes/image_bytes.py
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
load(width=None, height=None, axis_layout=('H', 'W', 'C'))
Load the image from the ImageBytes
into an
ImageNdArray
.
from docarray import BaseDoc
from docarray.typing import ImageNdArray, ImageUrl
class MyDoc(BaseDoc):
img_url: ImageUrl
doc = MyDoc(
img_url="https://upload.wikimedia.org/wikipedia/commons/8/80/"
"Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
)
img_tensor = doc.img_url.load()
assert isinstance(img_tensor, ImageNdArray)
img_tensor = doc.img_url.load(height=224, width=224)
assert img_tensor.shape == (224, 224, 3)
layout = ('C', 'W', 'H')
img_tensor = doc.img_url.load(height=100, width=200, axis_layout=layout)
assert img_tensor.shape == (3, 200, 100)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width |
Optional[int]
|
width of the image tensor. |
None
|
height |
Optional[int]
|
height of the image tensor. |
None
|
axis_layout |
Tuple[str, str, str]
|
ordering of the different image axes. 'H' = height, 'W' = width, 'C' = color channel |
('H', 'W', 'C')
|
Returns:
Type | Description |
---|---|
ImageNdArray
|
|
Source code in docarray/typing/bytes/image_bytes.py
load_pil()
Load the image from the bytes into a PIL.Image.Image
instance
from pydantic import parse_obj_as
from docarray import BaseDoc
from docarray.typing import ImageUrl
img_url = "https://upload.wikimedia.org/wikipedia/commons/8/80/Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
img_url = parse_obj_as(ImageUrl, img_url)
img = img_url.load_pil()
from PIL.Image import Image
assert isinstance(img, Image)
Returns:
Type | Description |
---|---|
Image
|
a Pillow image |
Source code in docarray/typing/bytes/image_bytes.py
VideoBytes
Bases: bytes
, AbstractType
Bytes that store a video and that can be load into a video tensor
Source code in docarray/typing/bytes/video_bytes.py
load(**kwargs)
Load the video from the bytes into a VideoLoadResult object consisting of:
- a
VideoNdArray
(VideoLoadResult.video
) - an
AudioNdArray
(VideoLoadResult.audio
) - an
NdArray
containing the key frame indices (VideoLoadResult.key_frame_indices
).
from docarray import BaseDoc
from docarray.typing import AudioNdArray, NdArray, VideoNdArray, VideoUrl
class MyDoc(BaseDoc):
video_url: VideoUrl
doc = MyDoc(
video_url='https://github.com/docarray/docarray/blob/main/tests/toydata/mov_bbb.mp4?raw=true'
)
video, audio, key_frame_indices = doc.video_url.load()
assert isinstance(video, VideoNdArray)
assert isinstance(audio, AudioNdArray)
assert isinstance(key_frame_indices, NdArray)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
supports all keyword arguments that are being supported by av.open() as described here |
{}
|
Returns:
Type | Description |
---|---|
VideoLoadResult
|
a |
Source code in docarray/typing/bytes/video_bytes.py
audio_bytes
AudioBytes
Bases: bytes
, AbstractType
Bytes that store an audio and that can be load into an Audio tensor
Source code in docarray/typing/bytes/audio_bytes.py
load()
Load the Audio from the AudioBytes
into an
AudioNdArray
.
from typing import Optional
from docarray import BaseDoc
from docarray.typing import AudioBytes, AudioNdArray, AudioUrl
class MyAudio(BaseDoc):
url: AudioUrl
tensor: Optional[AudioNdArray]
bytes_: Optional[AudioBytes]
frame_rate: Optional[float]
doc = MyAudio(url='https://www.kozco.com/tech/piano2.wav')
doc.bytes_ = doc.url.load_bytes()
doc.tensor, doc.frame_rate = doc.bytes_.load()
# Note this is equivalent to do
doc.tensor, doc.frame_rate = doc.url.load()
assert isinstance(doc.tensor, AudioNdArray)
Returns:
Type | Description |
---|---|
Tuple[AudioNdArray, int]
|
tuple of an |
Source code in docarray/typing/bytes/audio_bytes.py
image_bytes
ImageBytes
Bases: bytes
, AbstractType
Bytes that store an image and that can be load into an image tensor
Source code in docarray/typing/bytes/image_bytes.py
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
load(width=None, height=None, axis_layout=('H', 'W', 'C'))
Load the image from the ImageBytes
into an
ImageNdArray
.
from docarray import BaseDoc
from docarray.typing import ImageNdArray, ImageUrl
class MyDoc(BaseDoc):
img_url: ImageUrl
doc = MyDoc(
img_url="https://upload.wikimedia.org/wikipedia/commons/8/80/"
"Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
)
img_tensor = doc.img_url.load()
assert isinstance(img_tensor, ImageNdArray)
img_tensor = doc.img_url.load(height=224, width=224)
assert img_tensor.shape == (224, 224, 3)
layout = ('C', 'W', 'H')
img_tensor = doc.img_url.load(height=100, width=200, axis_layout=layout)
assert img_tensor.shape == (3, 200, 100)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width |
Optional[int]
|
width of the image tensor. |
None
|
height |
Optional[int]
|
height of the image tensor. |
None
|
axis_layout |
Tuple[str, str, str]
|
ordering of the different image axes. 'H' = height, 'W' = width, 'C' = color channel |
('H', 'W', 'C')
|
Returns:
Type | Description |
---|---|
ImageNdArray
|
|
Source code in docarray/typing/bytes/image_bytes.py
load_pil()
Load the image from the bytes into a PIL.Image.Image
instance
from pydantic import parse_obj_as
from docarray import BaseDoc
from docarray.typing import ImageUrl
img_url = "https://upload.wikimedia.org/wikipedia/commons/8/80/Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
img_url = parse_obj_as(ImageUrl, img_url)
img = img_url.load_pil()
from PIL.Image import Image
assert isinstance(img, Image)
Returns:
Type | Description |
---|---|
Image
|
a Pillow image |
Source code in docarray/typing/bytes/image_bytes.py
video_bytes
VideoBytes
Bases: bytes
, AbstractType
Bytes that store a video and that can be load into a video tensor
Source code in docarray/typing/bytes/video_bytes.py
load(**kwargs)
Load the video from the bytes into a VideoLoadResult object consisting of:
- a
VideoNdArray
(VideoLoadResult.video
) - an
AudioNdArray
(VideoLoadResult.audio
) - an
NdArray
containing the key frame indices (VideoLoadResult.key_frame_indices
).
from docarray import BaseDoc
from docarray.typing import AudioNdArray, NdArray, VideoNdArray, VideoUrl
class MyDoc(BaseDoc):
video_url: VideoUrl
doc = MyDoc(
video_url='https://github.com/docarray/docarray/blob/main/tests/toydata/mov_bbb.mp4?raw=true'
)
video, audio, key_frame_indices = doc.video_url.load()
assert isinstance(video, VideoNdArray)
assert isinstance(audio, AudioNdArray)
assert isinstance(key_frame_indices, NdArray)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
supports all keyword arguments that are being supported by av.open() as described here |
{}
|
Returns:
Type | Description |
---|---|
VideoLoadResult
|
a |