ImageTensor
docarray.typing.tensor.image.image_ndarray
ImageNdArray
Bases: AbstractImageTensor
, NdArray
Subclass of NdArray
, to represent an image tensor.
Adds image-specific features to the tensor.
For instance the ability convert the tensor back to image bytes which are
optimized to send over the wire.
from typing import Optional
from docarray import BaseDoc
from docarray.typing import ImageBytes, ImageNdArray, ImageUrl
class MyImageDoc(BaseDoc):
title: str
tensor: Optional[ImageNdArray]
url: Optional[ImageUrl]
bytes: Optional[ImageBytes]
# from url
doc = MyImageDoc(
title='my_second_audio_doc',
url="https://upload.wikimedia.org/wikipedia/commons/8/80/"
"Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg",
)
doc.tensor = doc.url.load()
doc.bytes = doc.tensor.to_bytes()
Source code in docarray/typing/tensor/image/image_ndarray.py
docarray.typing.tensor.image.abstract_image_tensor
AbstractImageTensor
Bases: AbstractTensor
, ABC
Source code in docarray/typing/tensor/image/abstract_image_tensor.py
display()
Display image data from tensor in notebook.
Source code in docarray/typing/tensor/image/abstract_image_tensor.py
save(file_path)
Save image tensor to an image file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
path to an image file. If file is a string, open the file by that name, otherwise treat it as a file-like object. |
required |
Source code in docarray/typing/tensor/image/abstract_image_tensor.py
to_bytes(format='PNG')
Convert image tensor to ImageBytes
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format |
str
|
the image format use to store the image, can be 'PNG' , 'JPG' ... |
'PNG'
|
Returns:
Type | Description |
---|---|
ImageBytes
|
an ImageBytes object |
Source code in docarray/typing/tensor/image/abstract_image_tensor.py
docarray.typing.tensor.image.image_tensorflow_tensor
ImageTensorFlowTensor
Bases: TensorFlowTensor
, AbstractImageTensor
Subclass of TensorFlowTensor
,
to represent an image tensor. Adds image-specific features to the tensor.
For instance the ability convert the tensor back to
ImageBytes
which are
optimized to send over the wire.
from typing import Optional
from docarray import BaseDoc
from docarray.typing import ImageBytes, ImageTensorFlowTensor, ImageUrl
class MyImageDoc(BaseDoc):
title: str
tensor: Optional[ImageTensorFlowTensor]
url: Optional[ImageUrl]
bytes: Optional[ImageBytes]
doc = MyImageDoc(
title='my_second_image_doc',
url="https://upload.wikimedia.org/wikipedia/commons/8/80/"
"Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg",
)
doc.tensor = doc.url.load()
doc.bytes = doc.tensor.to_bytes()
Source code in docarray/typing/tensor/image/image_tensorflow_tensor.py
docarray.typing.tensor.image.image_torch_tensor
ImageTorchTensor
Bases: AbstractImageTensor
, TorchTensor
Subclass of TorchTensor
, to represent an image tensor.
Adds image-specific features to the tensor.
For instance the ability convert the tensor back to
ImageBytes
which are
optimized to send over the wire.
from typing import Optional
from docarray import BaseDoc
from docarray.typing import ImageBytes, ImageTorchTensor, ImageUrl
class MyImageDoc(BaseDoc):
title: str
tensor: Optional[ImageTorchTensor]
url: Optional[ImageUrl]
bytes: Optional[ImageBytes]
doc = MyImageDoc(
title='my_second_image_doc',
url="https://upload.wikimedia.org/wikipedia/commons/8/80/"
"Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg",
)
doc.tensor = doc.url.load()
doc.bytes = doc.tensor.to_bytes()