caikit.interfaces.vision.data_model.backends ============================================ .. py:module:: caikit.interfaces.vision.data_model.backends Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/caikit/interfaces/vision/data_model/backends/image_pil_backend/index Classes ------- .. autoapisummary:: caikit.interfaces.vision.data_model.backends.ImagePilBackend Package Contents ---------------- .. py:class:: ImagePilBackend(image_data: PIL_SOURCE_TYPES) Bases: :py:obj:`caikit.core.data_model.data_backends.DataModelBackendBase` A base interface class for accessing data from within a given backend data layout .. py:attribute:: _image_data .. py:attribute:: _export_format .. py:method:: get_attribute(data_model_class: caikit.core.data_model.base.DataBase, name: str) -> Any A data model backend must implement this in order to provide the frontend view the functionality needed to lazily extract data. Args: data_model_class (Type[DataBase]): The frontend data model class that is accessing this attribute name (str): The name of the attribute to access Returns: value: Union[Any, OneofFieldVal] The extracted attribute value or a OneofFieldVal that wraps the field val with an indicator about the oneof field that is set. .. py:method:: coerce_to_pil(image_data: PIL_SOURCE_TYPES) -> PIL.Image :classmethod: Given an object representing an image in a wide variety of formats, force it into a PIL image representation. Supported formats: - [PIL.Image.Image] loaded PIL image; this is a no-op - [str] path to an image on disk to be loaded - [pathlib.PosixPath] path to an image on disk to be loaded - [np.ndarray] Numpy array of type uint8 - [bytes] Image loaded into a bytes object Args: image_data: Raw data object to be coerced to a PIL image. Returns: PILImage.Image PIL image representation of the provided image data. .. py:method:: _coerce_from_numpy(image_data: numpy.ndarray) -> PIL.Image.Image :staticmethod: Given image data as a Numpy array, load it as a PIL image. Args: image_data: np.ndarray Numpy array representing an image (uint8). Returns: PIL.Image.Image PIL image representation of the numpy array. .. py:method:: _coerce_from_path(image_data: Union[str, pathlib.PosixPath]) -> PIL.Image :classmethod: Given a str, which we assume to be a path to an image on disk, or a Pathlib object, try to load it as a PIL image. Args: image_data: Union[pathlib.PosixPath, str] Path to be loaded. Returns: PIL.Image.Image PIL image representation of the image loaded from disk. .. py:method:: _coerce_from_bytes(image_data: bytes) -> PIL.Image :staticmethod: Given bytes, which we assume to represent a full image, try to load it as a PIL image. Args: image_data: bytes binary data to be loaded as a PIL image. Returns: PIL.Image.Image PIL image representation of the bytes object. .. py:method:: as_numpy() -> numpy.ndarray Zero-copy method to produce the PIL image as a numpy array. Returns: np.ndarray Numpy array representation of the PIL image data. .. py:method:: as_pil() -> PIL.Image.Image Return a handle to our PIL image. Returns: PIL.Image.Image PIL image representation of this data model object.