lm3_specimen_segmenter__unetpp_effb7_1024_dinov3_vith16plus_2048_selftrain
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++ v9: the network and training recipe of UNet++ v8, trained again on v8's own masks after LeafMachine3's paper cleanup (self-training). It produces the cleaned result directly: the paper-removal step that follows it in LeafMachine3 now removes a median 0.08% of its mask on random test sheets, against 1.2% of v8's. Default specimen_segmenter model in LeafMachine3 >= 3.0.1044, replacing v8.
LM3 metadata
| Field | Value |
|---|---|
| LM3 action | specimen_segmenter |
| LM3_default_model | true (replaces unetpp_effb7_1024_dinov3_vith16plus_2048_consensus) |
| LM3_version | 3.0.1044 (minimum; earlier releases do not know this model key) |
| Model key | unetpp_effb7_1024_dinov3_vith16plus_2048_selftrain (training run unetpp-v9-1024-dinov3_vith16plus_2048-v5targets-v8ep7llr-tta-30ep, epoch 30 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-25 |
| 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 30 of 30 |
The whole network is trained from the ImageNet encoder; it does not start from v8's weights. v8 and the paper-removal step 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 original targets of this model line.
- Generalized cross-entropy: Zhang and Sabuncu, "Generalized Cross Entropy Loss for Training Deep Neural Networks with Noisy Labels", 2018.
Files
| Folder | File | Use |
|---|---|---|
pytorch/ | best.pt | the exported weights (EMA copy at epoch 30, 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) |
coreml_fp32/ | model.mlpackage/, model.json | LM3 on macOS: Core ML on the Apple GPU, float32 |
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
Self-training: the targets are the released UNet++ v8 (revision 112f2da, epoch 7) run over all 27,772 sheets, then LeafMachine3's paper cleanup. For every sheet, on the 2,048-pixel grid every earlier target set used:
- v8 three times: as is, flipped horizontally, and with the sheet scaled to 0.75 inside the 1024 canvas.
- Target: the first pass thresholded at 0.5, then LeafMachine3's
LLR_Hyst_KeepBlobspaper removal (15.75% of a sheet is plant before it, 15.15% after). - Pixels where the three passes disagree are left out of training (weight 0; 0.58% of a sheet on average), so v9 does not learn v8's least certain calls.
v8's own targets (DINOv3 masks, context cleaning, Leafsnap leaf union, consensus weights) are described on its card. The result is dataset LM3_Specimen_Segmentation-dense-weak-bbox-from-plant-archival, masks pseudolabels_v5-unetpp_v8ep7-llr/final_v8llr and weights pseudolabels_v5-unetpp_v8ep7-llr/weights. Sheets whose mask is empty are skipped. Images, masks and weights are not distributed.
| Split | Sheets | Empty masks (skipped) |
|---|---|---|
| train | 22,277 | 147 |
| val | 2,782 | 23 |
| test | 2,713 | 19 |
The splits are the ones v1, v2 and v8 were trained with.
Training
v8's recipe unchanged: 30 epochs, batch 5, 1024 x 1024 letterbox, AdamW (lr 1e-4, weight decay 1e-4), cosine schedule, mixed precision, EMA with warm-up; generalized cross-entropy (q 0.7) + Dice + 0.5 x image-edge term (alpha 10), weighted per pixel; a 6-pixel band around every target outline is not learned unless the image has an edge there; the white letterbox pad is trained as background. Augmentation: flips, 90-degree rotations, transpose, brightness/contrast 0.2, hue/saturation/value 10/15/10.
Checkpoint. This is the last epoch. v8 was released at epoch 7 because its machine-made targets drop pale and thin plant, and plant recall fell as training went on; v9's targets do not have that bias, and plant recall on hand-placed points stayed between 0.91 and 0.93 for all 30 epochs. Label-free checks (full-sheet input, threshold 0.5) against the released v8 pipeline:
| Check | UNet++ v8 + paper removal (released pipeline) | UNet++ v9, no cleanup | UNet++ v9 + paper removal |
|---|---|---|---|
| Plant recall on hand-placed points (12 hard sheets) | 0.909 | 0.914 | 0.914 |
| Background points correct (same sheets) | 0.989 | 0.979 | 0.989 |
| Fill precision (24 sheets with thin stems on white paper) | 0.831 | 0.826 | 0.840 |
| Thin-structure recall (same sheets) | 0.709 | 0.709 | 0.696 |
| Petiole recall (50 Leafsnap photos) | 0.681 | 0.691 | 0.671 |
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. UNet++ v1 is unetpp_effb7_1024, UNet++ v2 is unetpp_effb7_1024_dinov3_vith16plus_2048, UNet++ v8 is unetpp_effb7_1024_dinov3_vith16plus_2048_consensus and UNet++ v9 is this model; "+ paper removal" is LeafMachine3's paper-removal step with its default method (LLR_Hyst_KeepBlobs).
During training (validation, 2,759 sheets, epoch 30): Dice 0.984, IoU 0.970, boundary F 0.913 -- against v8's own masks, so this measures how closely v9 reproduces its teacher, not quality.
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 test sheets; the validation split is in evaluation_metrics.json.
Against v8's training targets (DINOv3 masks after context cleaning and the Leafsnap leaf union):
| Model | Sheets | Dice (mean) | Dice (median) | Precision | Recall | Dice < 0.5 |
|---|---|---|---|---|---|---|
| UNet++ v1 raw | 150 of 2,713 | 0.873 | 0.927 | 0.883 | 0.895 | 5% |
| UNet++ v1 + paper removal | 150 of 2,713 | 0.881 | 0.939 | 0.905 | 0.888 | 4% |
| UNet++ v2 raw | 150 of 2,713 | 0.910 | 0.965 | 0.883 | 0.964 | 4% |
| UNet++ v2 + paper removal | 150 of 2,713 | 0.921 | 0.969 | 0.930 | 0.932 | 3% |
| UNet++ v8 raw | 150 of 2,713 | 0.938 | 0.970 | 0.928 | 0.965 | 1% |
| UNet++ v8 + paper removal | 150 of 2,713 | 0.927 | 0.964 | 0.938 | 0.935 | 1% |
| UNet++ v9 raw | 150 of 2,713 | 0.926 | 0.965 | 0.931 | 0.936 | 1% |
| UNet++ v9 + paper removal | 150 of 2,713 | 0.925 | 0.963 | 0.933 | 0.931 | 1% |
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:
| Model | Sheets | Dice (mean) | Dice (median) | Precision | Recall | Dice < 0.5 |
|---|---|---|---|---|---|---|
| UNet++ v1 raw | 150 of 1,840 | 0.949 | 0.977 | 0.952 | 0.959 | 2% |
| UNet++ v1 + paper removal | 150 of 1,840 | 0.934 | 0.964 | 0.962 | 0.920 | 2% |
| UNet++ v2 raw | 150 of 1,840 | 0.871 | 0.917 | 0.871 | 0.913 | 5% |
| UNet++ v2 + paper removal | 150 of 1,840 | 0.903 | 0.951 | 0.929 | 0.907 | 4% |
| UNet++ v8 raw | 150 of 1,840 | 0.907 | 0.951 | 0.911 | 0.931 | 2% |
| UNet++ v8 + paper removal | 150 of 1,840 | 0.919 | 0.965 | 0.939 | 0.924 | 2% |
| UNet++ v9 raw | 150 of 1,840 | 0.919 | 0.964 | 0.939 | 0.924 | 3% |
| UNet++ v9 + paper removal | 150 of 1,840 | 0.920 | 0.965 | 0.942 | 0.922 | 3% |
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++ v1 raw | 2.5% of 441 | 100.0% of 624 |
| UNet++ v1 + paper removal | 2.5% of 441 | 100.0% of 624 |
| 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 |
| UNet++ v9 raw | 90.9% of 441 | 97.9% of 624 |
| UNet++ v9 + paper removal | 90.9% of 441 | 98.9% 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.985 (minimum 0.916).
Known weaknesses: v9 learned the paper cleanup's decisions along with its benefits, so on sheets where a leaf is nearly the color of the paper (very pale or whitish leaves on tan paper) it can leave out part of that leaf even before any cleanup runs; thin, pale stems and roots on white paper are the other place it is cautious. Against the leaf segmenter's petioles on Leafsnap photos it matches v8 raw (0.69) and is slightly lower after the cleanup (0.67).
Examples
Background removal on the 20 sheets of the unetpp_effb7_1024 card (the same sheets as the v2 and v8 cards). Top row: Original | UNet++ v1 | UNet++ v2 | UNet++ v8; bottom row: UNet++ v8 + paper removal (the released v8 pipeline) | UNet++ v9 | UNet++ v9 + paper removal. Black marks what each model removed, red what paper removal deleted; the percentage is the share of the sheet kept. 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 v8 card on which unetpp_effb7_1024 removed most of the plant. Original | UNet++ v1 | UNet++ v2 | UNet++ v8 | UNet++ v9, raw model masks.
The same sheets with paper removal
LeafMachine3's paper-removal step (paperclean: true, default method LLR_Hyst_KeepBlobs) after each model. 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). Both masks are saved by default: the Reporter exports this model's own mask under Specimen_Masks/*_Specimen and the paper-cleaned one under *_Specimen_PaperCleaned, each as a binary mask, an RGB cutout and their inverses, and draws the cleaned mask as Overlay_Specimen_Segmentation. lm3 models install puts the model in models/specimen_segmenter/unetpp_effb7_1024_dinov3_vith16plus_2048_selftrain/; the settings name it by key:
On macOS, LM3 runs coreml_fp32/ with Core ML on the Apple GPU instead; its output matches this ONNX model to float32 rounding.
specimen_segmenter:
model: {key: unetpp_effb7_1024_dinov3_vith16plus_2048_selftrain, path: models/specimen_segmenter/unetpp_effb7_1024_dinov3_vith16plus_2048_selftrain/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_selftrain", "onnx/model.onnx")
Citation
Weaver, W. N. (2026) LeafMachine3. https://leafmachine.org