Skip to content

edgeimpulse/ml-block-efficientnet

Repository files navigation

EfficientNet base models for Edge Impulse

This repository contains the code to bring EfficientNet models into Edge Impulse.

Using this model

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.

Modifying the model code

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.

Running the pipeline

You run this pipeline via Docker. This encapsulates all dependencies and packages for you.

Running via Docker

  1. Install Docker Desktop.

  2. Install the Edge Impulse CLI v1.16.0 or higher.

  3. Create a new Edge Impulse project, and add an image dataset (see Adding sight to your sensors).

  4. 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.

  5. Open a command prompt or terminal window.

  6. Initialize the block:

    $ edge-impulse-blocks init
    
  7. Fetch new data via:

    $ edge-impulse-blocks runner --download-data data/
    
  8. Build the container:

    $ docker build -t efficientnet .
    
  9. 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/
    
  10. This creates a saved model ZIP file in the 'out' directory.

Adding extra dependencies

If you have extra packages that you want to install within the container, add them to requirements.txt and rebuild the container.

Adding new arguments

To add new arguments, see Custom learning blocks > Arguments to your script.

Fetching new data

To get up-to-date data from your project:

  1. Install the Edge Impulse CLI v1.16 or higher.

  2. Open a command prompt or terminal window.

  3. Fetch new data via:

    $ edge-impulse-blocks runner --download-data data/
    

Pushing the block back to Edge Impulse

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.

  1. Push the block:

    $ edge-impulse-blocks push
    
  2. 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.

Changing the block type (e.g. image classification, object detection or regression)

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.

About

EfficientNet transfer learning block for Edge Impulse

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published