AI Spaghetti Detection System for 3D Printing

Developing a real-time artificial intelligence monitoring system capable of detecting spaghetti printing failures on FDM 3D printers using YOLO and Raspberry Pi 5.

Project Overview AI + Computer Vision

For this project I developed an intelligent monitoring system designed to detect one of the most common failures in FDM 3D printing: the spaghetti failure.

A spaghetti failure occurs when the printer continues extruding filament incorrectly after a print detaches or fails, creating tangled strands of material that resemble spaghetti. These failures can waste large amounts of filament and printing time if they are not detected quickly.

The goal of this project was to create a low-cost embedded AI system capable of:

  • Monitoring a 3D printer in real time
  • Detecting spaghetti failures using computer vision
  • Sending remote notifications automatically
  • Streaming live video through a web interface
  • Running directly on a Raspberry Pi 5

The system combines machine learning, embedded systems, computer vision, networking, and real-time processing into a single integrated solution.

Problem Definition 3D Printing Failures

FDM 3D printers can operate for many hours continuously, making constant supervision difficult. One of the biggest risks during long prints is a spaghetti failure, where the printer extrudes filament uncontrollably after losing proper layer adhesion or positional accuracy.

These failures can:

  • Waste large amounts of filament
  • Damage printed parts
  • Create large cleaning problems
  • Waste electricity and machine time
  • Potentially damage the hotend or moving components

Commercial solutions exist, but many are expensive or require cloud-based subscriptions. This project focused on creating an affordable standalone alternative using open-source tools and embedded hardware.

Spaghetti failure example
Example of a spaghetti printing failure during FDM manufacturing.
Dataset Preparation Training Data

One of the most important parts of the project was preparing the dataset used to train the neural network.

Initially, several public datasets from Roboflow and online repositories were evaluated. However, many of them contained inconsistent labels and multiple categories related to printing defects.

The original datasets included labels such as:

  • Spaghetti
  • Spagatti
  • Stringing
  • Blobs
  • Cracks
  • Bed adhesion failure

Because these categories were visually similar, the model initially produced many false positives. To improve performance, the dataset was cleaned and reduced to focus exclusively on spaghetti failures.

The final dataset was also converted to grayscale in order to:

  • Reduce computational complexity
  • Improve embedded performance
  • Focus on geometry instead of color
  • Reduce lighting dependency
Dataset preparation
Cleaning and filtering the dataset for spaghetti-only detection.
YOLO Training Machine Learning

The neural network was trained using the YOLOv11n architecture. This version was selected because it provides a good balance between detection performance and computational efficiency, which is essential for Raspberry Pi deployment.

Multiple training experiments were performed while adjusting parameters such as:

  • Image size
  • Confidence threshold
  • Batch size
  • Epoch count
  • Data augmentation settings

During testing, several augmentations such as mosaic and aggressive transformations generated excessive false positives, so they were reduced or disabled in later experiments.

The model was trained on an NVIDIA RTX GPU using PyTorch and Ultralytics YOLO.

YOLO training process
Training process and performance evaluation of the YOLO model.
Embedded System Raspberry Pi 5

After training the model, the system was deployed to a Raspberry Pi 5 connected to a CSI camera module through the dedicated camera interface.

The Raspberry Pi performs:

  • Real-time image capture
  • Grayscale conversion
  • YOLO inference
  • Video visualization
  • Notification handling
  • Web streaming

To improve performance, the model was optimized and exported into lightweight formats compatible with embedded inference.

Running the system locally on the Raspberry Pi eliminates the need for cloud processing and allows the printer to be monitored continuously without external servers.

Raspberry Pi setup
Raspberry Pi 5 running the AI-based monitoring system.
Web Monitoring Interface HTTP Streaming

A web-based monitoring interface was developed using Flask and HTTP video streaming.

This interface allows the user to:

  • Watch the printer remotely in real time
  • View AI detections live
  • Monitor printer status remotely
  • Access the system from any device on the network

The interface displays the processed video feed directly from the Raspberry Pi, including detection overlays and status messages generated by the AI system.

This feature transforms the Raspberry Pi into a lightweight standalone monitoring server for additive manufacturing supervision.

Web monitoring interface
Real-time HTTP monitoring interface displaying the AI detection system.
Remote Alerts MQTT + NTFY

To improve usability, a remote alert system was integrated into the monitoring platform.

When the AI detects a spaghetti failure continuously for several seconds, the Raspberry Pi automatically sends notifications using MQTT and ntfy.

This system allows users to receive immediate alerts on their smartphones without constantly supervising the printer physically.

A cooldown system was also implemented to prevent notification spam caused by temporary false detections.

Notification system
Smartphone notifications triggered automatically after spaghetti detection.
Results System Performance

The final system successfully demonstrated real-time spaghetti detection running directly on embedded hardware.

After cleaning the dataset and simplifying the class structure, the number of false positives decreased significantly compared to the initial training attempts.

The grayscale preprocessing approach also helped improve inference speed while maintaining acceptable detection performance.

The complete system was capable of:

  • Capturing live video
  • Running AI inference continuously
  • Displaying detections in real time
  • Streaming through a web browser
  • Sending remote notifications automatically

These results demonstrate the feasibility of using low-cost embedded AI systems for additive manufacturing supervision.

Technical Considerations Embedded AI

Developing this system required balancing detection accuracy with embedded hardware limitations.

Several engineering decisions were necessary, including:

  • Model selection: choosing YOLOv11n for lightweight inference
  • Image preprocessing: grayscale conversion to reduce complexity
  • False positive reduction: simplifying the dataset classes
  • Embedded optimization: reducing image resolution for real-time execution
  • Network communication: integrating MQTT and HTTP streaming
  • System stability: preventing repeated false alerts

One of the most interesting aspects of this project was combining artificial intelligence, embedded systems, networking, and manufacturing into a single integrated workflow.

Reflection

This project allowed me to explore how artificial intelligence can be integrated into real manufacturing environments using affordable hardware.

I learned that training a neural network involves much more than simply selecting a model. Dataset quality, class consistency, preprocessing, and real-world testing all strongly influence system performance.

One of the most valuable lessons was understanding the challenges of deploying AI models on embedded hardware, where computational resources are limited and optimization becomes essential.

Overall, this project demonstrated how machine learning and computer vision can improve automation and monitoring processes in digital fabrication and additive manufacturing.