Instructions to use Arm/deit-tiny-int8-litert with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use Arm/deit-tiny-int8-litert 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
Full catalogue sync: example.py
Browse files- example.py +7 -6
example.py
CHANGED
|
@@ -14,6 +14,7 @@ import argparse
|
|
| 14 |
import json
|
| 15 |
import math
|
| 16 |
from pathlib import Path
|
|
|
|
| 17 |
|
| 18 |
import numpy as np
|
| 19 |
from PIL import Image
|
|
@@ -22,10 +23,9 @@ from PIL import Image
|
|
| 22 |
# Paths
|
| 23 |
# ---------------------------------------------------------------------------
|
| 24 |
SCRIPT_DIR = Path(__file__).parent.resolve()
|
| 25 |
-
_model_in_parent = SCRIPT_DIR.parent / "
|
| 26 |
-
MODEL_PATH = _model_in_parent if _model_in_parent.exists() else SCRIPT_DIR / "
|
| 27 |
IMAGE_PATH = SCRIPT_DIR / "sample_input.jpg"
|
| 28 |
-
CLASSES_PATH = SCRIPT_DIR / "imagenet_classes.json"
|
| 29 |
|
| 30 |
# ---------------------------------------------------------------------------
|
| 31 |
# Constants
|
|
@@ -97,10 +97,11 @@ def postprocess(logits: np.ndarray, top_k: int = TOP_K) -> list[dict]:
|
|
| 97 |
exp = np.exp(logits - logits.max())
|
| 98 |
probs = exp / exp.sum()
|
| 99 |
top_indices = np.argsort(probs)[::-1][:top_k]
|
| 100 |
-
|
| 101 |
-
|
|
|
|
| 102 |
return [
|
| 103 |
-
{"rank": i + 1, "class": classes[
|
| 104 |
for i, idx in enumerate(top_indices)
|
| 105 |
]
|
| 106 |
|
|
|
|
| 14 |
import json
|
| 15 |
import math
|
| 16 |
from pathlib import Path
|
| 17 |
+
from torchvision.models import GoogLeNet_Weights
|
| 18 |
|
| 19 |
import numpy as np
|
| 20 |
from PIL import Image
|
|
|
|
| 23 |
# Paths
|
| 24 |
# ---------------------------------------------------------------------------
|
| 25 |
SCRIPT_DIR = Path(__file__).parent.resolve()
|
| 26 |
+
_model_in_parent = SCRIPT_DIR.parent / "facebook__deit-tiny-patch16-224_litert_optimized.tflite"
|
| 27 |
+
MODEL_PATH = _model_in_parent if _model_in_parent.exists() else SCRIPT_DIR / "facebook__deit-tiny-patch16-224_litert_optimized.tflite"
|
| 28 |
IMAGE_PATH = SCRIPT_DIR / "sample_input.jpg"
|
|
|
|
| 29 |
|
| 30 |
# ---------------------------------------------------------------------------
|
| 31 |
# Constants
|
|
|
|
| 97 |
exp = np.exp(logits - logits.max())
|
| 98 |
probs = exp / exp.sum()
|
| 99 |
top_indices = np.argsort(probs)[::-1][:top_k]
|
| 100 |
+
# ImageNet class labels (1000 classes)
|
| 101 |
+
WEIGHTS = GoogLeNet_Weights.IMAGENET1K_V1
|
| 102 |
+
classes = WEIGHTS.meta["categories"]
|
| 103 |
return [
|
| 104 |
+
{"rank": i + 1, "class": classes[idx], "probability": float(probs[idx])}
|
| 105 |
for i, idx in enumerate(top_indices)
|
| 106 |
]
|
| 107 |
|