def test_mnist_pipeline(self): network = DiehlAndCook2015(n_inpt=784, n_neurons=400, exc=22.5, inh=17.5, dt=1.0, norm=78.4) environment = DatasetEnvironment(dataset=MNIST(path='../data/MNIST', download=True), train=True, intensity=0.25) pipeline = Pipeline(network=network, environment=environment, encoding=poisson, time=350) assert pipeline.network == network assert pipeline.env == environment assert pipeline.encoding == poisson assert pipeline.time == 350 assert pipeline.history_length is None
from bindsnet.encoding import poisson from bindsnet.pipeline import Pipeline from bindsnet.models import DiehlAndCook2015 from bindsnet.environment import DatasetEnvironment # Build network. network = DiehlAndCook2015(n_input=32 * 32 * 3, n_neurons=100, dt=1.0, exc=22.5, inh=17.5, nu=[0, 1e-2], norm=78.4) # Specify dataset wrapper environment. environment = DatasetEnvironment(dataset=CIFAR10(path='../../data/CIFAR10'), train=True) # Build pipeline from components. pipeline = Pipeline(network=network, environment=environment, encoding=poisson, time=50, plot_interval=1) # Train the network. labels = environment.labels for i in range(60000): # Choose an output neuron to clamp to spiking behavior. c = choice(10, size=1, replace=False) c = 10 * labels[i].long() + Tensor(c).long() clamp = torch.zeros(pipeline.time, network.n_neurons, dtype=torch.uint8)
n_sqrt = int(np.ceil(np.sqrt(n_neurons))) path = os.path.join('..', '..', 'data', 'CIFAR10') # Build network. network = DiehlAndCook2015(n_inpt=32 * 32 * 3, n_neurons=n_neurons, exc=exc, inh=inh, dt=dt, nu_pre=2e-5, nu_post=2e-3, norm=10.0) # Initialize data "environment". environment = DatasetEnvironment(dataset=CIFAR10(path=path, download=True), train=train, time=time, intensity=intensity) # Specify data encoding. encoding = poisson spikes = {} for layer in set(network.layers): spikes[layer] = Monitor(network.layers[layer], state_vars=['s'], time=time) network.add_monitor(spikes[layer], name='%s_spikes' % layer) voltages = {} for layer in set(network.layers) - {'X'}: voltages[layer] = Monitor(network.layers[layer], state_vars=['v'], time=time)
from bindsnet.encoding import poisson from bindsnet.pipeline import Pipeline from bindsnet.models import DiehlAndCook2015 from bindsnet.environment import DatasetEnvironment # Build Diehl & Cook 2015 network. network = DiehlAndCook2015(n_inpt=784, n_neurons=400, exc=22.5, inh=17.5, dt=1.0, norm=78.4) # Specify dataset wrapper environment. environment = DatasetEnvironment(dataset=MNIST(path='../../data/MNIST'), train=True, download=True, intensity=0.25) # Build pipeline from components. pipeline = Pipeline(network=network, environment=environment, encoding=poisson, time=350, plot_interval=1) # Train the network. for i in range(60000): pipeline.step() network._reset()
from bindsnet.encoding import poisson from bindsnet.pipeline import Pipeline from bindsnet.models import DiehlAndCook2015 from bindsnet.environment import DatasetEnvironment # Build Diehl & Cook 2015 network. network = DiehlAndCook2015(n_inpt=32 * 32 * 3, n_neurons=400, exc=22.5, inh=17.5, dt=1.0, norm=78.4) # Specify dataset wrapper environment. environment = DatasetEnvironment(dataset=CIFAR10(path='../../data/CIFAR10', download=True), train=True, intensity=0.25) # Build pipeline from components. pipeline = Pipeline(network=network, environment=environment, encoding=poisson, time=350, plot_interval=1) # Train the network. for i in range(60000): pipeline.step() network._reset()