Akida vision edge learning

This tutorial demonstrates the Akida NSoC edge learning capabilities using its built-in learning algorithm. It focuses on an image classification example, where an existing Akida network is re-trained to be able to classify images from 4 new classes.

Just a few samples (few-shot learning) of the new classes are sufficient to augment the Akida model with extra classes, while preserving high accuracy.

Please refer to the keyword spotting (KWS) tutorial for edge learning documentation, parameters fine tuning and steps details.

1. Dataset preparation

from akida import FullyConnected

import tensorflow_datasets as tfds

# Retrieve TensorFlow `coil100 <https://www.tensorflow.org/datasets/catalog/coil100>`__
# dataset
ds, ds_info = tfds.load('coil100:2.*.*', split='train', with_info=True)
print(ds_info.description)

Out:

Downloading and preparing dataset 124.63 MiB (download: 124.63 MiB, generated: 124.74 MiB, total: 249.37 MiB) to /root/tensorflow_datasets/coil100/2.0.0...

Dl Completed...: 0 url [00:00, ? url/s]

Dl Size...: 0 MiB [00:00, ? MiB/s]


Extraction completed...: 0 file [00:00, ? file/s]
Dl Completed...:   0%|          | 0/1 [00:00<?, ? url/s]

Dl Size...: 0 MiB [00:00, ? MiB/s]


Extraction completed...: 0 file [00:00, ? file/s]
Dl Completed...:   0%|          | 0/1 [00:00<?, ? url/s]

Dl Size...:   0%|          | 0/124 [00:00<?, ? MiB/s]


Extraction completed...: 0 file [00:00, ? file/s]

Dl Size...:   1%|          | 1/124 [00:01<02:35,  1.27s/ MiB]
Dl Completed...:   0%|          | 0/1 [00:01<?, ? url/s]

Dl Size...:   1%|          | 1/124 [00:01<02:35,  1.27s/ MiB]


Extraction completed...: 0 file [00:01, ? file/s]

Dl Size...:   2%|1         | 2/124 [00:01<01:38,  1.24 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:01<?, ? url/s]

Dl Size...:   2%|1         | 2/124 [00:01<01:38,  1.24 MiB/s]


Extraction completed...: 0 file [00:01, ? file/s]

Dl Size...:   2%|2         | 3/124 [00:02<01:17,  1.56 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:02<?, ? url/s]

Dl Size...:   2%|2         | 3/124 [00:02<01:17,  1.56 MiB/s]


Extraction completed...: 0 file [00:02, ? file/s]

Dl Size...:   3%|3         | 4/124 [00:02<01:10,  1.70 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:02<?, ? url/s]

Dl Size...:   3%|3         | 4/124 [00:02<01:10,  1.70 MiB/s]


Extraction completed...: 0 file [00:02, ? file/s]

Dl Size...:   4%|4         | 5/124 [00:03<01:10,  1.70 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:03<?, ? url/s]

Dl Size...:   4%|4         | 5/124 [00:03<01:10,  1.70 MiB/s]


Extraction completed...: 0 file [00:03, ? file/s]

Dl Size...:   5%|4         | 6/124 [00:03<01:07,  1.74 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:03<?, ? url/s]

Dl Size...:   5%|4         | 6/124 [00:03<01:07,  1.74 MiB/s]


Extraction completed...: 0 file [00:03, ? file/s]

Dl Size...:   6%|5         | 7/124 [00:04<01:05,  1.80 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:04<?, ? url/s]

Dl Size...:   6%|5         | 7/124 [00:04<01:05,  1.80 MiB/s]


Extraction completed...: 0 file [00:04, ? file/s]

Dl Size...:   6%|6         | 8/124 [00:04<01:03,  1.84 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:04<?, ? url/s]

Dl Size...:   6%|6         | 8/124 [00:04<01:03,  1.84 MiB/s]


Extraction completed...: 0 file [00:04, ? file/s]

Dl Size...:   7%|7         | 9/124 [00:05<01:01,  1.87 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:05<?, ? url/s]

Dl Size...:   7%|7         | 9/124 [00:05<01:01,  1.87 MiB/s]


Extraction completed...: 0 file [00:05, ? file/s]

Dl Size...:   8%|8         | 10/124 [00:05<01:00,  1.89 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:05<?, ? url/s]

Dl Size...:   8%|8         | 10/124 [00:05<01:00,  1.89 MiB/s]


Extraction completed...: 0 file [00:05, ? file/s]

Dl Size...:   9%|8         | 11/124 [00:06<00:59,  1.91 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:06<?, ? url/s]

Dl Size...:   9%|8         | 11/124 [00:06<00:59,  1.91 MiB/s]


Extraction completed...: 0 file [00:06, ? file/s]

Dl Size...:  10%|9         | 12/124 [00:06<00:58,  1.92 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:06<?, ? url/s]

Dl Size...:  10%|9         | 12/124 [00:06<00:58,  1.92 MiB/s]


Extraction completed...: 0 file [00:06, ? file/s]

Dl Size...:  10%|#         | 13/124 [00:07<00:57,  1.94 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:07<?, ? url/s]

Dl Size...:  10%|#         | 13/124 [00:07<00:57,  1.94 MiB/s]


Extraction completed...: 0 file [00:07, ? file/s]

Dl Size...:  11%|#1        | 14/124 [00:07<00:55,  1.97 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:07<?, ? url/s]

Dl Size...:  11%|#1        | 14/124 [00:07<00:55,  1.97 MiB/s]


Extraction completed...: 0 file [00:07, ? file/s]

Dl Size...:  12%|#2        | 15/124 [00:08<00:53,  2.03 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:08<?, ? url/s]

Dl Size...:  12%|#2        | 15/124 [00:08<00:53,  2.03 MiB/s]


Extraction completed...: 0 file [00:08, ? file/s]

Dl Size...:  13%|#2        | 16/124 [00:08<00:52,  2.05 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:08<?, ? url/s]

Dl Size...:  13%|#2        | 16/124 [00:08<00:52,  2.05 MiB/s]


Extraction completed...: 0 file [00:08, ? file/s]

Dl Size...:  14%|#3        | 17/124 [00:09<00:50,  2.11 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:09<?, ? url/s]

Dl Size...:  14%|#3        | 17/124 [00:09<00:50,  2.11 MiB/s]


Extraction completed...: 0 file [00:09, ? file/s]

Dl Size...:  15%|#4        | 18/124 [00:09<00:49,  2.15 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:09<?, ? url/s]

Dl Size...:  15%|#4        | 18/124 [00:09<00:49,  2.15 MiB/s]


Extraction completed...: 0 file [00:09, ? file/s]

Dl Size...:  15%|#5        | 19/124 [00:10<00:47,  2.20 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:10<?, ? url/s]

Dl Size...:  15%|#5        | 19/124 [00:10<00:47,  2.20 MiB/s]


Extraction completed...: 0 file [00:10, ? file/s]

Dl Size...:  16%|#6        | 20/124 [00:10<00:46,  2.25 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:10<?, ? url/s]

Dl Size...:  16%|#6        | 20/124 [00:10<00:46,  2.25 MiB/s]


Extraction completed...: 0 file [00:10, ? file/s]

Dl Size...:  17%|#6        | 21/124 [00:11<00:44,  2.31 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:11<?, ? url/s]

Dl Size...:  17%|#6        | 21/124 [00:11<00:44,  2.31 MiB/s]


Extraction completed...: 0 file [00:11, ? file/s]

Dl Size...:  18%|#7        | 22/124 [00:11<00:42,  2.41 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:11<?, ? url/s]

Dl Size...:  18%|#7        | 22/124 [00:11<00:42,  2.41 MiB/s]


Extraction completed...: 0 file [00:11, ? file/s]

Dl Size...:  19%|#8        | 23/124 [00:11<00:39,  2.53 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:11<?, ? url/s]

Dl Size...:  19%|#8        | 23/124 [00:11<00:39,  2.53 MiB/s]


Extraction completed...: 0 file [00:11, ? file/s]

Dl Size...:  19%|#9        | 24/124 [00:12<00:37,  2.66 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:12<?, ? url/s]

Dl Size...:  19%|#9        | 24/124 [00:12<00:37,  2.66 MiB/s]


Extraction completed...: 0 file [00:12, ? file/s]

Dl Size...:  20%|##        | 25/124 [00:12<00:36,  2.74 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:12<?, ? url/s]

Dl Size...:  20%|##        | 25/124 [00:12<00:36,  2.74 MiB/s]


Extraction completed...: 0 file [00:12, ? file/s]

Dl Size...:  21%|##        | 26/124 [00:12<00:37,  2.61 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:12<?, ? url/s]

Dl Size...:  21%|##        | 26/124 [00:12<00:37,  2.61 MiB/s]


Extraction completed...: 0 file [00:12, ? file/s]

Dl Size...:  22%|##1       | 27/124 [00:13<00:37,  2.62 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:13<?, ? url/s]

Dl Size...:  22%|##1       | 27/124 [00:13<00:37,  2.62 MiB/s]


Extraction completed...: 0 file [00:13, ? file/s]

Dl Size...:  23%|##2       | 28/124 [00:13<00:36,  2.64 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:13<?, ? url/s]

Dl Size...:  23%|##2       | 28/124 [00:13<00:36,  2.64 MiB/s]


Extraction completed...: 0 file [00:13, ? file/s]

Dl Size...:  23%|##3       | 29/124 [00:13<00:35,  2.71 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:13<?, ? url/s]

Dl Size...:  23%|##3       | 29/124 [00:13<00:35,  2.71 MiB/s]


Extraction completed...: 0 file [00:13, ? file/s]

Dl Size...:  24%|##4       | 30/124 [00:14<00:33,  2.77 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:14<?, ? url/s]

Dl Size...:  24%|##4       | 30/124 [00:14<00:33,  2.77 MiB/s]


Extraction completed...: 0 file [00:14, ? file/s]

Dl Size...:  25%|##5       | 31/124 [00:14<00:32,  2.84 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:14<?, ? url/s]

Dl Size...:  25%|##5       | 31/124 [00:14<00:32,  2.84 MiB/s]


Extraction completed...: 0 file [00:14, ? file/s]

Dl Size...:  26%|##5       | 32/124 [00:14<00:31,  2.94 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:14<?, ? url/s]

Dl Size...:  26%|##5       | 32/124 [00:14<00:31,  2.94 MiB/s]


Extraction completed...: 0 file [00:14, ? file/s]

Dl Size...:  27%|##6       | 33/124 [00:15<00:30,  2.98 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:15<?, ? url/s]

Dl Size...:  27%|##6       | 33/124 [00:15<00:30,  2.98 MiB/s]


Extraction completed...: 0 file [00:15, ? file/s]

Dl Size...:  27%|##7       | 34/124 [00:15<00:29,  3.03 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:15<?, ? url/s]

Dl Size...:  27%|##7       | 34/124 [00:15<00:29,  3.03 MiB/s]


Extraction completed...: 0 file [00:15, ? file/s]

Dl Size...:  28%|##8       | 35/124 [00:15<00:28,  3.12 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:15<?, ? url/s]

Dl Size...:  28%|##8       | 35/124 [00:15<00:28,  3.12 MiB/s]


Extraction completed...: 0 file [00:15, ? file/s]

Dl Size...:  29%|##9       | 36/124 [00:16<00:27,  3.15 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:16<?, ? url/s]

Dl Size...:  29%|##9       | 36/124 [00:16<00:27,  3.15 MiB/s]


Extraction completed...: 0 file [00:16, ? file/s]

Dl Size...:  30%|##9       | 37/124 [00:16<00:27,  3.19 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:16<?, ? url/s]

Dl Size...:  30%|##9       | 37/124 [00:16<00:27,  3.19 MiB/s]


Extraction completed...: 0 file [00:16, ? file/s]

Dl Size...:  31%|###       | 38/124 [00:16<00:27,  3.17 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:16<?, ? url/s]

Dl Size...:  31%|###       | 38/124 [00:16<00:27,  3.17 MiB/s]


Extraction completed...: 0 file [00:16, ? file/s]

Dl Size...:  31%|###1      | 39/124 [00:17<00:26,  3.21 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:17<?, ? url/s]

Dl Size...:  31%|###1      | 39/124 [00:17<00:26,  3.21 MiB/s]


Extraction completed...: 0 file [00:17, ? file/s]

Dl Size...:  32%|###2      | 40/124 [00:17<00:26,  3.23 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:17<?, ? url/s]

Dl Size...:  32%|###2      | 40/124 [00:17<00:26,  3.23 MiB/s]


Extraction completed...: 0 file [00:17, ? file/s]

Dl Size...:  33%|###3      | 41/124 [00:17<00:25,  3.23 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:17<?, ? url/s]

Dl Size...:  33%|###3      | 41/124 [00:17<00:25,  3.23 MiB/s]


Extraction completed...: 0 file [00:17, ? file/s]

Dl Size...:  34%|###3      | 42/124 [00:18<00:25,  3.25 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:18<?, ? url/s]

Dl Size...:  34%|###3      | 42/124 [00:18<00:25,  3.25 MiB/s]


Extraction completed...: 0 file [00:18, ? file/s]

Dl Size...:  35%|###4      | 43/124 [00:18<00:24,  3.26 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:18<?, ? url/s]

Dl Size...:  35%|###4      | 43/124 [00:18<00:24,  3.26 MiB/s]


Extraction completed...: 0 file [00:18, ? file/s]

Dl Size...:  35%|###5      | 44/124 [00:18<00:24,  3.24 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:18<?, ? url/s]

Dl Size...:  35%|###5      | 44/124 [00:18<00:24,  3.24 MiB/s]


Extraction completed...: 0 file [00:18, ? file/s]

Dl Size...:  36%|###6      | 45/124 [00:18<00:24,  3.24 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:18<?, ? url/s]

Dl Size...:  36%|###6      | 45/124 [00:18<00:24,  3.24 MiB/s]


Extraction completed...: 0 file [00:18, ? file/s]

Dl Size...:  37%|###7      | 46/124 [00:19<00:24,  3.25 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:19<?, ? url/s]

Dl Size...:  37%|###7      | 46/124 [00:19<00:24,  3.25 MiB/s]


Extraction completed...: 0 file [00:19, ? file/s]

Dl Size...:  38%|###7      | 47/124 [00:19<00:23,  3.27 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:19<?, ? url/s]

Dl Size...:  38%|###7      | 47/124 [00:19<00:23,  3.27 MiB/s]


Extraction completed...: 0 file [00:19, ? file/s]

Dl Size...:  39%|###8      | 48/124 [00:19<00:23,  3.27 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:19<?, ? url/s]

Dl Size...:  39%|###8      | 48/124 [00:19<00:23,  3.27 MiB/s]


Extraction completed...: 0 file [00:19, ? file/s]

Dl Size...:  40%|###9      | 49/124 [00:20<00:22,  3.31 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:20<?, ? url/s]

Dl Size...:  40%|###9      | 49/124 [00:20<00:22,  3.31 MiB/s]


Extraction completed...: 0 file [00:20, ? file/s]

Dl Size...:  40%|####      | 50/124 [00:20<00:22,  3.30 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:20<?, ? url/s]

Dl Size...:  40%|####      | 50/124 [00:20<00:22,  3.30 MiB/s]


Extraction completed...: 0 file [00:20, ? file/s]

Dl Size...:  41%|####1     | 51/124 [00:20<00:21,  3.34 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:20<?, ? url/s]

Dl Size...:  41%|####1     | 51/124 [00:20<00:21,  3.34 MiB/s]


Extraction completed...: 0 file [00:20, ? file/s]

Dl Size...:  42%|####1     | 52/124 [00:21<00:21,  3.38 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:21<?, ? url/s]

Dl Size...:  42%|####1     | 52/124 [00:21<00:21,  3.38 MiB/s]


Extraction completed...: 0 file [00:21, ? file/s]

Dl Size...:  43%|####2     | 53/124 [00:21<00:20,  3.42 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:21<?, ? url/s]

Dl Size...:  43%|####2     | 53/124 [00:21<00:20,  3.42 MiB/s]


Extraction completed...: 0 file [00:21, ? file/s]

Dl Size...:  44%|####3     | 54/124 [00:21<00:20,  3.45 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:21<?, ? url/s]

Dl Size...:  44%|####3     | 54/124 [00:21<00:20,  3.45 MiB/s]


Extraction completed...: 0 file [00:21, ? file/s]

Dl Size...:  44%|####4     | 55/124 [00:21<00:19,  3.53 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:21<?, ? url/s]

Dl Size...:  44%|####4     | 55/124 [00:21<00:19,  3.53 MiB/s]


Extraction completed...: 0 file [00:21, ? file/s]

Dl Size...:  45%|####5     | 56/124 [00:22<00:18,  3.60 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:22<?, ? url/s]

Dl Size...:  45%|####5     | 56/124 [00:22<00:18,  3.60 MiB/s]


Extraction completed...: 0 file [00:22, ? file/s]

Dl Size...:  46%|####5     | 57/124 [00:22<00:18,  3.67 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:22<?, ? url/s]

Dl Size...:  46%|####5     | 57/124 [00:22<00:18,  3.67 MiB/s]


Extraction completed...: 0 file [00:22, ? file/s]

Dl Size...:  47%|####6     | 58/124 [00:22<00:17,  3.74 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:22<?, ? url/s]

Dl Size...:  47%|####6     | 58/124 [00:22<00:17,  3.74 MiB/s]


Extraction completed...: 0 file [00:22, ? file/s]

Dl Size...:  48%|####7     | 59/124 [00:22<00:16,  3.83 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:22<?, ? url/s]

Dl Size...:  48%|####7     | 59/124 [00:22<00:16,  3.83 MiB/s]


Extraction completed...: 0 file [00:22, ? file/s]

Dl Size...:  48%|####8     | 60/124 [00:23<00:17,  3.60 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:23<?, ? url/s]

Dl Size...:  48%|####8     | 60/124 [00:23<00:17,  3.60 MiB/s]


Extraction completed...: 0 file [00:23, ? file/s]

Dl Size...:  49%|####9     | 61/124 [00:23<00:18,  3.45 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:23<?, ? url/s]

Dl Size...:  49%|####9     | 61/124 [00:23<00:18,  3.45 MiB/s]


Extraction completed...: 0 file [00:23, ? file/s]

Dl Size...:  50%|#####     | 62/124 [00:23<00:18,  3.35 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:23<?, ? url/s]

Dl Size...:  50%|#####     | 62/124 [00:23<00:18,  3.35 MiB/s]


Extraction completed...: 0 file [00:23, ? file/s]

Dl Size...:  51%|#####     | 63/124 [00:24<00:17,  3.39 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:24<?, ? url/s]

Dl Size...:  51%|#####     | 63/124 [00:24<00:17,  3.39 MiB/s]


Extraction completed...: 0 file [00:24, ? file/s]

Dl Size...:  52%|#####1    | 64/124 [00:24<00:17,  3.41 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:24<?, ? url/s]

Dl Size...:  52%|#####1    | 64/124 [00:24<00:17,  3.41 MiB/s]


Extraction completed...: 0 file [00:24, ? file/s]

Dl Size...:  52%|#####2    | 65/124 [00:24<00:17,  3.47 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:24<?, ? url/s]

Dl Size...:  52%|#####2    | 65/124 [00:24<00:17,  3.47 MiB/s]


Extraction completed...: 0 file [00:24, ? file/s]

Dl Size...:  53%|#####3    | 66/124 [00:24<00:16,  3.55 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:24<?, ? url/s]

Dl Size...:  53%|#####3    | 66/124 [00:24<00:16,  3.55 MiB/s]


Extraction completed...: 0 file [00:24, ? file/s]

Dl Size...:  54%|#####4    | 67/124 [00:25<00:15,  3.63 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:25<?, ? url/s]

Dl Size...:  54%|#####4    | 67/124 [00:25<00:15,  3.63 MiB/s]


Extraction completed...: 0 file [00:25, ? file/s]

Dl Size...:  55%|#####4    | 68/124 [00:25<00:15,  3.71 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:25<?, ? url/s]

Dl Size...:  55%|#####4    | 68/124 [00:25<00:15,  3.71 MiB/s]


Extraction completed...: 0 file [00:25, ? file/s]

Dl Size...:  56%|#####5    | 69/124 [00:25<00:14,  3.77 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:25<?, ? url/s]

Dl Size...:  56%|#####5    | 69/124 [00:25<00:14,  3.77 MiB/s]


Extraction completed...: 0 file [00:25, ? file/s]

Dl Size...:  56%|#####6    | 70/124 [00:25<00:14,  3.82 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:25<?, ? url/s]

Dl Size...:  56%|#####6    | 70/124 [00:25<00:14,  3.82 MiB/s]


Extraction completed...: 0 file [00:25, ? file/s]

Dl Size...:  57%|#####7    | 71/124 [00:26<00:13,  3.90 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:26<?, ? url/s]

Dl Size...:  57%|#####7    | 71/124 [00:26<00:13,  3.90 MiB/s]


Extraction completed...: 0 file [00:26, ? file/s]

Dl Size...:  58%|#####8    | 72/124 [00:26<00:13,  3.98 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:26<?, ? url/s]

Dl Size...:  58%|#####8    | 72/124 [00:26<00:13,  3.98 MiB/s]


Extraction completed...: 0 file [00:26, ? file/s]

Dl Size...:  59%|#####8    | 73/124 [00:26<00:12,  4.02 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:26<?, ? url/s]

Dl Size...:  59%|#####8    | 73/124 [00:26<00:12,  4.02 MiB/s]


Extraction completed...: 0 file [00:26, ? file/s]

Dl Size...:  60%|#####9    | 74/124 [00:26<00:12,  4.05 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:26<?, ? url/s]

Dl Size...:  60%|#####9    | 74/124 [00:26<00:12,  4.05 MiB/s]


Extraction completed...: 0 file [00:26, ? file/s]

Dl Size...:  60%|######    | 75/124 [00:27<00:12,  4.07 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:27<?, ? url/s]

Dl Size...:  60%|######    | 75/124 [00:27<00:12,  4.07 MiB/s]


Extraction completed...: 0 file [00:27, ? file/s]

Dl Size...:  61%|######1   | 76/124 [00:27<00:11,  4.06 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:27<?, ? url/s]

Dl Size...:  61%|######1   | 76/124 [00:27<00:11,  4.06 MiB/s]


Extraction completed...: 0 file [00:27, ? file/s]

Dl Size...:  62%|######2   | 77/124 [00:27<00:11,  4.12 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:27<?, ? url/s]

Dl Size...:  62%|######2   | 77/124 [00:27<00:11,  4.12 MiB/s]


Extraction completed...: 0 file [00:27, ? file/s]

Dl Size...:  63%|######2   | 78/124 [00:27<00:11,  4.14 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:27<?, ? url/s]

Dl Size...:  63%|######2   | 78/124 [00:27<00:11,  4.14 MiB/s]


Extraction completed...: 0 file [00:27, ? file/s]

Dl Size...:  64%|######3   | 79/124 [00:28<00:10,  4.17 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:28<?, ? url/s]

Dl Size...:  64%|######3   | 79/124 [00:28<00:10,  4.17 MiB/s]


Extraction completed...: 0 file [00:28, ? file/s]

Dl Size...:  65%|######4   | 80/124 [00:28<00:10,  4.15 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:28<?, ? url/s]

Dl Size...:  65%|######4   | 80/124 [00:28<00:10,  4.15 MiB/s]


Extraction completed...: 0 file [00:28, ? file/s]

Dl Size...:  65%|######5   | 81/124 [00:28<00:10,  4.13 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:28<?, ? url/s]

Dl Size...:  65%|######5   | 81/124 [00:28<00:10,  4.13 MiB/s]


Extraction completed...: 0 file [00:28, ? file/s]

Dl Size...:  66%|######6   | 82/124 [00:28<00:10,  4.16 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:28<?, ? url/s]

Dl Size...:  66%|######6   | 82/124 [00:28<00:10,  4.16 MiB/s]


Extraction completed...: 0 file [00:28, ? file/s]

Dl Size...:  67%|######6   | 83/124 [00:29<00:09,  4.18 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:29<?, ? url/s]

Dl Size...:  67%|######6   | 83/124 [00:29<00:09,  4.18 MiB/s]


Extraction completed...: 0 file [00:29, ? file/s]

Dl Size...:  68%|######7   | 84/124 [00:29<00:09,  4.21 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:29<?, ? url/s]

Dl Size...:  68%|######7   | 84/124 [00:29<00:09,  4.21 MiB/s]


Extraction completed...: 0 file [00:29, ? file/s]

Dl Size...:  69%|######8   | 85/124 [00:29<00:09,  4.15 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:29<?, ? url/s]

Dl Size...:  69%|######8   | 85/124 [00:29<00:09,  4.15 MiB/s]


Extraction completed...: 0 file [00:29, ? file/s]

Dl Size...:  69%|######9   | 86/124 [00:29<00:09,  4.12 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:29<?, ? url/s]

Dl Size...:  69%|######9   | 86/124 [00:29<00:09,  4.12 MiB/s]


Extraction completed...: 0 file [00:29, ? file/s]

Dl Size...:  70%|#######   | 87/124 [00:30<00:08,  4.20 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:30<?, ? url/s]

Dl Size...:  70%|#######   | 87/124 [00:30<00:08,  4.20 MiB/s]


Extraction completed...: 0 file [00:30, ? file/s]

Dl Size...:  71%|#######   | 88/124 [00:30<00:08,  4.20 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:30<?, ? url/s]

Dl Size...:  71%|#######   | 88/124 [00:30<00:08,  4.20 MiB/s]


Extraction completed...: 0 file [00:30, ? file/s]

Dl Size...:  72%|#######1  | 89/124 [00:30<00:08,  4.19 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:30<?, ? url/s]

Dl Size...:  72%|#######1  | 89/124 [00:30<00:08,  4.19 MiB/s]


Extraction completed...: 0 file [00:30, ? file/s]

Dl Size...:  73%|#######2  | 90/124 [00:30<00:08,  4.14 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:30<?, ? url/s]

Dl Size...:  73%|#######2  | 90/124 [00:30<00:08,  4.14 MiB/s]


Extraction completed...: 0 file [00:30, ? file/s]

Dl Size...:  73%|#######3  | 91/124 [00:31<00:07,  4.18 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:31<?, ? url/s]

Dl Size...:  73%|#######3  | 91/124 [00:31<00:07,  4.18 MiB/s]


Extraction completed...: 0 file [00:31, ? file/s]

Dl Size...:  74%|#######4  | 92/124 [00:31<00:07,  4.22 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:31<?, ? url/s]

Dl Size...:  74%|#######4  | 92/124 [00:31<00:07,  4.22 MiB/s]


Extraction completed...: 0 file [00:31, ? file/s]

Dl Size...:  75%|#######5  | 93/124 [00:31<00:07,  4.25 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:31<?, ? url/s]

Dl Size...:  75%|#######5  | 93/124 [00:31<00:07,  4.25 MiB/s]


Extraction completed...: 0 file [00:31, ? file/s]

Dl Size...:  76%|#######5  | 94/124 [00:31<00:07,  4.21 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:31<?, ? url/s]

Dl Size...:  76%|#######5  | 94/124 [00:31<00:07,  4.21 MiB/s]


Extraction completed...: 0 file [00:31, ? file/s]

Dl Size...:  77%|#######6  | 95/124 [00:31<00:06,  4.30 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:31<?, ? url/s]

Dl Size...:  77%|#######6  | 95/124 [00:31<00:06,  4.30 MiB/s]


Extraction completed...: 0 file [00:31, ? file/s]

Dl Size...:  77%|#######7  | 96/124 [00:32<00:06,  4.33 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:32<?, ? url/s]

Dl Size...:  77%|#######7  | 96/124 [00:32<00:06,  4.33 MiB/s]


Extraction completed...: 0 file [00:32, ? file/s]

Dl Size...:  78%|#######8  | 97/124 [00:32<00:06,  4.31 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:32<?, ? url/s]

Dl Size...:  78%|#######8  | 97/124 [00:32<00:06,  4.31 MiB/s]


Extraction completed...: 0 file [00:32, ? file/s]

Dl Size...:  79%|#######9  | 98/124 [00:32<00:05,  4.38 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:32<?, ? url/s]

Dl Size...:  79%|#######9  | 98/124 [00:32<00:05,  4.38 MiB/s]


Extraction completed...: 0 file [00:32, ? file/s]

Dl Size...:  80%|#######9  | 99/124 [00:32<00:05,  4.41 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:32<?, ? url/s]

Dl Size...:  80%|#######9  | 99/124 [00:32<00:05,  4.41 MiB/s]


Extraction completed...: 0 file [00:32, ? file/s]

Dl Size...:  81%|########  | 100/124 [00:33<00:05,  4.49 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:33<?, ? url/s]

Dl Size...:  81%|########  | 100/124 [00:33<00:05,  4.49 MiB/s]


Extraction completed...: 0 file [00:33, ? file/s]

Dl Size...:  81%|########1 | 101/124 [00:33<00:05,  4.53 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:33<?, ? url/s]

Dl Size...:  81%|########1 | 101/124 [00:33<00:05,  4.53 MiB/s]


Extraction completed...: 0 file [00:33, ? file/s]

Dl Size...:  82%|########2 | 102/124 [00:33<00:04,  4.60 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:33<?, ? url/s]

Dl Size...:  82%|########2 | 102/124 [00:33<00:04,  4.60 MiB/s]


Extraction completed...: 0 file [00:33, ? file/s]

Dl Size...:  83%|########3 | 103/124 [00:33<00:04,  4.64 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:33<?, ? url/s]

Dl Size...:  83%|########3 | 103/124 [00:33<00:04,  4.64 MiB/s]


Extraction completed...: 0 file [00:33, ? file/s]

Dl Size...:  84%|########3 | 104/124 [00:33<00:04,  4.79 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:33<?, ? url/s]

Dl Size...:  84%|########3 | 104/124 [00:33<00:04,  4.79 MiB/s]


Extraction completed...: 0 file [00:33, ? file/s]

Dl Size...:  85%|########4 | 105/124 [00:34<00:03,  4.85 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:34<?, ? url/s]

Dl Size...:  85%|########4 | 105/124 [00:34<00:03,  4.85 MiB/s]


Extraction completed...: 0 file [00:34, ? file/s]

Dl Size...:  85%|########5 | 106/124 [00:34<00:03,  4.86 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:34<?, ? url/s]

Dl Size...:  85%|########5 | 106/124 [00:34<00:03,  4.86 MiB/s]


Extraction completed...: 0 file [00:34, ? file/s]

Dl Size...:  86%|########6 | 107/124 [00:34<00:03,  4.99 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:34<?, ? url/s]

Dl Size...:  86%|########6 | 107/124 [00:34<00:03,  4.99 MiB/s]


Extraction completed...: 0 file [00:34, ? file/s]

Dl Size...:  87%|########7 | 108/124 [00:34<00:03,  5.14 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:34<?, ? url/s]

Dl Size...:  87%|########7 | 108/124 [00:34<00:03,  5.14 MiB/s]


Extraction completed...: 0 file [00:34, ? file/s]

Dl Size...:  88%|########7 | 109/124 [00:34<00:02,  5.20 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:34<?, ? url/s]

Dl Size...:  88%|########7 | 109/124 [00:34<00:02,  5.20 MiB/s]


Extraction completed...: 0 file [00:34, ? file/s]

Dl Size...:  89%|########8 | 110/124 [00:35<00:02,  5.30 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:35<?, ? url/s]

Dl Size...:  89%|########8 | 110/124 [00:35<00:02,  5.30 MiB/s]


Extraction completed...: 0 file [00:35, ? file/s]

Dl Size...:  90%|########9 | 111/124 [00:35<00:02,  5.43 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:35<?, ? url/s]

Dl Size...:  90%|########9 | 111/124 [00:35<00:02,  5.43 MiB/s]


Extraction completed...: 0 file [00:35, ? file/s]

Dl Size...:  90%|######### | 112/124 [00:35<00:02,  5.55 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:35<?, ? url/s]

Dl Size...:  90%|######### | 112/124 [00:35<00:02,  5.55 MiB/s]


Extraction completed...: 0 file [00:35, ? file/s]

Dl Size...:  91%|#########1| 113/124 [00:35<00:01,  5.66 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:35<?, ? url/s]

Dl Size...:  91%|#########1| 113/124 [00:35<00:01,  5.66 MiB/s]


Extraction completed...: 0 file [00:35, ? file/s]

Dl Size...:  92%|#########1| 114/124 [00:35<00:01,  5.73 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:35<?, ? url/s]

Dl Size...:  92%|#########1| 114/124 [00:35<00:01,  5.73 MiB/s]


Extraction completed...: 0 file [00:35, ? file/s]

Dl Size...:  93%|#########2| 115/124 [00:35<00:01,  5.92 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:35<?, ? url/s]

Dl Size...:  93%|#########2| 115/124 [00:35<00:01,  5.92 MiB/s]


Extraction completed...: 0 file [00:35, ? file/s]

Dl Size...:  94%|#########3| 116/124 [00:36<00:01,  5.98 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:36<?, ? url/s]

Dl Size...:  94%|#########3| 116/124 [00:36<00:01,  5.98 MiB/s]


Extraction completed...: 0 file [00:36, ? file/s]

Dl Size...:  94%|#########4| 117/124 [00:36<00:01,  6.08 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:36<?, ? url/s]

Dl Size...:  94%|#########4| 117/124 [00:36<00:01,  6.08 MiB/s]


Extraction completed...: 0 file [00:36, ? file/s]

Dl Size...:  95%|#########5| 118/124 [00:36<00:00,  6.25 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:36<?, ? url/s]

Dl Size...:  95%|#########5| 118/124 [00:36<00:00,  6.25 MiB/s]


Extraction completed...: 0 file [00:36, ? file/s]

Dl Size...:  96%|#########5| 119/124 [00:36<00:00,  6.52 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:36<?, ? url/s]

Dl Size...:  96%|#########5| 119/124 [00:36<00:00,  6.52 MiB/s]


Extraction completed...: 0 file [00:36, ? file/s]

Dl Size...:  97%|#########6| 120/124 [00:36<00:00,  6.52 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:36<?, ? url/s]

Dl Size...:  97%|#########6| 120/124 [00:36<00:00,  6.52 MiB/s]


Extraction completed...: 0 file [00:36, ? file/s]

Dl Size...:  98%|#########7| 121/124 [00:36<00:00,  5.90 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:36<?, ? url/s]

Dl Size...:  98%|#########7| 121/124 [00:36<00:00,  5.90 MiB/s]


Extraction completed...: 0 file [00:36, ? file/s]

Dl Size...:  98%|#########8| 122/124 [00:36<00:00,  6.62 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:36<?, ? url/s]

Dl Size...:  98%|#########8| 122/124 [00:36<00:00,  6.62 MiB/s]


Extraction completed...: 0 file [00:36, ? file/s]

Dl Size...:  99%|#########9| 123/124 [00:37<00:00,  6.12 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:37<?, ? url/s]

Dl Size...:  99%|#########9| 123/124 [00:37<00:00,  6.12 MiB/s]


Extraction completed...: 0 file [00:37, ? file/s]

Dl Size...: 100%|##########| 124/124 [00:37<00:00,  5.92 MiB/s]
Dl Completed...:   0%|          | 0/1 [00:37<?, ? url/s]

Dl Size...: 100%|##########| 124/124 [00:37<00:00,  5.92 MiB/s]


Extraction completed...: 0 file [00:37, ? file/s]
Dl Completed...: 100%|##########| 1/1 [00:37<00:00, 37.44s/ url]
Dl Completed...: 100%|##########| 1/1 [00:37<00:00, 37.44s/ url]

Dl Size...: 100%|##########| 124/124 [00:37<00:00,  5.92 MiB/s]


Extraction completed...: 0 file [00:37, ? file/s]
Dl Completed...: 100%|##########| 1/1 [00:37<00:00, 37.44s/ url]

Dl Size...: 100%|##########| 124/124 [00:37<00:00,  5.92 MiB/s]


Extraction completed...:   0%|          | 0/1 [00:37<?, ? file/s]


Extraction completed...: 100%|##########| 1/1 [00:39<00:00, 39.20s/ file]
Dl Completed...: 100%|##########| 1/1 [00:39<00:00, 37.44s/ url]

Dl Size...: 100%|##########| 124/124 [00:39<00:00,  5.92 MiB/s]


Extraction completed...: 100%|##########| 1/1 [00:39<00:00, 39.20s/ file]
Extraction completed...: 100%|##########| 1/1 [00:39<00:00, 39.20s/ file]

Dl Size...: 100%|##########| 124/124 [00:39<00:00,  3.16 MiB/s]

Dl Completed...: 100%|##########| 1/1 [00:39<00:00, 39.20s/ url]

Generating splits...:   0%|          | 0/1 [00:00<?, ? splits/s]

Generating train examples...:   0%|          | 0/7200 [00:00<?, ? examples/s]

Generating train examples...:   7%|6         | 476/7200 [00:00<00:01, 4752.12 examples/s]

Generating train examples...:  14%|#3        | 1000/7200 [00:00<00:01, 5036.67 examples/s]

Generating train examples...:  21%|##1       | 1530/7200 [00:00<00:01, 5153.07 examples/s]

Generating train examples...:  29%|##8       | 2059/7200 [00:00<00:00, 5206.74 examples/s]

Generating train examples...:  36%|###5      | 2585/7200 [00:00<00:00, 5225.54 examples/s]

Generating train examples...:  43%|####3     | 3108/7200 [00:00<00:00, 5220.57 examples/s]

Generating train examples...:  51%|#####     | 3637/7200 [00:00<00:00, 5240.91 examples/s]

Generating train examples...:  58%|#####7    | 4165/7200 [00:00<00:00, 5250.93 examples/s]

Generating train examples...:  65%|######5   | 4695/7200 [00:00<00:00, 5263.77 examples/s]

Generating train examples...:  73%|#######2  | 5223/7200 [00:01<00:00, 5268.27 examples/s]

Generating train examples...:  80%|#######9  | 5753/7200 [00:01<00:00, 5276.94 examples/s]

Generating train examples...:  87%|########7 | 6283/7200 [00:01<00:00, 5281.10 examples/s]

Generating train examples...:  95%|#########4| 6812/7200 [00:01<00:00, 5279.98 examples/s]



Shuffling /root/tensorflow_datasets/coil100/2.0.0.incompleteK2Y7FL/coil100-train.tfrecord*...:   0%|          | 0/7200 [00:00<?, ? examples/s]

Shuffling /root/tensorflow_datasets/coil100/2.0.0.incompleteK2Y7FL/coil100-train.tfrecord*...:  98%|#########7| 7023/7200 [00:00<00:00, 70222.20 examples/s]


Generating splits...: 100%|##########| 1/1 [00:01<00:00,  1.49s/ splits]

Dataset coil100 downloaded and prepared to /root/tensorflow_datasets/coil100/2.0.0. Subsequent calls will reuse this data.
The dataset contains 7200 color images of 100 objects
(72 images per object). The objects have a wide variety of complex geometric and reflectance characteristics.
The objects were placed on a motorized turntable against a black background.
The turntable was rotated through 360 degrees to vary object pose with respect to a fxed color camera.
Images of the objects were taken at pose intervals of   5 degrees.This corresponds to
72 poses per object
# Select the 4 cup objects that will be used as new classes
object_ids = [15, 17, 24, 42]
object_dict = {k: [] for k in object_ids}
for data in ds:
    object_id = data['object_id'].numpy()
    if object_id in object_dict.keys():
        object_dict[object_id].append(data['image'].numpy())
import matplotlib.pyplot as plt

# Display one image per selected object
f, axarr = plt.subplots(1, len(object_dict))
i = 0
for k in object_dict:
    axarr[i].axis('off')
    axarr[i].imshow(object_dict[k][0])
    axarr[i].set_title(k, fontsize=10)
    i += 1
plt.show()
15, 17, 24, 42

2. Prepare Akida model for learning

from akida_models import akidanet_edge_imagenet_pretrained
from cnn2snn import convert

# Load a pre-trained model
model_keras = akidanet_edge_imagenet_pretrained()

# Convert it to akida
model_ak = convert(model_keras)

Out:

Downloading data from http://data.brainchip.com/models/akidanet_edge/akidanet_imagenet_224_alpha_50_edge_iq8_wq4_aq4.h5

   16384/15993616 [..............................] - ETA: 13s
  303104/15993616 [..............................] - ETA: 3s 
  819200/15993616 [>.............................] - ETA: 2s
 1277952/15993616 [=>............................] - ETA: 1s
 1769472/15993616 [==>...........................] - ETA: 1s
 2252800/15993616 [===>..........................] - ETA: 1s
 2719744/15993616 [====>.........................] - ETA: 1s
 3235840/15993616 [=====>........................] - ETA: 1s
 3743744/15993616 [======>.......................] - ETA: 1s
 4259840/15993616 [======>.......................] - ETA: 1s
 4792320/15993616 [=======>......................] - ETA: 1s
 5324800/15993616 [========>.....................] - ETA: 1s
 5865472/15993616 [==========>...................] - ETA: 1s
 6414336/15993616 [===========>..................] - ETA: 1s
 6971392/15993616 [============>.................] - ETA: 0s
 7544832/15993616 [=============>................] - ETA: 0s
 8077312/15993616 [==============>...............] - ETA: 0s
 8634368/15993616 [===============>..............] - ETA: 0s
 9207808/15993616 [================>.............] - ETA: 0s
 9797632/15993616 [=================>............] - ETA: 0s
10371072/15993616 [==================>...........] - ETA: 0s
10723328/15993616 [===================>..........] - ETA: 0s
11280384/15993616 [====================>.........] - ETA: 0s
11730944/15993616 [=====================>........] - ETA: 0s
12181504/15993616 [=====================>........] - ETA: 0s
12648448/15993616 [======================>.......] - ETA: 0s
13123584/15993616 [=======================>......] - ETA: 0s
13615104/15993616 [========================>.....] - ETA: 0s
14082048/15993616 [=========================>....] - ETA: 0s
14508032/15993616 [==========================>...] - ETA: 0s
14860288/15993616 [==========================>...] - ETA: 0s
15245312/15993616 [===========================>..] - ETA: 0s
15605760/15993616 [============================>.] - ETA: 0s
15998976/15993616 [==============================] - 2s 0us/step

16007168/15993616 [==============================] - 2s 0us/step
from akida import AkidaUnsupervised

# Replace the last layer by a classification layer
num_classes = len(object_dict)
num_neurons_per_class = 1
num_weights = 350
model_ak.pop_layer()
layer_fc = FullyConnected(name='akida_edge_layer',
                          units=num_classes * num_neurons_per_class,
                          activation=False)
model_ak.add(layer_fc)
model_ak.compile(optimizer=AkidaUnsupervised(num_weights=num_weights,
                                             num_classes=num_classes,
                                             learning_competition=0.1))
model_ak.summary()

Out:

                 Model Summary
________________________________________________
Input shape    Output shape  Sequences  Layers
================================================
[224, 224, 3]  [1, 1, 4]     1          16
________________________________________________

             SW/conv_0-akida_edge_layer (Software)
________________________________________________________________
Layer (type)                 Output shape    Kernel shape
================================================================
conv_0 (InputConv.)          [112, 112, 16]  (3, 3, 3, 16)
________________________________________________________________
conv_1 (Conv.)               [112, 112, 32]  (3, 3, 16, 32)
________________________________________________________________
conv_2 (Conv.)               [56, 56, 64]    (3, 3, 32, 64)
________________________________________________________________
conv_3 (Conv.)               [56, 56, 64]    (3, 3, 64, 64)
________________________________________________________________
separable_4 (Sep.Conv.)      [28, 28, 128]   (3, 3, 64, 1)
________________________________________________________________
                                             (1, 1, 64, 128)
________________________________________________________________
separable_5 (Sep.Conv.)      [28, 28, 128]   (3, 3, 128, 1)
________________________________________________________________
                                             (1, 1, 128, 128)
________________________________________________________________
separable_6 (Sep.Conv.)      [14, 14, 256]   (3, 3, 128, 1)
________________________________________________________________
                                             (1, 1, 128, 256)
________________________________________________________________
separable_7 (Sep.Conv.)      [14, 14, 256]   (3, 3, 256, 1)
________________________________________________________________
                                             (1, 1, 256, 256)
________________________________________________________________
separable_8 (Sep.Conv.)      [14, 14, 256]   (3, 3, 256, 1)
________________________________________________________________
                                             (1, 1, 256, 256)
________________________________________________________________
separable_9 (Sep.Conv.)      [14, 14, 256]   (3, 3, 256, 1)
________________________________________________________________
                                             (1, 1, 256, 256)
________________________________________________________________
separable_10 (Sep.Conv.)     [14, 14, 256]   (3, 3, 256, 1)
________________________________________________________________
                                             (1, 1, 256, 256)
________________________________________________________________
separable_11 (Sep.Conv.)     [14, 14, 256]   (3, 3, 256, 1)
________________________________________________________________
                                             (1, 1, 256, 256)
________________________________________________________________
separable_12 (Sep.Conv.)     [7, 7, 512]     (3, 3, 256, 1)
________________________________________________________________
                                             (1, 1, 256, 512)
________________________________________________________________
separable_13 (Sep.Conv.)     [1, 1, 512]     (3, 3, 512, 1)
________________________________________________________________
                                             (1, 1, 512, 512)
________________________________________________________________
spike_generator (Sep.Conv.)  [1, 1, 2048]    (3, 3, 512, 1)
________________________________________________________________
                                             (1, 1, 512, 2048)
________________________________________________________________
akida_edge_layer (Fully.)    [1, 1, 4]       (1, 1, 2048, 4)
________________________________________________________________

              Learning Summary
____________________________________________
Learning Layer    # Input Conn.  # Weights
============================================
akida_edge_layer  2048           350
____________________________________________

3. Edge learning with Akida

import numpy as np

from tensorflow.image import resize_with_crop_or_pad
from time import time

# Learn objects in num_shots shot(s)
num_shots = 1
for i in range(len(object_ids)):
    start = time()
    train_images = object_dict[object_ids[i]][:num_shots]
    for image in train_images:
        padded_image = resize_with_crop_or_pad(image, 224, 224)
        model_ak.fit(np.expand_dims(padded_image, axis=0), i)
    end = time()
    print(f'Learned object {object_ids[i]} (class {i}) with \
            {len(train_images)} sample(s) in {end-start:.2f}s')

Out:

Learned object 15 (class 0) with             1 sample(s) in 0.12s
Learned object 17 (class 1) with             1 sample(s) in 0.13s
Learned object 24 (class 2) with             1 sample(s) in 0.12s
Learned object 42 (class 3) with             1 sample(s) in 0.12s
import statistics as stat

# Check accuracy against remaining samples
accuracy = []
for i in range(len(object_ids)):
    test_images = object_dict[object_ids[i]][num_shots:]
    predictions = np.zeros(len(test_images))
    for j in range(len(test_images)):
        padded_image = resize_with_crop_or_pad(test_images[j], 224, 224)
        predictions[j] = model_ak.predict_classes(np.expand_dims(padded_image,
                                                                 axis=0),
                                                  num_classes=num_classes)
    accuracy.append(100 * np.sum(predictions == i) / len(test_images))
    print(f'Accuracy testing object {object_ids[i]} (class {i}) with \
            {len(test_images)} sample(s): {accuracy[i]:.2f}%')

mean_accuracy = stat.mean(accuracy)
print(f'Mean accuracy: {mean_accuracy:.2f}%')

# For non-regression purpose
assert mean_accuracy > 94

Out:

Accuracy testing object 15 (class 0) with             71 sample(s): 100.00%
Accuracy testing object 17 (class 1) with             71 sample(s): 100.00%
Accuracy testing object 24 (class 2) with             71 sample(s): 100.00%
Accuracy testing object 42 (class 3) with             71 sample(s): 91.55%
Mean accuracy: 97.89%

Total running time of the script: ( 1 minutes 24.181 seconds)

Gallery generated by Sphinx-Gallery