-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add table transformer example (#1043)
Signed-off-by: Mengni Wang <[email protected]>
- Loading branch information
1 parent
3c3673d
commit eb8a956
Showing
10 changed files
with
537 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...les/onnxrt/object_detection/table_transformer/quantization/ptq_static/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Step-by-Step | ||
============ | ||
|
||
This example show how to export, quantize and evaluate the DETR R18 model for table structure recognition task based on PubTables-1M dataset. | ||
|
||
# Prerequisite | ||
|
||
## 1. Environment | ||
|
||
```shell | ||
pip install neural-compressor | ||
pip install -r requirements.txt | ||
bash prepare.sh | ||
``` | ||
> Note: Validated ONNX Runtime [Version](/docs/source/installation_guide.md#validated-software-environment). | ||
## 2. Prepare Dataset | ||
|
||
Download dataset according to this [doc](https://github.com/microsoft/table-transformer/tree/main#training-and-evaluation-data). | ||
|
||
## 3. Prepare Model | ||
|
||
```shell | ||
wget https://huggingface.co/bsmock/tatr-pubtables1m-v1.0/resolve/main/pubtables1m_structure_detr_r18.pth | ||
|
||
bash export.sh --input_model=/path/to/pubtables1m_structure_detr_r18.pth \ | ||
--output_model=/path/to/export \ # model path as *.onnx | ||
--dataset_location=/path/to/dataset_folder # dataset_folder should contains 'words' sub-folder | ||
``` | ||
|
||
# Run | ||
|
||
## 1. Quantization | ||
|
||
Static quantization with QOperator format: | ||
|
||
```bash | ||
bash run_tuning.sh --input_model=path/to/model \ # model path as *.onnx | ||
--output_model=path/to/save \ # model path as *.onnx | ||
--dataset_location=/path/to/dataset_folder # dataset_folder should contains 'words' sub-folder | ||
``` | ||
|
||
## 2. Benchmark | ||
|
||
```bash | ||
bash run_benchmark.sh --input_model=path/to/model \ # model path as *.onnx | ||
--dataset_location=/path/to/dataset_folder # dataset_folder should contains 'words' sub-folder | ||
--mode=performance # or accuracy | ||
``` |
43 changes: 43 additions & 0 deletions
43
examples/onnxrt/object_detection/table_transformer/quantization/ptq_static/export.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
function main { | ||
init_params "$@" | ||
export_model | ||
|
||
} | ||
|
||
# init params | ||
function init_params { | ||
|
||
for var in "$@" | ||
do | ||
case $var in | ||
--input_model=*) | ||
input_model=$(echo $var |cut -f2 -d=) | ||
;; | ||
--output_model=*) | ||
output_model=$(echo $var |cut -f2 -d=) | ||
;; | ||
--dataset_location=*) | ||
dataset_location=$(echo $var |cut -f2 -d=) | ||
;; | ||
esac | ||
done | ||
|
||
} | ||
|
||
function export_model { | ||
cd table-transformer/src | ||
python main.py \ | ||
--model_load_path ${input_model} \ | ||
--output_model ${output_model} \ | ||
--data_root_dir ${dataset_location}/PubTables1M-Structure-PASCAL-VOC \ | ||
--table_words_dir ${dataset_location}/PubTables1M-Table-Words-JSON \ | ||
--mode 'export' \ | ||
--data_type structure \ | ||
--device cpu \ | ||
--config_file structure_config.json | ||
} | ||
|
||
main "$@" |
Oops, something went wrong.