DeltaFelicia commited on
Commit
334548e
·
1 Parent(s): a4e302a

Fill in model card

Browse files
Files changed (1) hide show
  1. README.md +355 -0
README.md CHANGED
@@ -1,3 +1,358 @@
1
  ---
2
  license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ language:
4
+ - en
5
+ library_name: transformers
6
+ tags:
7
+ - biology
8
+ - CV
9
+ - images
10
+ - animals
11
+ - beetles
12
+ - image-segmentation
13
+ - mask2former
14
+ - entomology
15
+ datasets: imageomics/sentinel-beetles
16
+ metrics:
17
+ - mean_iou
18
+ model_description: >-
19
+ Fine-tuned Mask2Former models for semantic segmentation of beetle body parts
20
+ on pinned specimen images. Two checkpoints are provided: a 5-class model
21
+ (head, pronotum, elytra, legs, antennas) and a 9-class model (head, eyes,
22
+ mouthparts, pronotum, elytra, tail, legs, antennas, pin). Part of the
23
+ BeetleFlow pipeline for large-scale beetle image processing.
24
  ---
25
+
26
+ # Model Card for BeetleFlow
27
+
28
+ BeetleFlow provides fine-tuned **Mask2Former** checkpoints for **semantic segmentation of beetle body parts** on cropped, pinned specimen images. This repository hosts two variants:
29
+
30
+ | Checkpoint | Segmented parts (excluding background) | Labels |
31
+ |------------|------------------------------------------|--------|
32
+ | [`5-class`](./5-class) | 5 parts | background, head, pronotum, elytra, legs, antennas |
33
+ | [`9-class`](./9-class) | 9 parts | background, head, eyes, mouthparts, pronotum, elytra, tail, legs, antennas, pin |
34
+
35
+ These models are the segmentation stage of [BeetleFlow](https://github.com/Imageomics/BeetleFlow): an integrative deep learning pipeline for beetle image processing (detection → cropping → segmentation).
36
+
37
+ ## Model Details
38
+
39
+ ### Model Description
40
+
41
+ Mask2Former with a Swin-Large backbone, fine-tuned for pixel-level semantic segmentation of morphological regions on pinned ground-beetle images. Models are initialized from [`facebook/mask2former-swin-large-ade-semantic`](https://huggingface.co/facebook/mask2former-swin-large-ade-semantic) and trained on manually annotated RGB masks derived from the [sentinel-beetles](https://huggingface.co/datasets/imageomics/sentinel-beetles) dataset.
42
+
43
+ - **Developed by:** Fangxun Liu
44
+ - **Model type:** Semantic segmentation (Mask2Former)
45
+ - **Language(s) (NLP):** N/A (computer vision model)
46
+ - **License:** [MIT](https://opensource.org/licenses/MIT) (model weights and code); training images are [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
47
+ - **Fine-tuned from model:** [`facebook/mask2former-swin-large-ade-semantic`](https://huggingface.co/facebook/mask2former-swin-large-ade-semantic)
48
+
49
+ ### Model Sources
50
+
51
+ - **Repository:** [https://github.com/Imageomics/BeetleFlow](https://github.com/Imageomics/BeetleFlow)
52
+ - **Paper:** BeetleFlow: An Integrative Deep Learning Pipeline for Beetle Image Processing — *NeurIPS 2025 Workshop for Imageomics: Discovering Biological Knowledge from Images Using AI*
53
+ - **Demo:** See [batch inference usage](#how-to-get-started-with-the-model) below
54
+
55
+ ## Uses
56
+
57
+ ### Direct Use
58
+
59
+ - Segment beetle body parts on cropped, single-specimen images produced by the BeetleFlow detection and cropping pipeline.
60
+ - Generate per-pixel part masks for downstream morphological measurements and ecological analyses.
61
+ - Run batch inference over folders of cropped beetle images.
62
+
63
+ ### Downstream Use
64
+
65
+ - Extract part-specific traits (e.g., elytra length, pronotum area) for biodiversity and phenomics research.
66
+ - Integrate segmentation outputs into the full BeetleFlow workflow alongside detection and metadata matching.
67
+
68
+ ### Out-of-Scope Use
69
+
70
+ - Detection or localization of beetles in full tray images (use the BeetleFlow detection stage instead).
71
+ - Segmentation of non-beetle insects without additional fine-tuning.
72
+ - Species identification or taxonomic classification.
73
+ - Images with substantially different imaging conditions (e.g., field photos, non-museum lighting) without retraining or validation.
74
+
75
+ ## Bias, Risks, and Limitations
76
+
77
+ - Models are trained on pinned ground-beetle specimens from NEON pitfall-trap imagery; performance may degrade on other beetle families, imaging setups, or specimen preparations.
78
+ - The 5-class and 9-class label schemes differ in granularity; choose the checkpoint that matches your annotation protocol.
79
+ - Small or occluded body parts (e.g., legs, antennas) may be harder to segment accurately.
80
+ - Segmentation quality depends on upstream cropping; poorly cropped inputs will reduce mask quality.
81
+
82
+ ### Recommendations
83
+
84
+ - Use the checkpoint (`5-class` or `9-class`) that matches your target annotation schema.
85
+ - Validate model outputs on a held-out sample from your target domain before deploying at scale.
86
+ - Cite both this model and the original [sentinel-beetles](https://huggingface.co/datasets/imageomics/sentinel-beetles) dataset when publishing results.
87
+
88
+ ## How to Get Started with the Model
89
+
90
+ ### Load from Hugging Face Hub
91
+
92
+ ```python
93
+ import torch
94
+ import cv2
95
+ import numpy as np
96
+ from transformers import Mask2FormerForUniversalSegmentation, Mask2FormerImageProcessor
97
+
98
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
99
+
100
+ # Choose "imageomics/BeetleFlow" subfolder: "5-class" or "9-class"
101
+ model_id = "imageomics/BeetleFlow"
102
+ subfolder = "5-class" # or "9-class"
103
+
104
+ processor = Mask2FormerImageProcessor.from_pretrained(model_id, subfolder=subfolder)
105
+ model = Mask2FormerForUniversalSegmentation.from_pretrained(model_id, subfolder=subfolder)
106
+ model.to(device).eval()
107
+
108
+ # Load image (BGR → RGB)
109
+ image_bgr = cv2.imread("beetle.jpg")
110
+ image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)
111
+
112
+ inputs = processor(images=image_rgb, return_tensors="pt").to(device)
113
+ with torch.no_grad():
114
+ outputs = model(**inputs)
115
+
116
+ pred_labels = processor.post_process_semantic_segmentation(
117
+ outputs, target_sizes=[image_rgb.shape[:2]]
118
+ )[0]
119
+ pred_map = pred_labels.cpu().numpy()
120
+ ```
121
+
122
+ ### Batch inference (BeetleFlow pipeline)
123
+
124
+ From the [BeetleFlow repository](https://github.com/Imageomics/BeetleFlow), after cloning and installing segmentation dependencies:
125
+
126
+ ```bash
127
+ python pipeline/3_segmentation/batch_inference.py \
128
+ --model ./checkpoints/5-class \
129
+ --input_dir /path/to/cropped/images/dir \
130
+ --output_dir /path/to/output/dir
131
+ ```
132
+
133
+ The script searches for `single_beetles` subfolders under `--input_dir` and writes predicted masks and overlay images to `--output_dir`.
134
+
135
+ ### Evaluate on a test set
136
+
137
+ ```bash
138
+ python pipeline/3_segmentation/test.py \
139
+ --model ./checkpoints/5-class \
140
+ --input /path/to/data \
141
+ --imgsz 512 512
142
+ ```
143
+
144
+ Expect `input/test_images/` and `input/test_masks/` with paired RGB mask images.
145
+
146
+ ## Training Details
147
+
148
+ ### Training Data
149
+
150
+ Models are trained on manually annotated beetle part segmentation data from pinned specimen images in the [Beetles as Sentinel Taxa dataset](https://huggingface.co/datasets/imageomics/sentinel-beetles). Dataset details:
151
+
152
+ **5-class**
153
+ - Parts: head, pronotum, elytra, legs, antennas (+ background)
154
+ - 340 labeled beetles with RGB masks
155
+ - Split: 272 training / 68 test images
156
+
157
+ **9-class**
158
+ - Parts: head, eyes, mouthparts, pronotum, elytra, tail, legs, antennas, pin (+ background)
159
+ - 330 labeled beetles with RGB masks
160
+ - Split: 264 training / 66 test images
161
+
162
+ Training uses `train_images/` and `valid_images/` (with corresponding `train_masks/` and `valid_masks/`) under the data root. See the [dataset README](https://github.com/Imageomics/BeetleFlow/tree/main/data) for mask color conventions.
163
+
164
+ ### Training Procedure
165
+
166
+ #### Preprocessing
167
+
168
+ - Resize to 512×512 (width × height).
169
+ - **Training augmentations** (Albumentations): horizontal flip (p=0.5), random brightness/contrast (p=0.25), rotation (±25°).
170
+ - **Validation augmentations:** resize and normalize only.
171
+ - **Normalization:** ADE20K mean `[123.675, 116.280, 103.530]` and std `[58.395, 57.120, 57.375]` (scaled to [0, 1]).
172
+ - RGB masks are converted to integer class labels using fixed color palettes defined in `config.py`.
173
+
174
+ #### Training Hyperparameters
175
+
176
+ - **Optimizer:** AdamW, learning rate `1e-4`
177
+ - **Batch size:** 10
178
+ - **Epochs:** 30
179
+ - **Image size:** 512 × 512
180
+ - **LR scheduler:** MultiStepLR (optional, `--scheduler`; milestones default `[50]`, gamma `0.1`)
181
+ - **Random seed:** 42
182
+ - **Training regime:** fp32
183
+ - **Checkpoint selection:** best validation loss (`model_loss`) and best validation mIoU (`model_iou`)
184
+
185
+ #### Speeds, Sizes, Times
186
+
187
+ Training was performed on a single NVIDIA A100 GPU (40 GB) with 8 DataLoader workers. Training time was ~0.5 GPU-hours per model.
188
+
189
+ ## Evaluation
190
+
191
+ Evaluation follows `pipeline/3_segmentation/test.py`: predictions are compared against held-out RGB masks at 512×512 resolution using the Hugging Face `evaluate` library.
192
+
193
+ ### Testing Data, Factors & Metrics
194
+
195
+ #### Testing Data
196
+
197
+ Held-out test images and RGB masks (`test_images/`, `test_masks/`) from the BeetleFlow segmentation dataset (68 images for 5-class; 66 images for 9-class). Masks use the same color-to-label mapping as training.
198
+
199
+ #### Factors
200
+
201
+ - Segmentation granularity: 5-class vs. 9-class label scheme
202
+ - Body part category (per-class IoU reported separately)
203
+
204
+ #### Metrics
205
+
206
+ - **Mean IoU (mIoU):** average Intersection-over-Union across all semantic classes; primary metric
207
+ - **Mean accuracy:** average per-class pixel accuracy across all semantic classes
208
+ - **Per-category IoU:** IoU for each semantic class (background, head, pronotum, etc.)
209
+
210
+ ### Results
211
+
212
+ Evaluated on the held-out test split using `test.py` at 512×512 resolution.
213
+
214
+ #### 5-class
215
+
216
+ | Metric | Value |
217
+ |--------|-------|
218
+ | Mean IoU | 0.8511 |
219
+ | Mean Accuracy | 0.9102 |
220
+
221
+ | Class | IoU |
222
+ |-------|-----|
223
+ | background | 0.9501 |
224
+ | head | 0.8364 |
225
+ | pronotum | 0.9185 |
226
+ | elytra | 0.9469 |
227
+ | legs | 0.7957 |
228
+ | antennas | 0.6593 |
229
+
230
+ #### 9-class
231
+
232
+ | Metric | Value |
233
+ |--------|-------|
234
+ | Mean IoU | 0.7738 |
235
+ | Mean Accuracy | 0.8663 |
236
+
237
+ | Class | IoU |
238
+ |-------|-----|
239
+ | background | 0.9616 |
240
+ | head | 0.8309 |
241
+ | eyes | 0.6843 |
242
+ | mouthparts | 0.6008 |
243
+ | pronotum | 0.9099 |
244
+ | elytra | 0.9397 |
245
+ | tail | 0.5349 |
246
+ | legs | 0.8539 |
247
+ | antennas | 0.7008 |
248
+ | pin | 0.7213 |
249
+
250
+ #### Summary
251
+
252
+ The 5-class model achieves higher overall mIoU (0.851) than the 9-class model (0.774), reflecting the greater difficulty of fine-grained part segmentation. Both models segment large, structurally distinct regions well (elytra, pronotum, background; IoU > 0.91 for 5-class). Smaller or thinner structures are more challenging: antennas (0.659) in the 5-class model, and mouthparts (0.601), tail (0.535), and eyes (0.684) in the 9-class model. The recommended checkpoint for deployment is `model_iou` (saved when validation mIoU is highest). Use `5-class` for coarser part groupings and `9-class` when fine-grained regions (eyes, mouthparts, tail, pin) are needed.
253
+
254
+ ## Model Examination
255
+
256
+ Not applicable for this release. Validation segmentation overlays are saved during training (`valid_preds/`) for qualitative inspection.
257
+
258
+ ## Environmental Impact
259
+
260
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://doi.org/10.48550/arXiv.1910.09700).
261
+
262
+ - **Hardware Type:** a single NVIDIA A100 GPU (40 GB)
263
+ - **Hours used:** ~0.5 GPU-hours per model
264
+ - **Cloud Provider:** Ohio Supercomputer Center (OSC)
265
+ - **Compute Region:** United States
266
+ - **Carbon Emitted:** 0.14 kg CO2 eq. (two models)
267
+
268
+ ## Technical Specifications
269
+
270
+ ### Model Architecture and Objective
271
+
272
+ - **Architecture:** [Mask2Former](https://huggingface.co/docs/transformers/model_doc/mask2former) for universal segmentation (`Mask2FormerForUniversalSegmentation`)
273
+ - **Backbone:** Swin Transformer Large (pretrained on ADE20K semantic segmentation)
274
+ - **Objective:** Mask-classification loss (cross-entropy + dice + mask losses) for semantic part segmentation
275
+ - **Output:** Per-pixel class map over beetle body parts
276
+ - **Input:** RGB images; processed via `Mask2FormerImageProcessor`
277
+
278
+ ### Compute Infrastructure
279
+
280
+ #### Hardware
281
+
282
+ - **Training:** NVIDIA GPU with CUDA support recommended
283
+ - **Inference:** GPU recommended; CPU inference supported but slower
284
+
285
+ #### Software
286
+
287
+ - Python 3.x
288
+ - PyTorch
289
+ - [Transformers](https://huggingface.co/docs/transformers) ≥ 4.40 (trained with 4.55.2)
290
+ - OpenCV, Albumentations, `evaluate`, tqdm
291
+ - See [`requirements_segmentation.txt`](https://github.com/Imageomics/BeetleFlow/blob/main/requirements_segmentation.txt) in the BeetleFlow repository
292
+
293
+ ## Citation
294
+
295
+ If you use these models, please cite BeetleFlow and the underlying dataset.
296
+
297
+ **BibTeX (software):**
298
+
299
+ ```bibtex
300
+ @software{beetleflow2026,
301
+ author = {Liu, Fangxun and Rayeed, S M and Stevens, Samuel and East, Alyson and Chiang, Cheng Hsuan and Lee, Colin and Yi, Daniel and Yang, Junke and Naik, Tejas and Wang, Ziyi and Kilrain, Connor and Buckwalter, Elijah H. and Hou, Jiacheng and Bueno, Saul Ibaven and Wang, Shuheng and Ma, Xinyue and Liu, Yifan and Tao, Zhiyuan and Zhang, Ziheng and Sokol, Eric and Belitz, Michael and Record, Sydne and Stewart, Charles V. and Chao, Wei-Lun},
302
+ title = {BeetleFlow: An Integrative Deep Learning Pipeline for Beetle Image Processing},
303
+ version = {1.0.0},
304
+ year = {2026},
305
+ url = {https://github.com/Imageomics/BeetleFlow},
306
+ doi = {10.5281/zenodo.21251293}
307
+ }
308
+ ```
309
+
310
+ **BibTeX (paper):**
311
+
312
+ ```bibtex
313
+ @inproceedings{liu2025beetleflow,
314
+ title = {BeetleFlow: An Integrative Deep Learning Pipeline for Beetle Image Processing},
315
+ author = {Liu, Fangxun and Rayeed, S M and Stevens, Samuel and East, Alyson and Chiang, Cheng Hsuan and Lee, Colin and Yi, Daniel and Yang, Junke and Naik, Tejas and Wang, Ziyi and Kilrain, Connor and Buckwalter, Elijah H. and Hou, Jiacheng and Bueno, Saul Ibaven and Wang, Shuheng and Ma, Xinyue and Liu, Yifan and Tao, Zhiyuan and Zhang, Ziheng and Sokol, Eric and Belitz, Michael and Record, Sydne and Stewart, Charles V. and Chao, Wei-Lun},
316
+ booktitle = {NeurIPS 2025 Workshop for Imageomics: Discovering Biological Knowledge from Images Using AI},
317
+ year = {2025}
318
+ }
319
+ ```
320
+
321
+ **Dataset:**
322
+
323
+ ```bibtex
324
+ @misc{East-beetles-2025,
325
+ author = {Alyson East and Michael Belitz and Leah Cotton and Jacqueline Dominguez and Isabelle Betancourt and S M Rayeed and Fangxun Liu and David Carlyn and Connor Kilrain and Jiaman Wu and Chandra Earl and Hilmar Lapp and Kayla I. Perry and Charles Stewart and Matthew J. Thompson and Elizabeth G. Campolongo and Wei-Lun Chao and Eric R. Sokol and Sydne Record},
326
+ title = {Beetles as Sentinel Taxa: Predicting drought conditions from {NEON} specimen imagery (Revision 5026be7)},
327
+ year = {2026},
328
+ url = {https://huggingface.co/datasets/imageomics/sentinel-beetles},
329
+ doi = {10.57967/hf/8716},
330
+ publisher = {Hugging Face}
331
+ }
332
+ ```
333
+
334
+ ## Acknowledgements
335
+
336
+ This work was supported by the [Imageomics Institute](https://imageomics.org), which is funded by the US National Science Foundation's Harnessing the Data Revolution (HDR) program under [Award #2118240](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2118240) (Imageomics: A New Frontier of Biological Information Powered by Knowledge-Guided Machine Learning). Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.
337
+
338
+ This work was in part conceived at [Funcapalooza](https://github.com/Imageomics/FuncaPalooza-2025).
339
+
340
+ ## Glossary
341
+
342
+ - **mIoU (mean Intersection over Union):** Average IoU across all semantic classes; primary evaluation metric.
343
+ - **5-class / 9-class:** Coarse vs. fine-grained beetle part label schemes (see table at top).
344
+ - **RGB mask:** Segmentation ground truth stored as a color image where each part has a fixed RGB value (see `config.py` / dataset README).
345
+
346
+ ## More Information
347
+
348
+ - Full pipeline documentation: [BeetleFlow GitHub](https://github.com/Imageomics/BeetleFlow)
349
+ - Segmentation training code: [`pipeline/3_segmentation`](https://github.com/Imageomics/BeetleFlow/tree/main/pipeline/3_segmentation)
350
+ - Segmentation dataset: [`data/`](https://github.com/Imageomics/BeetleFlow/tree/main/data)
351
+
352
+ ## Model Card Authors
353
+
354
+ Fangxun Liu
355
+
356
+ ## Model Card Contact
357
+
358
+ Open a [Discussion](https://huggingface.co/imageomics/BeetleFlow/discussions) on this model repository, or file an issue on [GitHub](https://github.com/Imageomics/BeetleFlow/issues).