deeplake.core.sample¶
-
class
deeplake.core.sample.Sample¶ -
__init__(path: Optional[str] = None, array: Optional[numpy.ndarray] = None, buffer: Union[bytes, memoryview, None] = None, compression: Optional[str] = None, verify: bool = False, shape: Optional[Tuple[int]] = None, dtype: Optional[str] = None, creds: Optional[Dict] = None, storage: Optional[deeplake.core.storage.provider.StorageProvider] = None)¶ Represents a single sample for a tensor. Provides all important meta information in one place.
Note
If
self.is_lazyisTrue, thisSampledoesn’t actually have any data loaded. To read this data, simply try to read it into a numpy array (sample.array)Parameters: - path (str) – Path to a sample stored on the local file system that represents a single sample. If
pathis provided,arrayshould not be. Implicitly makesself.is_lazy == True. - array (np.ndarray) – Array that represents a single sample. If
arrayis provided,pathshould not be. Implicitly makesself.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
True. - 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.
- path (str) – Path to a sample stored on the local file system that represents a single sample. If
-
array¶ Return numpy array corresponding to the sample. Decompresses the sample if necessary.
Example
>>> 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.
Note
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.Parameters: compression (Optional[str]) – self.arraywill be compressed into this format. IfcompressionisNone, returnuncompressed_bytes().Returns: Bytes for the compressed sample. Contains all metadata required to decompress within these bytes. Return type: bytes Raises: ValueError– On recompression of unsupported formats.
-
pil¶ Return PIL image corresponding to the sample. Decompresses the sample if necessary.
Example
>>> sample = deeplake.read("./images/dog.jpg") >>> pil = sample.pil >>> pil.size (480, 323)
-
uncompressed_bytes() → Optional[bytes]¶ Returns uncompressed bytes.
-