Hi! I am new to using NengoDL and am working through a conversion example, using a pre-trained Keras VGG16 model. Following the converter examples from the NengoDL documentation, I am able to convert the model without issue. However, when I attempt to simulate on Google Colab, which should have over 10GB of RAM, the runtime quickly runs through the memory and promptly crashes. The main code steps are included below.
Do you have any recommendations for converting a model, such as VGG16 to SNN? Verifying using the Converter.verify() function also resulted in the following mismatch:
ValueError Traceback (most recent call last)
in ()
----> 1 converter.verify()
/usr/local/lib/python3.6/dist-packages/nengo_dl/converter.py in verify(self, training, inputs, atol, rtol)
272 logger.info(“Nengo:\n%s”, nengo_vals[fails])
273 raise ValueError(
–> 274 "Output of Keras model does not match output of converted "
275 “Nengo network”
276 )
ValueError: Output of Keras model does not match output of converted Nengo network
Thank you kindly for your help and insight!
%matplotlib inline
from urllib.request import urlretrieve
import nengo
%tensorflow_version 2.x
import tensorflow as tf
device_name = tf.test.gpu_device_name()
# Set through Edit > Notebook Settings > Enable GPU
if device_name != '/device:GPU:0':
raise SystemError('GPU device not found')
print('Found GPU at: {}'.format(device_name))
import numpy as np
import matplotlib.pyplot as plt
import nengo_dl
from tensorflow.keras.applications import vgg16
vgg_model = vgg16.VGG16(weights='imagenet')
(train_images, train_labels), (test_images, test_labels) = (
tf.keras.datasets.mnist.load_data())
# flatten images
train_images = train_images.reshape((train_images.shape[0], -1))
test_images = test_images.reshape((test_images.shape[0], -1))
for i in range(3):
plt.figure()
plt.imshow(np.reshape(train_images[i], (28, 28)),
cmap="gray")
plt.axis('off')
plt.title(str(train_labels[i]));
from keras.activations import softmax, relu, sigmoid
# Change activiation function to ReLU since SNN does not support Softmax
vgg_model.layers[-1].activation = relu
converter = nengo_dl.Converter(vgg_model,max_to_avg_pool=True,swap_activations={tf.keras.activations.relu: nengo.SpikingRectifiedLinear()})
converter.verify()
minibatch_size = 64
with nengo_dl.Simulator(converter.net, minibatch_size=minibatch_size) as sim:
sim.step()