Skip to content

Commit 0878bea

Browse files
authored
Refine Keras Examples for INC New API (#219)
Signed-off-by: zehao-intel <[email protected]>
1 parent 764357b commit 0878bea

File tree

30 files changed

+596
-794
lines changed

30 files changed

+596
-794
lines changed

.azure-pipelines/scripts/codeScan/pyspelling/inc_dict.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,6 +2398,8 @@ amsgrad
23982398
qoperator
23992399
apis
24002400
CPz
2401+
PostTrainingQuantConfig
2402+
dgpu
24012403
Nsh
24022404
UmK
24032405
fe

examples/.config/model_params_tensorflow.json

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@
4040
"model_src_dir": "image_recognition/keras_models/resnet101/quantization/ptq",
4141
"dataset_location": "/tf_dataset/dataset/imagenet",
4242
"input_model": "/tf_dataset2/models/tensorflow/resnet101_keras/saved_model/",
43-
"yaml": "resnet101.yaml",
44-
"strategy": "basic",
45-
"batch_size": 1,
46-
"new_benchmark": true
43+
"main_script": "main.py",
44+
"batch_size": 32
4745
},
4846
"resnet_v1_50_slim": {
4947
"model_src_dir": "image_recognition/tensorflow_models/quantization/ptq/slim",
@@ -121,10 +119,8 @@
121119
"model_src_dir": "image_recognition/keras_models/inception_v3/quantization/ptq",
122120
"dataset_location": "/tf_dataset/dataset/imagenet",
123121
"input_model": "/tf_dataset2/models/tensorflow/inception_v3_keras/saved_model/",
124-
"yaml": "inception_v3.yaml",
125-
"strategy": "basic",
126-
"batch_size": 1,
127-
"new_benchmark": true
122+
"main_script": "main.py",
123+
"batch_size": 32
128124
},
129125
"inception_v3_slim": {
130126
"model_src_dir": "image_recognition/tensorflow_models/quantization/ptq/slim",
@@ -319,10 +315,8 @@
319315
"model_src_dir": "image_recognition/keras_models/resnetv2_101/quantization/ptq",
320316
"dataset_location": "/tf_dataset/dataset/imagenet",
321317
"input_model": "/tf_dataset2/models/tensorflow/resnetv2_101_keras/saved_model",
322-
"yaml": "resnetv2_101.yaml",
323-
"strategy": "basic",
324-
"batch_size": 1,
325-
"new_benchmark": true
318+
"main_script": "main.py",
319+
"batch_size": 32
326320
},
327321
"resnetv2_152": {
328322
"model_src_dir": "image_recognition/tensorflow_models/quantization/ptq",
@@ -364,10 +358,8 @@
364358
"model_src_dir": "image_recognition/keras_models/mobilenet_v2/quantization/ptq",
365359
"dataset_location": "/tf_dataset/dataset/imagenet",
366360
"input_model": "/tf_dataset2/models/tensorflow/mobilenet_v2_keras/saved_model/",
367-
"yaml": "mobilenet_v2.yaml",
368-
"strategy": "basic",
369-
"batch_size": 1,
370-
"new_benchmark": true
361+
"main_script": "main.py",
362+
"batch_size": 32
371363
},
372364
"mobilenetv3": {
373365
"model_src_dir": "image_recognition/tensorflow_models/quantization/ptq",

examples/tensorflow/image_recognition/keras_models/inception_v3/quantization/ptq/README.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ This example can run on Intel CPUs and GPUs.
1212
# Install Intel® Neural Compressor
1313
pip install neural-compressor
1414
```
15-
### 2. Install Intel Tensorflow
15+
### 2. Install Tensorflow
1616
```shell
17-
pip install intel-tensorflow
17+
pip install tensorflow
1818
```
1919
> Note: Supported Tensorflow [Version](../../../../../../../README.md).
2020
@@ -26,7 +26,8 @@ Intel Extension for Tensorflow is mandatory to be installed for quantizing the m
2626
```shell
2727
pip install --upgrade intel-extension-for-tensorflow[gpu]
2828
```
29-
For any more details, please follow the procedure in [install-gpu-drivers](https://github.com/intel-innersource/frameworks.ai.infrastructure.intel-extension-for-tensorflow.intel-extension-for-tensorflow/blob/master/docs/install/install_for_gpu.md#install-gpu-drivers)
29+
Please refer to the [Installation Guides](https://dgpu-docs.intel.com/installation-guides/ubuntu/ubuntu-focal-dc.html) for latest Intel GPU driver installation.
30+
For any more details, please follow the procedure in [install-gpu-drivers](https://github.com/intel-innersource/frameworks.ai.infrastructure.intel-extension-for-tensorflow.intel-extension-for-tensorflow/blob/master/docs/install/install_for_gpu.md#install-gpu-drivers).
3031

3132
#### Quantizing the model on Intel CPU(Experimental)
3233
Intel Extension for Tensorflow for Intel CPUs is experimental currently. It's not mandatory for quantizing the model on Intel CPUs.
@@ -43,12 +44,25 @@ python prepare_model.py --output_model=/path/to/model
4344
```
4445
`--output_model ` the model should be saved as SavedModel format or H5 format.
4546

46-
## Write Yaml config file
47-
In examples directory, there is a inception_v3.yaml for tuning the model on Intel CPUs. The 'framework' in the yaml is set to 'tensorflow'. If running this example on Intel GPUs, the 'framework' should be set to 'tensorflow_itex' and the device in yaml file should be set to 'gpu'. The inception_v3_itex.yaml is prepared for the GPU case. We could remove most of items and only keep mandatory item for tuning. We also implement a calibration dataloader and have evaluation field for creation of evaluation function at internal neural_compressor.
47+
## Quantization Config
48+
The Quantization Config class has default parameters setting for running on Intel CPUs. If running this example on Intel GPUs, the 'backend' parameter should be set to 'itex' and the 'device' parameter should be set to 'gpu'.
49+
50+
```
51+
config = PostTrainingQuantConfig(
52+
device="gpu",
53+
backend="itex",
54+
...
55+
)
56+
```
4857

4958
## Run Command
59+
#### Tune
5060
```shell
51-
bash run_tuning.sh --config=inception_v3.yaml --input_model=./path/to/model --output_model=./result --eval_data=/path/to/evaluation/dataset --calib_data=/path/to/calibration/dataset
52-
bash run_benchmark.sh --config=inception_v3.yaml --input_model=./path/to/model --mode=performance --eval_data=/path/to/evaluation/dataset
61+
bash run_tuning.sh --input_model=./path/to/model --output_model=./result --dataset_location=/path/to/evaluation/dataset
5362
```
5463

64+
#### Benchmark
65+
```shell
66+
bash run_benchmark.sh --input_model=./path/to/model --dataset_location=/path/to/evaluation/dataset --mode=performance
67+
bash run_benchmark.sh --input_model=./path/to/model --dataset_location=/path/to/evaluation/dataset --mode=accuracy
68+
```

examples/tensorflow/image_recognition/keras_models/inception_v3/quantization/ptq/inception_v3.yaml

Lines changed: 0 additions & 49 deletions
This file was deleted.

examples/tensorflow/image_recognition/keras_models/inception_v3/quantization/ptq/inception_v3_itex.yaml

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)