CIFAR-10 in the 'Converting a Keras model to an SNN on Loihi" Notebook

I want to import the CIFAR-10 dataset into the ‘Converting a Keras Model to an SNN on Loihi’ notebook.
It uploads ok, but when I try to train the model, I get an error reading “input data: should have rank 3 (batch_size, n_steps, dimensions), found rank 4”. I know there is an example on using the CIFAR-10 Dataset in a Convolutional Network, but I want to use it in this notebook since I need to be able to see the epoch time and accuracies. How do I get this dataset to work with the Keras to SNN example notebook?

Without knowing the exact code you are using, I cannot comment as to why you are encountering this issue. My guess would be no more helpful than the error message, which is to say that the data you provided to the model is incorrectly shaped.

The CIFAR-10 Loihi notebook also allows you to see the training epoch time and accuracies. To see the training epoch time, you will need to enable training (cell 8, do_training = True). As for the accuracies, cell 10 displays the accuracies for a test run.

From my experimentation, the conversion is pretty straight forward. First, loading the dataset is the same as with the MNIST dataset:

(
    (train_images, train_labels),
    (test_images, test_labels),
) = tf.keras.datasets.cifar10.load_data()

Next, we take note of the shape of the image data:

print(train_images[0].shape)  # should print (32, 32, 3)

Most of the remaining code in the Keras-to-Loihi notebook is unchanged, save for the code that works with the images, or plots the images. As examples:

# The MNIST code
for i in range(3):
    plt.subplot(1, 3, i + 1)
    plt.imshow(np.reshape(train_images[i], (28, 28)), cmap="gray")
    plt.axis("off")
    plt.title(str(train_labels[i, 0, 0]))

# The equivalent CIFAR-10 code:
for i in range(3):
    plt.subplot(1, 3, i + 1)
    plt.imshow(np.reshape(train_images[i], (32, 32, 3)), cmap="gray")
    plt.axis("off")
    plt.title(str(train_labels[i, 0, 0]))

For the Keras model:

# The MNIST code
inp = tf.keras.Input(shape=(28, 28, 1), name="input")

# The equivalent CIFAR-10 code:
inp = tf.keras.Input(shape=(32, 32, 3), name="input")