mlboydaisuke commited on
Commit
2a3bde4
·
verified ·
1 Parent(s): 1c3d989

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +88 -0
README.md ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: litert
4
+ pipeline_tag: image-classification
5
+ tags:
6
+ - litert
7
+ - tflite
8
+ - android
9
+ - on-device
10
+ - gpu
11
+ - fine-grained
12
+ - plant-identification
13
+ - plantnet
14
+ - resnet18
15
+ ---
16
+
17
+ # PlantNet-300K ResNet18 — LiteRT (plant species ID, GPU)
18
+
19
+ On-device **fine-grained plant species identification** — 1081 species — running
20
+ **fully on the LiteRT `CompiledModel` GPU** delegate (no CPU fallback). A
21
+ [PlantNet-300K](https://github.com/plantnet/PlantNet-300K) (NeurIPS 2021) ResNet18.
22
+ ~16 ms/frame on a Pixel 8a.
23
+
24
+ - **Architecture:** torchvision ResNet18 (pure CNN).
25
+ - **Weights:** [cpoisson/plantnet300k-resnet18](https://huggingface.co/cpoisson/plantnet300k-resnet18) · Apache-2.0.
26
+ - **Classes:** 1081 plant species (Latin names).
27
+ - **Size:** 47 MB.
28
+
29
+ ![PlantNet-300K plant identification](hero.png)
30
+
31
+ ## I/O
32
+
33
+ - **Input:** `[1, 3, 224, 224]` NCHW, RGB, ImageNet-normalized
34
+ (mean `[0.485,0.456,0.406]`, std `[0.229,0.224,0.225]`; center-crop then resize 224).
35
+ - **Output:** `[1, 1081]` species logits — softmax + top-k for the predicted species.
36
+
37
+ **Labels:** class index `i` maps to the `i`-th species when the PlantNet-300K
38
+ species-id strings are sorted (torchvision `ImageFolder` order); names from
39
+ `plantnet300K_species_id_2_name.json`.
40
+
41
+ ## GPU conversion
42
+
43
+ Plain torchvision ResNet18 — a pure CNN. It converts to a fully GPU-compatible graph
44
+ (**37/37 nodes on the delegate, 1 partition**; device corr 0.99999, top-1 match) with
45
+ **one patch**: the ResNet stem `MaxPool2d(padding=1)` lowers to a PADV2 with `-inf`
46
+ padding (`PADV2: src has wrong size` on the Mali delegate), replaced by an explicit
47
+ 0-pad + unpadded maxpool — exact, since the maxpool input is post-ReLU (≥ 0).
48
+ CPU-exact vs PyTorch (corr 0.99999999999).
49
+
50
+ ## Minimal usage
51
+
52
+ ### Kotlin (Android, LiteRT CompiledModel GPU)
53
+
54
+ ```kotlin
55
+ val options = CompiledModel.Options(Accelerator.GPU)
56
+ val model = CompiledModel.create(context.assets, "plantnet.tflite", options, null)
57
+ val inBufs = model.createInputBuffers()
58
+ val outBufs = model.createOutputBuffers()
59
+
60
+ inBufs[0].writeFloat(inputNCHW) // [1,3,224,224], RGB, ImageNet-norm
61
+ model.run(inBufs, outBufs)
62
+ val logits = outBufs[0].readFloat() // [1081]
63
+ val top = logits.indices.sortedByDescending { logits[it] }.take(5) // species indices
64
+ ```
65
+
66
+ ### Python (LiteRT / ai-edge-litert)
67
+
68
+ ```python
69
+ from ai_edge_litert.interpreter import Interpreter
70
+ import numpy as np
71
+
72
+ it = Interpreter(model_path="plantnet.tflite"); it.allocate_tensors()
73
+ inp, out = it.get_input_details(), it.get_output_details()
74
+ it.set_tensor(inp[0]["index"], x) # [1,3,224,224] float32, ImageNet-norm
75
+ it.invoke()
76
+ logits = it.get_tensor(out[0]["index"])[0] # [1081]
77
+ top5 = logits.argsort()[::-1][:5]
78
+ ```
79
+
80
+ ## Conversion
81
+
82
+ Converted with **litert-torch** (`build_plantnet.py`): loads the Apache-2.0 ResNet18
83
+ weights, applies the ZeroPadMaxPool patch, and exports.
84
+
85
+ ## License
86
+
87
+ Apache-2.0 (weights: cpoisson/plantnet300k-resnet18). PlantNet-300K code: BSD-2-Clause
88
+ (plantnet/PlantNet-300K, NeurIPS 2021).