/usr/local/lib/python3.6/site-packages/datasets/features/__pycache__
Edit: /usr/local/lib/python3.6/site-packages/datasets/features/__pycache__/image.cpython-36.pyc (10600B)
3
<%Eg/ @ s@ U d dl Z d dlmZmZ d dlmZ d dlmZmZm Z m
Z
mZmZm
Z
d dlZd dlZddlmZ ddlmZ ddlmZ dd lmZ dd
lmZmZmZ erd dlZddl m!Z! da"eee# "eG d
d dZ$ee# dddZ%de&dddZ'de(dddZ)e
ee# ee( eej* ed f ee( dddZ+dS ) N) dataclassfield)BytesIO)
TYPE_CHECKINGAnyClassVarDictListOptionalUnion )config)xopen)
array_cast)
is_local_path)first_non_null_valueno_op_if_value_is_nullstring_to_dict )FeatureTypec @ s e Zd ZU dZdZedZee dZ e
e ejej
ej dZe
e ed dddZedd Zeeeejdf ed
ddZdedd
d
dZedeedf f dddZeejejejf ejdddZdejeejdddZ dS )Imagea Image feature to read image data from an image file.
Input: The Image feature accepts as input:
- A :obj:`str`: Absolute path to the image file (i.e. random access is allowed).
- A :obj:`dict` with the keys:
- path: String with relative path of the image file to the archive file.
- bytes: Bytes of the image file.
This is useful for archived files with sequential access.
- An :obj:`np.ndarray`: NumPy array representing an image.
- A :obj:`PIL.Image.Image`: PIL image object.
Args:
decode (:obj:`bool`, default ``True``): Whether to decode the image data. If `False`,
returns the underlying dictionary in the format {"path": image_path, "bytes": image_bytes}.
Examples:
```py
>>> from datasets import load_dataset, Image
>>> ds = load_dataset("beans", split="train")
>>> ds.features["image"]
Image(decode=True, id=None)
>>> ds[0]["image"]
>>> ds = ds.cast_column('image', Image(decode=False))
{'bytes': None,
'path': '/root/.cache/huggingface/datasets/downloads/extracted/b0a21163f78769a2cf11f58dfc767fb458fc7cea5c05dccc0144a2c0f0bc1292/train/healthy/healthy_train.85.jpg'}
```
TNzPIL.Image.Image)bytespathF)defaultinitreprc C s | j S )N)pa_type)self r A/usr/local/lib/python3.6/site-packages/datasets/features/image.py__call__C s zImage.__call__)valuereturnc C s t jrddl}ntdt|tr,|ddS t|tjrZ|jj |j
tj}dt|dS t||jjrpt
|S |jddk rtjj|d rd|jddS |jddk s|jddk r|jd|jddS td| d dS )
a Encode example into a format for Arrow.
Args:
value (:obj:`str`, :obj:`np.ndarray`, :obj:`PIL.Image.Image` or :obj:`dict`): Data passed as input to Image feature.
Returns:
:obj:`dict` with "path" and "bytes" fields
r Nz4To support encoding images, please install 'Pillow'.)r r r )r r r zUAn image sample should have one of 'path' or 'bytes' but they are missing or None in .)r
PIL_AVAILABLE PIL.ImageImportError
isinstancestrnpndarrayr fromarrayastypeuint8image_to_bytesencode_pil_imagegetosr isfile
ValueError)r r! PILimager r r encode_exampleF s
zImage.encode_examplec C s | j stdtjrddl}ntd|dkr2i }|d |d }}|dkr|dkrftd| dnt|r||jj |}nx|j
d d }yt|tjd }|j
|} W n tk
r d} Y nX t|d| d
}
t|
j }W dQ R X |jj |}n|jj t|}|j |S )aW Decode example image file into image data.
Args:
value (obj:`str` or :obj:`dict`): a string with the absolute image file path, a dictionary with
keys:
- path: String with absolute or relative image file path.
- bytes: The bytes of the image file.
token_per_repo_id (:obj:`dict`, optional): To access and decode
image files from private repositories on the Hub, you can pass
a dictionary repo_id (str) -> token (bool or str)
Returns:
:obj:`PIL.Image.Image`
zMDecoding is disabled for this feature. Please use Image(decode=True) instead.r Nz4To support decoding images, please install 'Pillow'.r r zCAn image should have one of 'path' or 'bytes' but both are None in r# z::r repo_idrb)use_auth_token)decodeRuntimeErrorr
r$ r% r&