snnn001 commited on
Commit
a0bf5b9
·
verified ·
1 Parent(s): 4c2fec8

Restore previous model card

Browse files
Files changed (1) hide show
  1. README.md +134 -9
README.md CHANGED
@@ -1,23 +1,148 @@
1
  ---
2
  library_name: litert
 
3
  tags:
4
- - litert
5
- - tflite
6
  - vision
7
  - image-classification
 
 
8
  datasets:
9
  - imagenet-1k
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  ---
11
 
12
- # convnext_tiny
13
 
14
- LiteRT TFLite conversion of the TorchVision `convnext_tiny` model.
15
 
16
- ## Files
17
 
18
- - `convnext_tiny.tflite`
19
- - `convnext_tiny_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.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_tiny
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.8246
26
+ - name: Top 5 Accuracy (Full Precision)
27
+ type: accuracy
28
+ value: 0.9613
29
  ---
30
 
31
+ # Convnext Tiny
32
 
33
+ ConvNeXt Tiny model designed as a lightweight, pure convolutional backbone for efficient visual recognition in the "Roaring 20s." 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 "modernizes" the standard ResNet by adopting Transformer-inspired inductive biases, such as depthwise convolutions with \\(7 \times 7 \\) kernels and inverted bottlenecks. With approximately 28M parameters and 4.5 GFLOPs, it achieves accuracy levels comparable to the Swin-T Transformer while maintaining the simplicity and high throughput of a standard ConvNet.
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): 82.52%
41
+ acc@5 (on ImageNet-1K): 96.146%
42
+ num_params: 28589128
43
+
44
 
45
+ ## Intended uses & limitations
46
+
47
+ 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.
48
+
49
+
50
+ ## How to Use
51
+
52
+ ​​**1. Install Dependencies**
53
+
54
+ Ensure your Python environment is set up with the required libraries. Run the following command in your terminal
55
+
56
+ ```bash
57
+ pip install numpy Pillow huggingface_hub ai-edge-litert
58
+ ```
59
+
60
+ **2. Prepare Your Image**
61
+
62
+ 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
+
65
+ **3. Save the Script**
66
+
67
+ Create a new file named `classify.py`, paste the script below into it, and save the file
68
+
69
+ ```python
70
+ #!/usr/bin/env python3
71
+ import argparse, json
72
+ import numpy as np
73
+ from PIL import Image
74
+ from huggingface_hub import hf_hub_download
75
+ from ai_edge_litert.compiled_model import CompiledModel
76
+
77
+ def preprocess(img: Image.Image) -> np.ndarray:
78
+ img = img.convert("RGB")
79
+ w, h = img.size
80
+ s = 236
81
+ if w < h:
82
+ img = img.resize((s, int(round(h * s / w))), Image.BILINEAR)
83
+ else:
84
+ img = img.resize((int(round(w * s / h)), s), Image.BILINEAR)
85
+ left = (img.size[0] - 224) // 2
86
+ top = (img.size[1] - 224) // 2
87
+ img = img.crop((left, top, left + 224, top + 224))
88
+
89
+ x = np.asarray(img, dtype=np.float32) / 255.0
90
+ x = (x - np.array([0.485, 0.456, 0.406], dtype=np.float32)) / np.array(
91
+ [0.229, 0.224, 0.225], dtype=np.float32
92
+ )
93
+ return np.expand_dims(x, axis=0)
94
+
95
+ def main():
96
+ ap = argparse.ArgumentParser()
97
+ ap.add_argument("--image", required=True)
98
+ args = ap.parse_args()
99
+
100
+ model_path = hf_hub_download("litert-community/convnext_tiny", “convnext_tiny.tflite")
101
+ labels_path = hf_hub_download(
102
+ "huggingface/label-files", "imagenet-1k-id2label.json", repo_type="dataset"
103
+ )
104
+ with open(labels_path, "r", encoding="utf-8") as f:
105
+ id2label = {int(k): v for k, v in json.load(f).items()}
106
+
107
+ img = Image.open(args.image)
108
+ x = preprocess(img)
109
+
110
+ model = CompiledModel.from_file(model_path)
111
+ inp = model.create_input_buffers(0)
112
+ out = model.create_output_buffers(0)
113
+
114
+ inp[0].write(x)
115
+ model.run_by_index(0, inp, out)
116
+
117
+ req = model.get_output_buffer_requirements(0, 0)
118
+ y = out[0].read(req["buffer_size"] // np.dtype(np.float32).itemsize, np.float32)
119
+
120
+ pred = int(np.argmax(y))
121
+ label = id2label.get(pred, f"class_{pred}")
122
+
123
+ print(f"Top-1 class index: {pred}")
124
+ print(f"Top-1 label: {label}")
125
+ if __name__ == "__main__":
126
+ main()
127
+ ```
128
+ **4. Execute the Python Script**
129
+
130
+ Run the below command
131
+
132
+ ```bash
133
+ python classify.py --image cat.jpg
134
+ ```
135
+
136
+ ### BibTeX entry and citation info
137
+
138
+ ```bibtex
139
+ @misc{liu2022convnet2020s,
140
+ title={A ConvNet for the 2020s},
141
+ author={Zhuang Liu and Hanzi Mao and Chao-Yuan Wu and Christoph Feichtenhofer and Trevor Darrell and Saining Xie},
142
+ year={2022},
143
+ eprint={2201.03545},
144
+ archivePrefix={arXiv},
145
+ primaryClass={cs.CV},
146
+ url={https://arxiv.org/abs/2201.03545},
147
+ }
148
+ ```