This repository contains the code to bring EfficientNet models into Edge Impulse.
Just want to use this model? You don't need this repository. In your Edge Impulse project go to any 'Transfer learning (images)' block, click Choose a different model and select EfficientNet.
You can use this repository as a basis to bring other types of ML base models into Edge Impulse. As a primer, read the Custom learning blocks page in the Edge Impulse docs.
You run this pipeline via Docker. This encapsulates all dependencies and packages for you.
-
Install Docker Desktop.
-
Install the Edge Impulse CLI v1.16.0 or higher.
-
Create a new Edge Impulse project, and add an image dataset (see Adding sight to your sensors).
-
Under Create impulse, set the resolution to a square size (e.g. 224x224), then add a 'Image' processing block (make sure it's set to RGB), and a 'Transfer Learning (Images)' ML block.
-
Open a command prompt or terminal window.
-
Initialize the block:
$ edge-impulse-blocks init
-
Fetch new data via:
$ edge-impulse-blocks runner --download-data data/
-
Build the container:
$ docker build -t efficientnet .
-
Run the container to test the script (you don't need to rebuild the container if you make changes):
macOS, Linux
$ docker run --rm -v $PWD:/app efficientnet \ --data-directory /app/data \ --epochs 20 \ --learning-rate 0.001 \ --model-size b0 \ --use-pretrained-weights \ --out-directory out/
Windows (Command prompt)
$ docker run --rm -v "%cd%":/app efficientnet \ --data-directory /app/data \ --epochs 20 \ --learning-rate 0.001 \ --model-size b0 \ --use-pretrained-weights \ --out-directory out/
Windows (Powershell)
$ docker run --rm -v ${PWD}$:/app efficientnet \ --data-directory /app/data \ --epochs 20 \ --learning-rate 0.001 \ --model-size b0 \ --use-pretrained-weights \ --out-directory out/
-
This creates a saved model ZIP file in the 'out' directory.
If you have extra packages that you want to install within the container, add them to requirements.txt
and rebuild the container.
To add new arguments, see Custom learning blocks > Arguments to your script.
To get up-to-date data from your project:
-
Install the Edge Impulse CLI v1.16 or higher.
-
Open a command prompt or terminal window.
-
Fetch new data via:
$ edge-impulse-blocks runner --download-data data/
You can also push this block back to Edge Impulse, that makes it available like any other ML block so you can retrain your model when new data comes in, or deploy the model to device. See Docs > Adding custom learning blocks for more information.
-
Push the block:
$ edge-impulse-blocks push
-
The block is now available under any of your projects via Create impulse > Add learning block, then select the block via 'Choose a different model' on the 'Transfer learning' page.
If you want to change the block type because you're classifying a different data type, or build a model with a different output format, run:
$ rm parameters.json .ei-block-config
$ edge-impulse-blocks init
And answer the wizard. This'll create a new parameters.json file.