Instructions to use litert-community/MobileNet-v3-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/MobileNet-v3-small 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
Upload GPU-compatible LiteRT artifacts
Browse files- README.md +9 -144
- mobilenet_v3_small.tflite +2 -2
- mobilenet_v3_small_dynamic_wi8_afp32.tflite +3 -0
README.md
CHANGED
|
@@ -1,158 +1,23 @@
|
|
| 1 |
---
|
| 2 |
library_name: litert
|
| 3 |
-
pipeline_tag: image-classification
|
| 4 |
tags:
|
|
|
|
|
|
|
| 5 |
- vision
|
| 6 |
- image-classification
|
| 7 |
-
- google
|
| 8 |
-
- computer-vision
|
| 9 |
datasets:
|
| 10 |
- imagenet-1k
|
| 11 |
-
model-index:
|
| 12 |
-
- name: litert-community/MobileNet-v3-small
|
| 13 |
-
results:
|
| 14 |
-
- task:
|
| 15 |
-
type: image-classification
|
| 16 |
-
name: Image Classification
|
| 17 |
-
dataset:
|
| 18 |
-
name: ImageNet-1k
|
| 19 |
-
type: imagenet-1k
|
| 20 |
-
config: default
|
| 21 |
-
split: validation
|
| 22 |
-
metrics:
|
| 23 |
-
- name: Top 1 Accuracy (Full Precision)
|
| 24 |
-
type: accuracy
|
| 25 |
-
value: 0.6762
|
| 26 |
-
- name: Top 5 Accuracy (Full Precision)
|
| 27 |
-
type: accuracy
|
| 28 |
-
value: 0.8740
|
| 29 |
---
|
| 30 |
|
| 31 |
-
# MobileNet
|
| 32 |
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
##
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
The original model has:
|
| 42 |
-
acc@1 (on ImageNet-1K): 67.668%
|
| 43 |
-
acc@5 (on ImageNet-1K): 87.402%
|
| 44 |
-
num_params: 2,542,856
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
The license information of the original model was missing.
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
## Intended uses & limitations
|
| 51 |
-
|
| 52 |
-
The model files were converted from pretrained weights from PyTorch Vision. The models may have their own licenses or terms and conditions derived from PyTorch Vision and the dataset used for training. It is your responsibility to determine whether you have permission to use the models for your use case.
|
| 53 |
-
|
| 54 |
-
## How to Use
|
| 55 |
-
|
| 56 |
-
**1. Install Dependencies** Ensure your Python environment is set up with the required libraries. Run the following command in your terminal:
|
| 57 |
-
|
| 58 |
-
```bash
|
| 59 |
-
pip install numpy Pillow huggingface_hub ai-edge-litert
|
| 60 |
-
```
|
| 61 |
-
|
| 62 |
-
**2. Prepare Your Image** The script expects an image file to analyze. Make sure you have an image (e.g., cat.jpg or car.png) saved in the same working directory as your script.
|
| 63 |
-
|
| 64 |
-
**3. Save the Script** Create a new file named `classify.py`, paste the script below into it, and save the file:
|
| 65 |
-
|
| 66 |
-
```python
|
| 67 |
-
#!/usr/bin/env python3
|
| 68 |
-
import argparse, json
|
| 69 |
-
import numpy as np
|
| 70 |
-
from PIL import Image
|
| 71 |
-
from huggingface_hub import hf_hub_download
|
| 72 |
-
from ai_edge_litert.compiled_model import CompiledModel
|
| 73 |
-
|
| 74 |
-
def preprocess(img: Image.Image) -> np.ndarray:
|
| 75 |
-
img = img.convert("RGB")
|
| 76 |
-
w, h = img.size
|
| 77 |
-
s = 256
|
| 78 |
-
if w < h:
|
| 79 |
-
img = img.resize((s, int(round(h * s / w))), Image.BILINEAR)
|
| 80 |
-
else:
|
| 81 |
-
img = img.resize((int(round(w * s / h)), s), Image.BILINEAR)
|
| 82 |
-
left = (img.size[0] - 224) // 2
|
| 83 |
-
top = (img.size[1] - 224) // 2
|
| 84 |
-
img = img.crop((left, top, left + 224, top + 224))
|
| 85 |
-
|
| 86 |
-
x = np.asarray(img, dtype=np.float32) / 255.0
|
| 87 |
-
x = (x - np.array([0.485, 0.456, 0.406], dtype=np.float32)) / np.array(
|
| 88 |
-
[0.229, 0.224, 0.225], dtype=np.float32
|
| 89 |
-
)
|
| 90 |
-
return x
|
| 91 |
-
|
| 92 |
-
def main():
|
| 93 |
-
ap = argparse.ArgumentParser()
|
| 94 |
-
ap.add_argument("--image", required=True)
|
| 95 |
-
args = ap.parse_args()
|
| 96 |
-
|
| 97 |
-
model_path = hf_hub_download("litert-community/MobileNet-v3-small", "mobilenet_v3_small.tflite")
|
| 98 |
-
labels_path = hf_hub_download(
|
| 99 |
-
"huggingface/label-files", "imagenet-1k-id2label.json", repo_type="dataset"
|
| 100 |
-
)
|
| 101 |
-
with open(labels_path, "r", encoding="utf-8") as f:
|
| 102 |
-
id2label = {int(k): v for k, v in json.load(f).items()}
|
| 103 |
-
|
| 104 |
-
img = Image.open(args.image)
|
| 105 |
-
x = preprocess(img)
|
| 106 |
-
|
| 107 |
-
model = CompiledModel.from_file(model_path)
|
| 108 |
-
inp = model.create_input_buffers(0)
|
| 109 |
-
out = model.create_output_buffers(0)
|
| 110 |
-
|
| 111 |
-
inp[0].write(x)
|
| 112 |
-
model.run_by_index(0, inp, out)
|
| 113 |
-
|
| 114 |
-
req = model.get_output_buffer_requirements(0, 0)
|
| 115 |
-
y = out[0].read(req["buffer_size"] // np.dtype(np.float32).itemsize, np.float32)
|
| 116 |
-
|
| 117 |
-
pred = int(np.argmax(y))
|
| 118 |
-
label = id2label.get(pred, f"class_{pred}")
|
| 119 |
-
|
| 120 |
-
print(f"Top-1 class index: {pred}")
|
| 121 |
-
print(f"Top-1 label: {label}")
|
| 122 |
-
if __name__ == "__main__":
|
| 123 |
-
main()
|
| 124 |
-
```
|
| 125 |
-
|
| 126 |
-
**4. Execute the Python Script** Run the below command:
|
| 127 |
-
|
| 128 |
-
```bash
|
| 129 |
-
python classify.py --image cat.jpg
|
| 130 |
-
```
|
| 131 |
-
|
| 132 |
-
### BibTeX entry and citation info
|
| 133 |
-
```bibtex
|
| 134 |
-
@article{DBLP:journals/corr/abs-1905-02244,
|
| 135 |
-
author = {Andrew Howard and
|
| 136 |
-
Mark Sandler and
|
| 137 |
-
Grace Chu and
|
| 138 |
-
Liang{-}Chieh Chen and
|
| 139 |
-
Bo Chen and
|
| 140 |
-
Mingxing Tan and
|
| 141 |
-
Weijun Wang and
|
| 142 |
-
Yukun Zhu and
|
| 143 |
-
Ruoming Pang and
|
| 144 |
-
Vijay Vasudevan and
|
| 145 |
-
Quoc V. Le and
|
| 146 |
-
Hartwig Adam},
|
| 147 |
-
title = {Searching for MobileNetV3},
|
| 148 |
-
journal = {CoRR},
|
| 149 |
-
volume = {abs/1905.02244},
|
| 150 |
-
year = {2019},
|
| 151 |
-
url = {http://arxiv.org/abs/1905.02244},
|
| 152 |
-
eprinttype = {arXiv},
|
| 153 |
-
eprint = {1905.02244},
|
| 154 |
-
timestamp = {Thu, 27 May 2021 16:20:51 +0200},
|
| 155 |
-
biburl = {https://dblp.org/rec/journals/corr/abs-1905-02244.bib},
|
| 156 |
-
bibsource = {dblp computer science bibliography, https://dblp.org}
|
| 157 |
-
}
|
| 158 |
-
```
|
|
|
|
| 1 |
---
|
| 2 |
library_name: litert
|
|
|
|
| 3 |
tags:
|
| 4 |
+
- litert
|
| 5 |
+
- tflite
|
| 6 |
- vision
|
| 7 |
- image-classification
|
|
|
|
|
|
|
| 8 |
datasets:
|
| 9 |
- imagenet-1k
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# MobileNet-v3-small
|
| 13 |
|
| 14 |
+
LiteRT TFLite conversion of the TorchVision `mobilenet_v3_small` model.
|
| 15 |
|
| 16 |
+
## Files
|
| 17 |
|
| 18 |
+
- `mobilenet_v3_small.tflite`
|
| 19 |
+
- `mobilenet_v3_small_dynamic_wi8_afp32.tflite`
|
| 20 |
|
| 21 |
+
## Notes
|
| 22 |
|
| 23 |
+
These artifacts were compiled with the LiteRT GPU compatibility profile and validated with LiteRT Python GPU execution.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mobilenet_v3_small.tflite
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c7a8324a93d991d6b972d431c2219026d371b72f683d32da61f432b11e336a54
|
| 3 |
+
size 10184432
|
mobilenet_v3_small_dynamic_wi8_afp32.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a93f73c57e09b1f0224ee9965ae92af6c7da16373b2b02f9db232721f5b0ced6
|
| 3 |
+
size 2741424
|