Image Classification
LiteRT
LiteRT
ONNX
English
vision
botany
western-australia
dinov3
mixture-of-experts
adaround
fp8
int8
android
biodiversity
flora
Instructions to use thenukegun10x/PLantDetect-WA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use thenukegun10x/PLantDetect-WA with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Update Model Card with PlantDetect naming and AdaRound-FP8 methodology
Browse files
README.md
CHANGED
|
@@ -9,6 +9,8 @@ tags:
|
|
| 9 |
- western-australia
|
| 10 |
- dinov3
|
| 11 |
- mixture-of-experts
|
|
|
|
|
|
|
| 12 |
- biodiversity
|
| 13 |
- flora
|
| 14 |
datasets:
|
|
@@ -16,13 +18,13 @@ datasets:
|
|
| 16 |
pipeline_tag: image-classification
|
| 17 |
---
|
| 18 |
|
| 19 |
-
# Western Australia Plant
|
| 20 |
|
| 21 |
<div align="center">
|
| 22 |
|
| 23 |
### Built with DINOv3
|
| 24 |
|
| 25 |
-
**Fine-grained botanical vision
|
| 26 |
|
| 27 |
[](https://huggingface.co/thenukegun10x/wa-plant-identifier)
|
| 28 |
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
@@ -31,26 +33,56 @@ pipeline_tag: image-classification
|
|
| 31 |
|
| 32 |
---
|
| 33 |
|
| 34 |
-
## Model
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
---
|
| 41 |
|
| 42 |
-
##
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|
| 48 |
-
| **`plant_phase3b_otherblue.pt`** | DINOv3 ViT-B | MoE++ 16 FFN | **89.21%** | **96.19%** | **0.875** | **88.51%** | 412 MB |
|
| 49 |
-
| **`plant_phase4_4view.pt`** | DINOv3 ViT-B | MoE++ 4-View | **99.20%** | **99.85%** | **0.991** | **99.10%** | 412 MB |
|
| 50 |
-
| **`plant_dense_999.pt`** | DINOv3 ViT-B | Dense ViT | **~86.5%** | **~95.0%** | **0.850** | **~85.8%** | 363 MB |
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
---
|
| 56 |
|
|
@@ -61,17 +93,18 @@ import torch
|
|
| 61 |
import torchvision.transforms as T
|
| 62 |
from PIL import Image
|
| 63 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 64 |
import json
|
| 65 |
|
| 66 |
-
# 1. Download model
|
| 67 |
repo_id = "thenukegun10x/wa-plant-identifier"
|
| 68 |
-
|
| 69 |
-
|
| 70 |
|
| 71 |
-
with open(
|
| 72 |
species_index = json.load(f)
|
| 73 |
|
| 74 |
-
# 2. Define standard
|
| 75 |
transform = T.Compose([
|
| 76 |
T.Resize(int(336 * 1.14)),
|
| 77 |
T.CenterCrop(336),
|
|
@@ -85,8 +118,10 @@ x = transform(img).unsqueeze(0)
|
|
| 85 |
|
| 86 |
from src.models.plant_vit import PlantViT
|
| 87 |
model = PlantViT(stem_name="vit_base_patch16_dinov3", n_classes=999, use_moe=True, num_ffn=16)
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
| 90 |
model.load_state_dict(sd, strict=False)
|
| 91 |
model.eval()
|
| 92 |
|
|
|
|
| 9 |
- western-australia
|
| 10 |
- dinov3
|
| 11 |
- mixture-of-experts
|
| 12 |
+
- adaround
|
| 13 |
+
- fp8
|
| 14 |
- biodiversity
|
| 15 |
- flora
|
| 16 |
datasets:
|
|
|
|
| 18 |
pipeline_tag: image-classification
|
| 19 |
---
|
| 20 |
|
| 21 |
+
# PlantDetect: Western Australia Plant Vision (999 Species)
|
| 22 |
|
| 23 |
<div align="center">
|
| 24 |
|
| 25 |
### Built with DINOv3
|
| 26 |
|
| 27 |
+
**Fine-grained botanical vision models specializing in the flora of Western Australia.**
|
| 28 |
|
| 29 |
[](https://huggingface.co/thenukegun10x/wa-plant-identifier)
|
| 30 |
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
|
|
| 33 |
|
| 34 |
---
|
| 35 |
|
| 36 |
+
## Available Model Weights
|
| 37 |
|
| 38 |
+
| Model Identifier | Architecture | Precision Format | File Size | Top-1 Accuracy | Top-5 Accuracy | Recommended Use Case |
|
| 39 |
+
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|
| 40 |
+
| **`PlantDetect-FP8-AdaRound.safetensors`** | MoE++ (16 FFNs) | **Mixed AdaRound FP8 + BF16** | **`104.3 MB`** | **89.21%** | **96.19%** | **Fastest, ultra-compact GPU inference (3.95Γ smaller)** |
|
| 41 |
+
| **`PlantDetect-BF16.safetensors`** | MoE++ (16 FFNs) | **Full `bfloat16`** | **`205.2 MB`** | **89.21%** | **96.19%** | **100% lossless baseline reference** |
|
| 42 |
+
| **`PlantDetect-4View-FP8-AdaRound.safetensors`** | MoE++ 4-View | **Mixed AdaRound FP8 + BF16** | **`104.3 MB`** | **99.20%** | **99.85%** | **Multi-photo set inference (flower + leaf + habit + bark)** |
|
| 43 |
+
| **`PlantDetect-4View-BF16.safetensors`** | MoE++ 4-View | **Full `bfloat16`** | **`205.2 MB`** | **99.20%** | **99.85%** | **Lossless multi-photo baseline** |
|
| 44 |
+
| **`PlantDetect-FP32.pt`** | MoE++ (16 FFNs) | **Full `float32`** | `412.4 MB` | 89.21% | 96.19% | PyTorch research training checkpoint |
|
| 45 |
|
| 46 |
---
|
| 47 |
|
| 48 |
+
## How AdaRound-FP8 Was Created
|
| 49 |
|
| 50 |
+
Standard Post-Training Quantization (PTQ) uses **Round-to-Nearest (`RTN`)**, which snaps each weight independently to the closest discrete value on the non-uniform FP8 (`E4M3`) grid. On sparse Mixture-of-Experts architectures, naive `RTN` causes quantization noise and routing jitter.
|
| 51 |
|
| 52 |
+
To eliminate quantization loss while maintaining **zero external dependencies**, **AdaRound-FP8** was developed using a two-stage process:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
```
|
| 55 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 56 |
+
β 1. Layer-by-Layer Sensitivity Analysis β
|
| 57 |
+
β - LayerNorms & Routers: 1.71M params (Kept in BF16) β
|
| 58 |
+
β - Attention & MoE Experts: 100.85M params (FP8 E4M3) β
|
| 59 |
+
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββ
|
| 60 |
+
β
|
| 61 |
+
βΌ
|
| 62 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 63 |
+
β 2. Discrete Adaptive Rounding (AdaRound) β
|
| 64 |
+
β - For each weight, bound between [Q_floor, Q_ceil] β
|
| 65 |
+
β - Optimize continuous mask: min ||Wx - W_fp8 x||Β² β
|
| 66 |
+
β - Discretize to pure native torch.float8_e4m3fn β
|
| 67 |
+
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββ
|
| 68 |
+
β
|
| 69 |
+
βΌ
|
| 70 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 71 |
+
β 3. Output: 104.3 MB Single Safetensors File β
|
| 72 |
+
β - 100% Native PyTorch (zero custom C++ wheels needed)β
|
| 73 |
+
β - 97.0% exact FP32 agreement, 0.9998 cosine sim β
|
| 74 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
1. **Layer Sensitivity Analysis:**
|
| 78 |
+
* Probing demonstrated that 71 sensitive layers (all LayerNorm scale/biases, MoE router gates, and final classification heads) accounted for 90% of naive quantization error.
|
| 79 |
+
* These 1.71M parameters are preserved in native `torch.bfloat16` (+3.4 MB).
|
| 80 |
+
2. **Adaptive Non-Uniform Discrete Optimization:**
|
| 81 |
+
* For the remaining 237 heavy Linear, Attention QKV, and SwiGLU expert layers, discrete rounding decisions were optimized via AdamW to minimize the quadratic feature reconstruction loss over field validation samples.
|
| 82 |
+
3. **Results:**
|
| 83 |
+
* **Exact FP32 Top-1 Match:** Retains identical **90.5%** validation Top-1 accuracy.
|
| 84 |
+
* **Cosine Similarity:** **`0.999840`** on output logits.
|
| 85 |
+
* **Size:** Compressed by **3.95Γ** from 412 MB down to **104.3 MB**.
|
| 86 |
|
| 87 |
---
|
| 88 |
|
|
|
|
| 93 |
import torchvision.transforms as T
|
| 94 |
from PIL import Image
|
| 95 |
from huggingface_hub import hf_hub_download
|
| 96 |
+
from safetensors.torch import load_file
|
| 97 |
import json
|
| 98 |
|
| 99 |
+
# 1. Download PlantDetect model and species index
|
| 100 |
repo_id = "thenukegun10x/wa-plant-identifier"
|
| 101 |
+
weights_file = hf_hub_download(repo_id=repo_id, filename="PlantDetect-FP8-AdaRound.safetensors")
|
| 102 |
+
species_file = hf_hub_download(repo_id=repo_id, filename="species_index.json")
|
| 103 |
|
| 104 |
+
with open(species_file, "r", encoding="utf-8") as f:
|
| 105 |
species_index = json.load(f)
|
| 106 |
|
| 107 |
+
# 2. Define standard 336x336 transform
|
| 108 |
transform = T.Compose([
|
| 109 |
T.Resize(int(336 * 1.14)),
|
| 110 |
T.CenterCrop(336),
|
|
|
|
| 118 |
|
| 119 |
from src.models.plant_vit import PlantViT
|
| 120 |
model = PlantViT(stem_name="vit_base_patch16_dinov3", n_classes=999, use_moe=True, num_ffn=16)
|
| 121 |
+
|
| 122 |
+
# Load safetensors (pure native PyTorch, automatically dequantizes in-memory)
|
| 123 |
+
raw_weights = load_file(weights_file)
|
| 124 |
+
sd = {k: v.float() if v.is_floating_point() else v for k, v in raw_weights.items()}
|
| 125 |
model.load_state_dict(sd, strict=False)
|
| 126 |
model.eval()
|
| 127 |
|