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

#1
Files changed (1) hide show
  1. README.md +118 -4
README.md CHANGED
@@ -1,8 +1,122 @@
1
  ---
2
- library_name: litert
3
  tags:
4
- - vision
5
- - image-classification
 
 
6
  datasets:
7
- - imagenet-1k
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ pipeline_tag: image-classification
3
  tags:
4
+ - vision
5
+ - image-classification
6
+ - google
7
+ - computer-vision
8
  datasets:
9
+ - imagenet-1k
10
+ model-index:
11
+ - name: litert-community/vgg11
12
+ results:
13
+ - task:
14
+ type: image-classification
15
+ name: Image Classification
16
+ dataset:
17
+ name: ImageNet-1k
18
+ type: imagenet-1k
19
+ config: default
20
+ split: validation
21
+ metrics:
22
+ - name: Top 1 Accuracy (Full Precision)
23
+ type: accuracy
24
+ value: 0.6897
25
+ - name: Top 5 Accuracy (Full Precision)
26
+ type: accuracy
27
+ value: 0.8865
28
  ---
29
+
30
+ # VGG11
31
+
32
+ VGG11 model pre-trained on ImageNet-1k. Originally introduced by Karen Simonyan and Andrew Zisserman in the influential paper, [**Very Deep Convolutional Networks for Large-Scale Image Recognition**](https://arxiv.org/abs/1409.1556) this configuration serves as the base 8-layer convolutional architecture (plus 3 fully connected layers) that proved the effectiveness of using small $3 \times 3$ filters to build deep networks while maintaining a manageable number of parameters.
33
+
34
+ ## Intended uses & limitations
35
+
36
+ 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.
37
+
38
+
39
+ ## Model description
40
+
41
+ The model was converted from a checkpoint from PyTorch Vision.
42
+
43
+ The original model has:
44
+ acc@1 (on ImageNet-1K): 69.02%
45
+ acc@5 (on ImageNet-1K): 88.628%
46
+ num_params: 132863336
47
+
48
+ The license information of the original model was missing.
49
+
50
+ ## Use
51
+ ```python
52
+ #!/usr/bin/env python3
53
+ import argparse, json
54
+ import numpy as np
55
+ from PIL import Image
56
+ from huggingface_hub import hf_hub_download
57
+ from ai_edge_litert.compiled_model import CompiledModel
58
+
59
+ def preprocess(img: Image.Image) -> np.ndarray:
60
+ img = img.convert("RGB")
61
+ w, h = img.size
62
+ s = 256
63
+ if w < h:
64
+ img = img.resize((s, int(round(h * s / w))), Image.BILINEAR)
65
+ else:
66
+ img = img.resize((int(round(w * s / h)), s), Image.BILINEAR)
67
+ left = (img.size[0] - 224) // 2
68
+ top = (img.size[1] - 224) // 2
69
+ img = img.crop((left, top, left + 224, top + 224))
70
+
71
+ x = np.asarray(img, dtype=np.float32) / 255.0
72
+ x = (x - np.array([0.485, 0.456, 0.406], dtype=np.float32)) / np.array(
73
+ [0.229, 0.224, 0.225], dtype=np.float32
74
+ )
75
+ return np.expand_dims(x, axis=0)
76
+
77
+ def main():
78
+ ap = argparse.ArgumentParser()
79
+ ap.add_argument("--image", required=True)
80
+ args = ap.parse_args()
81
+
82
+ model_path = hf_hub_download("litert-community/vgg11", "vgg11.tflite")
83
+ labels_path = hf_hub_download(
84
+ "huggingface/label-files", "imagenet-1k-id2label.json", repo_type="dataset"
85
+ )
86
+ with open(labels_path, "r", encoding="utf-8") as f:
87
+ id2label = {int(k): v for k, v in json.load(f).items()}
88
+
89
+ img = Image.open(args.image)
90
+ x = preprocess(img)
91
+
92
+ model = CompiledModel.from_file(model_path)
93
+ inp = model.create_input_buffers(0)
94
+ out = model.create_output_buffers(0)
95
+
96
+ inp[0].write(x)
97
+ model.run_by_index(0, inp, out)
98
+
99
+ req = model.get_output_buffer_requirements(0, 0)
100
+ y = out[0].read(req["buffer_size"] // np.dtype(np.float32).itemsize, np.float32)
101
+
102
+ pred = int(np.argmax(y))
103
+ label = id2label.get(pred, f"class_{pred}")
104
+
105
+ print(f"Top-1 class index: {pred}")
106
+ print(f"Top-1 label: {label}")
107
+ if __name__ == "__main__":
108
+ main()
109
+ ```
110
+ ### BibTeX entry and citation info
111
+
112
+ ```bibtex
113
+ @misc{simonyan2015deepconvolutionalnetworkslargescale,
114
+ title={Very Deep Convolutional Networks for Large-Scale Image Recognition},
115
+ author={Karen Simonyan and Andrew Zisserman},
116
+ year={2015},
117
+ eprint={1409.1556},
118
+ archivePrefix={arXiv},
119
+ primaryClass={cs.CV},
120
+ url={https://arxiv.org/abs/1409.1556},
121
+ }
122
+ ```