Note
Click here to download the full example code
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)
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<03:14, 1.58s/ MiB]
Dl Completed...: 0%| | 0/1 [00:01<?, ? url/s]
Dl Size...: 1%| | 1/124 [00:01<03:14, 1.58s/ MiB]
Extraction completed...: 0 file [00:01, ? file/s]
Dl Size...: 2%|1 | 2/124 [00:02<01:55, 1.06 MiB/s]
Dl Completed...: 0%| | 0/1 [00:02<?, ? url/s]
Dl Size...: 2%|1 | 2/124 [00:02<01:55, 1.06 MiB/s]
Extraction completed...: 0 file [00:02, ? file/s]
Dl Size...: 2%|2 | 3/124 [00:02<01:26, 1.40 MiB/s]
Dl Completed...: 0%| | 0/1 [00:02<?, ? url/s]
Dl Size...: 2%|2 | 3/124 [00:02<01:26, 1.40 MiB/s]
Extraction completed...: 0 file [00:02, ? file/s]
Dl Size...: 3%|3 | 4/124 [00:02<01:12, 1.65 MiB/s]
Dl Completed...: 0%| | 0/1 [00:02<?, ? url/s]
Dl Size...: 3%|3 | 4/124 [00:02<01:12, 1.65 MiB/s]
Extraction completed...: 0 file [00:02, ? file/s]
Dl Size...: 4%|4 | 5/124 [00:03<01:04, 1.84 MiB/s]
Dl Completed...: 0%| | 0/1 [00:03<?, ? url/s]
Dl Size...: 4%|4 | 5/124 [00:03<01:04, 1.84 MiB/s]
Extraction completed...: 0 file [00:03, ? file/s]
Dl Size...: 5%|4 | 6/124 [00:03<00:59, 1.98 MiB/s]
Dl Completed...: 0%| | 0/1 [00:03<?, ? url/s]
Dl Size...: 5%|4 | 6/124 [00:03<00:59, 1.98 MiB/s]
Extraction completed...: 0 file [00:03, ? file/s]
Dl Size...: 6%|5 | 7/124 [00:04<00:56, 2.09 MiB/s]
Dl Completed...: 0%| | 0/1 [00:04<?, ? url/s]
Dl Size...: 6%|5 | 7/124 [00:04<00:56, 2.09 MiB/s]
Extraction completed...: 0 file [00:04, ? file/s]
Dl Size...: 6%|6 | 8/124 [00:04<00:53, 2.17 MiB/s]
Dl Completed...: 0%| | 0/1 [00:04<?, ? url/s]
Dl Size...: 6%|6 | 8/124 [00:04<00:53, 2.17 MiB/s]
Extraction completed...: 0 file [00:04, ? file/s]
Dl Size...: 7%|7 | 9/124 [00:05<00:51, 2.25 MiB/s]
Dl Completed...: 0%| | 0/1 [00:05<?, ? url/s]
Dl Size...: 7%|7 | 9/124 [00:05<00:51, 2.25 MiB/s]
Extraction completed...: 0 file [00:05, ? file/s]
Dl Size...: 8%|8 | 10/124 [00:05<00:49, 2.29 MiB/s]
Dl Completed...: 0%| | 0/1 [00:05<?, ? url/s]
Dl Size...: 8%|8 | 10/124 [00:05<00:49, 2.29 MiB/s]
Extraction completed...: 0 file [00:05, ? file/s]
Dl Size...: 9%|8 | 11/124 [00:05<00:47, 2.37 MiB/s]
Dl Completed...: 0%| | 0/1 [00:05<?, ? url/s]
Dl Size...: 9%|8 | 11/124 [00:05<00:47, 2.37 MiB/s]
Extraction completed...: 0 file [00:05, ? file/s]
Dl Size...: 10%|9 | 12/124 [00:06<00:47, 2.37 MiB/s]
Dl Completed...: 0%| | 0/1 [00:06<?, ? url/s]
Dl Size...: 10%|9 | 12/124 [00:06<00:47, 2.37 MiB/s]
Extraction completed...: 0 file [00:06, ? file/s]
Dl Size...: 10%|# | 13/124 [00:06<00:46, 2.39 MiB/s]
Dl Completed...: 0%| | 0/1 [00:06<?, ? url/s]
Dl Size...: 10%|# | 13/124 [00:06<00:46, 2.39 MiB/s]
Extraction completed...: 0 file [00:06, ? file/s]
Dl Size...: 11%|#1 | 14/124 [00:07<00:45, 2.40 MiB/s]
Dl Completed...: 0%| | 0/1 [00:07<?, ? url/s]
Dl Size...: 11%|#1 | 14/124 [00:07<00:45, 2.40 MiB/s]
Extraction completed...: 0 file [00:07, ? file/s]
Dl Size...: 12%|#2 | 15/124 [00:07<00:44, 2.46 MiB/s]
Dl Completed...: 0%| | 0/1 [00:07<?, ? url/s]
Dl Size...: 12%|#2 | 15/124 [00:07<00:44, 2.46 MiB/s]
Extraction completed...: 0 file [00:07, ? file/s]
Dl Size...: 13%|#2 | 16/124 [00:07<00:43, 2.48 MiB/s]
Dl Completed...: 0%| | 0/1 [00:07<?, ? url/s]
Dl Size...: 13%|#2 | 16/124 [00:07<00:43, 2.48 MiB/s]
Extraction completed...: 0 file [00:07, ? file/s]
Dl Size...: 14%|#3 | 17/124 [00:08<00:42, 2.53 MiB/s]
Dl Completed...: 0%| | 0/1 [00:08<?, ? url/s]
Dl Size...: 14%|#3 | 17/124 [00:08<00:42, 2.53 MiB/s]
Extraction completed...: 0 file [00:08, ? file/s]
Dl Size...: 15%|#4 | 18/124 [00:08<00:41, 2.54 MiB/s]
Dl Completed...: 0%| | 0/1 [00:08<?, ? url/s]
Dl Size...: 15%|#4 | 18/124 [00:08<00:41, 2.54 MiB/s]
Extraction completed...: 0 file [00:08, ? file/s]
Dl Size...: 15%|#5 | 19/124 [00:09<00:40, 2.60 MiB/s]
Dl Completed...: 0%| | 0/1 [00:09<?, ? url/s]
Dl Size...: 15%|#5 | 19/124 [00:09<00:40, 2.60 MiB/s]
Extraction completed...: 0 file [00:09, ? file/s]
Dl Size...: 16%|#6 | 20/124 [00:09<00:39, 2.64 MiB/s]
Dl Completed...: 0%| | 0/1 [00:09<?, ? url/s]
Dl Size...: 16%|#6 | 20/124 [00:09<00:39, 2.64 MiB/s]
Extraction completed...: 0 file [00:09, ? file/s]
Dl Size...: 17%|#6 | 21/124 [00:09<00:38, 2.69 MiB/s]
Dl Completed...: 0%| | 0/1 [00:09<?, ? url/s]
Dl Size...: 17%|#6 | 21/124 [00:09<00:38, 2.69 MiB/s]
Extraction completed...: 0 file [00:09, ? file/s]
Dl Size...: 18%|#7 | 22/124 [00:10<00:37, 2.73 MiB/s]
Dl Completed...: 0%| | 0/1 [00:10<?, ? url/s]
Dl Size...: 18%|#7 | 22/124 [00:10<00:37, 2.73 MiB/s]
Extraction completed...: 0 file [00:10, ? file/s]
Dl Size...: 19%|#8 | 23/124 [00:10<00:35, 2.84 MiB/s]
Dl Completed...: 0%| | 0/1 [00:10<?, ? url/s]
Dl Size...: 19%|#8 | 23/124 [00:10<00:35, 2.84 MiB/s]
Extraction completed...: 0 file [00:10, ? file/s]
Dl Size...: 19%|#9 | 24/124 [00:10<00:34, 2.93 MiB/s]
Dl Completed...: 0%| | 0/1 [00:10<?, ? url/s]
Dl Size...: 19%|#9 | 24/124 [00:10<00:34, 2.93 MiB/s]
Extraction completed...: 0 file [00:10, ? file/s]
Dl Size...: 20%|## | 25/124 [00:11<00:32, 3.02 MiB/s]
Dl Completed...: 0%| | 0/1 [00:11<?, ? url/s]
Dl Size...: 20%|## | 25/124 [00:11<00:32, 3.02 MiB/s]
Extraction completed...: 0 file [00:11, ? file/s]
Dl Size...: 21%|## | 26/124 [00:11<00:31, 3.16 MiB/s]
Dl Completed...: 0%| | 0/1 [00:11<?, ? url/s]
Dl Size...: 21%|## | 26/124 [00:11<00:31, 3.16 MiB/s]
Extraction completed...: 0 file [00:11, ? file/s]
Dl Size...: 22%|##1 | 27/124 [00:11<00:29, 3.30 MiB/s]
Dl Completed...: 0%| | 0/1 [00:11<?, ? url/s]
Dl Size...: 22%|##1 | 27/124 [00:11<00:29, 3.30 MiB/s]
Extraction completed...: 0 file [00:11, ? file/s]
Dl Size...: 23%|##2 | 28/124 [00:11<00:27, 3.45 MiB/s]
Dl Completed...: 0%| | 0/1 [00:11<?, ? url/s]
Dl Size...: 23%|##2 | 28/124 [00:11<00:27, 3.45 MiB/s]
Extraction completed...: 0 file [00:11, ? file/s]
Dl Size...: 23%|##3 | 29/124 [00:12<00:26, 3.59 MiB/s]
Dl Completed...: 0%| | 0/1 [00:12<?, ? url/s]
Dl Size...: 23%|##3 | 29/124 [00:12<00:26, 3.59 MiB/s]
Extraction completed...: 0 file [00:12, ? file/s]
Dl Size...: 24%|##4 | 30/124 [00:12<00:25, 3.70 MiB/s]
Dl Completed...: 0%| | 0/1 [00:12<?, ? url/s]
Dl Size...: 24%|##4 | 30/124 [00:12<00:25, 3.70 MiB/s]
Extraction completed...: 0 file [00:12, ? file/s]
Dl Size...: 25%|##5 | 31/124 [00:12<00:23, 3.97 MiB/s]
Dl Completed...: 0%| | 0/1 [00:12<?, ? url/s]
Dl Size...: 25%|##5 | 31/124 [00:12<00:23, 3.97 MiB/s]
Extraction completed...: 0 file [00:12, ? file/s]
Dl Size...: 26%|##5 | 32/124 [00:12<00:22, 4.09 MiB/s]
Dl Completed...: 0%| | 0/1 [00:12<?, ? url/s]
Dl Size...: 26%|##5 | 32/124 [00:12<00:22, 4.09 MiB/s]
Extraction completed...: 0 file [00:12, ? file/s]
Dl Size...: 27%|##6 | 33/124 [00:13<00:20, 4.36 MiB/s]
Dl Completed...: 0%| | 0/1 [00:13<?, ? url/s]
Dl Size...: 27%|##6 | 33/124 [00:13<00:20, 4.36 MiB/s]
Extraction completed...: 0 file [00:13, ? file/s]
Dl Size...: 27%|##7 | 34/124 [00:13<00:20, 4.40 MiB/s]
Dl Completed...: 0%| | 0/1 [00:13<?, ? url/s]
Dl Size...: 27%|##7 | 34/124 [00:13<00:20, 4.40 MiB/s]
Extraction completed...: 0 file [00:13, ? file/s]
Dl Size...: 28%|##8 | 35/124 [00:13<00:19, 4.67 MiB/s]
Dl Completed...: 0%| | 0/1 [00:13<?, ? url/s]
Dl Size...: 28%|##8 | 35/124 [00:13<00:19, 4.67 MiB/s]
Extraction completed...: 0 file [00:13, ? file/s]
Dl Size...: 29%|##9 | 36/124 [00:13<00:17, 4.93 MiB/s]
Dl Completed...: 0%| | 0/1 [00:13<?, ? url/s]
Dl Size...: 29%|##9 | 36/124 [00:13<00:17, 4.93 MiB/s]
Extraction completed...: 0 file [00:13, ? file/s]
Dl Size...: 30%|##9 | 37/124 [00:13<00:16, 5.15 MiB/s]
Dl Completed...: 0%| | 0/1 [00:13<?, ? url/s]
Dl Size...: 30%|##9 | 37/124 [00:13<00:16, 5.15 MiB/s]
Extraction completed...: 0 file [00:13, ? file/s]
Dl Size...: 31%|### | 38/124 [00:13<00:16, 5.34 MiB/s]
Dl Completed...: 0%| | 0/1 [00:13<?, ? url/s]
Dl Size...: 31%|### | 38/124 [00:13<00:16, 5.34 MiB/s]
Extraction completed...: 0 file [00:13, ? file/s]
Dl Size...: 31%|###1 | 39/124 [00:14<00:15, 5.52 MiB/s]
Dl Completed...: 0%| | 0/1 [00:14<?, ? url/s]
Dl Size...: 31%|###1 | 39/124 [00:14<00:15, 5.52 MiB/s]
Extraction completed...: 0 file [00:14, ? file/s]
Dl Size...: 32%|###2 | 40/124 [00:14<00:14, 5.68 MiB/s]
Dl Completed...: 0%| | 0/1 [00:14<?, ? url/s]
Dl Size...: 32%|###2 | 40/124 [00:14<00:14, 5.68 MiB/s]
Extraction completed...: 0 file [00:14, ? file/s]
Dl Size...: 33%|###3 | 41/124 [00:14<00:14, 5.86 MiB/s]
Dl Completed...: 0%| | 0/1 [00:14<?, ? url/s]
Dl Size...: 33%|###3 | 41/124 [00:14<00:14, 5.86 MiB/s]
Extraction completed...: 0 file [00:14, ? file/s]
Dl Size...: 34%|###3 | 42/124 [00:14<00:13, 5.91 MiB/s]
Dl Completed...: 0%| | 0/1 [00:14<?, ? url/s]
Dl Size...: 34%|###3 | 42/124 [00:14<00:13, 5.91 MiB/s]
Extraction completed...: 0 file [00:14, ? file/s]
Dl Size...: 35%|###4 | 43/124 [00:14<00:14, 5.61 MiB/s]
Dl Completed...: 0%| | 0/1 [00:14<?, ? url/s]
Dl Size...: 35%|###4 | 43/124 [00:14<00:14, 5.61 MiB/s]
Extraction completed...: 0 file [00:14, ? file/s]
Dl Size...: 35%|###5 | 44/124 [00:14<00:14, 5.50 MiB/s]
Dl Completed...: 0%| | 0/1 [00:14<?, ? url/s]
Dl Size...: 35%|###5 | 44/124 [00:14<00:14, 5.50 MiB/s]
Extraction completed...: 0 file [00:14, ? file/s]
Dl Size...: 36%|###6 | 45/124 [00:15<00:15, 5.24 MiB/s]
Dl Completed...: 0%| | 0/1 [00:15<?, ? url/s]
Dl Size...: 36%|###6 | 45/124 [00:15<00:15, 5.24 MiB/s]
Extraction completed...: 0 file [00:15, ? file/s]
Dl Size...: 37%|###7 | 46/124 [00:15<00:14, 5.29 MiB/s]
Dl Completed...: 0%| | 0/1 [00:15<?, ? url/s]
Dl Size...: 37%|###7 | 46/124 [00:15<00:14, 5.29 MiB/s]
Extraction completed...: 0 file [00:15, ? file/s]
Dl Size...: 38%|###7 | 47/124 [00:15<00:14, 5.33 MiB/s]
Dl Completed...: 0%| | 0/1 [00:15<?, ? url/s]
Dl Size...: 38%|###7 | 47/124 [00:15<00:14, 5.33 MiB/s]
Extraction completed...: 0 file [00:15, ? file/s]
Dl Size...: 39%|###8 | 48/124 [00:15<00:13, 5.43 MiB/s]
Dl Completed...: 0%| | 0/1 [00:15<?, ? url/s]
Dl Size...: 39%|###8 | 48/124 [00:15<00:13, 5.43 MiB/s]
Extraction completed...: 0 file [00:15, ? file/s]
Dl Size...: 40%|###9 | 49/124 [00:15<00:13, 5.51 MiB/s]
Dl Completed...: 0%| | 0/1 [00:15<?, ? url/s]
Dl Size...: 40%|###9 | 49/124 [00:15<00:13, 5.51 MiB/s]
Extraction completed...: 0 file [00:15, ? file/s]
Dl Size...: 40%|#### | 50/124 [00:16<00:13, 5.56 MiB/s]
Dl Completed...: 0%| | 0/1 [00:16<?, ? url/s]
Dl Size...: 40%|#### | 50/124 [00:16<00:13, 5.56 MiB/s]
Extraction completed...: 0 file [00:16, ? file/s]
Dl Size...: 41%|####1 | 51/124 [00:16<00:12, 5.65 MiB/s]
Dl Completed...: 0%| | 0/1 [00:16<?, ? url/s]
Dl Size...: 41%|####1 | 51/124 [00:16<00:12, 5.65 MiB/s]
Extraction completed...: 0 file [00:16, ? file/s]
Dl Size...: 42%|####1 | 52/124 [00:16<00:12, 5.71 MiB/s]
Dl Completed...: 0%| | 0/1 [00:16<?, ? url/s]
Dl Size...: 42%|####1 | 52/124 [00:16<00:12, 5.71 MiB/s]
Extraction completed...: 0 file [00:16, ? file/s]
Dl Size...: 43%|####2 | 53/124 [00:16<00:12, 5.70 MiB/s]
Dl Completed...: 0%| | 0/1 [00:16<?, ? url/s]
Dl Size...: 43%|####2 | 53/124 [00:16<00:12, 5.70 MiB/s]
Extraction completed...: 0 file [00:16, ? file/s]
Dl Size...: 44%|####3 | 54/124 [00:16<00:13, 5.14 MiB/s]
Dl Completed...: 0%| | 0/1 [00:16<?, ? url/s]
Dl Size...: 44%|####3 | 54/124 [00:16<00:13, 5.14 MiB/s]
Extraction completed...: 0 file [00:16, ? file/s]
Dl Size...: 44%|####4 | 55/124 [00:17<00:13, 5.02 MiB/s]
Dl Completed...: 0%| | 0/1 [00:17<?, ? url/s]
Dl Size...: 44%|####4 | 55/124 [00:17<00:13, 5.02 MiB/s]
Extraction completed...: 0 file [00:17, ? file/s]
Dl Size...: 45%|####5 | 56/124 [00:17<00:14, 4.75 MiB/s]
Dl Completed...: 0%| | 0/1 [00:17<?, ? url/s]
Dl Size...: 45%|####5 | 56/124 [00:17<00:14, 4.75 MiB/s]
Extraction completed...: 0 file [00:17, ? file/s]
Dl Size...: 46%|####5 | 57/124 [00:17<00:14, 4.62 MiB/s]
Dl Completed...: 0%| | 0/1 [00:17<?, ? url/s]
Dl Size...: 46%|####5 | 57/124 [00:17<00:14, 4.62 MiB/s]
Extraction completed...: 0 file [00:17, ? file/s]
Dl Size...: 47%|####6 | 58/124 [00:17<00:14, 4.71 MiB/s]
Dl Completed...: 0%| | 0/1 [00:17<?, ? url/s]
Dl Size...: 47%|####6 | 58/124 [00:17<00:14, 4.71 MiB/s]
Extraction completed...: 0 file [00:17, ? file/s]
Dl Size...: 48%|####7 | 59/124 [00:17<00:14, 4.62 MiB/s]
Dl Completed...: 0%| | 0/1 [00:17<?, ? url/s]
Dl Size...: 48%|####7 | 59/124 [00:17<00:14, 4.62 MiB/s]
Extraction completed...: 0 file [00:17, ? file/s]
Dl Size...: 48%|####8 | 60/124 [00:18<00:13, 4.76 MiB/s]
Dl Completed...: 0%| | 0/1 [00:18<?, ? url/s]
Dl Size...: 48%|####8 | 60/124 [00:18<00:13, 4.76 MiB/s]
Extraction completed...: 0 file [00:18, ? file/s]
Dl Size...: 49%|####9 | 61/124 [00:18<00:12, 4.88 MiB/s]
Dl Completed...: 0%| | 0/1 [00:18<?, ? url/s]
Dl Size...: 49%|####9 | 61/124 [00:18<00:12, 4.88 MiB/s]
Extraction completed...: 0 file [00:18, ? file/s]
Dl Size...: 50%|##### | 62/124 [00:18<00:13, 4.76 MiB/s]
Dl Completed...: 0%| | 0/1 [00:18<?, ? url/s]
Dl Size...: 50%|##### | 62/124 [00:18<00:13, 4.76 MiB/s]
Extraction completed...: 0 file [00:18, ? file/s]
Dl Size...: 51%|##### | 63/124 [00:18<00:13, 4.49 MiB/s]
Dl Completed...: 0%| | 0/1 [00:18<?, ? url/s]
Dl Size...: 51%|##### | 63/124 [00:18<00:13, 4.49 MiB/s]
Extraction completed...: 0 file [00:18, ? file/s]
Dl Size...: 52%|#####1 | 64/124 [00:19<00:14, 4.19 MiB/s]
Dl Completed...: 0%| | 0/1 [00:19<?, ? url/s]
Dl Size...: 52%|#####1 | 64/124 [00:19<00:14, 4.19 MiB/s]
Extraction completed...: 0 file [00:19, ? file/s]
Dl Size...: 52%|#####2 | 65/124 [00:19<00:14, 3.99 MiB/s]
Dl Completed...: 0%| | 0/1 [00:19<?, ? url/s]
Dl Size...: 52%|#####2 | 65/124 [00:19<00:14, 3.99 MiB/s]
Extraction completed...: 0 file [00:19, ? file/s]
Dl Size...: 53%|#####3 | 66/124 [00:19<00:14, 3.93 MiB/s]
Dl Completed...: 0%| | 0/1 [00:19<?, ? url/s]
Dl Size...: 53%|#####3 | 66/124 [00:19<00:14, 3.93 MiB/s]
Extraction completed...: 0 file [00:19, ? file/s]
Dl Size...: 54%|#####4 | 67/124 [00:19<00:14, 3.91 MiB/s]
Dl Completed...: 0%| | 0/1 [00:19<?, ? url/s]
Dl Size...: 54%|#####4 | 67/124 [00:19<00:14, 3.91 MiB/s]
Extraction completed...: 0 file [00:19, ? file/s]
Dl Size...: 55%|#####4 | 68/124 [00:20<00:14, 3.90 MiB/s]
Dl Completed...: 0%| | 0/1 [00:20<?, ? url/s]
Dl Size...: 55%|#####4 | 68/124 [00:20<00:14, 3.90 MiB/s]
Extraction completed...: 0 file [00:20, ? file/s]
Dl Size...: 56%|#####5 | 69/124 [00:20<00:14, 3.91 MiB/s]
Dl Completed...: 0%| | 0/1 [00:20<?, ? url/s]
Dl Size...: 56%|#####5 | 69/124 [00:20<00:14, 3.91 MiB/s]
Extraction completed...: 0 file [00:20, ? file/s]
Dl Size...: 56%|#####6 | 70/124 [00:20<00:13, 3.91 MiB/s]
Dl Completed...: 0%| | 0/1 [00:20<?, ? url/s]
Dl Size...: 56%|#####6 | 70/124 [00:20<00:13, 3.91 MiB/s]
Extraction completed...: 0 file [00:20, ? file/s]
Dl Size...: 57%|#####7 | 71/124 [00:20<00:13, 3.94 MiB/s]
Dl Completed...: 0%| | 0/1 [00:20<?, ? url/s]
Dl Size...: 57%|#####7 | 71/124 [00:20<00:13, 3.94 MiB/s]
Extraction completed...: 0 file [00:20, ? file/s]
Dl Size...: 58%|#####8 | 72/124 [00:21<00:13, 3.98 MiB/s]
Dl Completed...: 0%| | 0/1 [00:21<?, ? url/s]
Dl Size...: 58%|#####8 | 72/124 [00:21<00:13, 3.98 MiB/s]
Extraction completed...: 0 file [00:21, ? file/s]
Dl Size...: 59%|#####8 | 73/124 [00:21<00:12, 4.04 MiB/s]
Dl Completed...: 0%| | 0/1 [00:21<?, ? url/s]
Dl Size...: 59%|#####8 | 73/124 [00:21<00:12, 4.04 MiB/s]
Extraction completed...: 0 file [00:21, ? file/s]
Dl Size...: 60%|#####9 | 74/124 [00:21<00:12, 4.03 MiB/s]
Dl Completed...: 0%| | 0/1 [00:21<?, ? url/s]
Dl Size...: 60%|#####9 | 74/124 [00:21<00:12, 4.03 MiB/s]
Extraction completed...: 0 file [00:21, ? file/s]
Dl Size...: 60%|###### | 75/124 [00:21<00:12, 4.07 MiB/s]
Dl Completed...: 0%| | 0/1 [00:21<?, ? url/s]
Dl Size...: 60%|###### | 75/124 [00:21<00:12, 4.07 MiB/s]
Extraction completed...: 0 file [00:21, ? file/s]
Dl Size...: 61%|######1 | 76/124 [00:22<00:11, 4.13 MiB/s]
Dl Completed...: 0%| | 0/1 [00:22<?, ? url/s]
Dl Size...: 61%|######1 | 76/124 [00:22<00:11, 4.13 MiB/s]
Extraction completed...: 0 file [00:22, ? file/s]
Dl Size...: 62%|######2 | 77/124 [00:22<00:11, 4.13 MiB/s]
Dl Completed...: 0%| | 0/1 [00:22<?, ? url/s]
Dl Size...: 62%|######2 | 77/124 [00:22<00:11, 4.13 MiB/s]
Extraction completed...: 0 file [00:22, ? file/s]
Dl Size...: 63%|######2 | 78/124 [00:22<00:11, 4.15 MiB/s]
Dl Completed...: 0%| | 0/1 [00:22<?, ? url/s]
Dl Size...: 63%|######2 | 78/124 [00:22<00:11, 4.15 MiB/s]
Extraction completed...: 0 file [00:22, ? file/s]
Dl Size...: 64%|######3 | 79/124 [00:22<00:10, 4.13 MiB/s]
Dl Completed...: 0%| | 0/1 [00:22<?, ? url/s]
Dl Size...: 64%|######3 | 79/124 [00:22<00:10, 4.13 MiB/s]
Extraction completed...: 0 file [00:22, ? file/s]
Dl Size...: 65%|######4 | 80/124 [00:23<00:10, 4.14 MiB/s]
Dl Completed...: 0%| | 0/1 [00:23<?, ? url/s]
Dl Size...: 65%|######4 | 80/124 [00:23<00:10, 4.14 MiB/s]
Extraction completed...: 0 file [00:23, ? file/s]
Dl Size...: 65%|######5 | 81/124 [00:23<00:10, 4.17 MiB/s]
Dl Completed...: 0%| | 0/1 [00:23<?, ? url/s]
Dl Size...: 65%|######5 | 81/124 [00:23<00:10, 4.17 MiB/s]
Extraction completed...: 0 file [00:23, ? file/s]
Dl Size...: 66%|######6 | 82/124 [00:23<00:10, 4.12 MiB/s]
Dl Completed...: 0%| | 0/1 [00:23<?, ? url/s]
Dl Size...: 66%|######6 | 82/124 [00:23<00:10, 4.12 MiB/s]
Extraction completed...: 0 file [00:23, ? file/s]
Dl Size...: 67%|######6 | 83/124 [00:23<00:09, 4.19 MiB/s]
Dl Completed...: 0%| | 0/1 [00:23<?, ? url/s]
Dl Size...: 67%|######6 | 83/124 [00:23<00:09, 4.19 MiB/s]
Extraction completed...: 0 file [00:23, ? file/s]
Dl Size...: 68%|######7 | 84/124 [00:24<00:09, 4.16 MiB/s]
Dl Completed...: 0%| | 0/1 [00:24<?, ? url/s]
Dl Size...: 68%|######7 | 84/124 [00:24<00:09, 4.16 MiB/s]
Extraction completed...: 0 file [00:24, ? file/s]
Dl Size...: 69%|######8 | 85/124 [00:24<00:09, 4.19 MiB/s]
Dl Completed...: 0%| | 0/1 [00:24<?, ? url/s]
Dl Size...: 69%|######8 | 85/124 [00:24<00:09, 4.19 MiB/s]
Extraction completed...: 0 file [00:24, ? file/s]
Dl Size...: 69%|######9 | 86/124 [00:24<00:09, 3.89 MiB/s]
Dl Completed...: 0%| | 0/1 [00:24<?, ? url/s]
Dl Size...: 69%|######9 | 86/124 [00:24<00:09, 3.89 MiB/s]
Extraction completed...: 0 file [00:24, ? file/s]
Dl Size...: 70%|####### | 87/124 [00:24<00:09, 3.88 MiB/s]
Dl Completed...: 0%| | 0/1 [00:24<?, ? url/s]
Dl Size...: 70%|####### | 87/124 [00:24<00:09, 3.88 MiB/s]
Extraction completed...: 0 file [00:24, ? file/s]
Dl Size...: 71%|####### | 88/124 [00:25<00:10, 3.57 MiB/s]
Dl Completed...: 0%| | 0/1 [00:25<?, ? url/s]
Dl Size...: 71%|####### | 88/124 [00:25<00:10, 3.57 MiB/s]
Extraction completed...: 0 file [00:25, ? file/s]
Dl Size...: 72%|#######1 | 89/124 [00:25<00:09, 3.53 MiB/s]
Dl Completed...: 0%| | 0/1 [00:25<?, ? url/s]
Dl Size...: 72%|#######1 | 89/124 [00:25<00:09, 3.53 MiB/s]
Extraction completed...: 0 file [00:25, ? file/s]
Dl Size...: 73%|#######2 | 90/124 [00:25<00:09, 3.51 MiB/s]
Dl Completed...: 0%| | 0/1 [00:25<?, ? url/s]
Dl Size...: 73%|#######2 | 90/124 [00:25<00:09, 3.51 MiB/s]
Extraction completed...: 0 file [00:25, ? file/s]
Dl Size...: 73%|#######3 | 91/124 [00:26<00:09, 3.51 MiB/s]
Dl Completed...: 0%| | 0/1 [00:26<?, ? url/s]
Dl Size...: 73%|#######3 | 91/124 [00:26<00:09, 3.51 MiB/s]
Extraction completed...: 0 file [00:26, ? file/s]
Dl Size...: 74%|#######4 | 92/124 [00:26<00:08, 3.56 MiB/s]
Dl Completed...: 0%| | 0/1 [00:26<?, ? url/s]
Dl Size...: 74%|#######4 | 92/124 [00:26<00:08, 3.56 MiB/s]
Extraction completed...: 0 file [00:26, ? file/s]
Dl Size...: 75%|#######5 | 93/124 [00:26<00:08, 3.62 MiB/s]
Dl Completed...: 0%| | 0/1 [00:26<?, ? url/s]
Dl Size...: 75%|#######5 | 93/124 [00:26<00:08, 3.62 MiB/s]
Extraction completed...: 0 file [00:26, ? file/s]
Dl Size...: 76%|#######5 | 94/124 [00:26<00:08, 3.67 MiB/s]
Dl Completed...: 0%| | 0/1 [00:26<?, ? url/s]
Dl Size...: 76%|#######5 | 94/124 [00:26<00:08, 3.67 MiB/s]
Extraction completed...: 0 file [00:26, ? file/s]
Dl Size...: 77%|#######6 | 95/124 [00:27<00:07, 3.68 MiB/s]
Dl Completed...: 0%| | 0/1 [00:27<?, ? url/s]
Dl Size...: 77%|#######6 | 95/124 [00:27<00:07, 3.68 MiB/s]
Extraction completed...: 0 file [00:27, ? file/s]
Dl Size...: 77%|#######7 | 96/124 [00:27<00:07, 3.51 MiB/s]
Dl Completed...: 0%| | 0/1 [00:27<?, ? url/s]
Dl Size...: 77%|#######7 | 96/124 [00:27<00:07, 3.51 MiB/s]
Extraction completed...: 0 file [00:27, ? file/s]
Dl Size...: 78%|#######8 | 97/124 [00:27<00:08, 3.27 MiB/s]
Dl Completed...: 0%| | 0/1 [00:27<?, ? url/s]
Dl Size...: 78%|#######8 | 97/124 [00:27<00:08, 3.27 MiB/s]
Extraction completed...: 0 file [00:27, ? file/s]
Dl Size...: 79%|#######9 | 98/124 [00:28<00:08, 3.19 MiB/s]
Dl Completed...: 0%| | 0/1 [00:28<?, ? url/s]
Dl Size...: 79%|#######9 | 98/124 [00:28<00:08, 3.19 MiB/s]
Extraction completed...: 0 file [00:28, ? file/s]
Dl Size...: 80%|#######9 | 99/124 [00:28<00:07, 3.16 MiB/s]
Dl Completed...: 0%| | 0/1 [00:28<?, ? url/s]
Dl Size...: 80%|#######9 | 99/124 [00:28<00:07, 3.16 MiB/s]
Extraction completed...: 0 file [00:28, ? file/s]
Dl Size...: 81%|######## | 100/124 [00:28<00:07, 3.17 MiB/s]
Dl Completed...: 0%| | 0/1 [00:28<?, ? url/s]
Dl Size...: 81%|######## | 100/124 [00:28<00:07, 3.17 MiB/s]
Extraction completed...: 0 file [00:28, ? file/s]
Dl Size...: 81%|########1 | 101/124 [00:29<00:07, 3.15 MiB/s]
Dl Completed...: 0%| | 0/1 [00:29<?, ? url/s]
Dl Size...: 81%|########1 | 101/124 [00:29<00:07, 3.15 MiB/s]
Extraction completed...: 0 file [00:29, ? file/s]
Dl Size...: 82%|########2 | 102/124 [00:29<00:06, 3.19 MiB/s]
Dl Completed...: 0%| | 0/1 [00:29<?, ? url/s]
Dl Size...: 82%|########2 | 102/124 [00:29<00:06, 3.19 MiB/s]
Extraction completed...: 0 file [00:29, ? file/s]
Dl Size...: 83%|########3 | 103/124 [00:29<00:06, 3.21 MiB/s]
Dl Completed...: 0%| | 0/1 [00:29<?, ? url/s]
Dl Size...: 83%|########3 | 103/124 [00:29<00:06, 3.21 MiB/s]
Extraction completed...: 0 file [00:29, ? file/s]
Dl Size...: 84%|########3 | 104/124 [00:29<00:06, 3.26 MiB/s]
Dl Completed...: 0%| | 0/1 [00:29<?, ? url/s]
Dl Size...: 84%|########3 | 104/124 [00:29<00:06, 3.26 MiB/s]
Extraction completed...: 0 file [00:29, ? file/s]
Dl Size...: 85%|########4 | 105/124 [00:30<00:05, 3.26 MiB/s]
Dl Completed...: 0%| | 0/1 [00:30<?, ? url/s]
Dl Size...: 85%|########4 | 105/124 [00:30<00:05, 3.26 MiB/s]
Extraction completed...: 0 file [00:30, ? file/s]
Dl Size...: 85%|########5 | 106/124 [00:30<00:05, 3.30 MiB/s]
Dl Completed...: 0%| | 0/1 [00:30<?, ? url/s]
Dl Size...: 85%|########5 | 106/124 [00:30<00:05, 3.30 MiB/s]
Extraction completed...: 0 file [00:30, ? file/s]
Dl Size...: 86%|########6 | 107/124 [00:30<00:05, 3.29 MiB/s]
Dl Completed...: 0%| | 0/1 [00:30<?, ? url/s]
Dl Size...: 86%|########6 | 107/124 [00:30<00:05, 3.29 MiB/s]
Extraction completed...: 0 file [00:30, ? file/s]
Dl Size...: 87%|########7 | 108/124 [00:31<00:04, 3.33 MiB/s]
Dl Completed...: 0%| | 0/1 [00:31<?, ? url/s]
Dl Size...: 87%|########7 | 108/124 [00:31<00:04, 3.33 MiB/s]
Extraction completed...: 0 file [00:31, ? file/s]
Dl Size...: 88%|########7 | 109/124 [00:31<00:04, 3.31 MiB/s]
Dl Completed...: 0%| | 0/1 [00:31<?, ? url/s]
Dl Size...: 88%|########7 | 109/124 [00:31<00:04, 3.31 MiB/s]
Extraction completed...: 0 file [00:31, ? file/s]
Dl Size...: 89%|########8 | 110/124 [00:31<00:04, 3.33 MiB/s]
Dl Completed...: 0%| | 0/1 [00:31<?, ? url/s]
Dl Size...: 89%|########8 | 110/124 [00:31<00:04, 3.33 MiB/s]
Extraction completed...: 0 file [00:31, ? file/s]
Dl Size...: 90%|########9 | 111/124 [00:32<00:03, 3.32 MiB/s]
Dl Completed...: 0%| | 0/1 [00:32<?, ? url/s]
Dl Size...: 90%|########9 | 111/124 [00:32<00:03, 3.32 MiB/s]
Extraction completed...: 0 file [00:32, ? file/s]
Dl Size...: 90%|######### | 112/124 [00:32<00:03, 3.35 MiB/s]
Dl Completed...: 0%| | 0/1 [00:32<?, ? url/s]
Dl Size...: 90%|######### | 112/124 [00:32<00:03, 3.35 MiB/s]
Extraction completed...: 0 file [00:32, ? file/s]
Dl Size...: 91%|#########1| 113/124 [00:32<00:03, 3.34 MiB/s]
Dl Completed...: 0%| | 0/1 [00:32<?, ? url/s]
Dl Size...: 91%|#########1| 113/124 [00:32<00:03, 3.34 MiB/s]
Extraction completed...: 0 file [00:32, ? file/s]
Dl Size...: 92%|#########1| 114/124 [00:32<00:02, 3.34 MiB/s]
Dl Completed...: 0%| | 0/1 [00:32<?, ? url/s]
Dl Size...: 92%|#########1| 114/124 [00:32<00:02, 3.34 MiB/s]
Extraction completed...: 0 file [00:32, ? file/s]
Dl Size...: 93%|#########2| 115/124 [00:33<00:02, 3.34 MiB/s]
Dl Completed...: 0%| | 0/1 [00:33<?, ? url/s]
Dl Size...: 93%|#########2| 115/124 [00:33<00:02, 3.34 MiB/s]
Extraction completed...: 0 file [00:33, ? file/s]
Dl Size...: 94%|#########3| 116/124 [00:33<00:02, 3.39 MiB/s]
Dl Completed...: 0%| | 0/1 [00:33<?, ? url/s]
Dl Size...: 94%|#########3| 116/124 [00:33<00:02, 3.39 MiB/s]
Extraction completed...: 0 file [00:33, ? file/s]
Dl Size...: 94%|#########4| 117/124 [00:33<00:02, 3.34 MiB/s]
Dl Completed...: 0%| | 0/1 [00:33<?, ? url/s]
Dl Size...: 94%|#########4| 117/124 [00:33<00:02, 3.34 MiB/s]
Extraction completed...: 0 file [00:33, ? file/s]
Dl Size...: 95%|#########5| 118/124 [00:34<00:01, 3.38 MiB/s]
Dl Completed...: 0%| | 0/1 [00:34<?, ? url/s]
Dl Size...: 95%|#########5| 118/124 [00:34<00:01, 3.38 MiB/s]
Extraction completed...: 0 file [00:34, ? file/s]
Dl Size...: 96%|#########5| 119/124 [00:34<00:01, 3.35 MiB/s]
Dl Completed...: 0%| | 0/1 [00:34<?, ? url/s]
Dl Size...: 96%|#########5| 119/124 [00:34<00:01, 3.35 MiB/s]
Extraction completed...: 0 file [00:34, ? file/s]
Dl Size...: 97%|#########6| 120/124 [00:34<00:01, 3.40 MiB/s]
Dl Completed...: 0%| | 0/1 [00:34<?, ? url/s]
Dl Size...: 97%|#########6| 120/124 [00:34<00:01, 3.40 MiB/s]
Extraction completed...: 0 file [00:34, ? file/s]
Dl Size...: 98%|#########7| 121/124 [00:35<00:00, 3.49 MiB/s]
Dl Completed...: 0%| | 0/1 [00:35<?, ? url/s]
Dl Size...: 98%|#########7| 121/124 [00:35<00:00, 3.49 MiB/s]
Extraction completed...: 0 file [00:35, ? file/s]
Dl Size...: 98%|#########8| 122/124 [00:35<00:00, 3.47 MiB/s]
Dl Completed...: 0%| | 0/1 [00:35<?, ? url/s]
Dl Size...: 98%|#########8| 122/124 [00:35<00:00, 3.47 MiB/s]
Extraction completed...: 0 file [00:35, ? file/s]
Dl Size...: 99%|#########9| 123/124 [00:35<00:00, 3.51 MiB/s]
Dl Completed...: 0%| | 0/1 [00:35<?, ? url/s]
Dl Size...: 99%|#########9| 123/124 [00:35<00:00, 3.51 MiB/s]
Extraction completed...: 0 file [00:35, ? file/s]
Dl Size...: 100%|##########| 124/124 [00:35<00:00, 3.56 MiB/s]
Dl Completed...: 0%| | 0/1 [00:35<?, ? url/s]
Dl Size...: 100%|##########| 124/124 [00:35<00:00, 3.56 MiB/s]
Extraction completed...: 0 file [00:35, ? file/s]
Dl Completed...: 100%|##########| 1/1 [00:36<00:00, 36.00s/ url]
Dl Completed...: 100%|##########| 1/1 [00:36<00:00, 36.00s/ url]
Dl Size...: 100%|##########| 124/124 [00:36<00:00, 3.56 MiB/s]
Extraction completed...: 0 file [00:36, ? file/s]
Dl Completed...: 100%|##########| 1/1 [00:36<00:00, 36.00s/ url]
Dl Size...: 100%|##########| 124/124 [00:36<00:00, 3.56 MiB/s]
Extraction completed...: 0%| | 0/1 [00:36<?, ? file/s]
Extraction completed...: 100%|##########| 1/1 [00:37<00:00, 37.86s/ file]
Dl Completed...: 100%|##########| 1/1 [00:37<00:00, 36.00s/ url]
Dl Size...: 100%|##########| 124/124 [00:37<00:00, 3.56 MiB/s]
Extraction completed...: 100%|##########| 1/1 [00:37<00:00, 37.86s/ file]
Extraction completed...: 100%|##########| 1/1 [00:37<00:00, 37.87s/ file]
Dl Size...: 100%|##########| 124/124 [00:37<00:00, 3.27 MiB/s]
Dl Completed...: 100%|##########| 1/1 [00:37<00:00, 37.87s/ 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 | 481/7200 [00:00<00:01, 4804.83 examples/s]
Generating train examples...: 14%|#3 | 980/7200 [00:00<00:01, 4912.59 examples/s]
Generating train examples...: 21%|## | 1485/7200 [00:00<00:01, 4973.68 examples/s]
Generating train examples...: 28%|##7 | 1992/7200 [00:00<00:01, 5008.43 examples/s]
Generating train examples...: 35%|###4 | 2502/7200 [00:00<00:00, 5038.65 examples/s]
Generating train examples...: 42%|####1 | 3008/7200 [00:00<00:00, 5044.65 examples/s]
Generating train examples...: 49%|####8 | 3515/7200 [00:00<00:00, 5051.60 examples/s]
Generating train examples...: 56%|#####5 | 4024/7200 [00:00<00:00, 5063.24 examples/s]
Generating train examples...: 63%|######2 | 4531/7200 [00:00<00:00, 5062.16 examples/s]
Generating train examples...: 70%|######9 | 5038/7200 [00:01<00:00, 5063.76 examples/s]
Generating train examples...: 77%|#######7 | 5546/7200 [00:01<00:00, 5066.44 examples/s]
Generating train examples...: 84%|########4 | 6053/7200 [00:01<00:00, 5065.45 examples/s]
Generating train examples...: 91%|#########1| 6560/7200 [00:01<00:00, 5061.21 examples/s]
Generating train examples...: 98%|#########8| 7068/7200 [00:01<00:00, 5064.49 examples/s]
Shuffling /root/tensorflow_datasets/coil100/2.0.0.incomplete9CZJTV/coil100-train.tfrecord*...: 0%| | 0/7200 [00:00<?, ? examples/s]
Shuffling /root/tensorflow_datasets/coil100/2.0.0.incomplete9CZJTV/coil100-train.tfrecord*...: 94%|#########4| 6774/7200 [00:00<00:00, 67732.96 examples/s]
Generating splits...: 100%|##########| 1/1 [00:01<00:00, 1.54s/ 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()
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)
Downloading data from http://data.brainchip.com/models/akidanet_edge/akidanet_imagenet_224_alpha_50_edge_iq8_wq4_aq4.h5.
0/15993520 [..............................] - ETA: 0s
212992/15993520 [..............................] - ETA: 3s
712704/15993520 [>.............................] - ETA: 2s
1302528/15993520 [=>............................] - ETA: 1s
1892352/15993520 [==>...........................] - ETA: 1s
2359296/15993520 [===>..........................] - ETA: 1s
3055616/15993520 [====>.........................] - ETA: 1s
3645440/15993520 [=====>........................] - ETA: 1s
4218880/15993520 [======>.......................] - ETA: 1s
4775936/15993520 [=======>......................] - ETA: 1s
5365760/15993520 [=========>....................] - ETA: 0s
5914624/15993520 [==========>...................] - ETA: 0s
6406144/15993520 [===========>..................] - ETA: 0s
6840320/15993520 [===========>..................] - ETA: 0s
7307264/15993520 [============>.................] - ETA: 0s
7766016/15993520 [=============>................] - ETA: 0s
8241152/15993520 [==============>...............] - ETA: 0s
8724480/15993520 [===============>..............] - ETA: 0s
9224192/15993520 [================>.............] - ETA: 0s
9723904/15993520 [=================>............] - ETA: 0s
10231808/15993520 [==================>...........] - ETA: 0s
10747904/15993520 [===================>..........] - ETA: 0s
11272192/15993520 [====================>.........] - ETA: 0s
11804672/15993520 [=====================>........] - ETA: 0s
12345344/15993520 [======================>.......] - ETA: 0s
12894208/15993520 [=======================>......] - ETA: 0s
13410304/15993520 [========================>.....] - ETA: 0s
13803520/15993520 [========================>.....] - ETA: 0s
14221312/15993520 [=========================>....] - ETA: 0s
14581760/15993520 [==========================>...] - ETA: 0s
15007744/15993520 [===========================>..] - ETA: 0s
15327232/15993520 [===========================>..] - ETA: 0s
15663104/15993520 [============================>.] - ETA: 0s
15990784/15993520 [============================>.] - ETA: 0s
15993520/15993520 [==============================] - 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()
Model Summary
________________________________________________
Input shape Output shape Sequences Layers
================================================
[224, 224, 3] [1, 1, 4] 1 16
________________________________________________
________________________________________________________________
Layer (type) Output shape Kernel shape
============= SW/conv_0-akida_edge_layer (Software) ============
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')
Learned object 15 (class 0) with 1 sample(s) in 0.13s
Learned object 17 (class 1) with 1 sample(s) in 0.11s
Learned object 24 (class 2) with 1 sample(s) in 0.11s
Learned object 42 (class 3) with 1 sample(s) in 0.11s
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
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): 87.32%
Mean accuracy: 96.83%
Total running time of the script: ( 1 minutes 26.397 seconds)