Deploy Forager's Field Station
Browse files- .gitattributes +5 -34
- .gitignore +10 -0
- README.md +59 -6
- app.py +312 -4
- examples/chanterelle.jpg +3 -0
- examples/lions_mane.jpg +3 -0
- examples/poison_hemlock.jpg +3 -0
- examples/wild_blueberry.jpg +3 -0
- examples/yarrow.jpg +3 -0
- models/berry_expert_classes.json +13 -0
- models/domain_router_v2_classes.json +6 -0
- models/energy_thresholds.json +26 -0
- models/highvalue_expert_classes.json +13 -0
- models/medicinals_expert_classes.json +23 -0
- pipeline/__init__.py +1 -0
- pipeline/convergence.py +110 -0
- pipeline/infer.py +150 -0
- pipeline/metadata.py +80 -0
- requirements.txt +4 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,6 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
examples/chanterelle.jpg filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
examples/lions_mane.jpg filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
examples/poison_hemlock.jpg filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
examples/wild_blueberry.jpg filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
examples/yarrow.jpg filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.gitignore
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
.venv/
|
| 4 |
+
.gradio/
|
| 5 |
+
.DS_Store
|
| 6 |
+
flagged/
|
| 7 |
+
# ONNX weights are large and live in forager_ml (source of truth); the HF Space
|
| 8 |
+
# gets them via deploy.py uploading from disk. Re-sync locally with
|
| 9 |
+
# scripts/sync_from_forager_ml.sh. Not tracked in this dev git repo.
|
| 10 |
+
models/*.onnx
|
README.md
CHANGED
|
@@ -1,15 +1,68 @@
|
|
| 1 |
---
|
| 2 |
-
title: Forager Field
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.16.0
|
| 8 |
-
python_version: '3.13'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
license: apache-2.0
|
| 12 |
short_description: Pocket-sized intelligence for identifying edible wild foods
|
| 13 |
---
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Forager's Field Station
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.16.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
short_description: Pocket-sized intelligence for identifying edible wild foods
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Forager's Field Station
|
| 15 |
+
|
| 16 |
+
Photograph a wild plant or mushroom and the model identifies it β **or refuses
|
| 17 |
+
when it isn't sure.** A domain router plus three `tf_efficientnet_lite2`
|
| 18 |
+
classifiers (~9M params each), ~0.04B parameters total. The same stack runs
|
| 19 |
+
offline on a Hailo 8L NPU in a handheld field device; this Space is its CPU twin.
|
| 20 |
+
|
| 21 |
+
Built for the **Build Small Hackathon** β Backyard AI track. The honest fit:
|
| 22 |
+
a forager in the woods has no signal, so a small on-device model isn't a
|
| 23 |
+
compromise, it's the only thing that works.
|
| 24 |
+
|
| 25 |
+
## How it works
|
| 26 |
+
|
| 27 |
+
```
|
| 28 |
+
photo ββΊ domain router (berry / mushroom / plant / other)
|
| 29 |
+
β conf < 0.74 or "other" ββΊ ABSTAIN
|
| 30 |
+
βΌ
|
| 31 |
+
ONE expert owns each domain (no cross-expert voting):
|
| 32 |
+
berry ββΊ berry_expert mushroom ββΊ highvalue_expert
|
| 33 |
+
plant ββΊ medicinals_expert
|
| 34 |
+
β below confidence gate ββΊ ABSTAIN
|
| 35 |
+
βΌ
|
| 36 |
+
SAFE / CAUTION / DEADLY + scientific name, lookalike, key difference
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
Single-expert routing is a safety choice: an off-domain expert never gets to
|
| 40 |
+
misclassify an input it doesn't own (e.g. the mushroom expert never sees a
|
| 41 |
+
plant, so it can't call a poison hemlock "ramps"). The deadly plants live in the
|
| 42 |
+
medicinals expert, which scored 0% toxic-as-edible on held-out validation.
|
| 43 |
+
|
| 44 |
+
The system is built to **refuse by default.** Across real-world test photos it
|
| 45 |
+
abstained rather than guess on the cases it couldn't handle, and never labelled
|
| 46 |
+
a deadly specimen as edible.
|
| 47 |
+
|
| 48 |
+
## Models
|
| 49 |
+
|
| 50 |
+
| Model | Domain | Classes |
|
| 51 |
+
|---|---|---|
|
| 52 |
+
| `domain_router_v2` | berry / mushroom / plant / other | 4 |
|
| 53 |
+
| `berry_expert` | wild berries + toxic lookalikes | 11 |
|
| 54 |
+
| `highvalue_expert` | chanterelles, morels, lion's mane, ginseng⦠| 11 |
|
| 55 |
+
| `medicinals_expert` | wild medicinal plants + toxic lookalikes | 21 |
|
| 56 |
+
|
| 57 |
+
Trained on iNaturalist research-grade observations. Apache-2.0.
|
| 58 |
+
|
| 59 |
+
## Safety notice
|
| 60 |
+
|
| 61 |
+
**Identification aid only β never an authority.** Wild plant and mushroom
|
| 62 |
+
identification carries fatal risk. No output should be acted on β including any
|
| 63 |
+
consumption decision β without independent verification by a qualified expert.
|
| 64 |
+
Amatoxin poisoning (Amanita, Galerina, Conocybe) is lethal with no reliable
|
| 65 |
+
field antidote. The maintainers accept no liability for decisions made from
|
| 66 |
+
model output.
|
| 67 |
+
|
| 68 |
+
β [HomesteaderLabs](https://homesteaderlabs.com)
|
app.py
CHANGED
|
@@ -1,7 +1,315 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
demo.launch()
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
app.py β Forager's Field Station (Gradio Space).
|
| 3 |
+
|
| 4 |
+
Photograph a wild plant or mushroom; the model identifies it β or refuses when
|
| 5 |
+
it isn't sure. A domain router + three tf_efficientnet_lite2 experts (~9M params
|
| 6 |
+
each), the same stack that runs offline on a Hailo NPU in a handheld field
|
| 7 |
+
device. This Space is styled as that device's copper-and-bronze e-ink readout.
|
| 8 |
+
|
| 9 |
+
Built for the Build Small Hackathon. Safety-first: this is an identification
|
| 10 |
+
aid, never an authority β SAFE is never presented as permission to eat.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import os
|
| 14 |
+
import time
|
| 15 |
+
|
| 16 |
import gradio as gr
|
| 17 |
|
| 18 |
+
from pipeline.convergence import build_result
|
| 19 |
+
from pipeline.infer import Pipeline
|
| 20 |
+
|
| 21 |
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
| 22 |
+
EXAMPLES_DIR = os.path.join(HERE, "examples")
|
| 23 |
+
PIPE = Pipeline()
|
| 24 |
+
|
| 25 |
+
# Safety tier -> (badge label, accent, glyph). These greens/ambers/reds are the
|
| 26 |
+
# SAFETY channel and are kept distinct from the copper/bronze brand chrome so the
|
| 27 |
+
# tier reads instantly. SAFE is never a green light: the label says "verify" and
|
| 28 |
+
# _card always appends a confirm-with-an-expert line.
|
| 29 |
+
INK_SAFE, INK_CAUTION, INK_DEADLY, INK_UNK = "#2f6b2b", "#87671c", "#8c1d14", "#57544c"
|
| 30 |
+
TIER = {
|
| 31 |
+
"SAFE": ("EDIBLE Β· VERIFY", INK_SAFE, "β"),
|
| 32 |
+
"CAUTION": ("CAUTION", INK_CAUTION, "β²"),
|
| 33 |
+
"DEADLY": ("DEADLY Β· DO NOT EAT", INK_DEADLY, "β"),
|
| 34 |
+
"UNKNOWN": ("UNKNOWN", INK_UNK, "?"),
|
| 35 |
+
}
|
| 36 |
+
DOMAIN_LABEL = {"berry": "Berry", "mushroom": "Mushroom", "plant": "Plant", "other": "Other"}
|
| 37 |
+
|
| 38 |
+
DARWIN = ("It is not the strongest of the species that survive, nor the most "
|
| 39 |
+
"intelligent, but the one most responsive to change.")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def _pretty(species: str) -> str:
|
| 43 |
+
return species.replace("_toxic", "").replace("_deadly", "").replace("_", " ").title()
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _idle(msg: str = "FIELD STATION READY") -> str:
|
| 47 |
+
return (
|
| 48 |
+
f"<div class='rdt-idle'><div class='rdt-idle-glyph'>β</div>"
|
| 49 |
+
f"<div class='rdt-idle-msg'>{msg}</div>"
|
| 50 |
+
f"<div class='rdt-idle-sub'>upload, capture, or pick a sample below to scan</div></div>"
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _loading() -> str:
|
| 55 |
+
"""Vine-growing animation shown while inference runs (no quote β too brief to read)."""
|
| 56 |
+
return """
|
| 57 |
+
<div class='loading'>
|
| 58 |
+
<svg class='vine' viewBox='0 0 120 220' xmlns='http://www.w3.org/2000/svg'>
|
| 59 |
+
<path class='stem' d='M60 212 C 40 190, 80 174, 60 152 C 42 132, 82 114, 60 94
|
| 60 |
+
C 42 76, 80 58, 60 36 C 50 24, 64 16, 60 8'/>
|
| 61 |
+
<g transform='translate(44,150) rotate(-38)'><ellipse class='leaf' style='animation-delay:.35s' rx='10' ry='4.3'/></g>
|
| 62 |
+
<g transform='translate(78,114) rotate(34)'><ellipse class='leaf' style='animation-delay:.55s' rx='10' ry='4.3'/></g>
|
| 63 |
+
<g transform='translate(42,76) rotate(-34)'><ellipse class='leaf' style='animation-delay:.75s' rx='9' ry='4'/></g>
|
| 64 |
+
<g transform='translate(78,46) rotate(36)'><ellipse class='leaf' style='animation-delay:.95s' rx='8' ry='3.6'/></g>
|
| 65 |
+
<circle class='bud' cx='60' cy='8' r='4'/>
|
| 66 |
+
</svg>
|
| 67 |
+
<div class='scan-label'>ANALYZING SPECIMEN</div>
|
| 68 |
+
</div>
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def _card(r) -> str:
|
| 73 |
+
label, color, glyph = TIER.get(r.safety, TIER["UNKNOWN"])
|
| 74 |
+
|
| 75 |
+
if r.abstained:
|
| 76 |
+
color, label, glyph = INK_UNK, "UNKNOWN", "?"
|
| 77 |
+
title, sub = "UNKNOWN", "not confident enough β refusing by default"
|
| 78 |
+
rows = [
|
| 79 |
+
f"<div class='rdt-row'>{r.key_diff}</div>",
|
| 80 |
+
f"<div class='rdt-meta'>ROUTER Β· {DOMAIN_LABEL.get(r.domain, r.domain)} "
|
| 81 |
+
f"@ {r.confidence*100:.0f}%</div>",
|
| 82 |
+
]
|
| 83 |
+
else:
|
| 84 |
+
title, sub = _pretty(r.species), "most likely β not confirmed"
|
| 85 |
+
rows = [
|
| 86 |
+
f"<div class='rdt-row'><i>{r.scientific_name}</i></div>",
|
| 87 |
+
f"<div class='rdt-row'>confidence <b>{r.confidence*100:.1f}%</b></div>",
|
| 88 |
+
]
|
| 89 |
+
if r.lookalike and r.lookalike != "N/A":
|
| 90 |
+
rows.append(
|
| 91 |
+
f"<div class='rdt-look'>β deadly look-alike: <b>{r.lookalike}</b><br>"
|
| 92 |
+
f"<span class='rdt-diff'>{r.key_diff}</span></div>"
|
| 93 |
+
)
|
| 94 |
+
elif r.key_diff:
|
| 95 |
+
rows.append(f"<div class='rdt-row rdt-diff'>{r.key_diff}</div>")
|
| 96 |
+
prefix = "DO NOT EAT. " if r.safety == "DEADLY" else ""
|
| 97 |
+
rows.append(
|
| 98 |
+
f"<div class='rdt-confirm'>β {prefix}Confirm with an expert before eating β "
|
| 99 |
+
f"identification aid, not an authority.</div>"
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
body = "".join(rows)
|
| 103 |
+
return (
|
| 104 |
+
f"<div class='rdt' style='--accent:{color}'>"
|
| 105 |
+
f" <div class='rdt-top'><span class='rdt-tag'>β FIELD READOUT</span>"
|
| 106 |
+
f" <span class='rdt-badge'>{glyph} {label}</span></div>"
|
| 107 |
+
f" <div class='rdt-title'>{title}</div>"
|
| 108 |
+
f" <div class='rdt-sub'>{sub}</div>"
|
| 109 |
+
f" <div class='rdt-body'>{body}</div>"
|
| 110 |
+
f"</div>"
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def identify(image):
|
| 115 |
+
"""Generator: show the vine animation, then the readout."""
|
| 116 |
+
if image is None:
|
| 117 |
+
yield _idle()
|
| 118 |
+
return
|
| 119 |
+
t0 = time.time()
|
| 120 |
+
yield _loading()
|
| 121 |
+
result = build_result(PIPE.identify(image))
|
| 122 |
+
elapsed = time.time() - t0
|
| 123 |
+
if elapsed < 1.6: # let the vine finish drawing
|
| 124 |
+
time.sleep(1.6 - elapsed)
|
| 125 |
+
yield _card(result)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
EXPERTS_PANEL = """
|
| 129 |
+
<div id='experts'>
|
| 130 |
+
<div class='ex-head'>β EXPERTS ONLINE β 4 MODELS</div>
|
| 131 |
+
<div class='ex-grid'>
|
| 132 |
+
<details class='ex'><summary>DOMAIN ROUTER</summary>
|
| 133 |
+
<div class='ex-body'>routes to berry Β· mushroom Β· plant Β· other β or abstains when unsure</div></details>
|
| 134 |
+
<details class='ex'><summary>BERRY EXPERT</summary>
|
| 135 |
+
<div class='ex-body'>11 species Β· wild berries + toxic look-alikes</div></details>
|
| 136 |
+
<details class='ex'><summary>HIGH-VALUE EXPERT</summary>
|
| 137 |
+
<div class='ex-body'>11 species Β· chanterelle Β· morel Β· lion's mane Β· ginseng</div></details>
|
| 138 |
+
<details class='ex'><summary>MEDICINALS EXPERT</summary>
|
| 139 |
+
<div class='ex-body'>21 species Β· wild medicinals + deadly look-alikes</div></details>
|
| 140 |
+
</div>
|
| 141 |
+
</div>
|
| 142 |
+
"""
|
| 143 |
+
|
| 144 |
+
QUOTE_BAR = (
|
| 145 |
+
f"<div id='quotebar'><span class='q'>“{DARWIN}”</span>"
|
| 146 |
+
f"<span class='q-by'>β Charles Darwin</span></div>"
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
SAFETY_NOTICE = (
|
| 150 |
+
"**Identification aid only β never an authority.** Wild plant and mushroom "
|
| 151 |
+
"ID carries fatal risk. Do not consume anything based on this output without "
|
| 152 |
+
"independent verification by a qualified expert. The system refuses by default "
|
| 153 |
+
"when unsure. Amatoxin poisoning is lethal with no reliable field antidote."
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
CSS = """
|
| 157 |
+
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600;700&family=Caveat:wght@600;700&display=swap');
|
| 158 |
+
|
| 159 |
+
:root {
|
| 160 |
+
--paper:#e6e4dd; --panel:#E3DBCA; --ink:#1b1a17; --ink2:#57544c; /* box panels */
|
| 161 |
+
--bronze:#7a3f1a; --copper:#b87333; /* HomesteaderLabs chrome */
|
| 162 |
+
}
|
| 163 |
+
.gradio-container, .gradio-container * {
|
| 164 |
+
font-family:'IBM Plex Mono','Courier New',monospace !important;
|
| 165 |
+
}
|
| 166 |
+
.gradio-container {
|
| 167 |
+
background:var(--paper) !important; color:var(--ink) !important;
|
| 168 |
+
background-image:repeating-linear-gradient(0deg,
|
| 169 |
+
rgba(27,26,23,.035) 0 1px, transparent 1px 3px) !important; /* e-ink scanlines */
|
| 170 |
+
max-width:940px !important; margin:0 auto !important;
|
| 171 |
+
}
|
| 172 |
+
footer { display:none !important; }
|
| 173 |
+
|
| 174 |
+
/* strip Gradio's default block chrome + row gutters so every panel shares one
|
| 175 |
+
width and the columns line up flush with the masthead/experts boxes */
|
| 176 |
+
.gradio-container .block { background:transparent !important; border:none !important;
|
| 177 |
+
box-shadow:none !important; padding:0 !important; box-sizing:border-box !important; }
|
| 178 |
+
.gradio-container .row { margin:0 !important; }
|
| 179 |
+
.gradio-container .html-container { padding:0 !important; }
|
| 180 |
+
.eink-input .image-container, .eink-input .image-frame, .eink-input .wrap,
|
| 181 |
+
.eink-input .upload-container, .eink-input .empty, .eink-input [data-testid='image'] {
|
| 182 |
+
background:var(--panel) !important; }
|
| 183 |
+
/* Gradio's themed labels/upload text were light (built for dark blocks) and turn
|
| 184 |
+
invisible on the eggshell panels β force them to ink. Leaves the readout card's
|
| 185 |
+
tier colors, the bronze SCAN button, and the DISPLAY tab untouched. */
|
| 186 |
+
.eink-input, .eink-input label, .eink-input .label-wrap, .eink-input span,
|
| 187 |
+
.eink-input p, .eink-input button:not(.eink-scan) { color:var(--ink) !important; }
|
| 188 |
+
.eink-screen { color:var(--ink); }
|
| 189 |
+
|
| 190 |
+
/* ββ masthead βββββββββββββββββββββββββββββββββββββββββββββββββ */
|
| 191 |
+
#masthead { border:3px solid var(--bronze); background:var(--panel);
|
| 192 |
+
padding:14px 18px; margin-bottom:12px; box-shadow:7px 7px 0 rgba(122,63,26,.55); }
|
| 193 |
+
#masthead .brand { font-size:.7rem; letter-spacing:.34em; color:var(--bronze); font-weight:700; }
|
| 194 |
+
#masthead .title { font-size:1.7rem; font-weight:700; letter-spacing:.04em; line-height:1.05;
|
| 195 |
+
margin-top:2px; color:var(--copper); }
|
| 196 |
+
#masthead .tag { font-family:'Caveat',cursive !important; font-size:1.4rem; color:var(--bronze);
|
| 197 |
+
margin-top:0; transform:rotate(-1.2deg); display:inline-block; }
|
| 198 |
+
#masthead .strip { margin-top:10px; padding-top:8px; border-top:2px dashed var(--bronze);
|
| 199 |
+
font-size:.66rem; letter-spacing:.16em; color:var(--ink2); display:flex; justify-content:space-between; }
|
| 200 |
+
|
| 201 |
+
/* ββ experts panel (collapsible) ββββββββββββββββββββββββββββββ */
|
| 202 |
+
#experts { border:2px solid var(--bronze); background:var(--panel); padding:10px 14px; margin-bottom:12px;
|
| 203 |
+
box-shadow:5px 5px 0 rgba(122,63,26,.4); }
|
| 204 |
+
#experts .ex-head { font-size:.68rem; letter-spacing:.22em; color:var(--copper); font-weight:700; margin-bottom:8px; }
|
| 205 |
+
#experts .ex-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(230px,1fr)); gap:6px 18px; }
|
| 206 |
+
#experts details.ex { border-left:4px solid var(--copper); padding:2px 0 2px 9px; }
|
| 207 |
+
#experts summary { cursor:pointer; list-style:none; font-size:.76rem; letter-spacing:.08em;
|
| 208 |
+
color:var(--ink); font-weight:700; display:flex; align-items:center; gap:7px; }
|
| 209 |
+
#experts summary::-webkit-details-marker { display:none; }
|
| 210 |
+
#experts summary::before { content:'βΈ'; color:var(--copper); font-size:.7rem; }
|
| 211 |
+
#experts details[open] summary::before { content:'βΎ'; }
|
| 212 |
+
#experts .ex-body { font-size:.7rem; color:var(--ink2); padding:4px 0 2px 14px; line-height:1.4; }
|
| 213 |
+
|
| 214 |
+
/* ββ controls βββββββββββββββββββββββββββββββββββββββββββββββββ */
|
| 215 |
+
.eink-input, .eink-screen { border:3px solid var(--bronze) !important; background:var(--panel) !important;
|
| 216 |
+
box-shadow:7px 7px 0 rgba(122,63,26,.55) !important; border-radius:0 !important; }
|
| 217 |
+
.eink-input { padding:6px !important; }
|
| 218 |
+
button.eink-scan { background:var(--bronze) !important; color:var(--paper) !important;
|
| 219 |
+
border:3px solid var(--bronze) !important; border-radius:0 !important; font-weight:700 !important;
|
| 220 |
+
letter-spacing:.18em !important; box-shadow:5px 5px 0 rgba(122,63,26,.4) !important; }
|
| 221 |
+
button.eink-scan:hover { background:var(--copper) !important; border-color:var(--copper) !important; }
|
| 222 |
+
|
| 223 |
+
.eink-screen { padding:0 !important; position:relative; min-height:330px; }
|
| 224 |
+
.eink-screen::before { content:'β DISPLAY'; position:absolute; top:-3px; left:-3px;
|
| 225 |
+
background:var(--bronze); color:var(--paper); font-size:.6rem; letter-spacing:.2em;
|
| 226 |
+
padding:3px 8px; z-index:2; }
|
| 227 |
+
|
| 228 |
+
/* ββ readout card βββββββββββββββββββββββββββββββββββββββββββββ */
|
| 229 |
+
.rdt { background:var(--panel); border-left:10px solid var(--accent);
|
| 230 |
+
padding:34px 18px 18px; min-height:330px; }
|
| 231 |
+
.rdt-top { display:flex; justify-content:space-between; align-items:center;
|
| 232 |
+
border-bottom:2px solid var(--ink); padding-bottom:7px; margin-bottom:12px;
|
| 233 |
+
font-size:.7rem; letter-spacing:.14em; }
|
| 234 |
+
.rdt-tag { color:var(--ink2); font-weight:600; }
|
| 235 |
+
.rdt-badge { color:var(--accent); font-weight:700; }
|
| 236 |
+
.rdt-title { font-size:1.55rem; font-weight:700; line-height:1.15; color:var(--ink); }
|
| 237 |
+
.rdt-sub { font-size:.7rem; letter-spacing:.1em; color:var(--ink2); margin-top:3px; text-transform:uppercase; }
|
| 238 |
+
.rdt-body { margin-top:14px; }
|
| 239 |
+
.rdt-row { line-height:1.6; font-size:.95rem; }
|
| 240 |
+
.rdt-row i { color:var(--ink2); }
|
| 241 |
+
.rdt-meta { margin-top:8px; font-size:.72rem; letter-spacing:.1em; color:var(--ink2); }
|
| 242 |
+
.rdt-diff { color:var(--ink2); font-size:.86rem; }
|
| 243 |
+
.rdt-look { margin-top:12px; padding:10px 12px; border:2px solid #8c1d14;
|
| 244 |
+
background:rgba(140,29,20,.06); color:#8c1d14; font-size:.9rem; line-height:1.5; }
|
| 245 |
+
.rdt-confirm { display:block; margin-top:14px; padding-top:10px; border-top:2px dashed var(--ink);
|
| 246 |
+
color:var(--accent); font-weight:700; font-size:.9rem; line-height:1.5; }
|
| 247 |
+
|
| 248 |
+
/* idle / standby */
|
| 249 |
+
.rdt-idle { min-height:330px; display:flex; flex-direction:column; align-items:center;
|
| 250 |
+
justify-content:center; text-align:center; color:var(--ink2); padding:24px; }
|
| 251 |
+
.rdt-idle-glyph { font-size:3rem; opacity:.5; color:var(--bronze); }
|
| 252 |
+
.rdt-idle-msg { margin-top:10px; font-size:1rem; font-weight:700; letter-spacing:.2em; }
|
| 253 |
+
.rdt-idle-sub { margin-top:6px; font-size:.74rem; letter-spacing:.08em; opacity:.8; }
|
| 254 |
+
|
| 255 |
+
/* ββ loading: vine only βββββββββββββββββββββββββββββββββββββββ */
|
| 256 |
+
.loading { min-height:330px; display:flex; flex-direction:column; align-items:center; justify-content:center; }
|
| 257 |
+
.vine { width:92px; height:170px; }
|
| 258 |
+
.vine .stem { fill:none; stroke:var(--bronze); stroke-width:3.6; stroke-linecap:round;
|
| 259 |
+
stroke-dasharray:320; stroke-dashoffset:320; animation:grow 1.35s ease-out forwards; }
|
| 260 |
+
.vine .leaf { fill:var(--copper); opacity:0; transform-box:fill-box; transform-origin:center;
|
| 261 |
+
animation:leafin .5s ease-out forwards; }
|
| 262 |
+
.vine .bud { fill:var(--copper); opacity:0; transform-box:fill-box; transform-origin:center;
|
| 263 |
+
animation:leafin .5s ease-out 1.1s forwards; }
|
| 264 |
+
@keyframes grow { to { stroke-dashoffset:0; } }
|
| 265 |
+
@keyframes leafin { from { opacity:0; transform:scale(0); } to { opacity:1; transform:scale(1); } }
|
| 266 |
+
@keyframes fadein { from { opacity:0; } to { opacity:1; } }
|
| 267 |
+
.scan-label { margin-top:12px; font-size:.72rem; letter-spacing:.24em; color:var(--copper);
|
| 268 |
+
font-weight:700; opacity:0; animation:fadein .6s ease-out .2s forwards; }
|
| 269 |
+
|
| 270 |
+
/* ββ Darwin quote bar (static, readable) ββββββββββββββββββββββ */
|
| 271 |
+
#quotebar { text-align:center; margin-top:16px; padding:14px 12px 4px; border-top:2px dashed var(--bronze); }
|
| 272 |
+
#quotebar .q { font-family:'Caveat',cursive !important; font-size:1.5rem; color:var(--bronze);
|
| 273 |
+
line-height:1.3; display:block; max-width:620px; margin:0 auto; }
|
| 274 |
+
#quotebar .q-by { font-size:.64rem; letter-spacing:.2em; color:var(--ink2); }
|
| 275 |
+
|
| 276 |
+
/* safety footer */
|
| 277 |
+
#notice { border:2px dashed var(--bronze) !important; background:transparent !important;
|
| 278 |
+
padding:10px 14px; margin-top:10px; font-size:.74rem !important; line-height:1.55 !important;
|
| 279 |
+
color:var(--ink2) !important; }
|
| 280 |
+
#notice * { font-size:.74rem !important; color:var(--ink2) !important; }
|
| 281 |
+
"""
|
| 282 |
+
|
| 283 |
+
with gr.Blocks(title="Forager's Field Station") as demo:
|
| 284 |
+
gr.HTML(
|
| 285 |
+
"<div id='masthead'>"
|
| 286 |
+
" <div class='brand'>HOMESTEADER LABS</div>"
|
| 287 |
+
" <div class='title'>FORAGER'S FIELD STATION</div>"
|
| 288 |
+
" <div class='tag'>Backyard AI Β· real-world stakes</div>"
|
| 289 |
+
" <div class='strip'><span>ROUTER + 3 EXPERTS Β· ~0.04B PARAMS</span>"
|
| 290 |
+
" <span>REFUSES BY DEFAULT</span></div>"
|
| 291 |
+
"</div>"
|
| 292 |
+
)
|
| 293 |
+
gr.HTML(EXPERTS_PANEL)
|
| 294 |
+
with gr.Row():
|
| 295 |
+
with gr.Column(scale=1):
|
| 296 |
+
img = gr.Image(type="pil", label="SPECIMEN", sources=["upload", "webcam"],
|
| 297 |
+
elem_classes="eink-input", height=300)
|
| 298 |
+
btn = gr.Button("βΈ SCAN SPECIMEN", variant="primary", elem_classes="eink-scan")
|
| 299 |
+
if os.path.isdir(EXAMPLES_DIR):
|
| 300 |
+
samples = [[os.path.join(EXAMPLES_DIR, f)] for f in (
|
| 301 |
+
"chanterelle.jpg", "lions_mane.jpg", "wild_blueberry.jpg",
|
| 302 |
+
"yarrow.jpg", "poison_hemlock.jpg") if os.path.exists(os.path.join(EXAMPLES_DIR, f))]
|
| 303 |
+
if samples:
|
| 304 |
+
gr.Examples(examples=samples, inputs=img,
|
| 305 |
+
label="No specimen handy? Try a sample:")
|
| 306 |
+
with gr.Column(scale=1, elem_classes="eink-screen"):
|
| 307 |
+
out = gr.HTML(_idle())
|
| 308 |
+
gr.HTML(QUOTE_BAR)
|
| 309 |
+
gr.Markdown(SAFETY_NOTICE, elem_id="notice")
|
| 310 |
+
|
| 311 |
+
btn.click(identify, inputs=img, outputs=out)
|
| 312 |
+
img.change(identify, inputs=img, outputs=out)
|
| 313 |
|
| 314 |
+
if __name__ == "__main__":
|
| 315 |
+
demo.launch(theme=gr.themes.Monochrome(), css=CSS)
|
examples/chanterelle.jpg
ADDED
|
Git LFS Details
|
examples/lions_mane.jpg
ADDED
|
Git LFS Details
|
examples/poison_hemlock.jpg
ADDED
|
Git LFS Details
|
examples/wild_blueberry.jpg
ADDED
|
Git LFS Details
|
examples/yarrow.jpg
ADDED
|
Git LFS Details
|
models/berry_expert_classes.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
"bittersweet_nightshade_toxic",
|
| 3 |
+
"blackberry_common",
|
| 4 |
+
"blueberry_highbush",
|
| 5 |
+
"blueberry_wild",
|
| 6 |
+
"canada_moonseed_deadly",
|
| 7 |
+
"elderberry_american",
|
| 8 |
+
"poison_ivy",
|
| 9 |
+
"pokeweed_toxic",
|
| 10 |
+
"staghorn_sumac",
|
| 11 |
+
"virginia_creeper_toxic",
|
| 12 |
+
"wild_grape_riverbank"
|
| 13 |
+
]
|
models/domain_router_v2_classes.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
"berry",
|
| 3 |
+
"mushroom",
|
| 4 |
+
"other",
|
| 5 |
+
"plant"
|
| 6 |
+
]
|
models/energy_thresholds.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"berry_expert": {
|
| 3 |
+
"p99": -2.6033,
|
| 4 |
+
"p95": -2.7896,
|
| 5 |
+
"p90": -2.8722,
|
| 6 |
+
"p85": -2.9346
|
| 7 |
+
},
|
| 8 |
+
"highvalue_expert": {
|
| 9 |
+
"p99": -2.8313,
|
| 10 |
+
"p95": -3.4466,
|
| 11 |
+
"p90": -3.5391,
|
| 12 |
+
"p85": -3.5952
|
| 13 |
+
},
|
| 14 |
+
"psychedelics_expert": {
|
| 15 |
+
"p99": -2.7753,
|
| 16 |
+
"p95": -2.9717,
|
| 17 |
+
"p90": -3.0823,
|
| 18 |
+
"p85": -3.1227
|
| 19 |
+
},
|
| 20 |
+
"medicinals_expert": {
|
| 21 |
+
"p99": -2.7018,
|
| 22 |
+
"p95": -3.1205,
|
| 23 |
+
"p90": -3.3293,
|
| 24 |
+
"p85": -3.414
|
| 25 |
+
}
|
| 26 |
+
}
|
models/highvalue_expert_classes.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
"chaga_medicinal",
|
| 3 |
+
"chanterelles_edible",
|
| 4 |
+
"chicken_of_the_woods",
|
| 5 |
+
"ginseng_american",
|
| 6 |
+
"high_value_toxics",
|
| 7 |
+
"lions_mane",
|
| 8 |
+
"morels_edible",
|
| 9 |
+
"ostrich_fern_fiddlehead",
|
| 10 |
+
"ramps_wild_leek",
|
| 11 |
+
"reishi_northeast",
|
| 12 |
+
"saffron_crocus"
|
| 13 |
+
]
|
models/medicinals_expert_classes.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
"boneset",
|
| 3 |
+
"burdock",
|
| 4 |
+
"catnip",
|
| 5 |
+
"coltsfoot",
|
| 6 |
+
"echinacea",
|
| 7 |
+
"foxglove_toxic",
|
| 8 |
+
"goldenrod",
|
| 9 |
+
"motherwort",
|
| 10 |
+
"mullein",
|
| 11 |
+
"plantain_broadleaf",
|
| 12 |
+
"poison_hemlock_deadly",
|
| 13 |
+
"red_clover",
|
| 14 |
+
"st_johns_wort",
|
| 15 |
+
"stinging_nettle",
|
| 16 |
+
"valerian",
|
| 17 |
+
"water_hemlock_deadly",
|
| 18 |
+
"white_snakeroot_toxic",
|
| 19 |
+
"wild_bergamot",
|
| 20 |
+
"wild_carrot",
|
| 21 |
+
"wood_nettle",
|
| 22 |
+
"yarrow"
|
| 23 |
+
]
|
pipeline/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
"""Field Station inference pipeline (ONNX / CPU)."""
|
pipeline/convergence.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
convergence.py β Turn an infer.Pipeline result into a single ForagerResult.
|
| 3 |
+
|
| 4 |
+
Ported from forager_ml with the Hailo coupling removed: instead of a
|
| 5 |
+
RawPrediction it takes the plain dict returned by infer.Pipeline.identify().
|
| 6 |
+
The safety-first philosophy is unchanged β abstain by default, flag DEADLY
|
| 7 |
+
prominently, never present a below-threshold guess as an identification.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from dataclasses import dataclass
|
| 11 |
+
|
| 12 |
+
from .metadata import SPECIES_METADATA, UNKNOWN_META
|
| 13 |
+
|
| 14 |
+
LOW_CONFIDENCE_THRESHOLD = 0.50 # below this -> flagged low_confidence
|
| 15 |
+
EXPERT_CONFIDENCE_THRESHOLD = 0.60 # a committed (non-deadly) ID must clear this.
|
| 16 |
+
# These experts are accurate but underconfident
|
| 17 |
+
# on SAFE classes (avg ~0.5β0.6); 0.60 balances
|
| 18 |
+
# decisiveness (75% safe-correct) against residual
|
| 19 |
+
# deadly-as-safe. The UX never treats SAFE as a
|
| 20 |
+
# green light β see app.py β so the gate is a
|
| 21 |
+
# usability dial, not the safety mechanism.
|
| 22 |
+
DEADLY_VETO_FLOOR = 0.40 # a DEADLY call at/above this overrides any
|
| 23 |
+
# higher-confidence SAFE/CAUTION call from
|
| 24 |
+
# another expert (safety-biased arbitration)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@dataclass
|
| 28 |
+
class ForagerResult:
|
| 29 |
+
domain: str
|
| 30 |
+
species: str # class key, or "unknown"
|
| 31 |
+
scientific_name: str
|
| 32 |
+
confidence: float
|
| 33 |
+
safety: str # SAFE | CAUTION | DEADLY | UNKNOWN
|
| 34 |
+
lookalike: str
|
| 35 |
+
key_diff: str
|
| 36 |
+
low_confidence: bool
|
| 37 |
+
expert_model: str
|
| 38 |
+
abstained: bool
|
| 39 |
+
reason: str # why we abstained (or "" when committed)
|
| 40 |
+
|
| 41 |
+
@property
|
| 42 |
+
def is_deadly(self) -> bool:
|
| 43 |
+
return self.safety == "DEADLY" and not self.low_confidence
|
| 44 |
+
|
| 45 |
+
@property
|
| 46 |
+
def is_unknown(self) -> bool:
|
| 47 |
+
return self.species == "unknown"
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
_ABSTAIN_REASON = {
|
| 51 |
+
"uncertain_domain": "Couldn't confidently place this in a known domain.",
|
| 52 |
+
"off_domain": "This doesn't look like anything in the trained domains.",
|
| 53 |
+
"low_confidence": "Leaning toward an answer, but not confident enough to commit.",
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _abstain(domain: str, reason: str, conf: float = 0.0, expert: str = "none") -> ForagerResult:
|
| 58 |
+
return ForagerResult(
|
| 59 |
+
domain=domain, species="unknown", scientific_name=UNKNOWN_META["scientific"],
|
| 60 |
+
confidence=conf, safety="UNKNOWN", lookalike=UNKNOWN_META["lookalike"],
|
| 61 |
+
key_diff=_ABSTAIN_REASON.get(reason, UNKNOWN_META["key_diff"]),
|
| 62 |
+
low_confidence=True, expert_model=expert, abstained=True, reason=reason,
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def _commit(domain: str, c: dict) -> ForagerResult:
|
| 67 |
+
species = c["species"]
|
| 68 |
+
meta = SPECIES_METADATA.get(species, UNKNOWN_META)
|
| 69 |
+
conf = float(c["confidence"])
|
| 70 |
+
return ForagerResult(
|
| 71 |
+
domain=domain, species=species, scientific_name=meta["scientific"], confidence=conf,
|
| 72 |
+
safety=meta["safety"], lookalike=meta["lookalike"], key_diff=meta["key_diff"],
|
| 73 |
+
low_confidence=conf < LOW_CONFIDENCE_THRESHOLD, expert_model=c["expert"],
|
| 74 |
+
abstained=False, reason="",
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def build_result(call: dict) -> ForagerResult:
|
| 79 |
+
"""
|
| 80 |
+
`call` is the dict from infer.Pipeline.identify().
|
| 81 |
+
|
| 82 |
+
Safety-biased arbitration across the domain's experts:
|
| 83 |
+
1. If ANY expert flags a DEADLY species at >= DEADLY_VETO_FLOOR, surface
|
| 84 |
+
that β a deadly vote vetoes a more-confident SAFE/CAUTION call from an
|
| 85 |
+
off-domain expert (prevents e.g. hemlock -> "ramps" because highvalue
|
| 86 |
+
is more confident than medicinals).
|
| 87 |
+
2. Otherwise take the highest-confidence call, abstaining if it can't
|
| 88 |
+
clear EXPERT_CONFIDENCE_THRESHOLD.
|
| 89 |
+
"""
|
| 90 |
+
domain = call.get("domain", "unknown")
|
| 91 |
+
|
| 92 |
+
if call.get("abstain") and "calls" not in call:
|
| 93 |
+
return _abstain(domain, call.get("reason", "low_confidence"),
|
| 94 |
+
float(call.get("confidence", 0.0)), call.get("expert", "none"))
|
| 95 |
+
|
| 96 |
+
calls = call.get("calls", [])
|
| 97 |
+
if not calls:
|
| 98 |
+
return _abstain(domain, "low_confidence")
|
| 99 |
+
|
| 100 |
+
for c in calls:
|
| 101 |
+
c["safety"] = SPECIES_METADATA.get(c["species"], UNKNOWN_META)["safety"]
|
| 102 |
+
|
| 103 |
+
deadly = [c for c in calls if c["safety"] == "DEADLY" and c["confidence"] >= DEADLY_VETO_FLOOR]
|
| 104 |
+
if deadly:
|
| 105 |
+
return _commit(domain, max(deadly, key=lambda c: c["confidence"]))
|
| 106 |
+
|
| 107 |
+
best = max(calls, key=lambda c: c["confidence"])
|
| 108 |
+
if best["confidence"] < EXPERT_CONFIDENCE_THRESHOLD:
|
| 109 |
+
return _abstain(domain, "low_confidence", best["confidence"], best["expert"])
|
| 110 |
+
return _commit(domain, best)
|
pipeline/infer.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
infer.py β Two-stage ONNX inference for the Field Station Space.
|
| 3 |
+
|
| 4 |
+
Mirrors the on-device forager_ml pipeline (domain router -> expert routing ->
|
| 5 |
+
abstention) but runs on CPU via onnxruntime instead of the Hailo NPU.
|
| 6 |
+
|
| 7 |
+
Stage 1: domain router classifies the frame into berry / mushroom / plant / other.
|
| 8 |
+
Stage 2: route to the matching expert(s); for multi-expert domains run both and
|
| 9 |
+
keep the higher-confidence call. Abstain (UNKNOWN) when the router is
|
| 10 |
+
unsure, the domain is "other", or the winning expert is below threshold.
|
| 11 |
+
|
| 12 |
+
Preprocessing note: these ONNX files are the bare timm tf_efficientnet_lite2
|
| 13 |
+
models (no normalization baked in), so inputs are ImageNet-normalized
|
| 14 |
+
[1, 3, 224, 224] β NOT the [0,255] NHWC the HEF expects.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
import json
|
| 18 |
+
import os
|
| 19 |
+
|
| 20 |
+
import numpy as np
|
| 21 |
+
import onnxruntime as ort
|
| 22 |
+
from PIL import Image
|
| 23 |
+
|
| 24 |
+
MODELS_DIR = os.path.join(os.path.dirname(__file__), "..", "models")
|
| 25 |
+
|
| 26 |
+
ROUTER = "domain_router_v2"
|
| 27 |
+
# The psychedelics/mycologist expert is intentionally NOT shipped in this public
|
| 28 |
+
# Space: it is never routed to (mushroom -> highvalue only) and a psilocybin
|
| 29 |
+
# identifier invites policy scrutiny for zero functional gain. It still lives in
|
| 30 |
+
# forager_ml and can ship as its own model repo.
|
| 31 |
+
EXPERTS = ["berry_expert", "highvalue_expert", "medicinals_expert"]
|
| 32 |
+
|
| 33 |
+
# Router domain -> the ONE expert that owns it. Single-expert routing (no
|
| 34 |
+
# cross-expert voting): an off-domain expert never gets to misclassify an input
|
| 35 |
+
# it doesn't own β e.g. highvalue never sees a plant, so it can't call a hemlock
|
| 36 |
+
# "ramps". The deadly plants live in medicinals (0% toxic-as-edible FAR).
|
| 37 |
+
# "other" is intentionally absent => abstain. The mycologist/psychedelics expert
|
| 38 |
+
# is held out of the live path (weak on real photos; benched).
|
| 39 |
+
DOMAIN_EXPERTS: dict[str, str] = {
|
| 40 |
+
"berry": "berry_expert",
|
| 41 |
+
"mushroom": "highvalue_expert",
|
| 42 |
+
"plant": "medicinals_expert",
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
# Gates (match the on-device convergence thresholds).
|
| 46 |
+
ROUTER_CONFIDENCE_THRESHOLD = 0.74
|
| 47 |
+
EXPERT_CONFIDENCE_THRESHOLD = 0.75
|
| 48 |
+
|
| 49 |
+
# Energy-OOD vote suppression: an expert's vote is dropped when its input energy
|
| 50 |
+
# exceeds the in-domain threshold (i.e. the frame is out-of-domain for that
|
| 51 |
+
# expert). This stops an off-domain expert from out-voting the correct one β
|
| 52 |
+
# e.g. highvalue calling a hemlock "ramps". Thresholds are fp32 in-domain
|
| 53 |
+
# percentiles in models/energy_thresholds.json (correct -logsumexp energy).
|
| 54 |
+
# With single-expert routing there are no competing votes to suppress, and
|
| 55 |
+
# val-calibrated thresholds over-fire on real photos. Off by default; the
|
| 56 |
+
# router's "other" class + the confidence gate carry OOD.
|
| 57 |
+
ENABLE_ENERGY_SUPPRESSION = False
|
| 58 |
+
ENERGY_SUPPRESS_PERCENTILE = "p90"
|
| 59 |
+
|
| 60 |
+
_IMAGENET_MEAN = np.array([0.485, 0.456, 0.406], dtype=np.float32)
|
| 61 |
+
_IMAGENET_STD = np.array([0.229, 0.224, 0.225], dtype=np.float32)
|
| 62 |
+
_RESIZE_SHORT = int(224 * 1.14) # 255, matches the training/val transform
|
| 63 |
+
_CROP = 224
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def preprocess(img: Image.Image) -> np.ndarray:
|
| 67 |
+
"""PIL image -> ImageNet-normalized float32 NCHW [1, 3, 224, 224]."""
|
| 68 |
+
img = img.convert("RGB")
|
| 69 |
+
w, h = img.size
|
| 70 |
+
if w <= h:
|
| 71 |
+
nw, nh = _RESIZE_SHORT, round(_RESIZE_SHORT * h / w)
|
| 72 |
+
else:
|
| 73 |
+
nw, nh = round(_RESIZE_SHORT * w / h), _RESIZE_SHORT
|
| 74 |
+
img = img.resize((nw, nh), Image.BILINEAR)
|
| 75 |
+
left = (nw - _CROP) // 2
|
| 76 |
+
top = (nh - _CROP) // 2
|
| 77 |
+
img = img.crop((left, top, left + _CROP, top + _CROP))
|
| 78 |
+
|
| 79 |
+
x = np.asarray(img, dtype=np.float32) / 255.0 # HWC, [0,1]
|
| 80 |
+
x = (x - _IMAGENET_MEAN) / _IMAGENET_STD # ImageNet normalize
|
| 81 |
+
x = np.transpose(x, (2, 0, 1))[None] # 1, C, H, W
|
| 82 |
+
return np.ascontiguousarray(x, dtype=np.float32)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def _softmax(logits: np.ndarray) -> np.ndarray:
|
| 86 |
+
z = logits - logits.max()
|
| 87 |
+
e = np.exp(z)
|
| 88 |
+
return e / e.sum()
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def _energy(logits: np.ndarray) -> float:
|
| 92 |
+
"""Correct energy E(x) = -logsumexp(logits). Higher = more out-of-domain."""
|
| 93 |
+
m = logits.max()
|
| 94 |
+
return -float(m + np.log(np.exp(logits - m).sum()))
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class Pipeline:
|
| 98 |
+
"""Loads all ONNX sessions once and runs the two-stage identification."""
|
| 99 |
+
|
| 100 |
+
def __init__(self, models_dir: str = MODELS_DIR):
|
| 101 |
+
self._sessions: dict[str, ort.InferenceSession] = {}
|
| 102 |
+
self._classes: dict[str, list[str]] = {}
|
| 103 |
+
for name in [ROUTER, *EXPERTS]:
|
| 104 |
+
self._sessions[name] = ort.InferenceSession(
|
| 105 |
+
os.path.join(models_dir, f"{name}_logits.onnx"),
|
| 106 |
+
providers=["CPUExecutionProvider"],
|
| 107 |
+
)
|
| 108 |
+
with open(os.path.join(models_dir, f"{name}_classes.json")) as f:
|
| 109 |
+
self._classes[name] = json.load(f)
|
| 110 |
+
|
| 111 |
+
self._energy_thr: dict[str, float] = {}
|
| 112 |
+
thr_path = os.path.join(models_dir, "energy_thresholds.json")
|
| 113 |
+
if ENABLE_ENERGY_SUPPRESSION and os.path.exists(thr_path):
|
| 114 |
+
with open(thr_path) as f:
|
| 115 |
+
table = json.load(f)
|
| 116 |
+
self._energy_thr = {n: v[ENERGY_SUPPRESS_PERCENTILE] for n, v in table.items()}
|
| 117 |
+
|
| 118 |
+
def _run(self, name: str, x: np.ndarray) -> tuple[str, float, float]:
|
| 119 |
+
"""Returns (top_class, top_confidence, energy)."""
|
| 120 |
+
logits = self._sessions[name].run(None, {"input": x})[0][0]
|
| 121 |
+
probs = _softmax(logits)
|
| 122 |
+
idx = int(probs.argmax())
|
| 123 |
+
return self._classes[name][idx], float(probs[idx]), _energy(logits)
|
| 124 |
+
|
| 125 |
+
def identify(self, img: Image.Image) -> dict:
|
| 126 |
+
"""
|
| 127 |
+
Returns a dict describing the call:
|
| 128 |
+
{ domain, domain_confidence, abstain, reason?,
|
| 129 |
+
expert?, species?, confidence?, runner_up? }
|
| 130 |
+
"""
|
| 131 |
+
x = preprocess(img)
|
| 132 |
+
|
| 133 |
+
# ββ Stage 1: domain router βββββββββββββββββββββββββββββββββββββββββββ
|
| 134 |
+
domain, dconf, _ = self._run(ROUTER, x)
|
| 135 |
+
out = {"domain": domain, "domain_confidence": dconf}
|
| 136 |
+
|
| 137 |
+
if dconf < ROUTER_CONFIDENCE_THRESHOLD or domain not in DOMAIN_EXPERTS:
|
| 138 |
+
reason = "uncertain_domain" if dconf < ROUTER_CONFIDENCE_THRESHOLD else "off_domain"
|
| 139 |
+
return {**out, "abstain": True, "reason": reason}
|
| 140 |
+
|
| 141 |
+
# ββ Stage 2: run the single expert that owns this domain. Optional
|
| 142 |
+
# energy gate abstains if the frame is out-of-domain for that expert.
|
| 143 |
+
ename = DOMAIN_EXPERTS[domain]
|
| 144 |
+
species, conf, energy = self._run(ename, x)
|
| 145 |
+
thr = self._energy_thr.get(ename)
|
| 146 |
+
if thr is not None and energy > thr:
|
| 147 |
+
return {**out, "abstain": True, "reason": "off_domain"}
|
| 148 |
+
|
| 149 |
+
call = {"expert": ename, "species": species, "confidence": conf, "energy": round(energy, 4)}
|
| 150 |
+
return {**out, "abstain": False, "calls": [call]}
|
pipeline/metadata.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
metadata.py β Per-species safety metadata.
|
| 3 |
+
|
| 4 |
+
Lifted verbatim from the forager_ml inference pipeline (convergence.py) so the
|
| 5 |
+
Space stays decoupled from the Hailo runtime. Keep in sync via
|
| 6 |
+
scripts/sync_from_forager_ml.sh if the source dict changes.
|
| 7 |
+
|
| 8 |
+
safety tiers: SAFE | CAUTION | DEADLY | UNKNOWN
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
SPECIES_METADATA: dict[str, dict] = {
|
| 12 |
+
# ββ Berry expert ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 13 |
+
"blackberry_common": {"safety": "SAFE", "scientific": "Rubus allegheniensis", "lookalike": "Pokeweed (young)", "key_diff": "Pokeweed has smooth stems, white flowers"},
|
| 14 |
+
"blueberry_highbush": {"safety": "SAFE", "scientific": "Vaccinium corymbosum", "lookalike": "Canada moonseed", "key_diff": "Moonseed has one crescent seed, no true drupelets"},
|
| 15 |
+
"blueberry_wild": {"safety": "SAFE", "scientific": "Vaccinium angustifolium", "lookalike": "Canada moonseed", "key_diff": "Moonseed has one crescent seed, no true drupelets"},
|
| 16 |
+
"elderberry_american": {"safety": "CAUTION", "scientific": "Sambucus canadensis", "lookalike": "Pokeweed", "key_diff": "Elderberry has compound leaves; must be cooked"},
|
| 17 |
+
"staghorn_sumac": {"safety": "SAFE", "scientific": "Rhus typhina", "lookalike": "Poison sumac", "key_diff": "Poison sumac has white berries, swampy habitat"},
|
| 18 |
+
"wild_grape_riverbank": {"safety": "SAFE", "scientific": "Vitis riparia", "lookalike": "Canada moonseed", "key_diff": "Grape has tendrils and true seeds"},
|
| 19 |
+
"bittersweet_nightshade_toxic": {"safety": "DEADLY", "scientific": "Solanum dulcamara", "lookalike": "N/A", "key_diff": "Purple flowers, red-to-black berries β avoid"},
|
| 20 |
+
"canada_moonseed_deadly": {"safety": "DEADLY", "scientific": "Menispermum canadense", "lookalike": "Wild grape", "key_diff": "Crescent-shaped seed, no tendrils"},
|
| 21 |
+
"poison_ivy": {"safety": "DEADLY", "scientific": "Toxicodendron radicans", "lookalike": "N/A", "key_diff": "Leaves of three, let it be"},
|
| 22 |
+
"pokeweed_toxic": {"safety": "DEADLY", "scientific": "Phytolacca americana", "lookalike": "Elderberry", "key_diff": "Pink-red stems, hollow; all parts toxic"},
|
| 23 |
+
"virginia_creeper_toxic": {"safety": "CAUTION", "scientific": "Parthenocissus quinquefolia","lookalike": "N/A", "key_diff": "5-leaflet vine; berries toxic"},
|
| 24 |
+
|
| 25 |
+
# ββ High-value expert βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 26 |
+
"chanterelles_edible": {"safety": "SAFE", "scientific": "Cantharellus cibarius", "lookalike": "Jack-o'-lantern", "key_diff": "Jack-o'-lantern has true gills, grows in clusters"},
|
| 27 |
+
"morels_edible": {"safety": "SAFE", "scientific": "Morchella esculenta", "lookalike": "False morel", "key_diff": "True morel is fully hollow; false morel has cottony interior"},
|
| 28 |
+
"chicken_of_the_woods": {"safety": "SAFE", "scientific": "Laetiporus sulphureus", "lookalike": "N/A", "key_diff": "Unmistakable orange shelf; avoid on conifers"},
|
| 29 |
+
"lions_mane": {"safety": "SAFE", "scientific": "Hericium erinaceus", "lookalike": "N/A", "key_diff": "White cascade of teeth β no true lookalike"},
|
| 30 |
+
"chaga_medicinal": {"safety": "SAFE", "scientific": "Inonotus obliquus", "lookalike": "Burnt wood knot", "key_diff": "Orange-yellow interior when cut"},
|
| 31 |
+
"reishi_mushroom": {"safety": "SAFE", "scientific": "Ganoderma lucidum", "lookalike": "N/A", "key_diff": "Shiny lacquered cap, white pore surface β verify species for region"},
|
| 32 |
+
"reishi_northeast": {"safety": "SAFE", "scientific": "Ganoderma tsugae", "lookalike": "N/A", "key_diff": "Shiny lacquered cap, white pore surface"},
|
| 33 |
+
"ramps_wild_leek": {"safety": "SAFE", "scientific": "Allium tricoccum", "lookalike": "Lily of the valley", "key_diff": "Lily of the valley has no garlic smell β critical check"},
|
| 34 |
+
"ostrich_fern_fiddlehead": {"safety": "CAUTION", "scientific": "Matteuccia struthiopteris", "lookalike": "Bracken fern", "key_diff": "Ostrich fern has deep U-shaped groove on stem"},
|
| 35 |
+
"ginseng_american": {"safety": "SAFE", "scientific": "Panax quinquefolius", "lookalike": "N/A", "key_diff": "Protected species β observe, don't harvest"},
|
| 36 |
+
"saffron_crocus": {"safety": "SAFE", "scientific": "Crocus sativus", "lookalike": "Autumn crocus", "key_diff": "Autumn crocus is highly toxic β 3 stigmas only in saffron"},
|
| 37 |
+
"high_value_toxics": {"safety": "DEADLY", "scientific": "Various", "lookalike": "N/A", "key_diff": "High-value toxic lookalike class β do not consume"},
|
| 38 |
+
|
| 39 |
+
# ββ Psychedelics / mycologist expert ββββββββββββββββββββββββββββββββββββββ
|
| 40 |
+
"amanita_phalloides_deadly": {"safety": "DEADLY", "scientific": "Amanita phalloides", "lookalike": "Puffball (young)", "key_diff": "Death cap has volva at base, white gills, ring"},
|
| 41 |
+
"amanita_muscaria_toxic": {"safety": "DEADLY", "scientific": "Amanita muscaria", "lookalike": "N/A", "key_diff": "Red cap with white warts β highly toxic"},
|
| 42 |
+
"galerina_marginata_toxic": {"safety": "DEADLY", "scientific": "Galerina marginata", "lookalike": "Psilocybe species", "key_diff": "Rusty brown spore print; ring present β deadly lookalike"},
|
| 43 |
+
"conocybe_filaris_deadly": {"safety": "DEADLY", "scientific": "Conocybe filaris", "lookalike": "Psilocybe species", "key_diff": "Rusty-brown spores; tiny ring on stem"},
|
| 44 |
+
"gymnopilus_junonius": {"safety": "CAUTION", "scientific": "Gymnopilus junonius", "lookalike": "Chanterelle", "key_diff": "Very bitter taste; yellow-orange gills"},
|
| 45 |
+
"panaeolus_cinctulus": {"safety": "CAUTION", "scientific": "Panaeolus cinctulus", "lookalike": "Edible field mushrooms", "key_diff": "Brown rim band on cap; dung/rich soil habitat"},
|
| 46 |
+
"psilocybe_ovoideocystidiata": {"safety": "CAUTION", "scientific": "Psilocybe ovoideocystidiata","lookalike": "Galerina marginata", "key_diff": "Blue bruising; wood chip habitat; rusty spores in Galerina"},
|
| 47 |
+
"psilocybe_cubensis": {"safety": "CAUTION", "scientific": "Psilocybe cubensis", "lookalike": "Galerina marginata", "key_diff": "Bruises blue; purple-black spore print β Galerina does not bruise"},
|
| 48 |
+
"psilocybe_cyanescens": {"safety": "CAUTION", "scientific": "Psilocybe cyanescens", "lookalike": "Galerina marginata", "key_diff": "Wavy cap edge; strong blue bruising"},
|
| 49 |
+
"psilocybe_semilanceata": {"safety": "CAUTION", "scientific": "Psilocybe semilanceata", "lookalike": "Conocybe filaris", "key_diff": "Pointed nipple-cap; deep blue bruising"},
|
| 50 |
+
"psilocybe_azurescens": {"safety": "CAUTION", "scientific": "Psilocybe azurescens", "lookalike": "Galerina marginata", "key_diff": "Caramel cap, very potent blue bruising"},
|
| 51 |
+
"psilocybe_caerulipes": {"safety": "CAUTION", "scientific": "Psilocybe caerulipes", "lookalike": "Galerina marginata", "key_diff": "Blue stem base; deciduous wood debris habitat"},
|
| 52 |
+
"other_mushroom": {"safety": "UNKNOWN", "scientific": "Unknown", "lookalike": "N/A", "key_diff": "Cannot identify β do not consume"},
|
| 53 |
+
"panax_quinquefolius_ginseng_conservation": {
|
| 54 |
+
"safety": "SAFE", "scientific": "Panax quinquefolius", "lookalike": "N/A", "key_diff": "Protected β observe only, do not harvest"},
|
| 55 |
+
|
| 56 |
+
# ββ Medicinals expert βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 57 |
+
"boneset": {"safety": "CAUTION", "scientific": "Eupatorium perfoliatum", "lookalike": "White snakeroot", "key_diff": "White snakeroot has heart-shaped leaves, highly toxic β confirm perfoliate leaf pairs"},
|
| 58 |
+
"burdock": {"safety": "SAFE", "scientific": "Arctium lappa", "lookalike": "Rhubarb (leaves)", "key_diff": "Rhubarb leaves are highly toxic; burdock has burr seedheads"},
|
| 59 |
+
"catnip": {"safety": "SAFE", "scientific": "Nepeta cataria", "lookalike": "N/A", "key_diff": "Square stem, grey-green downy leaves, minty-musty scent"},
|
| 60 |
+
"coltsfoot": {"safety": "CAUTION", "scientific": "Tussilago farfara", "lookalike": "Dandelion (flower)", "key_diff": "Coltsfoot flowers appear before leaves; pyrrolizidine alkaloids β avoid internal use"},
|
| 61 |
+
"echinacea": {"safety": "SAFE", "scientific": "Echinacea purpurea", "lookalike": "N/A", "key_diff": "Spiny orange-brown cone with drooping purple rays"},
|
| 62 |
+
"foxglove_toxic": {"safety": "DEADLY", "scientific": "Digitalis purpurea", "lookalike": "Comfrey (rosette)", "key_diff": "Foxglove has tubular spotted flowers; all parts highly toxic β cardiac glycosides"},
|
| 63 |
+
"goldenrod": {"safety": "SAFE", "scientific": "Solidago canadensis", "lookalike": "N/A", "key_diff": "Arching plumes of small yellow flowers in late summer"},
|
| 64 |
+
"motherwort": {"safety": "CAUTION", "scientific": "Leonurus cardiaca", "lookalike": "N/A", "key_diff": "Square stem, deeply lobed leaves, pink-purple flowers; avoid in pregnancy"},
|
| 65 |
+
"mullein": {"safety": "SAFE", "scientific": "Verbascum thapsus", "lookalike": "N/A", "key_diff": "Distinctive tall spike, large velvety basal rosette leaves"},
|
| 66 |
+
"plantain_broadleaf": {"safety": "SAFE", "scientific": "Plantago major", "lookalike": "N/A", "key_diff": "Oval ribbed leaves, parallel veins, narrow seedhead spike"},
|
| 67 |
+
"poison_hemlock_deadly": {"safety": "DEADLY", "scientific": "Conium maculatum", "lookalike": "Wild carrot", "key_diff": "Purple-blotched hollow stem, musty smell, no hairy stem β ALL parts deadly"},
|
| 68 |
+
"red_clover": {"safety": "SAFE", "scientific": "Trifolium pratense", "lookalike": "N/A", "key_diff": "Pink-purple globe flowers, trifoliate leaves with pale V-chevron"},
|
| 69 |
+
"st_johns_wort": {"safety": "CAUTION", "scientific": "Hypericum perforatum", "lookalike": "N/A", "key_diff": "Yellow 5-petalled flowers with black dots; translucent leaf dots; photosensitizing"},
|
| 70 |
+
"stinging_nettle": {"safety": "SAFE", "scientific": "Urtica dioica", "lookalike": "Wood nettle", "key_diff": "Cook or dry to neutralize sting; serrated leaves, opposite pairs"},
|
| 71 |
+
"valerian": {"safety": "CAUTION", "scientific": "Valeriana officinalis", "lookalike": "Water hemlock", "key_diff": "Water hemlock has purple-streaked hollow stem, chambered root β deadly; valerian has pinnate leaves"},
|
| 72 |
+
"water_hemlock_deadly": {"safety": "DEADLY", "scientific": "Cicuta maculata", "lookalike": "Wild carrot / Valerian", "key_diff": "Chambered root, purple-streaked hollow stem β most violently toxic plant in NA"},
|
| 73 |
+
"white_snakeroot_toxic": {"safety": "DEADLY", "scientific": "Ageratina altissima", "lookalike": "Boneset", "key_diff": "Heart-shaped leaves, flat-topped white flowers; causes milk sickness β avoid"},
|
| 74 |
+
"wild_bergamot": {"safety": "SAFE", "scientific": "Monarda fistulosa", "lookalike": "N/A", "key_diff": "Lavender ragged flowers, square stem, oregano-like scent"},
|
| 75 |
+
"wild_carrot": {"safety": "CAUTION", "scientific": "Daucus carota", "lookalike": "Poison hemlock / Water hemlock", "key_diff": "Hairy stem, central purple floret, carroty smell β confirm all three before use"},
|
| 76 |
+
"wood_nettle": {"safety": "SAFE", "scientific": "Laportea canadensis", "lookalike": "Stinging nettle", "key_diff": "Alternate leaves (vs opposite in stinging nettle); forested habitat; cook to neutralize"},
|
| 77 |
+
"yarrow": {"safety": "CAUTION", "scientific": "Achillea millefolium", "lookalike": "Poison hemlock (leaf)", "key_diff": "Flat-topped white flower clusters, ferny aromatic leaves; hemlock has blotched hollow stem"},
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
UNKNOWN_META = {"safety": "UNKNOWN", "scientific": "Unknown", "lookalike": "N/A", "key_diff": "No confident identification"}
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==6.16.0
|
| 2 |
+
onnxruntime==1.18.0
|
| 3 |
+
numpy<2
|
| 4 |
+
pillow
|