Training Custom YOLO Models

MIRA uses the Ultralytics YOLO framework for object detection. While MIRA comes with default weights, you may need to train a custom model to detect specific spore species or adapt to unique lighting conditions.

The workflow consists of four main phases:

Phase 1: Image Acquisition

The quality of your model depends entirely on the quality of your dataset.

📸 Capture Tips
  • Diversity: Capture images with varying spore densities.

  • Focus: Include slightly out-of-focus images to make the model robust.

  • Backgrounds: Take pictures of “empty” chambers to reduce false positives (Background images).

  • Resolution: Use the resolution you intend to use in production (e.g., ArduCam 20MP native resolution).

🛠️ MIRA Integration

Use MIRA’s Batch Capture feature to quickly gather hundreds of images.

Set a 2-second delay and move the microscope stage slightly between captures to vary the field of view.

Phase 2: Annotation

Once you have your images, you must draw boxes around the spores to teach the AI what to look for.

Roboflow is a web-based platform that simplifies the whole process.

  1. Upload: Import your raw images.

  2. Annotate: Use the “Auto-Label” or manual box tools.

  3. Augment: Apply rotations, blur, or noise to artificially increase your dataset size.

  4. Export: Choose the YOLOv11 PyTorch format.

If you prefer to keep your data offline:

  • CVAT: Powerful, professional open-source annotation tool.

  • Label Studio: Versatile and supports many data types.

  • LabelImg: Simple, lightweight tool specifically for bounding boxes.

Phase 3: Model Training

We recommend using the latest YOLO models (YOLOv8, YOLOv10, or YOLOv11) from Ultralytics.

🚀 Training Environments
  • Google Colab: Free GPU access. Perfect if you don’t have a powerful NVIDIA card.

  • Local PC: Fastest if you have a local NVIDIA GPU (RTX 30 series or better).

# Example: Training with the Ultralytics CLI
pip install ultralytics
yolo task=detect mode=train model=yolov11n.pt data=your_data.yaml epochs=100 imgsz=640

For detailed instructions, refer to the Ultralytics Training Documentation.

Phase 4: Using your Model in MIRA

After training, you will find a file named best.pt in your training output folder (usually runs/detect/train/weights/).

📥 Import
  1. Copy the best.pt file to your computer.

  2. In MIRA, click the Load Models button.

  3. Select the folder containing your .pt file. MIRA will list all available models in the dropdown.

⚙️ Optimization
  • Thresholds: Adjust the Confidence slider in MIRA based on your model’s performance.

  • Classes: MIRA will automatically detect the class names defined during your training (e.g., “spore”, “pollen”, “debris”).

💡 Need a starting point?

You can find pre-trained weights and example datasets on our repository or check the Ultralytics HUB for an all-in-one training experience.