lm3_specimen_segmenter__unetpp_effb7_1024_dinov3_vith16plus_2048
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). Same network and input as lm3_specimen_segmenter__unetpp_effb7_1024; trained on new targets: masks derived from detector boxes with DINOv3 features instead of from SAM 3. Was the default specimen_segmenter model in LeafMachine3 3.0.1042; from 3.0.1043 the default is lm3_specimen_segmenter__unetpp_effb7_1024_dinov3_vith16plus_2048_consensus (UNet++ v8), and this model stays available as an alternate (lm3 models install --model specimen_segmenter=unetpp_effb7_1024_dinov3_vith16plus_2048).
LM3 metadata
| Field | Value |
|---|---|
| LM3 action | specimen_segmenter |
| LM3_default_model | false (default in 3.0.1042, replaced by unetpp_effb7_1024_dinov3_vith16plus_2048_consensus from 3.0.1043) |
| LM3_version | 3.0.1042 (minimum; earlier releases do not know this model key) |
| Model key | unetpp_effb7_1024_dinov3_vith16plus_2048 (training run unetpp-v2-1024-dinov3_vith16plus_2048-full-unionneg-final_grabcut, epoch 28 of 50) |
| 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-21 |
| Iteration | 2 (replaces iteration 1, epoch 22 of the same run: same targets and regime, later checkpoint) |
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 28, the best validation epoch of the run |
The whole network is fine-tuned; only the encoder starts from pretrained weights. DINOv3 is not part of this model: it 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 whose features turned boxes into training masks (see Training data).
- GrabCut: Rother, Kolmogorov and Blake, "GrabCut: Interactive Foreground Extraction using Iterated Graph Cuts", 2004 (OpenCV implementation); guided filter: He, Sun and Tang, 2013.
Files
| Folder | File | Use |
|---|---|---|
pytorch/ | best.pt | training checkpoint (model + EMA weights); 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 training targets are machine-generated from boxes, in five steps:
- Images. The training images of the LeafMachine3 plant detector (
LM3_Plant, 23,726) and archival detector (LM3_Archival, 8,470), deduplicated (4,424 duplicates removed): 27,772 sheets from 100 labeling projects. - Boxes. LeafMachine3's own detectors, run on every sheet the way a LeafMachine3 run does: the plant detector (
lm3_plant_detector__yolo26x_det_1280, conf 0.3) and the archival detector (lm3_archival_detector__yolo26x_det_1280, conf 0.25). Both were trained on hand-drawn Labelbox boxes; these are their predictions. LeafMachine3's plant detector has no Specimen class, so Specimen boxes come fromlm3_specimen_detector__yolo26n_det_640(conf 0.35). - Weak labels. Plant boxes mark plant (weight 2), Specimen boxes mark plant (weight 1), archival boxes mark background (weight 2), and 20 random boxes per sheet placed clear of every other box mark background (weight 1). Archival
EnvelopeandAttached_Itemboxes count as Specimen boxes, since packets hold plant material. Archival overrules plant; plant overrules Specimen. Everything else is unlabeled. - DINOv3 probe. Each sheet, resized to a 2,048-pixel long edge, goes through a frozen DINOv3 ViT-H+/16 (one 1,280-dimensional feature per 16 x 16 pixel patch). Inside the plant and Specimen boxes, patches that look like the paper or the mounting are flagged by two filters (per sheet: closer to the sheet's background clusters than to its plant-box mean; across the training set: Gaussian mixtures of plant and background features) and treated as background. A small head (LayerNorm, Linear 1280 to 256, GELU, Linear 256 to 1) learns from the background patches directly and from each box as a multiple-instance bag: the top 40% of a plant box's patches, and the top 15% of a Specimen box's, should be plant. Validation: 99.7% of background patches correct, 99.4% of plant boxes satisfied.
- Masks. The head's per-patch plant probability (with a horizontal-flip average), upsampled with a guided filter, seeds GrabCut at 2,048 pixels: confident patches (p >= 0.5) are sure plant, the other kept patches and a two-patch ring are probable background, everything else (and every archival, random-background or flagged patch) is sure background. The result is a binary mask; on average 16.4% of a sheet is plant.
The result is dataset LM3_Specimen_Segmentation-dense-weak-bbox-from-plant-archival with masks pseudolabels_dinov3_vith16plus_2048-full-unionneg/final_grabcut. Sheets whose mask came out empty (239, mostly calibration photos, label-only sheets and Leafsnap leaves inside an archival box) are skipped. 9,934 of the sheets are Leafsnap lab and field photographs. Images and masks are not distributed.
| Split | Sheets | Empty masks (skipped) |
|---|---|---|
| train | 22,277 | 196 |
| val | 2,782 | 24 |
| test | 2,713 | 19 |
The splits are LM3_Plant's (sheets only in LM3_Archival keep its split), the same splits unetpp_effb7_1024 was trained with, so no sheet is held out from one model and trained on by the other.
Training
50 epochs planned (this is epoch 28, the best validation epoch of the run), batch 5, 1024 x 1024 letterbox, AdamW (lr 1e-4, weight decay 1e-4), cosine schedule over the planned epochs, mixed precision, EMA with warm-up. Loss: binary cross-entropy + Dice + 0.5 x boundary (Sobel edge) term, all weighted per pixel; 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. Same network and regime as unetpp_effb7_1024 apart from the loss weighting, the pad and the batch size (4 there). The run was stopped during epoch 50 after validation Dice against the pseudo masks had peaked at epoch 28 (0.939) and drifted down slowly afterward (0.937 at epoch 49).
Evaluation
Scores are agreement with machine-generated masks, not with human annotation, and the two target sets below have opposite biases: the DINOv3 masks this model trains on, and the SAM 3-derived masks unetpp_effb7_1024 trains on. Each model is favored on its own targets. Read them as consistency checks and judge quality from the examples. In the tables, UNet++ v1 is unetpp_effb7_1024 and UNet++ v2 is this model.
During training (validation, 2,758 sheets, against the DINOv3 masks, best epoch): Dice 0.939, IoU 0.901, boundary F 0.750.
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, both UNet++ models, with and without LeafMachine3's paper-removal step:
Against the DINOv3 masks (this model's targets; dense-weak test and val splits):
| Split | Model | Sheets | Dice (mean) | Dice (median) | Precision | Recall | Dice < 0.5 |
|---|---|---|---|---|---|---|---|
| test | UNet++ v1 raw | 150 of 2,713 | 0.838 | 0.906 | 0.887 | 0.840 | 7% |
| test | UNet++ v1 + paper removal | 150 of 2,713 | 0.831 | 0.910 | 0.911 | 0.824 | 8% |
| 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.864 | 0.946 | 0.964 | 0.830 | 6% |
| val | UNet++ v1 raw | 150 of 2,782 | 0.856 | 0.920 | 0.887 | 0.863 | 5% |
| val | UNet++ v1 + paper removal | 150 of 2,782 | 0.823 | 0.911 | 0.892 | 0.821 | 9% |
| 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.856 | 0.958 | 0.953 | 0.828 | 8% |
Against the SAM 3-derived masks (unetpp_effb7_1024's targets; the same samples its card is scored on). These targets were themselves cleaned with the paper-removal rule, which favors the "+ paper removal" rows:
| Split | Model | Sheets | Dice (mean) | Dice (median) | Precision | Recall | Dice < 0.5 |
|---|---|---|---|---|---|---|---|
| test | UNet++ v1 raw | 150 of 1,840 | 0.949 | 0.977 | 0.952 | 0.959 | 2% |
| test | UNet++ v1 + paper removal | 150 of 1,840 | 0.936 | 0.979 | 0.976 | 0.927 | 3% |
| 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.916 | 0.955 | 0.954 | 0.901 | 2% |
| val | UNet++ v1 raw | 150 of 1,910 | 0.942 | 0.979 | 0.953 | 0.950 | 3% |
| val | UNet++ v1 + paper removal | 150 of 1,910 | 0.940 | 0.981 | 0.967 | 0.935 | 3% |
| 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.916 | 0.960 | 0.962 | 0.890 | 2% |
Hand-placed points. On 12 sheets where unetpp_effb7_1024 failed, plant and background points were placed by hand (10 sheets are in this model's 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 | 1.1% of 441 | 100.0% of 624 |
| UNet++ v2 raw | 73.5% of 441 | 95.0% of 624 |
| UNet++ v2 + paper removal | 22.9% of 441 | 100.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.961): the differences are boundary pixels.
Against its own targets and on the hand-placed points, paper removal lowers this model's recall a lot (it deletes plant that matches the paper); against the SAM 3 targets it raises precision (it deletes paper this model kept). Known weaknesses: on white paper the model can fill the paper between sparse stems and branches (panels 13 and 16 below), which paper removal partly cleans up; where the plant and the paper are close in color, paper removal deletes plant (see the last set of examples).
Examples
Background removal on the 20 sheets of the unetpp_effb7_1024 card, by that model (UNet++ v1) and this one (UNet++ v2). 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 earlier UNet++ failed on
Held-out sheets 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++ v1 | UNet++ v2, raw model masks.
The same sheets with paper removal
LeafMachine3 follows the model with a paper-removal step (paperclean: true, the default): it samples the paper around the mask and deletes large regions inside the mask that match its color. Red marks what it deleted. On the first 4 sheets (the ones above) the plant and the paper are close in color, so the step removes plant as well as paper. On the last 4 it does what it is for: it removes paper the model kept, such as the paper between leaf lobes, and pale holes in leaves.
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). One mask per specimen is stored; the Reporter draws it as Overlay_Specimen_Segmentation and exports it under Specimen_Masks (binary mask and RGB cutout). lm3 models install puts it in models/specimen_segmenter/unetpp_effb7_1024_dinov3_vith16plus_2048/; the settings name it by key:
specimen_segmenter:
model: {key: unetpp_effb7_1024_dinov3_vith16plus_2048, path: models/specimen_segmenter/unetpp_effb7_1024_dinov3_vith16plus_2048/model.onnx, format: onnx}
paperclean: true
from huggingface_hub import hf_hub_download
path = hf_hub_download("phyloforfun/lm3_specimen_segmenter__unetpp_effb7_1024_dinov3_vith16plus_2048", "onnx/model.onnx")
Citation
Weaver, W. N. (2026) LeafMachine3. https://leafmachine.org