- class deeplake.core.sample.Sample
- __init__(path: Optional[str] = None, array: Optional[ndarray] = None, buffer: Optional[Union[bytes, memoryview]] = None, compression: Optional[str] = None, verify: bool = False, shape: Optional[Tuple[int]] = None, dtype: Optional[str] = None, creds: Optional[Dict] = None, storage: Optional[StorageProvider] = 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.
- 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: Optional[str]) 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() Optional[bytes]
Returns uncompressed bytes.