snntoolbox.datasets

The modules in this package provide functionality to load and process datasets into the SNN conversion toolbox.

snntoolbox.datasets.utils

The main purpose of this module is to load a dataset from disk and feed it to the toolbox in one of the formats it can handle.

For details see

get_dataset Get dataset, either from .npz files or keras.ImageDataGenerator.

@author: rbodo

snntoolbox.datasets.utils.get_dataset(config)[source]

Get dataset, either from .npz files or keras.ImageDataGenerator.

Returns Dictionaries with keys x_test and y_test if data set was loaded in .npz format, or with dataflow key if data will be loaded from .jpg, .png, or .bmp files by a keras.ImageDataGenerator.

Parameters:config (configparser.ConfigParser) – Settings.
Returns:
  • normset (dict) – Used to normalized the network parameters.
  • testset (dict) – Used to test the networks.
snntoolbox.datasets.utils.try_get_normset_from_scalefacs(config)[source]

Instead of loading a normalization data set to calculate scale-factors, try to get the scale-factors stored on disk during a previous run.

Parameters:config (configparser.ConfigParser) – Settings.
Returns:A dictionary with single key ‘scale_facs’. The corresponding value is itself a dictionary containing the scale factors for each layer. Returns None if no scale factors were found.
Return type:Union[dict, None]
snntoolbox.datasets.utils.to_categorical(y, nb_classes)[source]

Convert class vector to binary class matrix.

If the input y has shape (nb_samples,) and contains integers from 0 to nb_classes, the output array will be of dimension (nb_samples, nb_classes).

snntoolbox.datasets.utils.load_npz(path, filename)[source]

Load dataset from an .npz file.

Parameters:
  • filename (string) – Name of file.
  • path (string) – Location of dataset to load.
Returns:

The dataset as a numpy array containing samples.

Return type:

tuple[np.array]