- Kesiena Berezi
- Ball Bearing Classification Project
- MEE206 - Mechanical Student Design Project
- Description: This project implements a complete computer vision and robotics system
-
for automatically classifying and sorting ball bearings by material type -
(Brass, Nylon, Steel) and size (1/2" and 1/4"). The system combines -
machine learning, real-time inference on Raspberry Pi, and mechanical -
sorting using Arduino-controlled servos.
This project implements a complete computer vision and robotics system for automatically classifying and sorting ball bearings by material type (Brass, Nylon, Steel) and size (1/2" and 1/4"). The system combines machine learning, real-time inference on Raspberry Pi, and mechanical sorting using Arduino-controlled servos.
- Machine Learning Pipeline: VGG16-based CNN for material classification with transfer learning
- Real-time Inference: TensorFlow Lite deployment on Raspberry Pi with camera integration
- Mechanical Sorting: Arduino-controlled servo system for automated bearing routing
- Serial Communication: Seamless communication between Pi and Arduino for classification codes
- Data Visualization: Tools for exploring dataset and analyzing model performance
- Quantized Models: Optimized models for fast inference on edge devices
The system consists of three main components:
- Raspberry Pi: Captures images and performs real-time classification
- Arduino: Controls servo motors for mechanical sorting
- Machine Learning Model: Classifies bearings into 6 categories (3 materials × 2 sizes)
- Trains a VGG16-based convolutional neural network for ball bearing classification
- Uses transfer learning with ImageNet weights and data augmentation
- Supports 3 material classes: Brass, Nylon, Steel
- Usage:
python VGG16Train.py [train_dir] [validation_dir] [model_save_path]
- Evaluates trained VGG16 model on test data
- Generates confusion matrix, classification reports, and visualizes misclassified samples
- Provides comprehensive model performance analysis
- Usage:
python VGG16ID.py [model_path] [test_data_dir]
- Organizes ball bearing image dataset into train/validation/test splits
- Creates structured directories for machine learning pipeline
- Supports 70/15/15 split ratio for Brass, Nylon, and Steel classes
- Usage:
python ReorgData_materials.py
- Visualizes sample images from ball bearing dataset
- Generates sample visualization grid for each material class
- Helps understand data distribution and image characteristics
- Usage:
python explore_images.py
- Real-time ball bearing classification using TensorFlow Lite on Raspberry Pi
- Captures images from PiCamera2, performs inference, and displays results
- Implements voting system for stability with confidence scores and FPS display
- Usage:
python raspberry_pi_inference.py
- Serial communication script for Raspberry Pi bearing classifier
- Listens for "CAPTURE" commands via serial, performs real-time classification
- Returns classification codes (0-6) to Arduino for mechanical sorting control
- Note: Uses quantized model for faster inference
- Usage:
python rasp_script.py
- Arduino firmware for mechanical ball bearing sorting system
- Controls servo motors to sort bearings into 6 categories based on material and size
- Receives classification codes from Raspberry Pi via serial communication
- Positions servos accordingly for automated sorting
- Usage: Upload to Arduino Uno/Mega via Arduino IDE
- Raspberry Pi 4 with PiCamera2 module
- Arduino Uno/Mega with servo motors
- Mechanical sorting mechanism with drop zones
- Ball bearings for testing (Brass, Nylon, Steel in 1/2" and 1/4" sizes)
tensorflow>=2.5.0
numpy>=1.19.5
matplotlib>=3.4.2
pillow>=8.2.0
scikit-learn>=0.24.2
seaborn>=0.11.1
opencv-python>=4.5.2
tflite_runtime
picamera2
pyserial
- Arduino IDE
- Servo.h library
git clone <repository-url>
cd Ball_Bearing_Classificationpip install -r requirements.txtcd ML
python ReorgData_materials.pypython "VGG16Train (2).py"python "VGG16ID (1).py"- Install PiCamera2:
sudo apt install -y python3-picamera2 - Install TFLite Runtime for ARM
- Upload Arduino firmware
- Organize Data: Run
ReorgData_materials.pyto split dataset - Train Model: Run
VGG16Train (2).pyto train VGG16 classifier - Evaluate Performance: Run
VGG16ID (1).pyto analyze results - Convert to TFLite: Export model for Raspberry Pi deployment
- Start Arduino: Upload
main.cppand power on Arduino - Start Raspberry Pi: Run
rasp_script.pyfor serial communication - Test System: Place bearings in inspection area
- Monitor Sorting: Watch automated classification and sorting
- Classification Accuracy: ~85% on test data
- Inference Time: ~30ms on Raspberry Pi 4
- Known Issues: Model occasionally misclassifies Brass as Steel (~15% error rate)
- Solution: Model was overfit to training setup for optimal performance
- Alternative: Consider using Google's Teachable Machine for faster training and deployment
- Quantized Model: The
rasp_script.pyuses a quantized TensorFlow Lite model for faster inference on the Raspberry Pi - Overfitting Issue: The model was intentionally overfit to the specific training setup for optimal performance. Any changes to the physical setup (lighting, camera position, etc.) may cause misclassifications
- Teachable Machine Alternative: Due to the overfitting challenges, Google's Teachable Machine was found to be faster for training and deployment, with better performance on the Pi even when our custom model was quantized
- Model Limitations: The current model works well for the specific setup it was trained on, but may not generalize well to different environments
- Serial Communication Issues: Check port settings and baud rate
- Camera Not Found: Ensure PiCamera2 is properly installed
- Servo Movement Problems: Verify servo connections and power supply
- Model Loading Errors: Check TFLite runtime installation
Ball_Bearing_Classification/
├── ML/ # Machine learning scripts
│ ├── VGG16Train (2).py
│ ├── VGG16ID (1).py
│ ├── ReorgData_materials.py
│ └── explore_images.py
├── Raspberry Scripts/ # Pi camera and inference
│ ├── raspberry_pi_inference.py
│ └── rasp_script.py
├── arduino firmware/ # Hardware control
│ └── main.cpp
├── models/ # Trained models
├── requirements.txt # Python dependencies
└── README.md
This project is licensed under the MIT License.
Kesiena Berezi Developed for MEE206 - Mechanical Student Design Project.
- VGG16 architecture for transfer learning
- Google Teachable Machine
- TensorFlow Lite for edge deployment
- PiCamera2 for Raspberry Pi camera integration
- Arduino Servo library for mechanical control