Skip to content

dataset

sorix.utils.data.dataset

Dataset

Dataset(X, y=None, transform=None, target_transform=None)

Base class for all datasets in Sorix.

Inspired by PyTorch's Dataset API, it provides a standard way to wrap data and apply transformations during retrieval.

Parameters:

  • X (Any) –

    Feature data (NumPy array, list, etc.).

  • y (Any, default: None ) –

    Target data (optional).

  • transform (Optional[Callable], default: None ) –

    A function/transform that takes in a sample and returns a transformed version.

  • target_transform (Optional[Callable], default: None ) –

    A function/transform that takes in the target and transforms it.

Source code in sorix/utils/data/dataset.py
def __init__(
    self, 
    X: Any, 
    y: Any = None, 
    transform: Optional[Callable] = None, 
    target_transform: Optional[Callable] = None
):
    if y is not None and len(X) != len(y):
        raise ValueError(f"X and y must have the same length. Got len(X)={len(X)} and len(y)={len(y)}")
    self.X = X
    self.y = y
    self.transform = transform
    self.target_transform = target_transform