Data#
Classes#
- class Data(data, uncertainty=None)[source]#
-
Stores data with uncertainties for uncertainty handling in BaseArchitecture.
- static collate(data, *, data_field=True)[source]#
Collates a list of Data objects into a single Data object.
- Overloads:
- __len__()[source]#
Returns the number of samples in the data.
- Returns:
intNumber of samples in the data
- apply(func, *args, types=(<class 'torch.Tensor'>, <class 'numpy.ndarray'>), **kwargs)[source]#
Applies a function or method to the data and uncertainty.
- Parameters:
- func
str|ApplyFunc[ArrayCT] Function, or method if string, to apply to the data and uncertainty
- *args
Arguments to pass to the function or method
- types
tuple[type[ArrayLike], …] Types to apply the function or method to, if data and uncertainty is not an instance of types, then data and uncertainty are returned unchanged, default = (Tensor, ndarray)
- **kwargs
Keyword arguments to pass to the function or method
- func
- Returns:
SelfSelf with function or method applied to the data and uncertainty
- copy()#
Clones the data and uncertainty.
Identical to Data.copy().
- cpu()[source]#
Moves data and uncertainty to CPU if they are Tensors.
- Returns:
SelfSelf with data and uncertainty on CPU
- detach()[source]#
Detaches data and uncertainty from the computation graph if they are Tensors.
- Returns:
SelfSelf with data and uncertainty detached from the computation graph
- to(*args, **kwargs)[source]#
See
torch.nn.Module.to().
- class DataList(data)[source]#
-
A list that stores tensors, arrays, or Datas and provides batch operations.
- static collate(data, *, data_field=True)[source]#
Collates a list of DataList objects into a single DataList object.
- Overloads:
- __len__()[source]#
Returns the number of samples in each element.
- Returns:
intNumber of samples in each element
- append(data)[source]#
Appends an element to the DataList.
- Parameters:
- data
DataT Element to append to the DataList
- data
- apply(func, *args, types=(<class 'netloader.data.Data'>, <class 'torch.Tensor'>, <class 'numpy.ndarray'>), **kwargs)[source]#
Applies a function or method to each element in the DataList.
- Parameters:
- func
str|Sequence[str|ApplyFunc[ArrayT]] |ApplyFunc[DataT] Function(s), or method(s) if string, to apply to each element in the DataList
- *args
Arguments to pass to the function or method
- types
tuple[type[DataLike], …] Types to apply the function or method to, if an element is not an instance of types, then that element is returned unchanged, default = (Data, Tensor, ndarray)
- **kwargs
Keyword arguments to pass to the function or method
- func
- Returns:
SelfSelf with function or method applied to each element in the DataList
- detach()[source]#
Detaches all tensors from the computation graph
- Returns:
SelfSelf with all tensors detached from the computation graph
- get(idx, list_=False)[source]#
Gets a subset of the DataList or a subset of each element in the DataList.
- Overloads:
- iter(list_=True)[source]#
Iterates over each element in the DataList.
- Overloads:
- iter(self, list_: Literal[True]) Iterator[DataT]
- len(list_=True)[source]#
Gets the length of the DataList or the length of each element in the DataList.
- to(*args, **kwargs)[source]#
See
torch.nn.Module.to().
- class BaseDataset(*args, **kwargs)[source]#
Bases:
Dataset[tuple[int,DataListT,DataListT,Any]],Generic[DataListT]Base dataset class for use with BaseNetwork.
- Attributes:
- extra
list[Any] |ArrayLike|NoneType Additional data for each sample in the dataset of length N with shape (N,…) and type Any
- idxs
ndarray Index for each sample in the dataset with shape (N) and type int
- low_dim
DataListT|NoneType Low dimensional data for each sample in the dataset with shape (N,…)
- high_dim
DataListT|NoneType High dimensional data for each sample in the dataset with shape (N,…), this is required
- extra
- __len__()[source]#
Returns the number of samples in the dataset
- Returns:
intNumber of samples in the dataset
- get_extra(idx)[source]#
Gets extra data for the sample of the given index
- Parameters:
- idx
int Sample index
- idx
- Returns:
AnySample extra data
Functions#
- data_collation(data, *, data_field=True)[source]#
Collates a list of ArrayLike, Data, or DataList objects into a single object.
- Overloads:
- Parameters:
- Returns:
- loader_init(dataset, *, return_idxs=False, batch_size=64, ratios=None, idxs=None, **kwargs)[source]#
Initialises data loaders from a subset of the dataset with the given ratios.
- Overloads:
- loader_init(dataset: DatasetT, *, return_idxs: Literal[False], batch_size: int = ..., ratios: list[float] | tuple[float, ...] | None = ..., idxs: list[numpy.ndarray] | tuple[numpy.ndarray, ...] | numpy.ndarray | None = ..., **kwargs: Any) tuple[torch.utils.data.dataloader.DataLoader[tuple[int, DataListT, DataListT, Any]], ...]
- loader_init(dataset: DatasetT, *, return_idxs: Literal[True], batch_size: int = ..., ratios: list[float] | tuple[float, ...] | None = ..., idxs: list[numpy.ndarray] | tuple[numpy.ndarray, ...] | numpy.ndarray | None = ..., **kwargs: Any) tuple[tuple[torch.utils.data.dataloader.DataLoader[tuple[int, DataListT, DataListT, Any]], ...], tuple[Sequence[int], ...]]
- Parameters:
- dataset
DatasetT Dataset to create data loaders from
- return_idxsbool,
Optional If the indexes for each data loader should be returned, default = False
- batch_size
int,Optional Batch size when sampling from the data loaders, default = 64
- ratios
list[float] |tuple[float, …] |NoneType,Optional Ratios of length M to split up the dataset into subsets, if idxs is provided, dataset will first be split up using idxs and ratios will be used on the remaining samples, default = (0.8,0.2)
- idxs
list[ndarray] |tuple[ndarray, …] |ndarray|NoneType,Optional Dataset indexes for creating the subsets with shape (N,S), where N is the number of subsets and S is the number of samples in each subset
- **kwargs
Any Optional keyword arguments to pass to DataLoader
- dataset
- Returns:
Types#
Protocols#
- class ApplyFunc(*args, **kwargs)[source]#
Bases:
Protocol[InArrayT_contra,P,OutArrayT_co]Protocol for functions that can be applied to Data objects in the apply method of Data and DataList.