lepinet

Identifies moths and butterflies to species, genus and family from a photo of a single specimen, with coherent ranks and confidence thresholds for backing off to a coarser rank.

  • Classification
  • Embedding
  • ViT-L/14 (BioCLIP-2)
  • ConvNeXt-L (DINOv3)
  • EfficientNetV2-S
  • closed vocabulary

4 assets

Format: ONNX, Safetensors

Identifies moths and butterflies to species, genus and family from a photo of a single specimen.

Intended use. Naming a photographed moth or butterfly: from citizen-science photos, museum images, or crops from automated light-trap cameras. It classifies one specimen per image. For trap screens or scenes, pair it with a detector such as flatbug and classify the crops. It is built to say how sure it is: below its thresholds it backs off from species to genus or family, or answers “unknown”.

Architecture and training

Three sizes of the same recipe, each in its own Hugging Face repo:

  • BioCLIP-2 ViT-L/14 (recommended, 321 M parameters). BioCLIP-2’s image tower, fine-tuned end to end with a cosine classifier.
  • DINOv3 ConvNeXt-L (217 M parameters). DINOv3’s self-supervised backbone, fine-tuned with a cosine classifier under an ArcFace margin. Distributed under the DINOv3 License.
  • EfficientNetV2-S (37 M parameters). ImageNet-initialised, with a cosine classifier trained under an ArcFace margin.

All three are trained on 6.3 M GBIF occurrence images of Lepidoptera (species with at least 50 images, capped at about 2,000 per species). All three are then made robust to automated light-trap imagery by self-training: about 2 % of training is unlabelled trap crops with pseudo-labels. In every published file, genus and family probabilities are sums of their species’ probabilities, so the three ranks never contradict each other. Framework: PyTorch/fastai, exported to ONNX.

Inputs and outputs

One RGB image, resized on its shorter side to 256 (ViT, which resamples it to 224 internally as in training), 320 (ConvNeXt) or 256 (EfficientNet) and centre-cropped. Pixel values go in as [0, 1]; normalisation is inside the ONNX graph. Outputs are species, genus and family probabilities, species logits, and an L2-normalised embedding (1024-d, 1536-d or 1280-d respectively). Labels are GBIF taxon keys, with scientific names in names.json. The repo’s predict.py needs only onnxruntime, numpy and Pillow.

Performance

Species macro-F1 (every species weighted equally), measured on the published ONNX files with the cards’ own preprocessing. The ViT’s in-distribution number is inflated slightly: BioCLIP-2’s pre-training saw part of the GBIF test fold. On the 217,856-image subset it never saw, the ViT scores 0.910.

evaluation setBioCLIP-2 ViT-L/14DINOv3 ConvNeXt-LEfficientNetV2-S
GBIF photos, full test fold: 629,742 images, 12,041 species (in-distribution)0.9210.9060.899
Probe: light-trap images, unseen nights (domain shift)0.7830.7770.765
Probe, held-out species (never seen in trap images)0.7850.7710.772

“Probe” is 15,200 light-trap images (368 Danish species) from capture nights never used in training. “Held-out species” is the 58 of those species for which no trap image was used at all. At a 95 % precision target (thresholds fitted on half the capture nights, verified on the other half), the ViT answers 90 % of trap images with 96 % precision, the ConvNeXt 81 % and the EfficientNet 90 % with 95 %, either at species or at a coarser rank. On 3,171 photos of 591 species outside the label set, the ViT wrongly commits to a species on only 17 % (ConvNeXt 21 %, EfficientNet 25 %), and otherwise backs off to a mostly correct genus or family, or says “unknown”.

Limitations

  • One specimen per image; it does not detect.
  • Closed label set. A species outside the 12,041 still gets one of them. The thresholds and the embedding help to flag it, but do not guarantee it.
  • Geographic bias. Training images are 36 % North American and 33 % European; South America and Africa together are 6 %. Expect the tropics to be served worse.
  • Domain shift. Accuracy on trap images is about 13 points below curated GBIF photos. The shipped thresholds are fitted on Danish light traps and should be re-fitted for other cameras.
  • Adults. Larvae are about 1 % of training images.

How to obtain the weights

Public, ungated Hugging Face repos, grouped in a collection. The ViT and EfficientNet weights are licensed CC-BY-NC-4.0 (non-commercial), because most training images are CC-BY-NC. The ConvNeXt is the exception: as a derivative of DINOv3 it is distributed under the DINOv3 License, with a separate request for non-commercial use. The training code is GPL-3.0. Each repo ships fp32, int8 (CPU) and fp16 (GPU) ONNX files (the EfficientNet has no int8), and the ViT also loads with transformers (trust_remote_code=True). The asset links above are pinned to the curated commit.

Citation

@software{mougeot_lepinet_2026,
  author = {Mougeot, Guillaume},
  title  = {lepinet: hierarchical Lepidoptera identification that knows what it does not know},
  year   = {2026},
  url    = {https://github.com/GuillaumeMougeot/lepinet}
}

Training data: GBIF.org (15 May 2025) GBIF Occurrence Download https://doi.org/10.15468/dl.hg37y9.