Skip to content

Commit 7265dfe

Browse files
authored
Add BEiT ONNXRT example (#1322)
Signed-off-by: yuwenzho <[email protected]>
1 parent ee54507 commit 7265dfe

File tree

9 files changed

+846
-0
lines changed

9 files changed

+846
-0
lines changed

examples/.config/model_params_onnxrt.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@
322322
"main_script": "main.py",
323323
"batch_size": 1
324324
},
325+
"beit": {
326+
"model_src_dir": "image_recognition/beit/quantization/ptq_static",
327+
"dataset_location": "/tf_dataset/pytorch/ImageNet/raw",
328+
"input_model": "/tf_dataset2/models/onnx/beit/beit_base_patch16_224_pt22k_ft22kto1k.onnx",
329+
"main_script": "main.py",
330+
"batch_size": 1
331+
},
325332
"mobilebert_squad_mlperf_qdq": {
326333
"model_src_dir": "nlp/onnx_model_zoo/mobilebert/quantization/ptq_static",
327334
"dataset_location": "/tf_dataset2/datasets/squad",

examples/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,12 @@ Intel® Neural Compressor validated examples with multiple compression technique
11331133
<td>Post-Training Static Quantization</td>
11341134
<td><a href="./onnxrt/body_analysis/onnx_model_zoo/arcface/quantization/ptq_static">qlinearops</a></td>
11351135
</tr>
1136+
<tr>
1137+
<td>BEiT</td>
1138+
<td>Image Recognition</td>
1139+
<td>Post-Training Static Quantization</td>
1140+
<td><a href="./onnxrt/image_recognition/beit/quantization/ptq_static">qlinearops</a></td>
1141+
</tr>
11361142
<tr>
11371143
<td>CodeBert</td>
11381144
<td>Natural Language Processing</td>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Step-by-Step
2+
============
3+
4+
This example load [BERT Pre-Training of Image Transformers](https://arxiv.org/abs/2106.08254)(BEiT) model and confirm its accuracy and performance based on [ImageNet-1k dataset](http://www.image-net.org/). You need to download this dataset yourself.
5+
6+
In this example, the BEiT model is pre-trained in a self-supervised fashion on ImageNet-22k - also called ImageNet-21k (14 million images, 21,841 classes) at resolution 224x224, and fine-tuned on the same dataset at resolution 224x224. It was first released in [this repository](https://github.com/microsoft/unilm/tree/master/beit).
7+
8+
9+
# Prerequisite
10+
11+
## 1. Environment
12+
```shell
13+
pip install neural-compressor
14+
pip install -r requirements.txt
15+
```
16+
> Note: Validated ONNX Runtime [Version](/docs/source/installation_guide.md#validated-software-environment).
17+
18+
## 2. Prepare Model
19+
20+
Prepare DETR R18 model for table structure recognition.
21+
22+
```shell
23+
python prepare_model.py --input_model=beit_base_patch16_224 --output_model=beit_base_patch16_224_pt22k_ft22kto1k.onnx
24+
```
25+
26+
## 3. Prepare Dataset
27+
28+
Download and extract [ImageNet-1k](http://www.image-net.org/) to dir: /path/to/imagenet. The dir include below folder:
29+
30+
```bash
31+
ls /path/to/imagenet
32+
train val
33+
```
34+
35+
# Run
36+
37+
## 1. Quantization
38+
39+
Quantize model with QLinearOps:
40+
41+
```bash
42+
bash run_quant.sh --input_model=/path/to/model \ # model path as *.onnx
43+
--dataset_location=/path/to/imagenet \
44+
--output_model=/path/to/save \
45+
--quant_format="QOperator"
46+
```
47+
48+
## 2. Benchmark
49+
50+
```bash
51+
bash run_benchmark.sh --input_model=/path/to/model \ # model path as *.onnx
52+
--dataset_location=/path/to/imagenet \
53+
--batch_size=batch_size \
54+
--mode=performance # or accuracy
55+
```

0 commit comments

Comments
 (0)