lm3_specimen_segmenter__unetpp_effb7_1024
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). Was the default specimen_segmenter model in LeafMachine3 3.0.0 to 3.0.1041; the current default is lm3_specimen_segmenter__unetpp_effb7_1024_dinov3_vith16plus_2048_consensus (UNet++ v8). This model stays available as an alternate (lm3 models install --model specimen_segmenter=unetpp_effb7_1024).
LM3 metadata
| Field | Value |
|---|---|
| LM3 action | specimen_segmenter |
| LM3_default_model | false (the default in 3.0.0 to 3.0.1041; now unetpp_effb7_1024_dinov3_vith16plus_2048_consensus) |
| LM3_version | 3.0.0 (minimum supported; later releases remain compatible) |
| Model key | unetpp_effb7_1024 (training run unet_masksFromSam3_paperclean_control_1024) |
| 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-07-28 |
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) of the best epoch |
The whole network is fine-tuned; only the encoder starts from pretrained weights.
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).
- SAM 3 (Meta): produced the first-generation masks the training targets descend from (see Training data).
Files
| Folder | File | Use |
|---|---|---|
pytorch/ | best.pt | training checkpoint (model, EMA, optimizer); retraining |
onnx/ | model.onnx | LM3 default runtime (onnxruntime), opset 17 |
torchscript/ | model.torchscript.pt | libtorch |
coreml/ | model.mlpackage/ | Apple devices |
docs/ | compare_*.jpg | example panels (see Examples) |
SHA-256 of every file is in manifest.json.
Training data
There is no hand-drawn ground truth for this task. The training targets are machine-generated masks, refined in three steps:
- Boxes to masks.
Specimenboxes from the LeafMachine3 plant detection set prompt SAM 3; the per-box masks are unioned, holes filled, and failed masks gated out. 21,098 sheets kept. - Self-training. A first UNet++ trained on those masks re-predicts every herbarium sheet; its cleaner predictions replace the SAM 3 masks. 2,193 field photographs are excluded as out of domain. 18,904 sheets.
- Paper removal. A color rule samples the mounting paper around each mask and deletes large in-mask regions that match it.
The result is dataset LM3_Specimen_Segmentation-specimen-unetMasksFromSam3-paperclean: 18,904 sheet images from 75 labeling projects, one plant class. Images and masks are not distributed.
| Split | Images |
|---|---|
| train | 15,154 |
| val | 1,910 |
| test | 1,840 |
Training
34 epochs, batch 4, 1024 x 1024 letterbox, AdamW (lr 1e-4, weight decay 1e-4), cosine schedule, mixed precision, EMA. Loss: Dice + binary cross-entropy + 0.5 x boundary (Sobel edge) term. Augmentation: horizontal and vertical flips, 90-degree rotations, transpose, brightness/contrast 0.2, hue/saturation/value 10/15/10.
Evaluation
Scores are agreement with the machine-generated masks described above, not with human annotation. They measure how well the model reproduces its training targets on held-out sheets; a model that corrects a flawed target is penalized for it. Read them as a consistency check and judge quality from the examples.
| Split | Sheets scored | Dice (mean) | Dice (median) | IoU (mean) |
|---|---|---|---|---|
| val, during training (best epoch) | 1,910 | 0.946 | ||
| val, exported ONNX | 150 of 1,910 | 0.941 | 0.979 | 0.909 |
| test, exported ONNX | 150 of 1,840 | 0.948 | 0.977 | 0.916 |
The ONNX rows are random samples of each split, scored at native sheet resolution; 2% of test sheets and 3% of val sheets score below 0.5 Dice. Known weakness: faint, dried-brown material on similarly colored paper can be under-segmented.
Examples
Background removal on the same sheets by this model (UNet++) and by the two other LeafMachine3 specimen segmenters trained on the same data, BiRefNet and YOLO26x-seg, for comparison. Black marks what each model removed; the percentage is the share of the sheet kept. Raw model masks, before LeafMachine3's paper-removal follow-up. 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 held-out test sheets.
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 follow-up (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).
from huggingface_hub import hf_hub_download
path = hf_hub_download("phyloforfun/lm3_specimen_segmenter__unetpp_effb7_1024", "onnx/model.onnx")
Citation
Weaver, W. N. (2026) LeafMachine3. https://leafmachine.org