Tetraopes Beetle Flower Detection Model
Model Description
This model detects whether photographs of Tetraopes beetles (Cerambycidae: Tetraopini) contain milkweed flowers or fruits (Asclepias spp.). It is designed to facilitate large-scale analysis of iNaturalist observations to identify beetle-plant associations for ecological and co-phylogenetic studies.
Model Architecture: Vision Transformer Large (ViT-L/14) with CLIP pre-training
Base Model: vit_large_patch14_clip_336.openai_ft_in12k_in1k
- Pre-trained by OpenAI on 400M image-text pairs (CLIP)
- Fine-tuned on ImageNet-12k and ImageNet-1k
- Input resolution: 336×336 pixels
Task: Binary image classification (flower present: yes/no)
Training Framework: FastAI with PyTorch backend
Last Updated: 2025-11-07
Intended Use
Primary Use Case
This model is designed specifically for:
- Identifying Tetraopes beetle observations on iNaturalist that show beetles on milkweed flowers/fruits
- Supporting ecological studies of beetle-plant associations
- Enabling large-scale analysis of host plant usage patterns
- Filtering iNaturalist photos for downstream analysis (e.g., host plant identification)
Intended Users
- Ecologists studying plant-insect interactions
- Entomologists researching Tetraopes biology
- Researchers conducting co-phylogenetic analyses
- Biodiversity scientists working with iNaturalist data
Out-of-Scope Use
This model is NOT intended for:
- General flower detection in arbitrary contexts
- Detection of beetles other than Tetraopes
- High-stakes decision making
- Any application where misclassification could cause harm
Limitations
- Taxonomic Scope: Trained specifically on Tetraopes beetles; may not generalize to other beetle genera
- Plant Scope: Optimized for milkweed (Asclepias) flowers/fruits; performance on other plants not evaluated
- Image Quality: Performance depends on image quality typical of iNaturalist photos
- Confidence Calibration: Based on validation analysis, only predictions with >80% confidence are recommended for use
- Small Training Set: Trained on only 121 manually labeled images; may not capture all variation
- Class Imbalance: Training data is approximately balanced, but real-world distribution is unknown
Training Data
Dataset Summary
- Source: Manually labeled photos from iNaturalist observations
- Total Images: 119
- With flowers (yes): 63
- Without flowers (no): 56
- Train/Val Split: 80/20 stratified by class (seed=42)
- Training: ~95 images
- Validation: ~24 images
- Image Source: iNaturalist community observations
Training Images
All training and validation images are from iNaturalist observations and remain under their original licenses. Links to all training/validation photos are provided below.
Notes:
- For observations with multiple photos, the first photo was used for training/validation.
- Original quality images (full resolution) were downloaded from iNaturalist and then resized to 336×336 pixels during training.
Training/Validation Images WITH Flowers (n=63)
| Observation ID | Photo ID | Taxon | Location | Date | Photo URL | Observation URL |
|---|---|---|---|---|---|---|
| 294117657 | 529366891 | Tetraopes annulatus | Milk River, AB T0K 1M0, Canada | 2025-06-29 | Photo | Observation |
| 28949859 | 45154147 | Tetraopes femoratus | Wayne, Utah, United States | 2019-07-12 | Photo | Observation |
| 30268404 | 47278404 | Tetraopes femoratus | Guadalupe County, NM, USA | 2019-07-26 | Photo | Observation |
| 306632555 | 552994059 | Tetraopes | Colorado, US | 2025-07-31 | Photo | Observation |
| 129351639 | 219808833 | Tetraopes femoratus | Las Vegas, NM, US | 2022-08-03 | Photo | Observation |
| 87493186 | 144223919 | Tetraopes quinquemaculatus | Illinois, US | 2021-07-17 | Photo | Observation |
| 310905379 | 561176590 | Tetraopes femoratus | Colfax, WA, US | 2025-08-30 | Photo | Observation |
| 169683166 | 294212111 | Tetraopes quinquemaculatus | Rome, WI, USA | 2023-06-23 | Photo | Observation |
| 290477669 | 522556815 | Tetraopes femoratus | FBP Native Plant Nursery, Eugene, OR 97405, United... | 2025-06-12 | Photo | Observation |
| 120970674 | 204659875 | Tetraopes discoideus | Fort Worth Botanic Garden, Fort Worth, TX, US | 2022-06-09 | Photo | Observation |
| 61981004 | 99245520 | Tetraopes tetrophthalmus | Sioux County, NE, USA | 2018-07-05 | Photo | Observation |
| 168435516 | 291907451 | Tetraopes tetrophthalmus | Dubuque, IA, USA | 2023-06-19 | Photo | Observation |
| 159767840 | 276055398 | Tetraopes texanus | Niederwald, TX 78640, USA | 2023-05-04 | Photo | Observation |
| 311178208 | 561712088 | Tetraopes | spook drive | 2025-09-02 | Photo | Observation |
| 244997587 | 437112237 | Tetraopes thermophilus | County Road 116, Cat Spring, TX, US | 2024-09-30 | Photo | Observation |
| 10235131 | 14150871 | Tetraopes discoideus | Payne County, OK, USA | 2011-05-21 | Photo | Observation |
| 258040781 | 462909370 | Tetraopes femoratus | Santa Cruz County, AZ, USA | 2019-08-07 | Photo | Observation |
| 84877387 | 139558762 | Tetraopes annulatus | Miller Rd, Los Lunas, NM, US | 2021-06-28 | Photo | Observation |
| 171115142 | 296888508 | Tetraopes annulatus | Minnesota, US | 2023-07-04 | Photo | Observation |
| 317292226 | 573326937 | Tetraopes tetrophthalmus | Westerville, OH, USA | 2023-07-07 | Photo | Observation |
| 311617229 | 562548352 | Tetraopes tetrophthalmus | Voss Pkwy, Middleton, WI, US | 2025-07-31 | Photo | Observation |
| 315730059 | 570377571 | Tetraopes tetrophthalmus | Markham, ON, Canada | 2025-06-27 | Photo | Observation |
| 9234594 | 12498299 | Tetraopes femoratus | Yécora, Son., Mexico | 2014-08-14 | Photo | Observation |
| 219086832 | 387753490 | Tetraopes melanurus | Orange County, US-FL, US | 2024-05-27 | Photo | Observation |
| 317648966 | 574011273 | Tetraopes | Division No. 1, CA-AB, CA | 2025-06-29 | Photo | Observation |
| 225241442 | 399325194 | Tetraopes quinquemaculatus | Lake Sherwood, WI 54457, USA | 2024-06-24 | Photo | Observation |
| 41561579 | 65937223 | Tetraopes thermophilus | Sandoval, TX, USA | 2020-04-06 | Photo | Observation |
| 124172311 | 210439879 | Tetraopes annulatus | 164th St S, Glyndon, MN, US | 2022-06-30 | Photo | Observation |
| 306388471 | 552528305 | Tetraopes femoratus | Vernon, BC V1T 9L7, Canada | 2025-08-14 | Photo | Observation |
| 294317775 | 529747990 | Tetraopes melanurus | Restricted Access: Camp Edwards, Sandwich, MA, US | 2025-06-30 | Photo | Observation |
| 173702174 | 301683822 | Tetraopes melanurus | Wright Rd, Federalsburg, MD, US | 2023-07-15 | Photo | Observation |
| 238889165 | 425371964 | Tetraopes femoratus | Garfield County, UT, USA | 2024-07-29 | Photo | Observation |
| 278530285 | 500121798 | Tetraopes melanurus | Florida, US | 2025-04-29 | Photo | Observation |
| 315720911 | 570373487 | Tetraopes tetrophthalmus | Swannanoa, NC 28778, USA | 2025-06-12 | Photo | Observation |
| 86641310 | 152048388 | Tetraopes femoratus | Brighton Blvd, Denver, CO, US | 2021-07-11 | Photo | Observation |
| 291618096 | 524692846 | Tetraopes melanurus | Manchester Road and Raefordvass Rd, Aberdeen, NC, ... | 2025-06-20 | Photo | Observation |
| 297367440 | 537877641 | Tetraopes annulatus | Denver Botanic Gardens, Denver, CO, US | 2025-07-12 | Photo | Observation |
| 293970457 | 529095525 | Tetraopes texanus | Bandera County, TX, USA | 2025-06-29 | Photo | Observation |
| 12981500 | 18877797 | Tetraopes quinquemaculatus | Vernon Parish, LA, USA | 2003-07-23 | Photo | Observation |
| 177126949 | 308025393 | Tetraopes annulatus | Coral Pink Sand Dunes State Park, Kanab, UT, US | 2023-07-09 | Photo | Observation |
| 316299132 | 571461156 | Tetraopes thermophilus | Clifton, TX 76634, USA | 2025-09-23 | Photo | Observation |
| 238251109 | 424136788 | Tetraopes femoratus | Garvin County, OK, USA | 2024-08-17 | Photo | Observation |
| 276769865 | 496993364 | Tetraopes texanus | Fort Worth Nature Center & Refuge | 2025-04-26 | Photo | Observation |
| 223337419 | 395713177 | Tetraopes tetrophthalmus | L St, Ord, NE, US | 2024-06-16 | Photo | Observation |
| 171268373 | 297172942 | Tetraopes femoratus | Uinta-Wasatch-Cache National Forest, Farmington, U... | 2023-07-04 | Photo | Observation |
| 296157175 | 533236106 | Tetraopes tetrophthalmus | Lincoln Township, KS 66901, USA | 2025-07-06 | Photo | Observation |
| 169426142 | 293730150 | Tetraopes femoratus | E Eighth Ave, Salt Lake City, UT, US | 2023-06-25 | Photo | Observation |
| 51041245 | 81074892 | Tetraopes quinquemaculatus | Michigan, US | 2020-06-26 | Photo | Observation |
| 53796540 | 85575805 | Tetraopes femoratus | Grand Staircase - Escalante National Monument, Bou... | 2020-07-17 | Photo | Observation |
| 126561450 | 214752198 | Tetraopes annulatus | Fort Sumner, NM 88119, USA | 2022-07-15 | Photo | Observation |
| 237993656 | 423636017 | Tetraopes discoideus | Brewster County, TX, USA | 2024-08-25 | Photo | Observation |
| 314082824 | 567259293 | Tetraopes tetrophthalmus | N Bell Ave, Chicago, IL, US | 2025-07-02 | Photo | Observation |
| 168746922 | 292486304 | Tetraopes texanus | Kerr County, TX, USA | 2020-06-29 | Photo | Observation |
| 233029688 | 414084830 | Tetraopes ineditus | autlan de navarro jalisco | 2024-07-31 | Photo | Observation |
| 102976398 | 172249054 | Tetraopes femoratus | Peñón Blanco, Dgo., México | 2020-07-18 | Photo | Observation |
| 124922174 | 211785052 | Tetraopes melanurus | Lake County, FL, USA | 2022-07-02 | Photo | Observation |
| 313702927 | 566526797 | Tetraopes tetrophthalmus | Nittany View Cir, State College, PA, US | 2025-08-15 | Photo | Observation |
| 50103733 | 79554627 | Tetraopes sublaevis | 29447, 29759 Old Julian Hwy, Ramona, CA 92065, USA | 2020-06-18 | Photo | Observation |
| 230635772 | 409538273 | Tetraopes batesi | 69916 Oax., México | 2024-07-20 | Photo | Observation |
| 112151787 | 189418289 | Tetraopes annulatus | Dawes County, NE, USA | 2015-07-19 | Photo | Observation |
| 48489985 | 1961612 | Tetraopes pilosus | Major, Oklahoma, United States | 2015-06-04 | Photo | Observation |
| 309623123 | 558738746 | Tetraopes texanus | Texas, US | 2023-06-06 | Photo | Observation |
| 311287532 | 561921793 | Tetraopes tetrophthalmus | Hodges Township, MN, USA | 2025-07-14 | Photo | Observation |
Training/Validation Images WITHOUT Flowers (n=56)
| Observation ID | Photo ID | Taxon | Location | Date | Photo URL | Observation URL |
|---|---|---|---|---|---|---|
| 310403056 | 560219856 | Tetraopes | Puebla, Pue., México | 2025-08-10 | Photo | Observation |
| 316781181 | 572363141 | Tetraopes femoratus | Longmont, CO, USA | 2025-09-26 | Photo | Observation |
| 94075801 | 156011833 | Tetraopes linsleyi | Belton vicinity, Bell County, Texas, USA | 2000-05-29 | Photo | Observation |
| 168833060 | 292645197 | Tetraopes femoratus | Stanislaus National Forest | 2023-06-21 | Photo | Observation |
| 307165291 | 554003735 | Tetraopes | 34670 Dgo., México | 2025-08-17 | Photo | Observation |
| 309480058 | 558469519 | Tetraopes discoideus | 34670 Dgo., México | 2025-08-26 | Photo | Observation |
| 312807182 | 564817043 | Tetraopes tetrophthalmus | Fort Washington, MD 20744, USA | 2025-09-06 | Photo | Observation |
| 317826616 | 574343081 | Tetraopes annulatus | Cheyenne County, CO, USA | 2025-06-17 | Photo | Observation |
| 178799501 | 311190794 | Tetraopes discoideus | Localización: 14.712488 -90.633943 | 2023-08-06 | Photo | Observation |
| 9364818 | 12714648 | Tetraopes annulatus | San Juan County, UT, USA | 2013-06-19 | Photo | Observation |
| 33991467 | 53446241 | Tetraopes varicornis | Tolcayuca, Hgo., México | 2019-06-27 | Photo | Observation |
| 302228753 | 544665415 | Tetraopes discoideus | Parker Rd, Ruidoso Downs, NM, US | 2025-07-29 | Photo | Observation |
| 314002462 | 567102203 | Tetraopes femoratus | Plains Conservation Center City of Aurora Open Spa... | 2025-09-14 | Photo | Observation |
| 312933708 | 565060621 | Tetraopes thermophilus | Valley Mills, TX 76689, USA | 2025-09-10 | Photo | Observation |
| 9935529 | 13635571 | Tetraopes discoideus | Sombrerete, Zacatecas, Mexico | 2012-07-24 | Photo | Observation |
| 310402358 | 560200381 | Tetraopes discoideus | Santa Cruz County, AZ, USA | 2025-08-20 | Photo | Observation |
| 309604310 | 558699556 | Tetraopes tetrophthalmus | Rehoboth, MA 02769, USA | 2025-05-25 | Photo | Observation |
| 309648179 | 558789581 | Tetraopes femoratus | Colorado, US | 2025-08-27 | Photo | Observation |
| 92643259 | 153427832 | Tetraopes | Santa Lucía Monteverde, Oax., México | 2021-08-20 | Photo | Observation |
| 313990753 | 567077940 | Tetraopes skillmani | Pima County, US-AZ, US | 2025-08-27 | Photo | Observation |
| 309342036 | 558195834 | Tetraopes | Downtown, Colorado Springs, CO, USA | 2025-08-25 | Photo | Observation |
| 14464908 | 21527043 | Tetraopes femoratus | Jerez de García Salinas, Zacatecas, Mexico | 2018-07-17 | Photo | Observation |
| 125330817 | 212523233 | Tetraopes quinquemaculatus | Jackson County, WI, USA | 2022-06-24 | Photo | Observation |
| 316660376 | 572148708 | Tetraopes femoratus | Canyonlands National Park, Monticello, UT, US | 2025-09-24 | Photo | Observation |
| 84122631 | 138228196 | Tetraopes batesi | Fraccionamiento Vista Real, Corregidora, Qro., Méx... | 2021-06-22 | Photo | Observation |
| 8010205 | 10600552 | Tetraopes femoratus | 73460, Tishomingo, OK, US | 2017-09-20 | Photo | Observation |
| 306599531 | 552916729 | Tetraopes tetrophthalmus | M36/Kelly SE fen (Putnum Twp) | 2025-08-15 | Photo | Observation |
| 307108230 | 553892043 | Tetraopes tetrophthalmus | Venetian Village, IL 60046, USA | 2025-08-17 | Photo | Observation |
| 299340155 | 539282063 | Tetraopes | Santa María del Oro, Nay., México | 2025-07-19 | Photo | Observation |
| 309862975 | 559199780 | Tetraopes tetrophthalmus | Spring St, Alnwick/Haldimand, ON, CA | 2022-08-16 | Photo | Observation |
| 304750565 | 549415703 | Tetraopes femoratus | W 73rd Ave, Denver, CO, US | 2025-08-08 | Photo | Observation |
| 304582396 | 549096605 | Tetraopes tetrophthalmus | University of Minnesota, Minneapolis, MN, US | 2025-08-07 | Photo | Observation |
| 320175989 | 578851620 | Tetraopes discoideus | N 25th St, McAllen, TX, US | 2025-10-04 | Photo | Observation |
| 316837863 | 572470432 | Tetraopes tetrophthalmus | Boone, NC, US | 2025-07-10 | Photo | Observation |
| 311563648 | 562443212 | Tetraopes annulatus | Sweetwater County, US-WY, US | 2025-09-04 | Photo | Observation |
| 14062739 | 20802869 | Tetraopes texanus | Austin, TX, USA | 2018-06-24 | Photo | Observation |
| 312382271 | 563719961 | Tetraopes discoideus | Adolfo López Mateos, Adolfo Lopez Mateos, Tixtla d... | 2025-08-31 | Photo | Observation |
| 304399717 | 548754239 | Tetraopes tetrophthalmus | Merrill, WI, US | 2025-08-06 | Photo | Observation |
| 178100161 | 309850840 | Tetraopes | Acámbaro, Gto., México | 2023-08-12 | Photo | Observation |
| 317311680 | 573363691 | Tetraopes tetrophthalmus | Lacewood Cres, Brampton, ON, CA | 2025-09-26 | Photo | Observation |
| 316641597 | 572110969 | Tetraopes tetrophthalmus | Wixom, MI 48393, USA | 2025-06-30 | Photo | Observation |
| 304300107 | 548551342 | Tetraopes femoratus | N Chaz Ct, Salt Lake City, UT, US | 2025-08-06 | Photo | Observation |
| 313129616 | 565435963 | Tetraopes tetrophthalmus | Cornell University, Ithaca, NY, US | 2025-09-11 | Photo | Observation |
| 136616795 | 233190550 | Tetraopes femoratus | Norman, OK 73072, USA | 2022-09-26 | Photo | Observation |
| 306838837 | 553381028 | Tetraopes femoratus | Foxfield, CO 80016, USA | 2025-08-16 | Photo | Observation |
| 312382275 | 563719999 | Tetraopes discoideus | Adolfo López Mateos, Adolfo Lopez Mateos, Tixtla d... | 2025-08-31 | Photo | Observation |
| 124280729 | 210636366 | Tetraopes discoideus | Santa Fe County, US-NM, US | 2022-07-01 | Photo | Observation |
| 320024424 | 578552754 | Tetraopes femoratus | Okanagan-Similkameen, BC, Canada | 2025-07-12 | Photo | Observation |
| 310275974 | 559969471 | Tetraopes annulatus | Cherry Hills Village, CO 80121, USA | 2025-08-30 | Photo | Observation |
| 320208571 | 578905449 | Tetraopes femoratus | Okanagan-Similkameen, BC, Canada | 2025-07-13 | Photo | Observation |
| 127797733 | 217001570 | Tetraopes umbonatus | Zumpango, Méx., México | 2022-07-23 | Photo | Observation |
| 304359205 | 548670157 | Tetraopes tetrophthalmus | Iles de Boucherville, QC, Canada | 2025-08-05 | Photo | Observation |
| 310671360 | 560730922 | Tetraopes | Evanston, IL, US | 2025-08-13 | Photo | Observation |
| 314627623 | 568278754 | Tetraopes tetrophthalmus | Tawes Dr, Elkton, MD, US | 2025-09-17 | Photo | Observation |
| 310951667 | 561267245 | Tetraopes femoratus | Garfield County, WA, USA | 2025-08-30 | Photo | Observation |
| 1557299 | 1927889 | Tetraopes umbonatus | Joquicingo, MX, MX | 2015-05-28 | Photo | Observation |
Training Procedure
Hyperparameters
Model: Vision Transformer Large (ViT-L/14)
- Architecture:
vit_large_patch14_clip_336.openai_ft_in12k_in1k - Patch size: 14×14
- Input resolution: 336×336 pixels
- Architecture:
Training Strategy: Transfer learning with fine-tuning
- Frozen epochs: 3 (train only classification head)
- Fine-tuning epochs: 3 (train all layers)
- Total epochs: 6
Optimization:
- Optimizer: AdamW (fastai default)
- Learning rate: Determined via lr_find() - valley of loss curve
- Learning rate schedule: One-cycle policy
- Batch size: 8 (per GPU)
- Weight decay: 0.01 (fastai default)
Hardware:
- 2× NVIDIA RTX A5000 GPUs (24GB each)
- DataParallel training for faster convergence
Data Augmentation:
- Geometric:
- Random rotation: ±10°
- Random zoom: 1.0-1.3×
- Random scale: 0.8-1.0×
- Random warp: ±0.2
- Horizontal flip: 50%
- Vertical flip: 50%
- Photometric:
- Random lighting: ±0.4
- Advanced:
- MixUp augmentation (α=0.4) - blends image pairs during training
- Normalization: ImageNet statistics (mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
- Geometric:
Class Balancing:
- Weighted sampling during training
- Sample weights calculated using normalized inverse frequency
- Formula: weight = total_samples / (num_classes × class_count)
Training Procedure Details
Data Preparation:
- Original quality images downloaded from iNaturalist (full resolution, typically ~2048px)
- Images resized to 336×336 using squish method (no cropping)
- Applied augmentation transforms
- Normalized with ImageNet statistics
Transfer Learning:
- Phase 1 (3 epochs): Froze all layers except classification head
- Phase 2 (3 epochs): Unfroze all layers for end-to-end fine-tuning
- Used MixUp augmentation throughout training
Validation:
- Evaluated on held-out 20% validation set
- No augmentation applied during validation
- Metrics: accuracy, error rate
Evaluation
Validation Results
- Validation Accuracy: 100% (25/25 images correct)
- Validation Error Rate: 0%
Confusion Matrix (Validation Set):
Predicted No Predicted Yes
Actual No 12 0
Actual Yes 0 13
Note: Perfect validation accuracy on a small dataset (25 images) suggests potential overfitting. Real-world performance is expected to be lower. Based on visual inspection of large-scale predictions, confidence thresholding (>80%) is recommended.
Large-Scale Prediction Results
The model was applied to 75,428 iNaturalist photos from 50,839 Tetraopes observations:
Predictions:
- Flower detected (yes): 31,419 (41.7%)
- No flower (no): 44,009 (58.3%)
- Mean confidence: 84.0%
High-Confidence Results (yes prediction with >80% confidence):
- Photos: 21,307 (28.2%)
- Unique observations: 15,916
- Recommendation: Only use predictions with >80% confidence based on manual validation
Performance by Taxon
| Taxon | Observations | Total Photos | High-Conf Photos | High-Conf Obs | % High-Conf |
|---|---|---|---|---|---|
| Tetraopes tetrophthalmus | 42,000.0 | 60,592.0 | 18,076 | 13,663.0 | 32.5% |
| Tetraopes femoratus | 4,581.0 | 7,753.0 | 1,672 | 1,148.0 | 25.1% |
| Tetraopes | 1,973.0 | 2,935.0 | 770 | 581.0 | 29.4% |
| Tetraopes melanurus | 708.0 | 1,059.0 | 118 | 94.0 | 13.3% |
| Tetraopes texanus | 485.0 | 912.0 | 157 | 106.0 | 21.9% |
| Tetraopes annulatus | 400.0 | 691.0 | 174 | 124.0 | 31.0% |
| Tetraopes basalis | 268.0 | 541.0 | 189 | 112.0 | 41.8% |
| Tetraopes discoideus | 153.0 | 269.0 | 41 | 31.0 | 20.3% |
| Tetraopes thermophilus | 56.0 | 162.0 | 45 | 20.0 | 35.7% |
| Tetraopes quinquemaculatus | 54.0 | 84.0 | 23 | 13.0 | 24.1% |
| Tetraopes batesi | 34.0 | 90.0 | 1 | 1.0 | 2.9% |
| Tetraopes pilosus | 30.0 | 59.0 | 22 | 12.0 | 40.0% |
| Tetraopes sublaevis | 23.0 | 73.0 | 15 | 7.0 | 30.4% |
| Tetraopes umbonatus | 15.0 | 38.0 | 0 | nan | nan% |
| Tetraopes mandibularis | 15.0 | 89.0 | 1 | 1.0 | 6.7% |
Showing top 15 of 25 taxa
Notes:
- "High-Conf Photos" = predictions with >80% confidence showing flowers
- "High-Conf Obs" = observations with at least one high-confidence flower photo
- Some taxa have limited observations; interpret results with caution
How to Use
Requirements
pip install fastai timm torch torchvision pandas
Loading the Model
from fastai.vision.all import *
import torch
# Download model from Hugging Face
model_path = 'tetraopes_flower_vit_large_patch14_clip_336.openai_ft_in12k_in1k.pth'
# Create a dummy DataLoader with the same structure as training
# (FastAI requires this to load the model)
from fastai.data.all import DataBlock, ColSplitter, ColReader
import pandas as pd
# Create minimal dataframe for loading
dummy_df = pd.DataFrame({'path': ['dummy.jpg'], 'label': ['yes'], 'is_valid': [False]})
dbl = DataBlock(
blocks=(ImageBlock, CategoryBlock),
get_x=ColReader('path'),
get_y=ColReader('label'),
splitter=ColSplitter('is_valid'),
item_tfms=Resize(336, method='squish'),
batch_tfms=Normalize.from_stats(*imagenet_stats)
)
dls = dbl.dataloaders(dummy_df, bs=1)
# Create learner and load weights
learn = vision_learner(
dls,
'vit_large_patch14_clip_336.openai_ft_in12k_in1k',
metrics=[error_rate, accuracy]
)
learn = learn.to_fp16() # Use mixed precision
learn.load(model_path.replace('.pth', '')) # Remove .pth extension
print("Model loaded successfully!")
Making Predictions
# Single image prediction
img_path = 'path/to/tetraopes_photo.jpg'
pred_class, pred_idx, probs = learn.predict(img_path)
print(f"Prediction: {pred_class}")
print(f"Confidence: {probs[pred_idx]:.2%}")
print(f"P(no flower): {probs[0]:.2%}")
print(f"P(with flower): {probs[1]:.2%}")
# Recommended: Filter by confidence threshold
confidence = probs[pred_idx]
if pred_class == 'yes' and confidence > 0.80:
print("High-confidence flower detection!")
else:
print("Low confidence or no flower detected")
Batch Predictions
from pathlib import Path
# Get all images
image_files = list(Path('images/').glob('*.jpg'))
# Create test DataLoader
test_dl = learn.dls.test_dl(image_files, bs=16)
# Get predictions
preds, _ = learn.get_preds(dl=test_dl)
# Process results
results = []
for idx, img_path in enumerate(image_files):
pred_idx = preds[idx].argmax().item()
pred_class = learn.dls.vocab[pred_idx]
confidence = float(preds[idx][pred_idx])
prob_no = float(preds[idx][0])
prob_yes = float(preds[idx][1])
results.append({
'image': img_path.name,
'prediction': pred_class,
'confidence': confidence,
'prob_no': prob_no,
'prob_yes': prob_yes,
'high_confidence_flower': pred_class == 'yes' and confidence > 0.80
})
results_df = pd.DataFrame(results)
print(results_df)
Model Card Authors
Bruno A. S. de Medeiros
Citation
If you use this model in your research, please cite:
@misc{tetraopes_flower_detector_2025,
author = {de Medeiros, Bruno A. S.},
title = {Tetraopes Beetle Flower Detection Model},
year = {2025},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/brunoasm/Tetraopes_on_flowers}},
note = {Vision Transformer model for detecting Tetraopes beetles on milkweed flowers}
}
Related Repository: The full code for training this model and conducting co-phylogenetic analyses is available at: https://github.com/de-Medeiros-insect-lab/Tetraopes_cophylogeny_analyses
Additional Information
Framework Versions
- Python: 3.13.9
- PyTorch: 2.6.0
- FastAI: 2.8.5
- timm: 1.0.21
Model Size
- Parameters: ~304M (ViT-Large)
- Model file size: ~3.4 GB
Computational Requirements
- Training: 2× NVIDIA RTX A5000 (24GB) - ~30 minutes total
- Inference:
- GPU recommended (any CUDA-capable GPU with 8GB+ VRAM)
- CPU inference possible but slow (~1-2 seconds per image)
- FP16 recommended for faster inference
License
This model is released under the Apache 2.0 license.
Important: The training images remain under their original iNaturalist licenses (typically CC-BY, CC-BY-NC, or CC0). Links to all training images with their original licenses are provided in the "Training Images" section above.
Contact
For questions or issues, please open an issue on the GitHub repository: https://github.com/de-Medeiros-insect-lab/Tetraopes_cophylogeny_analyses
Acknowledgments
- Training data from the iNaturalist community
- Pre-trained weights from OpenAI (CLIP) and timm library
- Training framework: FastAI