ads.feature_engineering.adsimage package#

Subpackages#

Submodules#

ads.feature_engineering.adsimage.image module#

The module helping to load/save images from/to the local path or OCI object storage bucket.

Classes#

ADSImage

Work with image files that are stored in Oracle Cloud Infrastructure Object Storage.

Examples

>>> from ads.feature_engineering import ADSImage
>>> from IPython.core.display import display
>>> img = ADSImage.open("1.jpg")
>>> display(img)
>>> img.save("oci://<bucket_name>@<namespace>/1.jpg")
>>> img1 = ADSImage.open("oci://<bucket_name>@<namespace>/1.jpg")
>>> display(img1)
class ads.feature_engineering.adsimage.image.ADSImage(img: Image, filename: str | None = None)[source]#

Bases: object

Work with image files that are stored in Oracle Cloud Infrastructure Object Storage. PIL (Python Imaging Library) is used as a backend to represent and manipulate images. The PIL adds support for opening, manipulating, processing and saving various image file formats.

img#

A PIL Image object.

Type:

Image.Image

filename#

The image filename.

Type:

str

save(self, path: str, ...) None[source]#

Saves the image under the given filename.

open(cls, path: str, ...) ADSImage[source]#

Opens the given image file.

Examples

>>> from ads.feature_engineering import ADSImage
>>> from IPython.core.display import display
>>> img = ADSImage.open("1.jpg")
>>> img.save("oci://<bucket_name>@<namespace>/1.jpg")
>>> img1 = ADSImage.open("oci://<bucket_name>@<namespace>/1.jpg")
>>> display(img1)

Initializes ADSImage object.

Parameters:
  • img (PIL.Image.Image) – The PIL Image object.

  • filename ((str, optional). Defaults to None.) – The image filename.

Returns:

Nothing.

Return type:

None

Raises:
  • TypeError – If img is not an instance of PIL.Image.Image.

  • ValueError – If img is not provided.

classmethod open(path: str, storage_options: Dict | None = None) ADSImage[source]#

Opens the given image file.

Parameters:
  • path (str) – The file path to open image. Can be local path or OCI object storage URI. Example: oci://<bucket_name>@<namespace>/1.jpg

  • storage_options ((Dict, optional). Defaults to None.) – The default authetication is set using ads.set_auth API. If you need to override the default, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create appropriate authentication signer and kwargs required to instantiate IdentityClient object.

Returns:

The instance of ADSImage.

Return type:

ADSImage

save(path: str, format: str | None = None, auth: Dict | None = None, **kwargs: Dict | None) None[source]#

Save the image under the given filename. If no format is specified, the format to use is determined from the image object or filename extension, if possible.

Parameters:
  • path (str) – The file path to save image. It can be a local path or an Oracle Cloud Infrastructure Object Storage URI. Example: oci://<bucket_name>@<namespace>/1.jpg

  • format ((str, optional). Defaults to None.) – If omitted and path has a file extension the format of the image will be based on the extension. Can be any format supported by PIL Image. The available options are described in the PIL image format documentation: https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html

  • auth ((Dict, optional). Defaults to None.) – The default authentication is set using ads.set_auth() API. To override the default behavior, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create an authentication signer and provide an IdentityClient object.

  • kwargs – Additional keyword arguments that would be passed to the PIL Image save() method.

Returns:

Nothing.

Return type:

None

to_bytes(**kwargs: Dict | None) BytesIO[source]#

Converts image to bytes. If no format is specified, the format to use is determined from the image object if it possible.

Parameters:

kwargs

format: (str, optional). Defaults to None.

If omitted and path has a file extension the format of the image will be based on the extension. Can be any format supported by PIL Image. The available options are described in the PIL image format documentation: https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html

Additional keyword arguments that would be passed to the PIL Image save() method.

Returns:

The image converted to bytes.

Return type:

BytesIO

ads.feature_engineering.adsimage.image_reader module#

The module loads and saves images from/to a local path or Oracle Object Storage.

Classes#

ADSImageReader

The class reads image files from a local path or an Oracle Cloud Infrastructure Object Storage bucket.

Examples

>>> from ads.feature_engineering import ADSImageReader
>>> image_reader = ADSImageReader.from_uri(path="oci://<bucket_name>@<namespace>/*.jpg")
>>> index=1
>>> for image in image_reader.read():
...     image.save(f"{index}.jpg")
...     index+=1
class ads.feature_engineering.adsimage.image_reader.ADSImageReader(reader: Reader)[source]#

Bases: object

The class reads image files from a local path or an Oracle Cloud Infrastructure Object Storage bucket.

from_uri(cls, path: Union[str, List[str]], ...) ADSImageReader[source]#

Constructs the ADSImageReader object.

read(self) Generator[ADSImage, Any, Any][source]#

Reads images.

Examples

>>> from ads.feature_engineering import ADSImageReader
>>> image_reader = ADSImageReader.from_uri(path="oci://<bucket_name>@<namespace>/*.jpg")
>>> index=1
>>> for image in image_reader.read():
...     image.save(f"{index}.jpg")
...     index+=1

Initializes ADSImageReader instance.

Parameters:

reader (Reader) – Can be any reader implementing the `Reader` interface.

Returns:

Nothing.

Return type:

None

classmethod from_uri(path: str | List[str], auth: Dict | None = None) ADSImageReader[source]#

Constructs the ADSImageReader object.

Parameters:
  • path (Union[str, List[str]]) –

    The path where the images located. Can be local path, OCI object storage URI or a list of paths. It is also support globbing. Example:

    oci://<bucket_name>@<namespace>/1.jpg [oci://<bucket_name>@<namespace>/1.jpg, oci://<bucket_name>@<namespace>/2.jpg] oci://<bucket_name>@<namespace>/*.jpg

  • auth ((Dict, optional). Defaults to None.) – The default authetication is set using ads.set_auth API. If you need to override the default, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create appropriate authentication signer and kwargs required to instantiate IdentityClient object.

Returns:

The ADSImageReader object.

Return type:

ADSImageReader

read() Generator[ADSImage, Any, Any][source]#

Read image files.

Yields:

Generator[ADSImage, Any, Any]

class ads.feature_engineering.adsimage.image_reader.ImageFileReader(path: str | List[str], auth: Dict | None = None)[source]#

Bases: object

The class reads image files from a local path or an Oracle Cloud Infrastructure Object Storage bucket.

Initializes ImageFileReader instance.

Parameters:
  • path (Union[str, List[str]]) –

    The path where the images located. Can be local path, OCI object storage URI or a list of paths. It is also support globbing. Example:

    oci://<bucket_name>@<namespace>/1.jpg [oci://<bucket_name>@<namespace>/1.jpg, oci://<bucket_name>@<namespace>/2.jpg] oci://<bucket_name>@<namespace>/*.jpg

  • auth ((Dict, optional). Defaults to None.) – The default authetication is set using ads.set_auth API. If you need to override the default, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create appropriate authentication signer and kwargs required to instantiate IdentityClient object.

Returns:

Nothing.

Return type:

None

Raises:
  • TypeError – If the path is not an instance of str or List[str].

  • ValueError – If the path is not provided.

read() Generator[ADSImage, Any, Any][source]#

Read image files.

Yields:

Generator[ADSImage, Any, Any]

Module contents#