image_classification

Image classification (ResNetv1-10 with CIFAR10)

This was adapted from:

Dataset

Model Topology

Performance (floating point model)

  • Accuracy - 86.2%

  • AUC - .989

Performance (quantized tflite model)

  • Accuracy - 86.1%

  • AUC - .988

Commands

# Do a "dry run" test training of the model
mltk train image_classification-test

# Train the model
mltk train image_classification

# Evaluate the trained model .tflite model
mltk evaluate image_classification --tflite

# Profile the model in the MVP hardware accelerator simulator
mltk profile image_classification --accelerator MVP

# Profile the model on a physical development board
mltk profile image_classification --accelerator MVP --device

Model Summary

mltk summarize image_classification --tflite

+-------+-----------------+-----------------+-----------------+-----------------------------------------------------+
| Index | OpCode          | Input(s)        | Output(s)       | Config                                              |
+-------+-----------------+-----------------+-----------------+-----------------------------------------------------+
| 0     | conv_2d         | 32x32x3 (int8)  | 32x32x16 (int8) | Padding:same stride:1x1 activation:relu             |
|       |                 | 3x3x3 (int8)    |                 |                                                     |
|       |                 | 16 (int32)      |                 |                                                     |
| 1     | conv_2d         | 32x32x16 (int8) | 32x32x16 (int8) | Padding:same stride:1x1 activation:relu             |
|       |                 | 3x3x16 (int8)   |                 |                                                     |
|       |                 | 16 (int32)      |                 |                                                     |
| 2     | conv_2d         | 32x32x16 (int8) | 32x32x16 (int8) | Padding:same stride:1x1 activation:none             |
|       |                 | 3x3x16 (int8)   |                 |                                                     |
|       |                 | 16 (int32)      |                 |                                                     |
| 3     | add             | 32x32x16 (int8) | 32x32x16 (int8) | Activation:relu                                     |
|       |                 | 32x32x16 (int8) |                 |                                                     |
| 4     | conv_2d         | 32x32x16 (int8) | 16x16x32 (int8) | Padding:same stride:2x2 activation:relu             |
|       |                 | 3x3x16 (int8)   |                 |                                                     |
|       |                 | 32 (int32)      |                 |                                                     |
| 5     | conv_2d         | 16x16x32 (int8) | 16x16x32 (int8) | Padding:same stride:1x1 activation:none             |
|       |                 | 3x3x32 (int8)   |                 |                                                     |
|       |                 | 32 (int32)      |                 |                                                     |
| 6     | conv_2d         | 32x32x16 (int8) | 16x16x32 (int8) | Padding:same stride:2x2 activation:none             |
|       |                 | 1x1x16 (int8)   |                 |                                                     |
|       |                 | 32 (int32)      |                 |                                                     |
| 7     | add             | 16x16x32 (int8) | 16x16x32 (int8) | Activation:relu                                     |
|       |                 | 16x16x32 (int8) |                 |                                                     |
| 8     | conv_2d         | 16x16x32 (int8) | 8x8x64 (int8)   | Padding:same stride:2x2 activation:relu             |
|       |                 | 3x3x32 (int8)   |                 |                                                     |
|       |                 | 64 (int32)      |                 |                                                     |
| 9     | conv_2d         | 8x8x64 (int8)   | 8x8x64 (int8)   | Padding:same stride:1x1 activation:none             |
|       |                 | 3x3x64 (int8)   |                 |                                                     |
|       |                 | 64 (int32)      |                 |                                                     |
| 10    | conv_2d         | 16x16x32 (int8) | 8x8x64 (int8)   | Padding:same stride:2x2 activation:none             |
|       |                 | 1x1x32 (int8)   |                 |                                                     |
|       |                 | 64 (int32)      |                 |                                                     |
| 11    | add             | 8x8x64 (int8)   | 8x8x64 (int8)   | Activation:relu                                     |
|       |                 | 8x8x64 (int8)   |                 |                                                     |
| 12    | average_pool_2d | 8x8x64 (int8)   | 1x1x64 (int8)   | Padding:valid stride:8x8 filter:8x8 activation:none |
| 13    | reshape         | 1x1x64 (int8)   | 64 (int8)       | BuiltinOptionsType=0                                |
|       |                 | 2 (int32)       |                 |                                                     |
| 14    | fully_connected | 64 (int8)       | 10 (int8)       | Activation:none                                     |
|       |                 | 64 (int8)       |                 |                                                     |
|       |                 | 10 (int32)      |                 |                                                     |
| 15    | softmax         | 10 (int8)       | 10 (int8)       | BuiltinOptionsType=9                                |
+-------+-----------------+-----------------+-----------------+-----------------------------------------------------+
Total MACs: 12.502 M
Total OPs: 25.122 M
Name: image_classification
Version: 1
Description: TinyML: Image classification - ResNetv1-10 with CIFAR10
Classes: airplane, automobile, bird, cat, deer, dog, frog, horse, ship, truck
hash: d170adc21388920caa3f64ba22cd5b5d
date: 2022-02-04T19:20:20.062Z
runtime_memory_size: 53972
samplewise_norm.rescale: 0.0
samplewise_norm.mean_and_std: False
.tflite file size: 99.3kB

Model Profiling Report

# Profile on physical EFR32xG24 using MVP accelerator
mltk profile image_classification --device --accelerator MVP

 Profiling Summary
 Name: image_classification
 Accelerator: MVP
 Input Shape: 1x32x32x3
 Input Data Type: int8
 Output Shape: 1x10
 Output Data Type: int8
 Flash, Model File Size (bytes): 99.2k
 RAM, Runtime Memory Size (bytes): 86.9k
 Operation Count: 25.2M
 Multiply-Accumulate Count: 12.4M
 Layer Count: 16
 Unsupported Layer Count: 0
 Accelerator Cycle Count: 9.3M
 CPU Cycle Count: 225.4k
 CPU Utilization (%): 2.4
 Clock Rate (hz): 78.0M
 Time (s): 118.9m
 Ops/s: 211.8M
 MACs/s: 104.7M
 Inference/s: 8.4

 Model Layers
 +-------+-----------------+--------+--------+------------+------------+----------+-------------------------+--------------+-----------------------------------------------------+
 | Index | OpCode          | # Ops  | # MACs | Acc Cycles | CPU Cycles | Time (s) | Input Shape             | Output Shape | Options                                             |
 +-------+-----------------+--------+--------+------------+------------+----------+-------------------------+--------------+-----------------------------------------------------+
 | 0     | conv_2d         | 933.9k | 442.4k | 583.4k     | 30.6k      | 7.5m     | 1x32x32x3,16x3x3x3,16   | 1x32x32x16   | Padding:same stride:1x1 activation:relu             |
 | 1     | conv_2d         | 4.8M   | 2.4M   | 1.8M       | 30.1k      | 22.3m    | 1x32x32x16,16x3x3x16,16 | 1x32x32x16   | Padding:same stride:1x1 activation:relu             |
 | 2     | conv_2d         | 4.7M   | 2.4M   | 1.8M       | 30.0k      | 22.3m    | 1x32x32x16,16x3x3x16,16 | 1x32x32x16   | Padding:same stride:1x1 activation:none             |
 | 3     | add             | 16.4k  | 0      | 57.4k      | 9.2k       | 840.0u   | 1x32x32x16,1x32x32x16   | 1x32x32x16   | Activation:relu                                     |
 | 4     | conv_2d         | 2.4M   | 1.2M   | 883.8k     | 15.3k      | 11.2m    | 1x32x32x16,32x3x3x16,32 | 1x16x16x32   | Padding:same stride:2x2 activation:relu             |
 | 5     | conv_2d         | 4.7M   | 2.4M   | 1.6M       | 30.2k      | 21.0m    | 1x16x16x32,32x3x3x32,32 | 1x16x16x32   | Padding:same stride:1x1 activation:none             |
 | 6     | conv_2d         | 270.3k | 131.1k | 131.2k     | 5.3k       | 1.7m     | 1x32x32x16,32x1x1x16,32 | 1x16x16x32   | Padding:same stride:2x2 activation:none             |
 | 7     | add             | 8.2k   | 0      | 28.7k      | 5.3k       | 450.0u   | 1x16x16x32,1x16x16x32   | 1x16x16x32   | Activation:relu                                     |
 | 8     | conv_2d         | 2.4M   | 1.2M   | 830.3k     | 15.3k      | 10.5m    | 1x16x16x32,64x3x3x32,64 | 1x8x8x64     | Padding:same stride:2x2 activation:relu             |
 | 9     | conv_2d         | 4.7M   | 2.4M   | 1.5M       | 30.2k      | 19.1m    | 1x8x8x64,64x3x3x64,64   | 1x8x8x64     | Padding:same stride:1x1 activation:none             |
 | 10    | conv_2d         | 266.2k | 131.1k | 115.4k     | 5.3k       | 1.5m     | 1x16x16x32,64x1x1x32,64 | 1x8x8x64     | Padding:same stride:2x2 activation:none             |
 | 11    | add             | 4.1k   | 0      | 14.4k      | 3.4k       | 240.0u   | 1x8x8x64,1x8x8x64       | 1x8x8x64     | Activation:relu                                     |
 | 12    | average_pool_2d | 4.2k   | 0      | 2.2k       | 3.9k       | 60.0u    | 1x8x8x64                | 1x1x1x64     | Padding:valid stride:8x8 filter:8x8 activation:none |
 | 13    | reshape         | 0      | 0      | 0          | 769.0      | 30.0u    | 1x1x1x64,2              | 1x64         | Type=none                                           |
 | 14    | fully_connected | 1.3k   | 640.0  | 1.0k       | 2.1k       | 30.0u    | 1x64,10x64,10           | 1x10         | Activation:none                                     |
 | 15    | softmax         | 50.0   | 0      | 0          | 8.2k       | 120.0u   | 1x10                    | 1x10         | Type=softmaxoptions                                 |
 +-------+-----------------+--------+--------+------------+------------+----------+-------------------------+--------------+-----------------------------------------------------+

Model Diagram

mltk view image_classification --tflite