snnn001 akashvverma1995 commited on
Commit
2fd06df
·
1 Parent(s): fa32e2a

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 (66ddce54459fa02dc0f9aa5d23e87405d2fe98cc)


Co-authored-by: Akash Verma <akashvverma1995@users.noreply.huggingface.co>

Files changed (1) hide show
  1. README.md +113 -2
README.md CHANGED
@@ -1,21 +1,132 @@
1
  ---
2
  library_name: litert
 
3
  tags:
4
  - vision
5
  - image-classification
 
 
6
  datasets:
7
  - imagenet-1k
8
  base_model:
9
  - google/efficientnet-b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  ---
 
11
  # EfficientNet B4
12
 
13
- EfficientNet B4 model pre-trained on ImageNet-1k.
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  ## Intended uses & limitations
16
 
17
  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.
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  ### BibTeX entry and citation info
20
 
21
  ```bibtex
@@ -26,4 +137,4 @@ The model files were converted from pretrained weights from PyTorch Vision. The
26
  year={2019},
27
  volume={abs/1905.11946}
28
  }
29
- ```
 
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
  base_model:
12
  - google/efficientnet-b4
13
+ model-index:
14
+ - name: litert-community/efficientnet_b4
15
+ results:
16
+ - task:
17
+ type: image-classification
18
+ name: Image Classification
19
+ dataset:
20
+ name: ImageNet-1k
21
+ type: imagenet-1k
22
+ config: default
23
+ split: validation
24
+ metrics:
25
+ - name: Top 1 Accuracy (Full Precision)
26
+ type: accuracy
27
+ value: 0.8339
28
+ - name: Top 5 Accuracy (Full Precision)
29
+ type: accuracy
30
+ value: 0.9660
31
+ - name: Top 1 Accuracy (Dynamic Quantized wi8 afp32)
32
+ type: accuracy
33
+ value: 0.6354
34
+ - name: Top 5 Accuracy (Dynamic Quantized wi8 afp32)
35
+ type: accuracy
36
+ value: 0.7724
37
  ---
38
+
39
  # EfficientNet B4
40
 
41
+ EfficientNet B4 model pre-trained on ImageNet-1k. Originally introduced by Tan and Le in the influential paper,[ **EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks**](https://arxiv.org/abs/1905.11946) this model utilizes compound scaling to systematically balance network depth, width, and resolution, enabling superior accuracy with significantly higher efficiency than traditional architectures.
42
+
43
+ ## Model description
44
+
45
+ The model was converted from a checkpoint from PyTorch Vision.
46
+
47
+ The original model has:
48
+ acc@1 (on ImageNet-1K): 83.384%
49
+ acc@5 (on ImageNet-1K): 96.594%
50
+ num_params: 19,341,616
51
+
52
+ The license information of the original model was missing.
53
 
54
  ## Intended uses & limitations
55
 
56
  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.
57
 
58
+ ## Use
59
+
60
+ ```python
61
+ #!/usr/bin/env python3
62
+ import argparse, json
63
+ import numpy as np
64
+ from PIL import Image
65
+ from huggingface_hub import hf_hub_download
66
+ from ai_edge_litert.compiled_model import CompiledModel
67
+
68
+
69
+ def preprocess(img: Image.Image) -> np.ndarray:
70
+ img = img.convert("RGB")
71
+ w, h = img.size
72
+ s = 384
73
+ if w < h:
74
+ img = img.resize((s, int(round(h * s / w))), Image.BICUBIC)
75
+ else:
76
+ img = img.resize((int(round(w * s / h)), s), Image.BICUBIC)
77
+ left = (img.size[0] - 380) // 2
78
+ top = (img.size[1] - 380) // 2
79
+ img = img.crop((left, top, left + 380, top + 380))
80
+
81
+
82
+ x = np.asarray(img, dtype=np.float32) / 255.0
83
+ x = (x - np.array([0.485, 0.456, 0.406], dtype=np.float32)) / np.array(
84
+ [0.229, 0.224, 0.225], dtype=np.float32
85
+ )
86
+ return np.transpose(x, (2, 0, 1))
87
+
88
+
89
+ def main():
90
+ ap = argparse.ArgumentParser()
91
+ ap.add_argument("--image", required=True)
92
+ args = ap.parse_args()
93
+
94
+
95
+ model_path = hf_hub_download("litert-community/efficientnet_b4", "efficientnet_b4.tflite")
96
+ labels_path = hf_hub_download(
97
+ "huggingface/label-files", "imagenet-1k-id2label.json", repo_type="dataset"
98
+ )
99
+ with open(labels_path, "r", encoding="utf-8") as f:
100
+ id2label = {int(k): v for k, v in json.load(f).items()}
101
+
102
+
103
+ img = Image.open(args.image)
104
+ x = preprocess(img)
105
+
106
+
107
+ model = CompiledModel.from_file(model_path)
108
+ inp = model.create_input_buffers(0)
109
+ out = model.create_output_buffers(0)
110
+
111
+
112
+ inp[0].write(x)
113
+ model.run_by_index(0, inp, out)
114
+
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
+
120
+ pred = int(np.argmax(y))
121
+ label = id2label.get(pred, f"class_{pred}")
122
+
123
+
124
+ print(f"Top-1 class index: {pred}")
125
+ print(f"Top-1 label: {label}")
126
+ if __name__ == "__main__":
127
+ main()
128
+ ```
129
+
130
  ### BibTeX entry and citation info
131
 
132
  ```bibtex
 
137
  year={2019},
138
  volume={abs/1905.11946}
139
  }
140
+ ```