- class deeplake.core.sample.Sample¶
- __init__(path: str | None = None, array: ndarray | None = None, buffer: bytes | memoryview | None = None, compression: str | None = None, verify: bool = False, shape: Tuple[int] | None = None, dtype: str | None = None, creds: Dict | None = None, storage: StorageProvider | None = None)¶
Represents a single sample for a tensor. Provides all important meta information in one place.
Sampledoesn’t actually have any data loaded. To read this data, simply try to read it into a numpy array (sample.array)
path (str) – Path to a sample stored on the local file system that represents a single sample. If
arrayshould not be. Implicitly makes
self.is_lazy == True.
array (np.ndarray) – Array that represents a single sample. If
pathshould not be. Implicitly makes
self.is_lazy == False.
buffer – (bytes): Byte buffer that represents a single sample. If compressed,
compressionargument should be provided.
compression (str) – Specify in case of byte buffer.
verify (bool) – If a path is provided, verifies the sample if
shape (Tuple[int]) – Shape of the sample.
dtype (optional, str) – Data type of the sample.
creds (optional, Dict) – Credentials for s3, gcp and http urls.
storage (optional, StorageProvider) – Storage provider.
ValueError – Cannot create a sample from both a
- property array: ndarray¶
Return numpy array corresponding to the sample. Decompresses the sample if necessary.
>>> sample = deeplake.read("./images/dog.jpg") >>> arr = sample.array >>> arr.shape (323, 480, 3)
- compressed_bytes(compression: str | None) bytes ¶
Returns this sample as compressed bytes.
If this sample is pointing to a path and the requested
compressionis the same as it’s stored in, the data is returned without re-compressing.
compression (Optional[str]) –
self.arraywill be compressed into this format. If
Bytes for the compressed sample. Contains all metadata required to decompress within these bytes.
- Return type:
ValueError – On recompression of unsupported formats.
- property pil: Image¶
Return PIL image corresponding to the sample. Decompresses the sample if necessary.
>>> sample = deeplake.read("./images/dog.jpg") >>> pil = sample.pil >>> pil.size (480, 323)
- uncompressed_bytes() bytes | None ¶
Returns uncompressed bytes.