The core idea of image classification is this: first let the model learn the features of various categories (classes). Then, when it encounters an object to identify, the model compares these features one by one, produces a similarity score for each class, and the class with the highest similarity is the most likely result.
Before training your own model, first get familiar with the whole workflow using the official example, and confirm that your environment and the AI service are working properly.
Examples.Image classification example and open it.After opening it, you will see a structure similar to the following:
assets/
--image.jpg # Test image used for recognition
python/
--main.py # Main program
app.yaml # Application configuration file
The core logic of main.py:
from arduino.app_utils import App
from arduino.app_bricks.image_classification import ImageClassification
image_classification = ImageClassification()
with open("assets/image.jpg", "rb") as f:
frame = f.read()
out = image_classification.classify(frame)
if out and "classification" in out:
for i, obj_det in enumerate(out["classification"]):
detected_object = obj_det.get("class_name", None)
confidence = obj_det.get("confidence", None)
print(f"Object Detected! '{detected_object}' with confidence: {confidence}%")
App.run()
app.yamlThis is the most critical step in the whole workflow. Open app.yaml and confirm that the bricks field already declares image_classification:
name: Image classification
icon: 📷
description: Image classification
bricks:
- arduino:image_classification
⚠️ If
bricksis empty (bricks: []), the AI inference service will not start, and you will get aFailed to resolve 'ei-classification-runner'error at runtime.
Run button in the upper right corner of App Lab.Python tab to view the output.Object Detected! 'espresso' with confidence: 48.23%
Of course, you cannot modify the official example directly. You need to click Copy and Edit App in the upper right corner to create your own new App. The code will be automatically copied into your new App.
After entering your new App, click the Add file button in the upper left corner, select Import from computer, and then select the image you want to recognize.
Note that the image you upload must be located under the assets folder. If it is not, use the left mouse button to click the image and drag it into the assets folder. Then re-run step 5.
Replace assets/image.jpg with your own image (or place the new image in assets/ and modify the filename in main.py).
Click Run again and observe the recognition result.
Note: The official example uses an ImageNet pre-trained model, which only recognizes 1000 common categories. If your image is not among them, the recognition result may be inaccurate. This is normal.
To make it easier for you to pick images for testing, here are some major categories:
Fish: goldfish, great white shark, tiger shark, hammerhead, electric ray, stingray, etc.
Birds: rooster, hen, ostrich, peacock, parrot, penguin, owl, etc.
Reptiles and amphibians: python, cobra, lizard, chameleon, crocodile, frog, salamander, etc.
Mammals: many dog breeds (golden retriever, Labrador, husky, etc.), felines (Persian cat, Siamese cat, lion, tiger, leopard, etc.), bear, elephant, panda, horse, cow, sheep, monkey, etc.
Insects and invertebrates: butterfly, bee, ant, spider, scorpion, lobster, crab, etc.
Everyday objects: guitar, backpack, umbrella, clock, bottle, chair, book, computer keyboard, etc.
Vehicles: car, motorcycle, bicycle, airplane, boat, train, etc.
After the program runs, click the output port below and select the Python button. The output should be similar to the following:
Object Detected! 'American alligator' with confidence: 32.94%
The above is the official fixed training model, which can only recognize categories predefined by the official team. Can we set our own recognition types?
Open Arduino App Lab and create a new application.
In the left Bricks panel, find Video Image Classification and add it to the project.
Click the AI models tab and click Train new AI model.
After creating it, the project does not have a property label at this point. You can add a label yourself, but this label is not the project's classification label. After uploading data, a pop-up window will appear, and at that point you need to select the project property, as shown in step 2 below.
Data acquisition and click Upload data. A remote upload option will pop up here for you to choose from. You can try it if needed.
Upload into category, select Training.Label, select Enter label, and manually enter the label name (e.g., apple).Upload data and confirm that the LABELS column in the list correctly displays the label.
After clicking upload, a pop-up window will appear asking you to choose the project's classification. Please select No. At this point, your project label will change to the img type.
Impulse design → Create impulse.Image and the learning block Transfer Learning (Images).Save impulse.
Image page, click Save parameters, then click Generate features.
classifier to enter the training interface, and click save and train. Here you need to check whether the number of training categories matches the number of image categories you uploaded.
Deployment page and select Arduino UNO Q as the deployment target.
Click Build and wait for compilation to finish.
After successful compilation, a Built Arduino UNO Q model prompt will appear.
It is currently known that Arduino App Lab version 0.10.0 has a bug: the automatic model push link from the Edge Impulse web page when clicking Go to Arduino (formerly Install to board) is broken. It will only download the eim to your local computer, and will not automatically upload it to the UNO Q board. The model will also not automatically appear in the Bricks drop-down list. After the official fix, one-click import will be possible. As of the date this tutorial was written, this bug has still not been resolved.
.eim File to UNO QOn your computer's terminal (PowerShell or CMD), run:
scp "C:\Users\Admin\Downloads\your-model-file.eim" arduino@192.168.201.187:/home/arduino/
If the path contains spaces or special characters, be sure to wrap it in double quotes.
After logging into UNO Q via SSH, run:
sudo apt update
sudo apt install -y python3-opencv portaudio19-dev unzip
cd ~
python3 -m venv ~/ei_venv
source ~/ei_venv/bin/activate
After activation,
(ei_venv)will appear in front of the terminal prompt.
In the virtual environment, run:
pip install edge_impulse_linux -i https://pypi.python.org/simple
pip install opencv-python-headless pyaudio six numpy
cd ~
git clone --depth 1 https://github.com/edgeimpulse/linux-sdk-python.git
--depth 1shallow clone reduces the chance of network interruption.
After cloning, the script is located at~/linux-sdk-python/examples/image-classification/classify-image.py.
If cloning is frequently interrupted, switch to Option B.
https://github.com/edgeimpulse/linux-sdk-pythonCode button on the right → Download ZIPC:\Users\Admin\Downloads\linux-sdk-python-master.zip. You can also click the blue button below to download it.On your computer's terminal, run:
scp "C:\Users\Admin\Downloads\linux-sdk-python-master.zip" arduino@192.168.xxx.xxx:/home/arduino/
cd ~
unzip linux-sdk-python-master.zip
mv ~/linux-sdk-python-master ~/linux-sdk-python
The file placement hierarchy and filenames here may vary. It is recommended to use the cd + filename and ls commands to check layer by layer until you find the classify-image.py file.
.eim Filechmod +x /home/arduino/your-model-file.eim
Before running, you need to upload a validation image to UNO Q. You can upload it via SSH.
scp "C:\Users\Admin\Downloads\apple.jpg" arduino@192.168.xxx.xxx:/home/arduino/
cd ~/linux-sdk-python/examples/image-classification/
python3 classify-image.py /home/arduino/your-model-file.eim /home/arduino/test-image.jpg
Expected output:
MODEL: /home/arduino/your-model-file.eim
Loaded runner for "project ID / Impulse ID"
Result (5 ms.) apple: 0.89 banana: 0.11
⚠️ The path must be an absolute path. Do not use
~, otherwise you will get aModel file does not existerror.
| Error | Cause | Solution |
|---|---|---|
No module named 'cv2' |
Missing OpenCV | pip install opencv-python-headless |
No module named 'pyaudio' |
Missing audio library | sudo apt install portaudio19-dev then pip install pyaudio |
No module named 'six' |
Missing six library | pip install six |
Model file ... is not executable |
No execute permission | chmod +x model-file.eim |
Model file does not exist |
Path uses ~ |
Use an absolute path /home/arduino/... |
unzip: command not found |
Missing extraction tool | sudo apt install -y unzip |
git clone interrupted |
Unstable network | Switch to Option B: local ZIP download |
Failed to resolve 'ei-classification-runner' |
Brick not declared in app.yaml |
Add arduino:image_classification to the bricks field in app.yaml |
/home/arduino/
├── ei_venv/ # Python virtual environment
├── linux-sdk-python/ # Official example scripts
│ └── examples/
│ └── image-classification/
│ └── classify-image.py
├── linux-sdk-python-master.zip # Option B archive (optional)
├── your-model-file.eim # Model file
└── test-image.jpg # Test image
Try the official Image Classification example in App Lab
↓
Create a project in App Lab → Enter Edge Impulse
↓
Create an Image Classification project in Edge Impulse
↓
Upload data and manually add labels
↓
Design Impulse → Generate features → Train model
↓
Select UNO Q in Deployment → Build → Download .eim
↓
scp transfer .eim to UNO Q
↓
apt install python3-opencv + portaudio19-dev + unzip
↓
cd ~ → Create venv virtual environment
↓
pip install edge_impulse_linux + opencv-python-headless + pyaudio + six + numpy
↓
Get the official example scripts (git clone or local ZIP download)
↓
chmod +x model file
↓
python3 classify-image.py model image (absolute path)
↓
Get classification result ✅