Classes and utilities for doing deep learning with Nengo.
Warning
These utilities were created before Nengo DL, which provides tighter integration between Nengo and TensorFlow. If you are new to Nengo or new to doing deep learning in Nengo, we recommend that you first check out Nengo DL to see if it fits your use case.
The following functions make use of Nengo’s RC file to set the location for data downloads. See the Nengo configuration documentation for instructions of editing RC files. Configuration settings are listed below.
[nengo_extras]
# directory to store downloaded datasets
data_dir = ~/data
nengo_extras.data.get_cifar10_tar_gz () |
|
nengo_extras.data.get_cifar100_tar_gz () |
|
nengo_extras.data.get_ilsvrc2012_tar_gz () |
|
nengo_extras.data.get_mnist_pkl_gz () |
|
nengo_extras.data.get_svhn_tar_gz () |
|
nengo_extras.data.get_svhn_tar_gz () |
|
nengo_extras.data.load_cifar10 ([filepath, …]) |
Load the CIFAR-10 dataset. |
nengo_extras.data.load_cifar100 ([filepath, …]) |
Load the CIFAR-100 dataset. |
nengo_extras.data.load_ilsvrc2012 ([…]) |
Load part of the ILSVRC 2012 (ImageNet) dataset. |
nengo_extras.data.load_mnist ([filepath, …]) |
Load the MNIST dataset. |
nengo_extras.data.load_svhn ([filepath, …]) |
Load the SVHN dataset. |
nengo_extras.data.spasafe_name (name[, …]) |
Make a name safe to use as a SPA semantic pointer name. |
nengo_extras.data.spasafe_names (label_names) |
Make names safe to use as SPA semantic pointer names. |
nengo_extras.data.one_hot_from_labels (labels) |
Turn integer labels into a one-hot encoding. |
nengo_extras.data.ZCAWhiten ([beta, gamma]) |
ZCA Whitening |
nengo_extras.data.
get_svhn_tar_gz
()[source]nengo_extras.data.
load_cifar10
(filepath=None, n_train=5, n_test=1, label_names=False)[source]¶Load the CIFAR-10 dataset.
Parameters: | filepath : str (optional, Default: None)
n_train : int (optional, Default: 6)
n_test : int (optional, Default: 6)
label_names : boolean (optional, Default: False)
|
---|---|
Returns: | train_set : (n_train, n_pixels) ndarray, (n_train,) ndarray
test_set : (n_test, n_pixels) ndarray, (n_test,) ndarray
label_names : list
|
nengo_extras.data.
load_cifar100
(filepath=None, fine_labels=True, label_names=False)[source]¶Load the CIFAR-100 dataset.
Parameters: | filepath : str (optional, Default: None)
fine_labels : boolean (optional, Default: True)
label_names : boolean (optional, Default: False)
|
---|---|
Returns: | train_set : (n_train, n_pixels) ndarray, (n_train,) ndarray
test_set : (n_test, n_pixels) ndarray, (n_test,) ndarray
label_names : list
|
nengo_extras.data.
load_ilsvrc2012
(filepath=None, n_files=None)[source]¶Load part of the ILSVRC 2012 (ImageNet) dataset.
This loads a small section of the ImageNet Large Scale Visual Recognition Challenge (ILSVRC) 2012 dataset. The images are from the test portion of the dataset, and can be used to test pretrained classifiers.
Parameters: | filepath : str (optional, Default: None)
n_files : int (optional, Default: None)
|
---|---|
Returns: | images : (n_images, nc, ny, nx) ndarray
labels : (n_images,) ndarray
data_mean : (nc, ny, nx) ndarray
label_names : list
|
nengo_extras.data.
load_mnist
(filepath=None, validation=False)[source]¶Load the MNIST dataset.
Parameters: | filepath : str (optional, Default: None)
validation : boolean (optional, Default: False)
|
---|---|
Returns: | train_set : (n_train, n_pixels) ndarray, (n_train,) ndarray
validation_set : (n_valid, n_pixels) ndarray, (n_valid,) ndarray
test_set : (n_test, n_pixels) ndarray, (n_test,) ndarray
|
nengo_extras.data.
load_svhn
(filepath=None, n_train=9, n_test=3, data_mean=False, label_names=False)[source]¶Load the SVHN dataset.
Parameters: | filepath : str (optional, Default: None)
n_train : int (optional, Default: 6)
n_test : int (optional, Default: 6)
label_names : boolean (optional, Default: False)
|
---|---|
Returns: | train_set : (n_train, n_pixels) ndarray, (n_train,) ndarray
test_set : (n_test, n_pixels) ndarray, (n_test,) ndarray
label_names : list
|
nengo_extras.data.
spasafe_name
(name, pre_comma_only=True)[source]¶Make a name safe to use as a SPA semantic pointer name.
Ensure a name conforms with SPA name standards. Replaces hyphens and spaces with underscores, removes all other characters, and makes the first letter uppercase.
Parameters: | pre_comma_only : boolean
|
---|
nengo_extras.data.
spasafe_names
(label_names, pre_comma_only=True)[source]¶Make names safe to use as SPA semantic pointer names.
Format a list of names to conform with SPA name standards. In addition
to running each name through spasafe_name
, this function numbers
duplicate names so they are unique.
Parameters: | pre_comma_only : boolean
|
---|
nengo_extras.data.
one_hot_from_labels
(labels, classes=None, dtype=<class 'float'>)[source]¶Turn integer labels into a one-hot encoding.
Parameters: | labels : (n,) array
classes : int or (n_classes,) array (optional)
dtype : dtype (optional)
|
---|
nengo_extras.keras.SoftLIF ([sigma, …]) |
|
nengo_extras.keras.load_model_pair (filepath) |
|
nengo_extras.keras.save_model_pair (model, …) |
|
nengo_extras.keras.LSUVinit (kmodel, X[, …]) |
Layer-sequential unit-variance initialization. |
nengo_extras.deepnetworks.
NeuronLayer
(n, neuron_type=Default, synapse=Default, gain=1.0, bias=0.0, amplitude=1.0, **kwargs)[source]¶nengo_extras.deepnetworks.
LocalLayer
(input_shape, filters, biases, strides=1, padding=0, **kwargs)[source]¶nengo_extras.deepnetworks.
ConvLayer
(input_shape, filters, biases, strides=1, padding=0, border='ceil', **kwargs)[source]¶nengo_extras.convnet.
Conv2d
(shape_in, filters, biases=None, strides=1, padding=0, border='ceil')[source]¶Perform 2-D (image) convolution on an input.
Parameters: | shape_in : 3-tuple (n_channels, height, width)
filters : array_like (n_filters, n_channels, f_height, f_width)
biases : array_like (1,) or (n_filters,) or (n_filters, height, width)
strides : 2-tuple (vertical, horizontal) or int
padding : 2-tuple (vertical, horizontal) or int
|
---|
nengo_extras.convnet.
Pool2d
(shape_in, pool_size, strides=None, kind='avg', mode='full')[source]¶Perform 2-D (image) pooling on an input.
Parameters: | shape_in : 3-tuple (channels, height, width)
pool_size : 2-tuple (vertical, horizontal) or int
strides : 2-tuple (vertical, horizontal) or int
kind : “avg” or “max”
mode : “full” or “valid”
|
---|
Attributes
shape_out | (3-tuple (channels, height, width)) Shape of the output image. |