Skip to content

Commit fb85779

Browse files
authored
Update Examples for TF 3x API (#1901)
Signed-off-by: zehao-intel <[email protected]>
1 parent 6b30207 commit fb85779

File tree

117 files changed

+39154
-31
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+39154
-31
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"keras": {
3+
"resnetv2_50": {
4+
"model_src_dir": "keras/image_recognition/resnet_v2_50/quantization/ptq",
5+
"dataset_location": "/tf_dataset/dataset/imagenet",
6+
"input_model": "/tf_dataset2/models/tensorflow/resnetv2_50_keras/saved_model",
7+
"main_script": "main.py",
8+
"batch_size": 32
9+
},
10+
"inception_v3": {
11+
"model_src_dir": "keras/image_recognition/inception_v3/quantization/ptq",
12+
"dataset_location": "/tf_dataset/dataset/imagenet",
13+
"input_model": "/tf_dataset2/models/tensorflow/inception_v3_keras/saved_model",
14+
"main_script": "main.py",
15+
"batch_size": 32
16+
}
17+
}
18+
}

examples/.config/model_params_tensorflow_3x.json

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88
"batch_size": 64,
99
"fp32_model_url": "https://storage.googleapis.com/intel-optimized-tensorflow/models/v2_7_0/fp32_bert_squad.pb"
1010
},
11+
"distilbert_base": {
12+
"model_src_dir": "nlp/distilbert_base/quantization/ptq",
13+
"dataset_location": "/tf_dataset2/datasets/sst2_validation_dataset",
14+
"input_model": "/tf_dataset2/models/tensorflow/distilbert_base/fp32/distilbert_base_fp32.pb",
15+
"main_script": "main.py",
16+
"batch_size": 128
17+
},
18+
"distilbert_base_sq": {
19+
"model_src_dir": "nlp/distilbert_base/quantization/ptq",
20+
"dataset_location": "/tf_dataset2/datasets/sst2_validation_dataset",
21+
"input_model": "/tf_dataset2/models/tensorflow/distilbert_base/fp32/distilbert_base_fp32.pb",
22+
"main_script": "main.py",
23+
"batch_size": 128
24+
},
1125
"opt_125m_sq": {
1226
"model_src_dir": "nlp/large_language_models/quantization/ptq/smoothquant",
1327
"dataset_location": "",
@@ -29,6 +43,42 @@
2943
"main_script": "main.py",
3044
"batch_size": 1
3145
},
46+
"transformer_lt": {
47+
"model_src_dir": "nlp/transformer_lt/quantization/ptq",
48+
"dataset_location": "/tf_dataset/tensorflow/transformer-lt-official-fp32-inference/transformer_lt_official_fp32_pretrained_model/data",
49+
"input_model": "/tf_dataset/tensorflow/transformer-lt-official-fp32-inference/transformer_lt_official_fp32_pretrained_model/graph/fp32_graphdef.pb",
50+
"main_script": "main.py",
51+
"batch_size": 64
52+
},
53+
"inception_v3": {
54+
"model_src_dir": "image_recognition/inception_v3/quantization/ptq",
55+
"dataset_location": "/tf_dataset/dataset/imagenet",
56+
"input_model": "/tf_dataset/pre-trained-models/inceptionv3/fp32/freezed_inceptionv3.pb",
57+
"main_script": "main.py",
58+
"batch_size": 32,
59+
"fp32_model_url": "https://storage.googleapis.com/intel-optimized-tensorflow/models/v1_8/inceptionv3_fp32_pretrained_model.pb"
60+
},
61+
"mobilenetv2": {
62+
"model_src_dir": "image_recognition/mobilenet_v2/quantization/ptq",
63+
"dataset_location": "/tf_dataset/dataset/imagenet",
64+
"input_model": "/tf_dataset/pre-train-model-slim/pbfile/frozen_pb/frozen_mobilenet_v2.pb",
65+
"main_script": "main.py",
66+
"batch_size": 32
67+
},
68+
"resnetv2_50": {
69+
"model_src_dir": "image_recognition/resnet_v2_50/quantization/ptq",
70+
"dataset_location": "/tf_dataset/dataset/imagenet",
71+
"input_model": "/tf_dataset/pre-train-model-slim/pbfile/frozen_pb/frozen_resnet_v2_50.pb",
72+
"main_script": "main.py",
73+
"batch_size": 32
74+
},
75+
"vgg16": {
76+
"model_src_dir": "image_recognition/vgg16/quantization/ptq",
77+
"dataset_location": "/tf_dataset/dataset/imagenet",
78+
"input_model": "/tf_dataset/pre-train-model-slim/pbfile/frozen_pb/frozen_vgg16.pb",
79+
"main_script": "main.py",
80+
"batch_size": 32
81+
},
3282
"ViT": {
3383
"model_src_dir": "image_recognition/vision_transformer/quantization/ptq",
3484
"dataset_location": "/tf_dataset/dataset/imagenet",
@@ -42,6 +92,63 @@
4292
"input_model": "/tf_dataset/tensorflow/graphsage/graphsage_frozen_model.pb",
4393
"main_script": "main.py",
4494
"batch_size": 1000
95+
},
96+
"faster_rcnn_resnet50": {
97+
"model_src_dir": "object_detection/faster_rcnn_resnet50/quantization/ptq",
98+
"dataset_location": "/tf_dataset/tensorflow/coco_val.record",
99+
"input_model": "/tf_dataset/pre-train-model-oob/object_detection/faster_rcnn_resnet50/frozen_inference_graph.pb",
100+
"main_script": "main.py",
101+
"batch_size": 10
102+
},
103+
"mask_rcnn_inception_v2": {
104+
"model_src_dir": "object_detection/mask_rcnn_inception_v2/quantization/ptq",
105+
"dataset_location": "/tf_dataset/tensorflow/coco_val.record",
106+
"input_model": "/tf_dataset/pre-train-model-oob/object_detection/mask_rcnn_inception_v2/frozen_inference_graph.pb",
107+
"main_script": "main.py",
108+
"batch_size": 10
109+
},
110+
"mask_rcnn_inception_v2_ckpt": {
111+
"model_src_dir": "object_detection/mask_rcnn_inception_v2/quantization/ptq",
112+
"dataset_location": "/tf_dataset/tensorflow/coco_val.record",
113+
"input_model": "/tf_dataset/pre-train-model-oob/object_detection/mask_rcnn_inception_v2",
114+
"main_script": "main.py",
115+
"batch_size": 10
116+
},
117+
"ssd_mobilenet_v1": {
118+
"model_src_dir": "object_detection/ssd_mobilenet_v1/quantization/ptq",
119+
"dataset_location": "/tf_dataset/tensorflow/coco_val.record",
120+
"input_model": "/tf_dataset/pre-train-model-oob/object_detection/ssd_mobilenet_v1/frozen_inference_graph.pb",
121+
"main_script": "main.py",
122+
"batch_size": 10
123+
},
124+
"ssd_mobilenet_v1_ckpt": {
125+
"model_src_dir": "object_detection/ssd_mobilenet_v1/quantization/ptq",
126+
"dataset_location": "/tf_dataset/tensorflow/coco_val.record",
127+
"input_model": "/tf_dataset/pre-train-model-oob/object_detection/ssd_mobilenet_v1",
128+
"main_script": "main.py",
129+
"batch_size": 10
130+
},
131+
"wide_deep_large_ds": {
132+
"model_src_dir": "recommendation/wide_deep_large_ds/quantization/ptq",
133+
"dataset_location": "/tf_dataset/tensorflow/wide_deep_large_ds/dataset",
134+
"input_model": "/tf_dataset/tensorflow/wide_deep_large_ds/fp32_optimized_graph.pb",
135+
"main_script": "main.py",
136+
"batch_size": 256,
137+
"fp32_model_url": "https://storage.googleapis.com/intel-optimized-tensorflow/models/v1_8/wide_deep_fp32_pretrained_model.pb"
138+
},
139+
"3dunet-mlperf": {
140+
"model_src_dir": "semantic_image_segmentation/3dunet-mlperf/quantization/ptq",
141+
"dataset_location": "/tf_dataset2/models/tensorflow/3dunet/build",
142+
"input_model": "/tf_dataset2/models/tensorflow/3dunet/3dunet_dynamic_ndhwc.pb",
143+
"main_script": "main.py",
144+
"batch_size": 100
145+
},
146+
"style_transfer": {
147+
"model_src_dir": "style_transfer/arbitrary_style_transfer/quantization/ptq",
148+
"dataset_location": "style_images,content_images",
149+
"input_model": "/tf_dataset/tensorflow/style_transfer/arbitrary_style_transfer/model.ckpt",
150+
"main_script": "main.py",
151+
"batch_size": 1
45152
}
46153
}
47154
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Step-by-Step
2+
============
3+
4+
This document list steps of reproducing inception_v3 model tuning and benchmark results via Neural Compressor.
5+
This example can run on Intel CPUs and GPUs.
6+
7+
> **Note**:
8+
> The models is supported in validated TensorFlow [Version](/docs/source/installation_guide.md#validated-software-environment).
9+
# Prerequisite
10+
11+
## 1. Environment
12+
13+
### Installation
14+
Recommend python 3.9 or higher version.
15+
```shell
16+
pip install -r requirements.txt
17+
```
18+
19+
### Install Intel Extension for Tensorflow
20+
#### Quantizing the model on Intel GPU(Mandatory to install ITEX)
21+
Intel Extension for Tensorflow is mandatory to be installed for quantizing the model on Intel GPUs.
22+
23+
```shell
24+
pip install --upgrade intel-extension-for-tensorflow[xpu]
25+
```
26+
For any more details, please follow the procedure in [install-gpu-drivers](https://github.com/intel/intel-extension-for-tensorflow/blob/main/docs/install/install_for_xpu.md#install-gpu-drivers)
27+
28+
#### Quantizing the model on Intel CPU(Optional to install ITEX)
29+
Intel Extension for Tensorflow for Intel CPUs is experimental currently. It's not mandatory for quantizing the model on Intel CPUs.
30+
31+
```shell
32+
pip install --upgrade intel-extension-for-tensorflow[cpu]
33+
```
34+
> **Note**:
35+
> The version compatibility of stock Tensorflow and ITEX can be checked [here](https://github.com/intel/intel-extension-for-tensorflow#compatibility-table). Please make sure you have installed compatible Tensorflow and ITEX.
36+
37+
## 2. Prepare pre-trained model
38+
39+
Download pre-trained PB
40+
```shell
41+
wget https://storage.googleapis.com/intel-optimized-tensorflow/models/v1_6/inceptionv3_fp32_pretrained_model.pb
42+
```
43+
44+
## 3. Prepare Dataset
45+
46+
TensorFlow [models](https://github.com/tensorflow/models) repo provides [scripts and instructions](https://github.com/tensorflow/models/tree/master/research/slim#an-automated-script-for-processing-imagenet-data) to download, process and convert the ImageNet dataset to the TF records format.
47+
We also prepared related scripts in ` examples/3.x_api/tensorflow/cv` directory. To download the raw images, the user must create an account with image-net.org. If you have downloaded the raw data and preprocessed the validation data by moving the images into the appropriate sub-directory based on the label (synset) of the image. we can use below command ro convert it to tf records format.
48+
49+
```shell
50+
cd examples/3.x_api/tensorflow/cv
51+
# convert validation subset
52+
bash prepare_dataset.sh --output_dir=./inception_v3/quantization/ptq/data --raw_dir=/PATH/TO/img_raw/val/ --subset=validation
53+
# convert train subset
54+
bash prepare_dataset.sh --output_dir=./inception_v3/quantization/ptq/data --raw_dir=/PATH/TO/img_raw/train/ --subset=train
55+
```
56+
> **Note**:
57+
> The raw ImageNet dataset resides in JPEG files should be in the following directory structure. Taking validation set as an example:<br>
58+
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/PATH/TO/img_raw/val/n01440764/ILSVRC2012_val_00000293.JPEG<br>
59+
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/PATH/TO/img_raw/val/n01440764/ILSVRC2012_val_00000543.JPEG<br>
60+
> where 'n01440764' is the unique synset label associated with these images.
61+
62+
# Run
63+
64+
## 1 Quantization
65+
66+
```shell
67+
bash run_quant.sh --input_model=/PATH/TO/inceptionv3_fp32_pretrained_model.pb \
68+
--output_model=./nc_inception_v3.pb --dataset_location=/path/to/ImageNet/
69+
```
70+
71+
## 2. Benchmark
72+
```shell
73+
bash run_benchmark.sh --input_model=./nc_inception_v3.pb --mode=accuracy --dataset_location=/path/to/ImageNet/ --batch_size=32
74+
bash run_benchmark.sh --input_model=./nc_inception_v3.pb --mode=performance --dataset_location=/path/to/ImageNet/ --batch_size=1
75+
```

0 commit comments

Comments
 (0)