snntorch.utils
snntorch.utils
contains a handful of utility functions for handling datasets.
- snntorch.utils.data_subset(dataset, subset, idx=0)[source]
Partition the dataset by a factor of
1/subset
without removing access to data and target attributes.Example:
from snntorch import utils from torchvision import datasets data_path = "path/to/data" subset = 10 # Download MNIST training set mnist_train = datasets.MNIST(data_path, train=True, download=True) print(len(mnist_train)) >>> 60000 # Reduce size of MNIST training set utils.data_subset(mnist_train, subset) print(len(mnist_train)) >>> 6000
- Parameters:
dataset (torchvision dataset) – Dataset
subset (int) – Factor to reduce dataset by
idx (int, optional) – Which subset of the train and test sets to index into, defaults to
0
- Returns:
Partitioned dataset
- Return type:
list of torch.utils.data
- snntorch.utils.reset(net)[source]
Check for the types of LIF neurons contained in net. Reset their hidden parameters to zero and detach them from the current computation graph.
- snntorch.utils.valid_split(ds_train, ds_val, split, seed=0)[source]
Randomly split a dataset into non-overlapping new datasets of given lengths. Optionally fix the generator for reproducible results. Operates similarly to
random_split
fromtorch.utils.data.dataset
but retains data and target attributes.Example
from snntorch import utils from torchvision import datasets data_path = "path/to/data" val_split = 0.1 # Download MNIST training set into mnist_val and mnist_train mnist_train = datasets.MNIST(data_path, train=True, download=True) mnist_val = datasets.MNIST(data_path, train=True, download=True) print(len(mnist_train)) >>> 60000 print(len(mnist_val)) >>> 60000 # Validation split mnist_train, mnist_val = utils.valid_split(mnist_train, mnist_val, val_split) print(len(mnist_train)) >>> 54000 print(len(mnist_val)) >>> 6000
- Parameters:
ds_train (torchvision dataset) – Training set
ds_val (torchvision dataset) – Validation set
split (Float) – Proportion of samples assigned to the validation set from the training set
seed (int, optional) – Fix to generate reproducible results, defaults to
0
- Returns:
Randomly split train and validation sets
- Return type:
list of torch.utils.data