Insect Detect ML - Model training and data processing

April 1, 2026 · View on GitHub

DOI PLOS ONE License: AGPL v3 DOI Zenodo

This repository contains Jupyter notebooks that can be used to train custom YOLOv5, YOLOv6, YOLOv7 and YOLOv8 object detection models or a custom YOLOv5 image classification model. All notebooks can be run in Google Colab, where you will have access to a free cloud GPU for fast training without special hardware requirements.

The Python script for classification of the captured insect images is available in the custom yolov5 fork and can be used together with the provided insect classification model.

Use the process_metadata.py script for post-processing of metadata .csv files with classification results.


Model training

Warning

Detection model training is currently being refactored and will be updated soon. YOLO detection models trained with the previous approach are not supported anymore after insect-detect v2.0.0.

You can find more information about detection model training at the Insect Detect Docs đź“‘.

  • YOLOv5 detection model training   Open In Colab

  • YOLOv6 detection model training   Open In Colab

  • YOLOv7 detection model training   Open In Colab

  • YOLOv8 detection model training   Open In Colab

    The PyTorch model weights can be converted to .blob format at tools.luxonis.com for on-device inference with the Luxonis OAK devices.

 

You can find more information about classification model training at the Insect Detect Docs đź“‘.

  • YOLOv5 classification model training   Open In Colab

    The notebook for classification model training includes export to ONNX format for faster CPU inference.


Classification

The modified classification script in the custom yolov5 fork includes the following added options:

  • --sort-top1 sort the classified images to folders with the predicted top1 class as folder name
  • --sort-prob sort images first by probability and then by top1 class (requires --sort-top1)
  • --concat-csv concatenate all metadata .csv files and append classification results to new columns

More information about deployment of the classification script can be found at the Insect Detect Docs đź“‘.

 

Classification model

Model
(.onnx)
size
(pixels)
Top1 Accuracytest
Precisiontest
Recalltest
F1 scoretest
EfficientNet-B01280.9720.9710.9670.969

Table Notes

  • The model was trained to 20 epochs with image size 128, batch size 64 and default settings and hyperparameters. Reproduce the model training with the provided Google Colab notebook.
  • Trained on Insect Detect - insect classification dataset v2 with 27 classes. To reproduce the dataset split, keep the default settings in the Colab notebook (train/val/test ratio = 0.7/0.2/0.1, random seed = 1).
  • Dataset can be explored at Roboflow Universe. Export from Roboflow compresses the images and can lead to a decreased model accuracy. It is recommended to use the uncompressed dataset from Zenodo.
Full model metrics on dataset test split (click to expand)
ClassImagesTop1 Accuracytest
Precisiontest
Recalltest
F1 scoretest
all21250.9720.9710.9670.969
ant1111.00.9911.00.996
bee1070.9630.9720.9630.967
bee_apis311.00.9691.00.984
bee_bombus1271.00.9921.00.996
beetle520.8850.920.8850.902
beetle_cocci780.9871.00.9870.994
beetle_oedem210.9050.9050.9050.905
bug390.8461.00.8460.917
bug_grapho191.01.01.01.0
fly1730.9710.9440.9710.957
fly_empi191.01.01.01.0
fly_sarco330.9090.9380.9090.923
fly_small1670.9580.9520.9580.955
hfly_episyr2530.9960.9960.9960.996
hfly_eristal1970.990.9950.990.992
hfly_eupeo1370.9850.9930.9850.989
hfly_myathr601.01.01.01.0
hfly_sphaero390.9741.00.9740.987
hfly_syrphus500.981.00.980.99
lepi241.00.961.00.98
none_bg860.9880.9660.9880.977
none_bird81.01.01.01.0
none_dirt850.9760.9020.9760.938
none_shadow660.9240.9530.9240.938
other790.8610.8830.8610.872
scorpionfly121.01.01.01.0
wasp521.01.01.01.0
Full model metrics on dataset validation split (click to expand)
ClassImagesTop1 Accuracyval
Precisionval
Recallval
F1 scoreval
all41890.980.9790.9740.976
ant2190.9950.9950.9950.995
bee2120.9670.9580.9670.962
bee_apis581.00.9671.00.983
bee_bombus2521.00.9961.00.998
beetle1040.9330.9420.9330.937
beetle_cocci1551.01.01.01.0
beetle_oedem390.8970.9720.8970.933
bug780.9490.9610.9490.955
bug_grapho371.01.01.01.0
fly3430.9830.9390.9830.96
fly_empi351.00.9721.00.986
fly_sarco630.8410.9640.8410.898
fly_small3320.970.9820.970.976
hfly_episyr5030.9960.9960.9960.996
hfly_eristal3901.01.01.01.0
hfly_eupeo2710.9890.9930.9890.991
hfly_myathr1180.9921.00.9920.996
hfly_sphaero741.00.9871.00.993
hfly_syrphus971.00.991.00.995
lepi450.9780.9780.9780.978
none_bg1700.9880.9820.9880.985
none_bird131.01.01.01.0
none_dirt1670.9820.9760.9820.979
none_shadow1290.9690.9840.9690.977
other1580.880.9030.880.891
scorpionfly241.01.01.01.0
wasp1030.991.00.990.995

Metadata post-processing

Install the required packages by running:

python.exe -m pip install -r requirements.txt

Or use the Python Launcher for Windows with:

py -m pip install -r requirements.txt

The process_metadata.py script can be used to automatically post-process the concatenated metadata .csv file after the classification step, as it will still contain multiple rows for each tracked insect.

The output of the script includes a *top1_final.csv file in which each row corresponds to an individual tracked insect and its classification result with the highest weighted probability. Additionally, several plots are generated that can give a first overview of the processed metadata.

More information about deployment of the post-processing script can be found at the Insect Detect Docs đź“‘.


Image processing

The process_images.py script can be used to calculate different metrics of the captured images (e.g. mean/median/min/max width/height) and remove corrupted .jpg images from the data folder (camera trap output). These can be rarely generated by the automated monitoring script (e.g. in power outage situations) and will cause an error while running the classification script.


License

This repository is licensed under the terms of the GNU Affero General Public License v3.0 (GNU AGPLv3).

Citation

If you use resources from this repository, please cite our paper:

Sittinger M, Uhler J, Pink M, Herz A (2024) Insect detect: An open-source DIY camera trap for automated insect monitoring. PLoS ONE 19(4): e0295474. https://doi.org/10.1371/journal.pone.0295474