Build an AI Print-Failure Watchdog with the Arduino UNO Q (Part 3): Training the Anomaly Model with Edge Impulse
Part 1: Idea, Case and Camera Mount
Part 2: Camera Setup and Training Images
Part 3: Training the Anomaly Model with Edge Impulse (this article)
Part 4: Building the Watchdog App with App Lab
Part 5: Optimisation and Finalisation
Status of the experiment: the camera at the 3D printer is running (part 2), and a week of everyday printing has produced roughly 2,600 training images — plus, thanks to an involuntary stringing incident, 20 genuine failure images. Today they become the actual AI: we train the anomaly model at Edge Impulse, stumble into two nasty traps, live through a brief moment of shock over a miserable F1 score — and in the end the model even corrects a mistake I made myself. One thing at a time.
The hardware for this series – an Arduino UNO Q*, its Media Carrier* and an IMX219 camera* – is covered in part 1.
The platform: Edge Impulse in two minutes
A quick word on the platform where all of this happens: Edge Impulse is a cloud platform specializing in AI for small devices — microcontrollers, single-board computers, phones. The charm for makers: the entire workflow runs in the browser-based “Studio”, from data management through assembling the processing pipeline to training, testing and export. You need neither your own GPU nor a Python environment; training happens on their servers — your own device only re-enters the stage at the very end, when the finished model moves onto it and runs fully offline from then on.
For this project the free developer plan is all it takes (create an account at studio.edgeimpulse.com), and the UNO Q is an officially supported target at Edge Impulse — the export fits without any tinkering. After logging in, create an empty project via “Create new project”; mine is simply called raspberry-tips-project-1. You will need two things from the project right away: the API key (found under Dashboard → Keys) for the image upload, and later the “Data acquisition” page, where everything uploaded shows up as preview tiles with labels.
Uploading the images — straight from the board, no extra software
Where do the images come from? Straight from the UNO Q: the collector service from part 2 stored them there under ~/dataset/no-anomaly/ — so there is no detour via the PC, the upload happens in an SSH session from the board to the cloud.
For uploads, Edge Impulse offers its own command-line tool, but it requires Node.js — and on the UNO Q, whose system partition is only about 10 GB on older images, I wanted to skip several hundred megabytes of dependencies. The leaner alternative: the ingestion API accepts images via plain HTTP upload, and curl is already on the board. My script for it lives in the GitHub repository (ei_upload.sh) — enter your project’s API key (Studio → Dashboard → Keys) and go:
wget https://raw.githubusercontent.com/raspberry-tips/uno-q-3d-print-watchdog/main/camera-setup/ei_upload.sh
nano ei_upload.sh # enter your EI_API_KEY
sh ei_upload.sh
Without arguments, the script uploads every image in ~/dataset/no-anomaly/ with the label no anomaly to the training data in batches of 20, and skips everything already in the Studio thanks to duplicate protection — so you can simply re-run it after every print. At the end it reports how many images arrived and how many Edge Impulse rejected, usually duplicates. If the API key is wrong, it stops and prints the error from Edge Impulse.
The failure images go up with the same script, just with the label anomaly and to the test data instead of training — the next section explains why. Put them in a folder of their own, for example ~/dataset/anomaly/, and pass folder, label and target as arguments:
sh ei_upload.sh ~/dataset/anomaly anomaly testing
Trap 1: “Poor training/test split ratio” — no, you don’t need 20% failure images
The images had barely landed when a warning greeted me: “The ‘no anomaly’ class has a poor training/test split ratio.” My first thought was probably the same as everyone’s: do I now have to collect failure images at an 80/20 ratio — hundreds of deliberately crashed prints? Thankfully: no. The warning refers exclusively to the split of the normal images between training and test data. The reasoning matters though: the test set needs normal images the model has never seen during training — because only those can measure how often it falsely raises alarms during normal operation. “Does it detect spaghetti?” and “does it nag during normal printing?” are two different questions, and only both together yield the alarm threshold later.
The fix is one click: Dashboard → scroll to “Danger zone” → “Perform train/test split”. Edge Impulse then moves about 20 percent of the normal images to the test set by itself. In my case: 2,082 images for training, 525 for testing (including the 20 with stringing).
Check afterwards: according to Edge Impulse, the split redistributes all data, failure images included. Mine stayed in the test set, but check under Data acquisition that every anomaly image is still in the test data, and move it back if not: with FOMO-AD, failure images have no place in the training set.
The impulse: 96×96 pixels and FOMO-AD
The processing pipeline — called an “impulse” at Edge Impulse — is assembled quickly: images get squashed to 96×96 pixels, an image block normalizes them, and behind it sits the learning block Visual Anomaly Detection (FOMO-AD). It works differently from classic image classification: a small network splits every image into patches and learns what the patches of normal scenes look like — which is why our good images suffice without any failure annotations. The output is exactly one value: the anomaly score.
Here is how you click the model together — the whole setup takes five minutes:
- Open Impulse design → Create impulse in the left menu. The first box, “Image data”, is already there: set width and height to 96 each, resize mode “Squash”.
- “Add a processing block” → choose “Image” (the topmost entry) — it handles normalization and color processing.
- “Add a learning block” → trap 2 lurks here (more on that in a moment): you need “Visual Anomaly Detection (FOMO-AD)”, which may hide behind “Show all blocks” depending on the view.
- “Save impulse” — the output on the right should read “1 (Anomaly score)”.
- In the new menu item “Image”: leave color depth at RGB → “Save parameters” → “Generate features” — this prepares all images for training and draws the feature explorer as a bonus.
Trap 2: there are TWO “Anomaly Detection” blocks
And here is the trap that cost me an evening: the learning block dialog also offers a block simply called “Anomaly Detection” — but that one is an autoencoder for sensor time series (acceleration, temperature and the like), not for images. The visual block may hide behind the “Show all blocks” link and is fully named “Visual Anomaly Detection (FOMO-AD)”. Pick the wrong one and training crashes with exactly this error:
ValueError: total size of new array must be unchanged,
input_shape = [96, 96, 3], output_shape = [96, 1]
Translated: the block is trying to squeeze a color image into a one-dimensional measurement series. If you ever see this message, you now know instantly what’s wrong — I had to run into the wall twice first.
Training: an unspectacular five minutes
After that, the actual training is almost disappointingly unspectacular: leave every setting at default, click “Start training”, wait five minutes. The feature explorer nicely previews what the model is about to learn — our normal images form several separate point clouds, one per print and lighting condition. These “islands of normality” are exactly what FOMO-AD memorizes.
The moment of shock: F1 score 0.23
Then the moment of truth: “Model testing” runs all 525 test images through the fresh model. Result: accuracy 74.67 percent, F1 score for the anomaly class a sobering 0.23. At this point I almost wrote the experiment off as failed — and that is exactly what I want to save you from, because this number says almost nothing about the model. It only says that the default threshold doesn’t fit our data.
A look at the raw data painted a completely different picture. All 20 stringing images were detected — one hundred percent. The anomaly scores separate razor-sharp: normal images sit at a median of 26, 99 percent below 33; the stringing images start at 44 with a median of 63. Between them lies a clean corridor. Only the default threshold of 27.3 sat right in the middle of the normal distribution and declared 133 harmless images anomalies. Threshold set to 40 (in Model testing via the filter icon next to “Classify all”), re-classified — and 0.23 turned into F1 1.00: every anomaly detected, zero false alarms.
The punchline: the model found my mistake
One thing kept bugging me: a single “normal” image stubbornly scored 62.8 — right in the middle of the anomaly range. False alarm? Not at all. Looking at the image:
A fine filament string stretches across the bed all the way to the nozzle — genuine stringing that simply got overlooked when sorting the training images. The model found a labeling error in its own test data. After relabeling, the test set stands at 21 anomalies, all detected. You could hardly wish for better confirmation that the anomaly detection isn’t just getting lucky.
What the board says about it: 41 milliseconds
That leaves the question of whether the UNO Q can actually handle the model. The deployment page does the math for the quantized model (int8): 41 milliseconds per image and just 3.9 MB of RAM on the Qualcomm chip. As a reminder: the watchdog is supposed to check one image every 15 seconds — so we are using roughly 0.3 percent of the available compute. Exporting is one click: on the deployment page pick the target “Linux (AARCH64)” and the build hands you the .eim file. Installing it on the board is a story for the next part.
Coming up in part 4
The experiment now stands better than I dared to hope at the start: a model that separates flawlessly on unseen data, trained from images that accumulated as a by-product of printing. But — and this matters — so far it has only passed in the Studio. In the next part the model moves onto the UNO Q and becomes a real watchdog app: camera, anomaly score, a time filter against single outliers, an alarm on the LED matrix and a report to Home Assistant. Then we print — and wait for the first real failure. (Spoiler: it arrived sooner than I would have liked.) Have fun building along!
Update: Part 4 is now online — continue with the watchdog app, the Home Assistant integration and the first real print failures.
Frequently asked questions
Edge Impulse recommends starting around 100 normal images, and it gets reliable from a few hundred. More important than quantity is variety: different objects, filament colors and every lighting condition that will occur in operation later. My roughly 2,000 images from a week of everyday printing were already comfortable — collected without a single extra step.
Nothing. FOMO-AD is included in the free developer plan, including training, testing and the export for the UNO Q. The plan has limits on compute time and project size, but they don’t matter for a project of this scale.
By principle, yes — it reports everything that clearly deviates from the learned normal state: shifted prints, toppled objects, and it did find that string across the bed. The flip side: it also reports harmless deviations like a hand in the frame. That is why the watchdog app in part 4 gets a time filter that only raises the alarm after several anomalous frames in a row.





