lm3_specimen_segmenter__unetpp_effb7_1024_dinov3_vith16plus_2048_consensus
UNet++ with an EfficientNet-B7 encoder that separates plant material from everything else on a herbarium specimen sheet (binary foreground mask, used for background removal). This is UNet++ v8: the same network and input as unetpp_effb7_1024_dinov3_vith16plus_2048 (UNet++ v2), trained again on cleaner targets, with per-pixel weights that say how far each target pixel can be trusted and a loss that tolerates wrong labels. It keeps far less of the paper that v2 filled in between stems and branches. Was the default specimen_segmenter model in LeafMachine3 3.0.1043; from 3.0.1044 the default is lm3_specimen_segmenter__unetpp_effb7_1024_dinov3_vith16plus_2048_selftrain (UNet++ v9, trained on this model's own masks after the paper cleanup). This model stays available as an alternate (lm3 models install --model specimen_segmenter=unetpp_effb7_1024_dinov3_vith16plus_2048_consensus). The versions are numbered in sequence: v3 to v7 were experiments that were never released.
LM3 metadata
| Field | Value |
|---|---|
| LM3 action | specimen_segmenter |
| LM3_default_model | false (default in 3.0.1043; replaced by unetpp_effb7_1024_dinov3_vith16plus_2048_selftrain from 3.0.1044) |
| LM3_version | 3.0.1043 (minimum; earlier releases do not know this model key) |
| Model key | unetpp_effb7_1024_dinov3_vith16plus_2048_consensus (training run unetpp-v8-1024-dinov3_vith16plus_2048-v4targets-consensus-weights-30ep, epoch 7 of 30) |
| Input | whole sheet image, letterboxed onto a white 1024 x 1024 square, RGB, ImageNet mean/std normalization; tensor input [1, 3, 1024, 1024] float32 |
| Output | logits [1, 1, 1024, 1024]; apply sigmoid, threshold 0.5, remove the letterbox pad, resize to the sheet |
| Classes (1) | plant (foreground) |
| Trained | 2026-10-23 |
| Iteration | 1 |
Architecture
| Component | Detail |
|---|---|
| Network | UNet++ (nested, densely connected skip pathways), segmentation_models_pytorch.UnetPlusPlus |
| Encoder | EfficientNet-B7, initialized from ImageNet weights (encoder_weights="imagenet") |
| Head | 1 output channel, no activation (logits) |
| Parameters | 66.4 M |
| Exported weights | the exponential-moving-average copy (decay 0.9998, with warm-up) at epoch 7 of 30 (see Training) |
The whole network is trained from the ImageNet encoder; it does not start from v2's weights. DINOv3, the v2 UNet++ and the LeafMachine3 leaf segmenter are not part of this model: they only produced the training targets.
Credits
- segmentation_models.pytorch (Pavel Iakubovskii, MIT): the UNet++ implementation and the pretrained encoder loader. https://github.com/qubvel-org/segmentation_models.pytorch
- UNet++: Zhou et al., "UNet++: A Nested U-Net Architecture for Medical Image Segmentation", 2018.
- EfficientNet-B7: Tan and Le, "EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks", 2019; ImageNet weights from EfficientNet-PyTorch (Apache-2.0).
- DINOv3 (Meta): Siméoni et al., "DINOv3", 2025. The frozen ViT-H+/16 backbone behind the v2 targets.
- GrabCut: Rother, Kolmogorov and Blake, 2004 (OpenCV implementation); guided filter: He, Sun and Tang, 2013.
- Generalized cross-entropy: Zhang and Sabuncu, "Generalized Cross Entropy Loss for Training Deep Neural Networks with Noisy Labels", 2018.
- LeafMachine3 leaf segmenter (
lm3_leaf_segmenter__yolo26x_seg_1024, YOLO26x-seg): leaf and petiole masks on the Leafsnap photographs (see Training data).
Files
| Folder | File | Use |
|---|---|---|
pytorch/ | best.pt | the exported weights (EMA copy at epoch 7, key ema) with the training config; retraining |
onnx/ | model.onnx | LM3 default runtime (onnxruntime), opset 17 |
torchscript/ | model.torchscript.pt | libtorch |
coreml/ | model.mlpackage/ | Apple devices (float16 input/output, iOS 16 / macOS 13) |
docs/ | compare_*.jpg, failure_*.jpg | example panels (see Examples) |
SHA-256 of every file is in manifest.json; training_metadata.json records the full training and dataset chain.
Training data
There is no hand-drawn ground truth for this task. The targets are machine-generated. They start from the v2 targets: detector boxes on 27,772 sheets turned into masks with a DINOv3 probe and GrabCut (steps 1 to 5 on the v2 card). Three steps follow:
- Context cleaning. v2 learned that paper surrounded by plant is plant, and its targets have the same flaw. The v2 UNet++ (iteration 1) was run on every sheet again with everything outside a moving 384-pixel window (on the 1024 letterbox) replaced by white or by a blur, so it sees each region without its surroundings. A pixel stays plant only where both the whole-sheet view and the windowed views say plant (the outline is restored within 4 pixels and dilated by 4). Sheets that would lose more than 90% of their mask keep the v2 mask (199 sheets). On average this removes 9.3% of each mask.
- Leafsnap leaves. On the 9,934 Leafsnap lab and field photographs, the mask is joined with the LeafMachine3 leaf segmenter's Leaf and Petiole masks (eroded by 1 pixel), minus its Hole masks. This adds the petioles and leaf tips the box-based masks miss (plant share on these photos 7.9% to 9.3%). 15 field photographs where the leaf segmenter's output was implausible keep the step-6 mask.
- Consensus weights. Every target pixel gets a weight from how many independent sources agree with it: the context-cleaned view, the v1 UNet++ (where its mask is plausible), the leaf segmenter and a thin-ridge detector. Weight 0 where the target says background but another source says plant (disputed pixels are not learned; 0.95% of a sheet on average); weight 2 for sure background (all sources agree, outside the plant boxes and at least 4 pixels from plant), archival boxes and the paper removed in step 6 (72.9%); weight 3 for hard negatives: strong-edge objects 10 to 30 pixels from the plant such as tape and clips (0.34%); weight 1 elsewhere (25.8%).
The result is dataset LM3_Specimen_Segmentation-dense-weak-bbox-from-plant-archival, masks pseudolabels_v4-v3ctx-leafsnapyolo/final_grabcut_ctx and weights pseudolabels_v4-v3ctx-leafsnapyolo/weights. Sheets whose mask is empty are skipped. Images, masks and weights are not distributed.
| Split | Sheets | Empty masks (skipped) |
|---|---|---|
| train | 22,277 | 202 |
| val | 2,782 | 29 |
| test | 2,713 | 20 |
The splits are the ones v1 and v2 were trained with, so no sheet is held out from one model and trained on by another.
Training
30 epochs, batch 5, 1024 x 1024 letterbox, AdamW (lr 1e-4, weight decay 1e-4), cosine schedule over the 30 epochs, mixed precision, EMA with warm-up. Loss, every term weighted per pixel by the consensus weights: generalized cross-entropy (q 0.7, which down-weights pixels the network confidently disagrees with) + Dice + 0.5 x an edge term that pulls mask edges onto image edges (alpha 10). A band of 6 pixels on both sides of every target outline is not learned unless the image itself has an edge there. The white letterbox pad is trained as background. Augmentation: horizontal and vertical flips, 90-degree rotations, transpose, brightness/contrast 0.2, hue/saturation/value 10/15/10.
Checkpoint. This is epoch 7, not the epoch with the best validation Dice against the targets (epoch 26). The targets drop pale, dried and thin plant material; agreement with them kept rising for the whole run, but plant recall on hand-placed points fell from epoch 7 on, as the network learned the targets' mistakes. Every epoch was checked without labels on fixed sheet sets (full-sheet input, threshold 0.5):
| Check | Epoch 7 (this model) | Epoch 26 (best validation Dice) |
|---|---|---|
| Plant recall on hand-placed points (12 hard sheets) | 0.909 | 0.762 |
| Background points correct (same sheets) | 0.981 | 0.992 |
| Fill precision (24 sheets with thin stems on white paper) | 0.671 | 0.654 |
| Thin-structure recall (same sheets) | 0.817 | 0.816 |
| Petiole recall (50 Leafsnap photos) | 0.691 | 0.710 |
| Validation Dice vs the training targets | 0.949 | 0.954 |
Evaluation
Scores are agreement with machine-generated masks, not with human annotation, and each target set has its own bias. Read them as consistency checks and judge quality from the examples. In the tables, UNet++ v2 is unetpp_effb7_1024_dinov3_vith16plus_2048 and UNet++ v8 is this model; "+ paper removal" is LeafMachine3's paper-removal step with its default method (LLR_Hyst_KeepBlobs).
During training (validation, 2,753 sheets, against this model's targets, epoch 7): Dice 0.949, IoU 0.914, boundary F 0.726.
Exported ONNX run the way LeafMachine3 runs it (the ingest working image, at most 3,200 pixels on the long side; threshold 0.5; scored at that resolution), on random samples (seed 7) of held-out sheets, with and without paper removal:
Against this model's targets (steps 6 and 7 above; dense-weak test and val splits):
| Split | Model | Sheets | Dice (mean) | Dice (median) | Precision | Recall | Dice < 0.5 |
|---|---|---|---|---|---|---|---|
| test | UNet++ v2 raw | 150 of 2,713 | 0.910 | 0.965 | 0.883 | 0.964 | 4% |
| test | UNet++ v2 + paper removal | 150 of 2,713 | 0.921 | 0.969 | 0.930 | 0.932 | 3% |
| test | UNet++ v8 raw | 150 of 2,713 | 0.938 | 0.970 | 0.928 | 0.965 | 1% |
| test | UNet++ v8 + paper removal | 150 of 2,713 | 0.927 | 0.964 | 0.938 | 0.935 | 1% |
| val | UNet++ v2 raw | 150 of 2,782 | 0.918 | 0.974 | 0.902 | 0.962 | 3% |
| val | UNet++ v2 + paper removal | 150 of 2,782 | 0.922 | 0.975 | 0.941 | 0.926 | 3% |
| val | UNet++ v8 raw | 150 of 2,782 | 0.939 | 0.977 | 0.931 | 0.970 | 3% |
| val | UNet++ v8 + paper removal | 150 of 2,782 | 0.927 | 0.974 | 0.940 | 0.936 | 3% |
Against the v2 targets (the same sheets before steps 6 and 7; they include the paper fill this model was trained to leave out, which favors v2):
| Split | Model | Sheets | Dice (mean) | Dice (median) | Precision | Recall | Dice < 0.5 |
|---|---|---|---|---|---|---|---|
| test | UNet++ v2 raw | 150 of 2,713 | 0.930 | 0.968 | 0.930 | 0.939 | 2% |
| test | UNet++ v2 + paper removal | 150 of 2,713 | 0.906 | 0.954 | 0.947 | 0.882 | 2% |
| test | UNet++ v8 raw | 150 of 2,713 | 0.904 | 0.955 | 0.936 | 0.903 | 3% |
| test | UNet++ v8 + paper removal | 150 of 2,713 | 0.891 | 0.950 | 0.942 | 0.877 | 4% |
| val | UNet++ v2 raw | 150 of 2,782 | 0.929 | 0.974 | 0.935 | 0.943 | 2% |
| val | UNet++ v2 + paper removal | 150 of 2,782 | 0.901 | 0.969 | 0.947 | 0.886 | 3% |
| val | UNet++ v8 raw | 150 of 2,782 | 0.911 | 0.970 | 0.933 | 0.913 | 3% |
| val | UNet++ v8 + paper removal | 150 of 2,782 | 0.895 | 0.968 | 0.938 | 0.885 | 4% |
Against the SAM 3-derived masks (unetpp_effb7_1024's targets; the samples its card is scored on). These targets were themselves cleaned with the original paper-removal rule:
| Split | Model | Sheets | Dice (mean) | Dice (median) | Precision | Recall | Dice < 0.5 |
|---|---|---|---|---|---|---|---|
| test | UNet++ v2 raw | 150 of 1,840 | 0.871 | 0.917 | 0.871 | 0.913 | 5% |
| test | UNet++ v2 + paper removal | 150 of 1,840 | 0.903 | 0.951 | 0.929 | 0.907 | 4% |
| test | UNet++ v8 raw | 150 of 1,840 | 0.907 | 0.951 | 0.911 | 0.931 | 2% |
| test | UNet++ v8 + paper removal | 150 of 1,840 | 0.919 | 0.965 | 0.939 | 0.924 | 2% |
| val | UNet++ v2 raw | 150 of 1,910 | 0.871 | 0.930 | 0.880 | 0.901 | 5% |
| val | UNet++ v2 + paper removal | 150 of 1,910 | 0.895 | 0.958 | 0.926 | 0.896 | 4% |
| val | UNet++ v8 raw | 150 of 1,910 | 0.907 | 0.952 | 0.919 | 0.919 | 3% |
| val | UNet++ v8 + paper removal | 150 of 1,910 | 0.921 | 0.965 | 0.947 | 0.913 | 2% |
Hand-placed points. On 12 sheets where unetpp_effb7_1024 failed, plant and background points were placed by hand (10 sheets are in the training split, 2 in test; 2 sheets hold no plant and have background points only):
| Model | Plant points inside the mask | Background points outside the mask |
|---|---|---|
| UNet++ v2 raw | 73.5% of 441 | 95.0% of 624 |
| UNet++ v2 + paper removal | 73.5% of 441 | 96.0% of 624 |
| UNet++ v8 raw | 90.5% of 441 | 98.1% of 624 |
| UNet++ v8 + paper removal | 90.5% of 441 | 99.0% of 624 |
The training loader decodes JPEGs at reduced size before the 1024 resize; LeafMachine3 decodes the full image. On 50 test sheets the two give masks with IoU 0.988 (minimum 0.953).
Known weaknesses: in tight angles on pale paper (between a petiole and the leaf base, between close stems) the model can still keep a wedge of paper; the paper-removal step takes most of it out (the IMG_KS_T2 Ginkgo leaf below). The step itself lowers recall a little against this model's own targets (it also removes some pale, dried stems and roots on white paper) while raising precision; it did not remove any hand-placed plant point. Against the v2 targets this model scores lower than v2 because those targets contain the paper fill it was trained to leave out.
Examples
Background removal on the 20 sheets of the unetpp_effb7_1024 card, by UNet++ v2 and this model (UNet++ v8). Black marks what each model removed; the percentage is the share of the sheet kept. Raw model masks, before LeafMachine3's paper-removal step. File names give each sheet's dataset split. Panels 1 to 12 are a standing comparison set that includes deliberately hard sheets (several from the training split); panels 13 to 20 are random test sheets.
Sheets the v1 UNet++ failed on
The held-out sheets of the unetpp_effb7_1024_dinov3_vith16plus_2048 card on which unetpp_effb7_1024 removed most of the plant: tan, brown or gray-green material on paper or card of a similar color. Original | UNet++ v2 | UNet++ v8, raw model masks.
The same sheets with paper removal
LeafMachine3 follows the model with a paper-removal step (paperclean: true, default method LLR_Hyst_KeepBlobs): it samples the paper around the mask, models paper and plant colors, and deletes regions inside the mask that are confidently paper. Red marks what it deleted. The last 4 sheets are ones where the step has paper to remove.
Use in LeafMachine3
Stage specimen_segmenter (no dependencies; runs on the whole working image, independent of the plant boxes). ONNX at 1024, sigmoid threshold conf (default 0.5), then the paper-removal step (paperclean: true, method LLR_Hyst_KeepBlobs while LLR_Hyst_KeepBlobs: true; false selects the original HSV method). One mask per specimen is stored; the Reporter draws it as Overlay_Specimen_Segmentation and exports both masks under Specimen_Masks: this model's own mask in *_Specimen and the paper-cleaned one in *_Specimen_PaperCleaned, each as a binary mask, an RGB cutout and their inverses. lm3 models install puts the model in models/specimen_segmenter/unetpp_effb7_1024_dinov3_vith16plus_2048_consensus/; the settings name it by key:
specimen_segmenter:
model: {key: unetpp_effb7_1024_dinov3_vith16plus_2048_consensus, path: models/specimen_segmenter/unetpp_effb7_1024_dinov3_vith16plus_2048_consensus/model.onnx, format: onnx}
paperclean: true
LLR_Hyst_KeepBlobs: true
from huggingface_hub import hf_hub_download
path = hf_hub_download("phyloforfun/lm3_specimen_segmenter__unetpp_effb7_1024_dinov3_vith16plus_2048_consensus", "onnx/model.onnx")
Citation
Weaver, W. N. (2026) LeafMachine3. https://leafmachine.org