/tiny-ml-classifier

Tiny ML classifier - Glasses or No Glasses

Primary LanguageJupyter NotebookMIT LicenseMIT

Tiny ML Classifier

Tiny ML classifier - Glasses or No Glasses

Image

DEMO

Todo (09.09.2021)

  • Create infrastructure for Git
  • Quick R&D
  • Free data
  • Transfer
  • Augmentation data
  • Pytorch or TF (as tflite)
  • free skeleton model for init weights (I think it will be EfficientNet-Lite* models, MobileNetV2 or ResNet50)
  • Training Loop (Use API for convertin to Tiny models - for example .tflite)
  • Create inference demo
  • Optimised
  • Bonus --->
    • Deployment for example RPi (with minimal memory - like RPi 3 with 1GB memory and without threading CPU)
    • Documentation on GitHub
    • Video demonstration realtime classification from Camera

Clone Tiny ML Classifier

git clone https://github.com/rvjenya/tiny-ml-classifier.git
or use ssh - git@github.com:rvjenya/tiny-ml-classifier.git
cd tiny-ml-classifier

Up env

Create env with Python3.7

python3.7 -m venv venv

source venv/bin/activate

./install.sh

Dataset

  • Go to (kaggle.com) and download Free dataset from - Here

Transfer and Augmentation

  • Tools for Augmentation data and exporting many formats (roboflow.com)

  • From Scratch Augmentation - use Albumentations

Use TF classification notebook

  • Open on your PC with GPU or Colab (I've attached colab version but you can export it to your GPU env) Open All Collab
https://colab.research.google.com/drive/1hThmbqVvYiMUD5AOORX_TXjLq2XiH-DO?usp=sharing

GPU Setting

Edit > Notebook settings or Runtime > Change runtime type and select GPU as Hardware accelerator

Training

  • Done Models:
    • mobilenet_v2 (will be faster)
    • Inception_v3

For all models I've made FP16 version tflite - you can use it on GPU.

Save TF and TFLite models

Final models .pb and .tflite here You can test my another tflite models with number calibration = 45 / 100 and 200 (If you want, you can try it parameters in TFLiteConverter step)

Training result

My result of training by 10 Epoch:

Image of plt

Test infer

Testing classification:

Image of plt Image of plt

Realtime Inference

DEMO

If you need specific architecture you can use these models:

  • FP32 (Full)
  • FP16 (optimisation for GPU)

for Realtime Camera Demo use:


(venv) python cam-demo.py

for Raspberry Pi Camera demo use

DEMO

python3 classify-cam-rpi.py \
  --model /model/tflite/optimise_to_3Mb/MobileNetV2/model.tflite \
  --labels /model/tflite/optimise_to_3Mb/MobileNetV2/labels.txt