rodneywitcher HarishPermal commited on
Commit
32076c6
·
1 Parent(s): 2402f6e

Update README: Add model card metadata, ImageNet-1k metrics, and LiteRT usage example (#1)

Browse files

- Update README: Add model card metadata, ImageNet-1k metrics, and LiteRT usage example (11f80ecc82b72b26c8cc322488af448f5ffa29bc)


Co-authored-by: HarishPermal <HarishPermal@users.noreply.huggingface.co>

Files changed (1) hide show
  1. README.md +137 -0
README.md CHANGED
@@ -1,8 +1,145 @@
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/shufflenet_v2_x2_0
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.7622
26
+ - name: Top 5 Accuracy (Full Precision)
27
+ type: accuracy
28
+ value: 0.9297
29
  ---
30
+
31
+ # ShuffleNet V2 x2.0
32
+
33
+ ShuffleNet V2 x2.0 model designed for high-performance applications on edge devices where both accuracy and latency are critical. Originally introduced by Ningning Ma, Xiangyu Zhang, Hai-Tao Zheng, Jian Sun in the influential paper, [**ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design**](https://arxiv.org/abs/1807.11164) this model scales the architecture to a 2.0x complexity multiplier, doubling the feature channels to significantly boost representational power. It achieves a Top-1 accuracy of approximately 76.2% on ImageNet-1K with roughly 0.58 GFLOPs and 7.4M parameters, maintaining high hardware efficiency through its optimized "channel split" and "channel shuffle" building blocks.
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): 76.23%
41
+ acc@5 (on ImageNet-1K): 93.006%
42
+ num_params: 7393996
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
+
49
+ ## How to Use
50
+
51
+ ​​**1. Install Dependencies**
52
+
53
+ Ensure your Python environment is set up with the required libraries. Run the following command in your terminal:
54
+
55
+ ```bash
56
+ pip install numpy Pillow huggingface_hub ai-edge-litert
57
+ ```
58
+
59
+ **2. Prepare Your Image**
60
+
61
+ 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.
62
+
63
+
64
+ **3. Save the Script**
65
+
66
+ Create a new file named `classify.py`, paste the script below into it, and save the file:
67
+
68
+ ```python
69
+ #!/usr/bin/env python3
70
+ import argparse, json
71
+ import numpy as np
72
+ from PIL import Image
73
+ from huggingface_hub import hf_hub_download
74
+ from ai_edge_litert.compiled_model import CompiledModel
75
+
76
+ def preprocess(img: Image.Image) -> np.ndarray:
77
+ img = img.convert("RGB")
78
+ w, h = img.size
79
+ s = 232
80
+ if w < h:
81
+ img = img.resize((s, int(round(h * s / w))), Image.BILINEAR)
82
+ else:
83
+ img = img.resize((int(round(w * s / h)), s), Image.BILINEAR)
84
+ left = (img.size[0] - 224) // 2
85
+ top = (img.size[1] - 224) // 2
86
+ img = img.crop((left, top, left + 224, top + 224))
87
+
88
+ x = np.asarray(img, dtype=np.float32) / 255.0
89
+ x = (x - np.array([0.485, 0.456, 0.406], dtype=np.float32)) / np.array(
90
+ [0.229, 0.224, 0.225], dtype=np.float32
91
+ )
92
+ return np.expand_dims(x, axis=0)
93
+
94
+ def main():
95
+ ap = argparse.ArgumentParser()
96
+ ap.add_argument("--image", required=True)
97
+ args = ap.parse_args()
98
+
99
+ model_path = hf_hub_download("litert-community/shufflenet_v2_x2_0", "shufflenet_v2_x2_0.tflite")
100
+ labels_path = hf_hub_download(
101
+ "huggingface/label-files", "imagenet-1k-id2label.json", repo_type="dataset"
102
+ )
103
+ with open(labels_path, "r", encoding="utf-8") as f:
104
+ id2label = {int(k): v for k, v in json.load(f).items()}
105
+
106
+ img = Image.open(args.image)
107
+ x = preprocess(img)
108
+
109
+ model = CompiledModel.from_file(model_path)
110
+ inp = model.create_input_buffers(0)
111
+ out = model.create_output_buffers(0)
112
+
113
+ inp[0].write(x)
114
+ model.run_by_index(0, inp, out)
115
+
116
+ req = model.get_output_buffer_requirements(0, 0)
117
+ y = out[0].read(req["buffer_size"] // np.dtype(np.float32).itemsize, np.float32)
118
+
119
+ pred = int(np.argmax(y))
120
+ label = id2label.get(pred, f"class_{pred}")
121
+
122
+ print(f"Top-1 class index: {pred}")
123
+ print(f"Top-1 label: {label}")
124
+ if __name__ == "__main__":
125
+ main()
126
+ ```
127
+ **4. Execute the Python Script** Run the below command:
128
+
129
+ ```bash
130
+ python classify.py --image cat.jpg
131
+ ```
132
+
133
+ ### BibTeX entry and citation info
134
+
135
+ ```bibtex
136
+ @misc{ma2018shufflenetv2practicalguidelines,
137
+ title={ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design},
138
+ author={Ningning Ma and Xiangyu Zhang and Hai-Tao Zheng and Jian Sun},
139
+ year={2018},
140
+ eprint={1807.11164},
141
+ archivePrefix={arXiv},
142
+ primaryClass={cs.CV},
143
+ url={https://arxiv.org/abs/1807.11164},
144
+ }
145
+ ```