snnn001 commited on
Commit
8424b0e
·
verified ·
1 Parent(s): 6adcbac

Upload GPU-compatible LiteRT artifacts

Browse files
Files changed (3) hide show
  1. README.md +9 -128
  2. resnet18.tflite +2 -2
  3. resnet18_dynamic_wi8_afp32.tflite +2 -2
README.md CHANGED
@@ -1,142 +1,23 @@
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/resnet18
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.6977
26
- - name: Top 5 Accuracy (Full Precision)
27
- type: accuracy
28
- value: 0.8913
29
- - name: Top 1 Accuracy (Dynamic Quantized wi8 afp32)
30
- type: accuracy
31
- value: 0.6967
32
- - name: Top 5 Accuracy (Dynamic Quantized wi8 afp32)
33
- type: accuracy
34
- value: 0.8901
35
  ---
36
 
37
- # ResNet 18
38
 
39
- The ResNet-18 architecture is a convolutional neural network pre-trained on the ImageNet-1k dataset. Originally introduced by He et al. in the landmark paper, [**Deep Residual Learning for Image Recognition**](https://arxiv.org/pdf/1512.03385), this model utilizes residual mapping to overcome the vanishing gradient problem, enabling the training of substantially deeper networks.
40
 
 
41
 
42
- ## Model description
 
43
 
44
- The model was converted from a checkpoint from PyTorch Vision.
45
 
46
- The original model has:
47
- acc@1 (on ImageNet-1K): 69.758%
48
- acc@5 (on ImageNet-1K): 89.078%
49
- num_params: 11,689,512
50
-
51
- ## Intended uses & limitations
52
-
53
- 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.
54
-
55
- ## How to Use
56
-
57
- **1. Install Dependencies** Ensure your Python environment is set up with the required libraries. Run the following command in your terminal:
58
-
59
- ```bash
60
- pip install numpy Pillow huggingface_hub ai-edge-litert
61
- ```
62
-
63
- **2. Prepare Your Image** 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.
64
-
65
- **3. Save the Script** 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 = 256
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.transpose(x, (2, 0, 1))
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/resnet18", "resnet18.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
-
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
- @inproceedings{he2016deep,
137
- title={Deep residual learning for image recognition},
138
- author={He, Kaiming and Zhang, Xiangyu and Ren, Shaoqing and Sun, Jian},
139
- booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition}, pages={770--778},
140
- year={2016}
141
- }
142
- ```
 
1
  ---
2
  library_name: litert
 
3
  tags:
4
+ - litert
5
+ - tflite
6
  - vision
7
  - image-classification
 
 
8
  datasets:
9
  - imagenet-1k
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  ---
11
 
12
+ # resnet18
13
 
14
+ LiteRT TFLite conversion of the TorchVision `resnet18` model.
15
 
16
+ ## Files
17
 
18
+ - `resnet18.tflite`
19
+ - `resnet18_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.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
resnet18.tflite CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:cf6a25c8ddaa1ce3457bdbd8a9fd3e1a327b334990efdaa8620ec97839e4163d
3
- size 46776012
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:068bd4bd67a18c0dcc55f91b73fb035317c26cccf94328528d6dd1788bc4a0f6
3
+ size 46750944
resnet18_dynamic_wi8_afp32.tflite CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9c3c5127eb486028d374b09b33c946bb36d3aff597e36f6df54e95b301ea0d34
3
- size 11809384
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a4c5ef4b7fc01e24508bd59ad32084a616dbe9a16b4c910c81a16808ac7b0b29
3
+ size 11784928