Skip to content
 
 

Repository files navigation

NeuroAdaptTrainer: A Fiji/ImageJ Plugin for YOLO-Based Neuron Segmentation, Interactive Correction and Transfer Learning

Fiji/ImageJ plugin for YOLO-based neuron segmentation in microscopy images. This project integrates a YOLO segmentation model into Fiji/ImageJ to assist neuron detection, manual correction, transfer learning and external model validation.

Main features

  • Single-image neuron segmentation from Fiji/ImageJ.
  • YOLO-based detection and segmentation of visible neuronal bodies.
  • Manual correction of detections:
    • select detections,
    • move detections,
    • delete false positives,
    • add missing neurons,
    • undo last correction.
  • Export of corrected annotations in YOLO segmentation format.
  • Transfer learning assistant for adapting the model to new image folders.
  • Optional hardware acceleration for retraining and validation:
    • CUDA,
    • Apple MPS,
    • CPU fallback.
  • External validation window to compare:
    • base model,
    • adapted model.
  • Export of comparison metrics to CSV.
  • Session logs generated as .log files.

Project structure

fiji-yolo-neuron-segmentation/
├── imagej-plugin/
│   ├── src/
│   ├── pom.xml
│   └── target/
├── installers/
│   ├── mac/
│   │   ├── install_mac.sh
│   │   └── NeuronSegmentationInstaller.app
│   ├── windows/
│   │   ├── install_windows.ps1
│   │   └── NeuronSegmentationInstaller.exe
│   └── imagej-plugin-0.1.0-SNAPSHOT.jar
├── yolo-inference/
│   ├── models/
│   │   ├── best.pt
│   │   └── README.md
│   ├── infer_one.py
│   ├── retrain_model.py
│   ├── compare_models.py
│   ├── verify_annotation_overlay.py
│   └── requirements.txt
└── training-results/

Plugin windows

The plugin provides three main windows inside Fiji/ImageJ.

1. Single Image Neuron Segmentation

Runs neuron segmentation on a single image and displays the detected neuronal regions. This window is intended for quick inference and visual inspection of the active model.

2. Neuron Transfer Learning Assistant

Processes a full image folder, allows the user to review and manually correct detections, saves the corrected annotations in YOLO segmentation format and retrains/adapts the active model using those annotations.

3. Model Comparison / External Validation

Compares the base YOLO model against an adapted model using an external validation dataset annotated in YOLO format. The comparison is performed on the same dataset for both models and exports the resulting metrics to a CSV file.

Transfer learning workflow

The adapted model is not trained from scratch. Retraining starts from the currently selected active model. If the selected image folder already has an associated active model, that model is reused. Otherwise, the global active model is used. If no active model is available, the system falls back to the base model best.pt.

The selected model is then fine-tuned using the annotations generated or corrected from the plugin.

The current adaptation parameters are:

epochs = 200
patience = 25
imgsz = 640
batch = 2
pretrained = True
val = True
device = CPU / CUDA / MPS depending on availability

Once generated, the adapted model can be selected as the active model for future inference.

External validation

The external validation module compares the base YOLO model and the adapted model on the same annotated dataset.

The validation dataset can be provided as:

  • a prepared YOLO data.yaml file,
  • a YOLO dataset folder containing a data.yaml file,
  • an image folder containing corrected annotations generated by the transfer learning assistant.

The comparison exports:

model_comparison_metrics.csv

Main exported metrics:

  • precision
  • recall
  • mAP50
  • mAP50-95
  • fitness

For segmentation, the most relevant metrics are the mask-based ones:

metrics/precision(M)
metrics/recall(M)
metrics/mAP50(M)
metrics/mAP50-95(M)

Installation

The plugin can be installed using the provided installers or manually by copying the plugin .jar file into the Fiji/ImageJ plugins folder.

Option 1: Installer

Installers are provided for macOS and Windows.

macOS

You can use the macOS installer application:

installers/mac/NeuronSegmentationInstaller.app

or run the installation script manually:

cd installers/mac
chmod +x install_mac.sh
./install_mac.sh

Windows

You can use the Windows installer executable:

installers/windows/NeuronSegmentationInstaller.exe

or run the PowerShell installer manually:

cd installers/windows
.\install_windows.ps1

The installer prepares the Python environment, installs the required dependencies and writes the configuration file used by the plugin.

Option 2: Manual plugin installation

The plugin .jar file is located at:

installers/imagej-plugin-0.1.0-SNAPSHOT.jar

To install it manually, copy this file into the Fiji/ImageJ plugins folder.

Example on macOS:

Fiji.app/plugins/

After copying the .jar, restart Fiji/ImageJ. The plugin should appear under:

Plugins > Neuron Segmentation

Manual installation only installs the Fiji/ImageJ plugin. The Python environment and configuration file must still be prepared separately if the installer is not used.

Configuration

The plugin uses a configuration file stored in:

~/.neuron-segmentation-assistant/config.properties

This file stores the paths and preferences required by the plugin:

python=...
script=...
retrain_script=...
compare_script=...
use_hardware_acceleration=true

Requirements

The Python dependencies are listed in:

yolo-inference/requirements.txt

Main dependencies:

  • Python
  • Ultralytics YOLO
  • PyTorch
  • OpenCV
  • NumPy

The Fiji/ImageJ plugin is developed in Java and built with Maven.

Notes

This tool is intended as an assisted workflow for neuron segmentation. The model provides an initial automatic prediction, but the user can review and correct detections before using them for transfer learning or validation.

The annotations generated during correction are used as technical reference annotations. A complete biological validation would require review by domain specialists.

About

ImageJ/Fiji plugin for YOLO-based neuron segmentation in microscopy images.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages