Instructions to use litert-community/convnext_large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/convnext_large 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
Update README: Add model card metadata, ImageNet-1k metrics, and LiteRT usage example
#1
by HarishPermal - opened
README.md
CHANGED
|
@@ -1,8 +1,146 @@
|
|
| 1 |
---
|
| 2 |
library_name: litert
|
|
|
|
| 3 |
tags:
|
| 4 |
- vision
|
| 5 |
- image-classification
|
|
|
|
|
|
|
| 6 |
datasets:
|
| 7 |
- imagenet-1k
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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/convnext_large
|
| 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.8441
|
| 26 |
+
- name: Top 5 Accuracy (Full Precision)
|
| 27 |
+
type: accuracy
|
| 28 |
+
value: 0.9698
|
| 29 |
---
|
| 30 |
+
|
| 31 |
+
# Convnext Large
|
| 32 |
+
|
| 33 |
+
ConvNeXt Large model designed as a powerful, pure convolutional alternative to Vision Transformers (ViTs) for high-end computer vision tasks. Originally introduced by Zhuang Liu, Hanzi Mao, Chao-Yuan Wu, Christoph Feichtenhofer, Trevor Darrell, Saining Xie. in the modernized paper, [**A ConvNet for the 2020s**](https://arxiv.org/abs/2201.03545), this model adopts "Transformer-like" design choices—such as depthwise convolutions with large kernels, inverted bottlenecks, and GELU activation—to achieve state-of-the-art scalability. With approximately 198M parameters and 34.4 GFLOPs, it competes favorably with large-scale hierarchical Transformers like Swin-L, offering superior simplicity and efficiency for detection and segmentation.
|
| 34 |
+
|
| 35 |
+
## Model description
|
| 36 |
+
|
| 37 |
+
The model was converted from a checkpoint from PyTorch Vision.
|
| 38 |
+
|
| 39 |
+
The original model has:
|
| 40 |
+
acc@1 (on ImageNet-1K): 84.414%
|
| 41 |
+
acc@5 (on ImageNet-1K): 96.976%
|
| 42 |
+
num_params: 197767336
|
| 43 |
+
|
| 44 |
+
## Intended uses & limitations
|
| 45 |
+
|
| 46 |
+
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.
|
| 47 |
+
|
| 48 |
+
## How to Use
|
| 49 |
+
|
| 50 |
+
**1. Install Dependencies**
|
| 51 |
+
|
| 52 |
+
Ensure your Python environment is set up with the required libraries. Run the following command in your terminal
|
| 53 |
+
|
| 54 |
+
```bash
|
| 55 |
+
pip install numpy Pillow huggingface_hub ai-edge-litert
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
**2. Prepare Your Image**
|
| 59 |
+
|
| 60 |
+
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.
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
**3. Save the Script**
|
| 64 |
+
|
| 65 |
+
Create a new file named `classify.py`, paste the script below into it, and save the file:
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
#!/usr/bin/env python3
|
| 69 |
+
import argparse, json
|
| 70 |
+
import numpy as np
|
| 71 |
+
from PIL import Image
|
| 72 |
+
from huggingface_hub import hf_hub_download
|
| 73 |
+
from ai_edge_litert.compiled_model import CompiledModel
|
| 74 |
+
|
| 75 |
+
def preprocess(img: Image.Image) -> np.ndarray:
|
| 76 |
+
img = img.convert("RGB")
|
| 77 |
+
w, h = img.size
|
| 78 |
+
s = 232
|
| 79 |
+
if w < h:
|
| 80 |
+
img = img.resize((s, int(round(h * s / w))), Image.BILINEAR)
|
| 81 |
+
else:
|
| 82 |
+
img = img.resize((int(round(w * s / h)), s), Image.BILINEAR)
|
| 83 |
+
left = (img.size[0] - 224) // 2
|
| 84 |
+
top = (img.size[1] - 224) // 2
|
| 85 |
+
img = img.crop((left, top, left + 224, top + 224))
|
| 86 |
+
|
| 87 |
+
x = np.asarray(img, dtype=np.float32) / 255.0
|
| 88 |
+
x = (x - np.array([0.485, 0.456, 0.406], dtype=np.float32)) / np.array(
|
| 89 |
+
[0.229, 0.224, 0.225], dtype=np.float32
|
| 90 |
+
)
|
| 91 |
+
return np.expand_dims(x, axis=0)
|
| 92 |
+
|
| 93 |
+
def main():
|
| 94 |
+
ap = argparse.ArgumentParser()
|
| 95 |
+
ap.add_argument("--image", required=True)
|
| 96 |
+
args = ap.parse_args()
|
| 97 |
+
|
| 98 |
+
model_path = hf_hub_download("litert-community/convnext_large", “convnext_large.tflite")
|
| 99 |
+
labels_path = hf_hub_download(
|
| 100 |
+
"huggingface/label-files", "imagenet-1k-id2label.json", repo_type="dataset"
|
| 101 |
+
)
|
| 102 |
+
with open(labels_path, "r", encoding="utf-8") as f:
|
| 103 |
+
id2label = {int(k): v for k, v in json.load(f).items()}
|
| 104 |
+
|
| 105 |
+
img = Image.open(args.image)
|
| 106 |
+
x = preprocess(img)
|
| 107 |
+
|
| 108 |
+
model = CompiledModel.from_file(model_path)
|
| 109 |
+
inp = model.create_input_buffers(0)
|
| 110 |
+
out = model.create_output_buffers(0)
|
| 111 |
+
|
| 112 |
+
inp[0].write(x)
|
| 113 |
+
model.run_by_index(0, inp, out)
|
| 114 |
+
|
| 115 |
+
req = model.get_output_buffer_requirements(0, 0)
|
| 116 |
+
y = out[0].read(req["buffer_size"] // np.dtype(np.float32).itemsize, np.float32)
|
| 117 |
+
|
| 118 |
+
pred = int(np.argmax(y))
|
| 119 |
+
label = id2label.get(pred, f"class_{pred}")
|
| 120 |
+
|
| 121 |
+
print(f"Top-1 class index: {pred}")
|
| 122 |
+
print(f"Top-1 label: {label}")
|
| 123 |
+
if __name__ == "__main__":
|
| 124 |
+
main()
|
| 125 |
+
```
|
| 126 |
+
**4. Execute the Python Script**
|
| 127 |
+
|
| 128 |
+
Run the below command
|
| 129 |
+
|
| 130 |
+
```bash
|
| 131 |
+
python classify.py --image cat.jpg
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
### BibTeX entry and citation info
|
| 135 |
+
|
| 136 |
+
```bibtex
|
| 137 |
+
@misc{liu2022convnet2020s,
|
| 138 |
+
title={A ConvNet for the 2020s},
|
| 139 |
+
author={Zhuang Liu and Hanzi Mao and Chao-Yuan Wu and Christoph Feichtenhofer and Trevor Darrell and Saining Xie},
|
| 140 |
+
year={2022},
|
| 141 |
+
eprint={2201.03545},
|
| 142 |
+
archivePrefix={arXiv},
|
| 143 |
+
primaryClass={cs.CV},
|
| 144 |
+
url={https://arxiv.org/abs/2201.03545},
|
| 145 |
+
}
|
| 146 |
+
```
|