Instructions to use mlgraham/species-classifier-arachnids with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use mlgraham/species-classifier-arachnids 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
Species classifier: arachnids
A 153-species arachnid classifier (spiders, scorpions, ticks, harvestmen) small enough for microcontrollers and the Coral Edge TPU. MobileNetV2 at full width and 160 px, full-integer int8, trained on the iNaturalist 2021 competition data. It fills the gap people hit first with Google's AIY insect model, which has no spiders. Part of species-classifiers.
| File | What it is |
|---|---|
arachnids_int8.tflite |
2.9 MB, full-integer, uint8 in and out. Runs as is on TensorFlow Lite Micro (ESP32-S3, Coral Dev Board Micro CPU, Raspberry Pi) and phones through LiteRT |
arachnids_int8_edgetpu.tflite |
the same model compiled with Edge TPU compiler 16.0, every op mapped, 2.89 MiB cached on-chip |
arachnids_float32.tflite |
float in and out, for desktop use or your own quantization |
arachnids_int8_vela.tflite |
the int8 model compiled with Arm's Vela for the Ethos-U55 in the Seeed Grove Vision AI V2, using Seeed's Himax configuration; upload it with SenseCraft AI's Model Assistant |
labels.txt |
one class per line, Latin name (Common name), line number = class index |
classes.json |
the full taxonomy per class (kingdom to species), for order and family roll-ups |
Accuracy
Measured on the int8 file over the 1,530 iNaturalist 2021 validation images for these species (10 per species), with an 87.5% centre crop:
| Input | Top-1 | Top-5 |
|---|---|---|
| Colour | 62.3% | 86.4% |
The PyTorch checkpoint scores 64.4% top-1. For comparison, Google's stock AIY insect model scores 59.1% top-1 on the iNat2021 species it shares, choosing among 1,022 classes.
Input contract
- Input
[1, 160, 160, 3]uint8 RGB, 0 to 255, no normalization; the model rescales internally. - Output
[1, 153]uint8 probabilities, scale 1/256 and zero point 0, soprob = value / 256. No background class. - Centre-crop to a square. The model was validated with an 87.5% centre crop (resize the short side to 183, crop 160), which is worth about a point over the whole frame.
- Ops are plain Conv2D, DepthwiseConv2D, Add, AveragePool, FullyConnected and Softmax, so the file converts for the Raspberry Pi AI Camera (IMX500) and Arm Ethos-U boards as well as the Edge TPU.
import numpy as np, tensorflow as tf
from PIL import Image
interp = tf.lite.Interpreter(model_path="arachnids_int8.tflite"); interp.allocate_tensors()
inp, out = interp.get_input_details()[0], interp.get_output_details()[0]
labels = open("labels.txt").read().splitlines()
img = Image.open("photo.jpg").convert("RGB")
w, h = img.size; s = min(w, h)
img = img.crop(((w - s) // 2, (h - s) // 2, (w - s) // 2 + s, (h - s) // 2 + s)).resize((160, 160))
interp.set_tensor(inp["index"], np.asarray(img, dtype=np.uint8)[None])
interp.invoke()
probs = interp.get_tensor(out["index"])[0] / 256.0
for i in np.argsort(-probs)[:3]:
print(f"{probs[i]:.2f} {labels[i]}")
How it was trained
MobileNetV2 1.0 at 160 px initialised from timm's mobilenetv2_100.ra_in1k ImageNet weights, hard labels, 12 epochs over the full iNat2021 training split (40,687 arachnid images), random resized crops, flips and colour jitter, AdamW with cosine decay. Trained in PyTorch on a laptop GPU through MPS, transplanted into Keras with a positional weight copy that verifies to a millionth, then exported with TensorFlow's full-integer converter calibrated on 300 training images. Every script is in the GitHub repository.
Provenance and license
Weights Apache-2.0, trained in the species-classifiers repository. Initialised from timm's ImageNet weights (Apache-2.0). Training images from the iNaturalist 2021 competition dataset; species names and taxonomy in labels.txt and classes.json come from it. The same files, with checksums, are in GitHub release v0.1.0.
Also a public Edge Impulse project that deploys straight to supported boards: https://studio.edgeimpulse.com/public/1132643/latest. And on Kaggle Models beside Google's originals: https://www.kaggle.com/models/mgraham0/species-classifiers
Not affiliated with iNaturalist or Google.
- Downloads last month
- 62
Model tree for mlgraham/species-classifier-arachnids
Base model
timm/mobilenetv2_100.ra_in1k