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.
- 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
.logfiles.
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/
The plugin provides three main windows inside Fiji/ImageJ.
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.
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.
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.
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.
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.yamlfile, - a YOLO dataset folder containing a
data.yamlfile, - 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)
The plugin can be installed using the provided installers or manually by copying the plugin .jar file into the Fiji/ImageJ plugins folder.
Installers are provided for macOS and Windows.
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.shYou can use the Windows installer executable:
installers/windows/NeuronSegmentationInstaller.exe
or run the PowerShell installer manually:
cd installers/windows
.\install_windows.ps1The installer prepares the Python environment, installs the required dependencies and writes the configuration file used by the plugin.
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.
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=trueThe 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.
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.