Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine Keras Examples for INC New API #219

Merged
merged 20 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .azure-pipelines/scripts/codeScan/pyspelling/inc_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,8 @@ amsgrad
qoperator
apis
CPz
PostTrainingQuantConfig
dgpu
Nsh
UmK
fe
Expand Down
24 changes: 8 additions & 16 deletions examples/.config/model_params_tensorflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@
"model_src_dir": "image_recognition/keras_models/resnet101/quantization/ptq",
"dataset_location": "/tf_dataset/dataset/imagenet",
"input_model": "/tf_dataset2/models/tensorflow/resnet101_keras/saved_model/",
"yaml": "resnet101.yaml",
"strategy": "basic",
"batch_size": 1,
"new_benchmark": true
"main_script": "main.py",
"batch_size": 32
},
"resnet_v1_50_slim": {
"model_src_dir": "image_recognition/tensorflow_models/quantization/ptq/slim",
Expand Down Expand Up @@ -121,10 +119,8 @@
"model_src_dir": "image_recognition/keras_models/inception_v3/quantization/ptq",
"dataset_location": "/tf_dataset/dataset/imagenet",
"input_model": "/tf_dataset2/models/tensorflow/inception_v3_keras/saved_model/",
"yaml": "inception_v3.yaml",
"strategy": "basic",
"batch_size": 1,
"new_benchmark": true
"main_script": "main.py",
"batch_size": 32
},
"inception_v3_slim": {
"model_src_dir": "image_recognition/tensorflow_models/quantization/ptq/slim",
Expand Down Expand Up @@ -319,10 +315,8 @@
"model_src_dir": "image_recognition/keras_models/resnetv2_101/quantization/ptq",
"dataset_location": "/tf_dataset/dataset/imagenet",
"input_model": "/tf_dataset2/models/tensorflow/resnetv2_101_keras/saved_model",
"yaml": "resnetv2_101.yaml",
"strategy": "basic",
"batch_size": 1,
"new_benchmark": true
"main_script": "main.py",
"batch_size": 32
},
"resnetv2_152": {
"model_src_dir": "image_recognition/tensorflow_models/quantization/ptq",
Expand Down Expand Up @@ -364,10 +358,8 @@
"model_src_dir": "image_recognition/keras_models/mobilenet_v2/quantization/ptq",
"dataset_location": "/tf_dataset/dataset/imagenet",
"input_model": "/tf_dataset2/models/tensorflow/mobilenet_v2_keras/saved_model/",
"yaml": "mobilenet_v2.yaml",
"strategy": "basic",
"batch_size": 1,
"new_benchmark": true
"main_script": "main.py",
"batch_size": 32
},
"mobilenetv3": {
"model_src_dir": "image_recognition/tensorflow_models/quantization/ptq",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ This example can run on Intel CPUs and GPUs.
# Install Intel® Neural Compressor
pip install neural-compressor
```
### 2. Install Intel Tensorflow
### 2. Install Tensorflow
```shell
pip install intel-tensorflow
pip install tensorflow
```
> Note: Supported Tensorflow [Version](../../../../../../../README.md).

Expand All @@ -26,7 +26,8 @@ Intel Extension for Tensorflow is mandatory to be installed for quantizing the m
```shell
pip install --upgrade intel-extension-for-tensorflow[gpu]
```
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)
Please refer to the [Installation Guides](https://dgpu-docs.intel.com/installation-guides/ubuntu/ubuntu-focal-dc.html) for latest Intel GPU driver installation.
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).

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

## Write Yaml config file
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.
## Quantization Config
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'.

```
config = PostTrainingQuantConfig(
device="gpu",
backend="itex",
...
)
```

## Run Command
#### Tune
```shell
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
bash run_benchmark.sh --config=inception_v3.yaml --input_model=./path/to/model --mode=performance --eval_data=/path/to/evaluation/dataset
bash run_tuning.sh --input_model=./path/to/model --output_model=./result --dataset_location=/path/to/evaluation/dataset
```

#### Benchmark
```shell
bash run_benchmark.sh --input_model=./path/to/model --dataset_location=/path/to/evaluation/dataset --mode=performance
bash run_benchmark.sh --input_model=./path/to/model --dataset_location=/path/to/evaluation/dataset --mode=accuracy
```

This file was deleted.

This file was deleted.