diff --git a/.azure-pipelines/model-test.yml b/.azure-pipelines/model-test.yml index 270a245bb65..8e7fd29ac28 100644 --- a/.azure-pipelines/model-test.yml +++ b/.azure-pipelines/model-test.yml @@ -10,6 +10,7 @@ pr: include: - neural_compressor - setup.py + - examples/tensorflow/oob_models/quantization/ptq exclude: - neural_compressor/ux diff --git a/.azure-pipelines/scripts/models/env_setup.sh b/.azure-pipelines/scripts/models/env_setup.sh index 06d2f03b680..1fb4ef7fe31 100644 --- a/.azure-pipelines/scripts/models/env_setup.sh +++ b/.azure-pipelines/scripts/models/env_setup.sh @@ -37,6 +37,9 @@ for i in "$@"; do --new_benchmark=*) new_benchmark=$(echo $i | sed "s/${PATTERN}//") ;; + --inc_new_api=*) + inc_new_api=$(echo $i | sed "s/${PATTERN}//") + ;; *) echo "Parameter $i not recognized." exit 1 @@ -61,7 +64,19 @@ fi $BOLD_YELLOW && echo "====== install requirements ======" && $RESET /bin/bash /neural-compressor/.azure-pipelines/scripts/install_nc.sh -cd ${WORK_SOURCE_DIR}/${model_src_dir} +cd ${WORK_SOURCE_DIR} +if [[ "${inc_new_api}" == "false" ]]; then + echo "copy old api examples to workspace..." + git clone -b old_api_examples https://github.com/intel/neural-compressor.git old-lpot-models + cd old-lpot-models + git branch + cd - + rm -rf ${model_src_dir} + mkdir -p ${model_src_dir} + cp -r old-lpot-models/examples/${framework}/${model_src_dir} ${WORK_SOURCE_DIR}/${model_src_dir}/../ +fi + +cd ${model_src_dir} pip install ruamel_yaml pip install psutil pip install protobuf==3.20.1 @@ -113,16 +128,18 @@ else $BOLD_RED && echo "Not found requirements.txt file." && $RESET fi -$BOLD_YELLOW && echo "======== update yaml config ========" && $RESET -$BOLD_YELLOW && echo -e "\nPrint origin yaml..." && $RESET -cat ${yaml} -python ${SCRIPTS_PATH}/update_yaml_config.py \ - --yaml=${yaml} \ - --framework=${framework} \ - --dataset_location=${dataset_location} \ - --batch_size=${batch_size} \ - --strategy=${strategy} \ - --new_benchmark=${new_benchmark} \ - --multi_instance='true' -$BOLD_YELLOW && echo -e "\nPrint updated yaml... " && $RESET -cat ${yaml} +if [[ "${inc_new_api}" == "false" ]]; then + $BOLD_YELLOW && echo "======== update yaml config ========" && $RESET + $BOLD_YELLOW && echo -e "\nPrint origin yaml..." && $RESET + cat ${yaml} + python ${SCRIPTS_PATH}/update_yaml_config.py \ + --yaml=${yaml} \ + --framework=${framework} \ + --dataset_location=${dataset_location} \ + --batch_size=${batch_size} \ + --strategy=${strategy} \ + --new_benchmark=${new_benchmark} \ + --multi_instance='true' + $BOLD_YELLOW && echo -e "\nPrint updated yaml... " && $RESET + cat ${yaml} +fi diff --git a/.azure-pipelines/scripts/models/run_model_trigger_common.sh b/.azure-pipelines/scripts/models/run_model_trigger_common.sh index a1e6719c583..88b20ba258c 100644 --- a/.azure-pipelines/scripts/models/run_model_trigger_common.sh +++ b/.azure-pipelines/scripts/models/run_model_trigger_common.sh @@ -29,6 +29,8 @@ do strategy=`echo $i | sed "s/${PATTERN}//"`;; --new_benchmark=*) new_benchmark=`echo $i | sed "s/${PATTERN}//"`;; + --inc_new_api=*) + inc_new_api=`echo $i | sed "s/${PATTERN}//"`;; --tuning_cmd=*) tuning_cmd=`echo $i | sed "s/${PATTERN}//"`;; --benchmark_cmd=*) @@ -62,7 +64,8 @@ if [ "${mode}" == "env_setup" ]; then --dataset_location=${dataset_location} \ --batch_size=${batch_size} \ --strategy=${strategy} \ - --new_benchmark=${new_benchmark} + --new_benchmark=${new_benchmark} \ + --inc_new_api="${inc_new_api}" elif [ "${mode}" == "tuning" ]; then cd ${WORK_SOURCE_DIR}/${model_src_dir} $BOLD_YELLOW && echo "workspace ${WORK_SOURCE_DIR}/${model_src_dir}" && $RESET diff --git a/.azure-pipelines/scripts/models/run_mxnet_models_trigger.sh b/.azure-pipelines/scripts/models/run_mxnet_models_trigger.sh index 7d97a35d95e..907326041b6 100644 --- a/.azure-pipelines/scripts/models/run_mxnet_models_trigger.sh +++ b/.azure-pipelines/scripts/models/run_mxnet_models_trigger.sh @@ -24,7 +24,7 @@ done FRAMEWORK="mxnet" FRAMEWORK_VERSION="1.9.1" - +inc_new_api=false # ======== set up config for mxnet models ======== if [ "${model}" == "resnet50v1" ]; then model_src_dir="image_recognition/cnn_models/quantization/ptq" diff --git a/.azure-pipelines/scripts/models/run_onnxrt_models_trigger.sh b/.azure-pipelines/scripts/models/run_onnxrt_models_trigger.sh index 112888f07db..1ac594168f6 100644 --- a/.azure-pipelines/scripts/models/run_onnxrt_models_trigger.sh +++ b/.azure-pipelines/scripts/models/run_onnxrt_models_trigger.sh @@ -24,7 +24,7 @@ done FRAMEWORK="onnxrt" FRAMEWORK_VERSION="1.13.1" - +inc_new_api=false # ======== set up config for onnxrt models ======== if [ "${model}" == "resnet50-v1-12" ]; then model_src_dir="image_recognition/onnx_model_zoo/resnet50/quantization/ptq" @@ -82,6 +82,7 @@ fi --new_benchmark=${new_benchmark} \ --tuning_cmd="${tuning_cmd}" \ --benchmark_cmd="${benchmark_cmd}" \ + --inc_new_api="${inc_new_api}" \ --mode=${mode} \ --USE_TUNE_ACC=${USE_TUNE_ACC} \ --PERF_STABLE_CHECK=${PERF_STABLE_CHECK} \ diff --git a/.azure-pipelines/scripts/models/run_pytorch_models_trigger.sh b/.azure-pipelines/scripts/models/run_pytorch_models_trigger.sh index 30b5a0c8344..1953cd872db 100644 --- a/.azure-pipelines/scripts/models/run_pytorch_models_trigger.sh +++ b/.azure-pipelines/scripts/models/run_pytorch_models_trigger.sh @@ -25,7 +25,7 @@ FRAMEWORK="pytorch" FRAMEWORK_VERSION="1.12.0+cpu" TORCH_VISION_VERSION="0.13.0+cpu" - +inc_new_api=false # ======== set up config for pytorch models ======== if [ "${model}" == "resnet18" ]; then model_src_dir="image_recognition/torchvision_models/quantization/ptq/cpu/eager" @@ -64,6 +64,7 @@ fi --new_benchmark=${new_benchmark} \ --tuning_cmd="${tuning_cmd}" \ --benchmark_cmd="${benchmark_cmd}" \ + --inc_new_api="${inc_new_api}" \ --mode=${mode} \ --USE_TUNE_ACC=${USE_TUNE_ACC} \ --PERF_STABLE_CHECK=${PERF_STABLE_CHECK} \ diff --git a/.azure-pipelines/scripts/models/run_tensorflow_models_trigger.sh b/.azure-pipelines/scripts/models/run_tensorflow_models_trigger.sh index 92d6735eae6..adaba1b739d 100644 --- a/.azure-pipelines/scripts/models/run_tensorflow_models_trigger.sh +++ b/.azure-pipelines/scripts/models/run_tensorflow_models_trigger.sh @@ -24,6 +24,7 @@ done FRAMEWORK="tensorflow" FRAMEWORK_VERSION="2.10.0" +inc_new_api=false # ======== set up config for tensorflow models ======== if [ "${model}" == "resnet50v1.5" ]; then model_src_dir="image_recognition/tensorflow_models/quantization/ptq" @@ -83,8 +84,9 @@ elif [ "${model}" == "darknet19" ]; then strategy="basic" batch_size=1 new_benchmark=false - tuning_cmd="bash run_tuning.sh --topology=${model} --dataset_location= --input_model=${input_model}" - benchmark_cmd="bash run_benchmark.sh --topology=${model} --dataset_location= --mode=benchmark --batch_size=1 --iters=500" + inc_new_api=true + tuning_cmd="bash run_tuning.sh --topology=${model} --input_model=${input_model}" + benchmark_cmd="bash run_benchmark.sh --topology=${model} --mode=performance --batch_size=1 --iters=500" elif [ "${model}" == "densenet-121" ]; then model_src_dir="oob_models/quantization/ptq" dataset_location="" @@ -93,8 +95,9 @@ elif [ "${model}" == "densenet-121" ]; then strategy="basic" batch_size=1 new_benchmark=false - tuning_cmd="bash run_tuning.sh --topology=${model} --dataset_location= --input_model=${input_model}" - benchmark_cmd="bash run_benchmark.sh --topology=${model} --dataset_location= --mode=benchmark --batch_size=1 --iters=500" + inc_new_api=true + tuning_cmd="bash run_tuning.sh --topology=${model} --input_model=${input_model}" + benchmark_cmd="bash run_benchmark.sh --topology=${model} --mode=performance --batch_size=1 --iters=500" elif [ "${model}" == "resnet-101" ]; then model_src_dir="oob_models/quantization/ptq" dataset_location="" @@ -103,8 +106,9 @@ elif [ "${model}" == "resnet-101" ]; then strategy="basic" batch_size=1 new_benchmark=false - tuning_cmd="bash run_tuning.sh --topology=${model} --dataset_location= --input_model=${input_model}" - benchmark_cmd="bash run_benchmark.sh --topology=${model} --dataset_location= --mode=benchmark --batch_size=1 --iters=500" + inc_new_api=true + tuning_cmd="bash run_tuning.sh --topology=${model} --input_model=${input_model}" + benchmark_cmd="bash run_benchmark.sh --topology=${model} --mode=performance --batch_size=1 --iters=500" elif [ "${model}" == "resnet50_fashion" ]; then model_src_dir="image_recognition/keras_models/resnet50_fashion/quantization/ptq" dataset_location="/tf_dataset2/datasets/mnist/FashionMNIST_small" @@ -131,6 +135,7 @@ fi --new_benchmark=${new_benchmark} \ --tuning_cmd="${tuning_cmd}" \ --benchmark_cmd="${benchmark_cmd}" \ + --inc_new_api="${inc_new_api}" \ --mode=${mode} \ --USE_TUNE_ACC=${USE_TUNE_ACC} \ --PERF_STABLE_CHECK=${PERF_STABLE_CHECK} \ diff --git a/examples/.config/model_params_tensorflow.json b/examples/.config/model_params_tensorflow.json index 22b9064ee55..05cb683d122 100644 --- a/examples/.config/model_params_tensorflow.json +++ b/examples/.config/model_params_tensorflow.json @@ -523,10 +523,8 @@ "model_src_dir": "recommendation/wide_deep_large_ds/quantization/ptq", "dataset_location": "/tf_dataset/tensorflow/wide_deep_large_ds/dataset", "input_model": "/tf_dataset/tensorflow/wide_deep_large_ds/fp32_optimized_graph.pb", - "yaml": "wide_deep_large_ds.yaml", - "strategy": "basic", - "batch_size": 256, - "new_benchmark": false + "main_script": "inference.py", + "batch_size": 256 }, "style_transfer": { "model_src_dir": "style_transfer/arbitrary_style_transfer/quantization/ptq", @@ -586,395 +584,308 @@ "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/AIPG_trained/text_classification/vdcnn/agnews/tf/aipg-vdcnn.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "arttrack-coco-multi": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/human_pose_estimation/arttrack/coco/tf/arttrack-coco-multi.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "arttrack-mpii-single": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/human_pose_estimation/arttrack/mpii/tf/arttrack-mpii-single.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "ava-face-recognition-3_0_0": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/Security/feature_extraction/ava/tf/ava-face-recognition-3.0.0.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "ava-person-vehicle-detection-stage2-2_0_0": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/Security/object_detection/common/ava/stage2/tf/ava-person-vehicle-detection-stage2-2.0.0.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "bert-base-uncased_L-12_H-768_A-12": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/language_representation/bert/base/uncased_L-12_H-768_A-12/tf/bert-base-uncased_L-12_H-768_A-12.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "darknet19": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicInHouse/classification/darknet19/darknet19.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "darknet53": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicInHouse/classification/darknet53/darknet53.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "deeplabv3": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/semantic_segmentation/deeplab/v3/deeplabv3.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "deepvariant_wgs": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/dna_sequencing/deepvariant/wgs/deepvariant_wgs.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "densenet-121": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/densenet/121/tf/densenet-121.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "densenet-161": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/densenet/161/tf/densenet-161.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "densenet-169": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/densenet/169/tf/densenet-169.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "east_resnet_v1_50": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/text_detection/east/tf/east_resnet_v1_50.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "efficientnet-b0": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/efficientnet/b0/tf/efficientnet-b0.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "efficientnet-b0_auto_aug": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/efficientnet/b0_auto_aug/tf/efficientnet-b0_auto_aug.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "efficientnet-b5": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/efficientnet/b5/tf/efficientnet-b5.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "facenet-20180408-102900": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/face_recognition/facenet/CASIA-WebFace/tf/facenet-20180408-102900.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "faster_rcnn_inception_v2_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/common/faster_rcnn/faster_rcnn_inception_v2_coco/tf/faster_rcnn_inception_v2_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "faster_rcnn_resnet101_ava_v2_1": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ckpt/faster_rcnn_resnet101_ava_v2/faster_rcnn_resnet101_ava_v2.1_2018_04_30/frozen_inference_graph.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "faster_rcnn_resnet101_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/common/faster_rcnn/faster_rcnn_resnet101_coco/tf/faster_rcnn_resnet101_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "faster_rcnn_resnet101_kitti": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ckpt/faster_rcnn_resnet101_kitti_2018_01_28/faster_rcnn_resnet101_kitti_2018_01_28/faster_rcnn_resnet101_kitti.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "faster_rcnn_resnet101_lowproposals_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ckpt/faster_rcnn_resnet101_lowproposals_coco_2018_01_28/faster_rcnn_resnet101_lowproposals_coco_2018_01_28/faster_rcnn_resnet101_lowproposals_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "faster_rcnn_resnet50_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/common/faster_rcnn/faster_rcnn_resnet50_coco/tf/faster_rcnn_resnet50_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "faster_rcnn_resnet50_lowproposals_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/common/faster_rcnn/faster_rcnn_resnet50_lowproposals_coco/tf/faster_rcnn_resnet50_lowproposals_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "googlenet-v1": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/googlenet/v1/tf/googlenet-v1.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "googlenet-v2": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/googlenet/v2/tf/googlenet-v2.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "googlenet-v3": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/googlenet/v3/tf/googlenet-v3.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "googlenet-v4": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/googlenet/v4/tf/googlenet-v4.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "Hierarchical_LSTM": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/Hierarchical/text8_freeze.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "image-retrieval-0001": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/image-retrieval-0001/image-retrieval-0001.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "inceptionv2_ssd": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/common/ssd_inceptionv2/tf/inceptionv2_ssd.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "3d-pose-baseline": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/human_pose_estimation/3d-pose-baseline/tf/3d-pose-baseline.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "cpm-person": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/human_pose_estimation/cpm/person/tf/cpm-person.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "ctpn": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/text_detection/ctpn/tf/ctpn.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "DSSD_12": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicInHouse/object_detection/common/dssd/DSSD_12/tf/DSSD_12.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "efficientnet-b7_auto_aug": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/efficientnet/b7_auto_aug/tf/efficientnet-b7_auto_aug.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "faster_rcnn_resnet101_fgvc": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ckpt/faster_rcnn_resnet101_fgvc_2018_07_19/faster_rcnn_resnet101_fgvc_2018_07_19/faster_rcnn_resnet101_fgvc.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "faster_rcnn_resnet50_fgvc": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ckpt/faster_rcnn_resnet50_fgvc_2018_07_19/faster_rcnn_resnet50_fgvc_2018_07_19/faster_rcnn_resnet50_fgvc.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "handwritten-score-recognition-0003": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/Retail//handwritten-score-recognition/0003/tf/handwritten-score-recognition-0003.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "HugeCTR": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/HugeCTR/HugeCTR.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "i3d-flow": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/action_recognition/i3d/flow/tf/i3d-flow.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "i3d-rgb": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/action_recognition/i3d/rgb/tf/i3d-rgb.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "icnet-camvid-ava-0001": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicCompressed/semantic_segmentation/icnet-camvid-tf-ws00/icnet-camvid-ava-0001.pb", - "yaml": "config.yaml", - "strategy": "basic", + "main_script": "tf_benchmark.py", "batch_size": 16, "new_benchmark": false }, @@ -982,8 +893,7 @@ "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicCompressed/semantic_segmentation/icnet-camvid-tf-ws30/icnet-camvid-ava-sparse-30-0001.pb", - "yaml": "config.yaml", - "strategy": "basic", + "main_script": "tf_benchmark.py", "batch_size": 16, "new_benchmark": false }, @@ -991,8 +901,7 @@ "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicCompressed/semantic_segmentation/icnet-camvid-tf-ws60/icnet-camvid-ava-sparse-60-0001.pb", - "yaml": "config.yaml", - "strategy": "basic", + "main_script": "tf_benchmark.py", "batch_size": 16, "new_benchmark": false }, @@ -1000,937 +909,729 @@ "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/Retail/object_attributes/emotions_recognition/0002/tf/icv-emotions-recognition-0002.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "inception-resnet-v2": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/inception-resnet/v2/tf/inception-resnet-v2.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "intel-labs-nonlocal-dehazing": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/IntelLabs/FastImageProcessing/NonlocalDehazing/intel-labs-nonlocal-dehazing.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 100 }, "learning-to-see-in-the-dark-fuji": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/IntelLabs/LearningToSeeInTheDark/Fuji/learning-to-see-in-the-dark-fuji.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "learning-to-see-in-the-dark-sony": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/IntelLabs/LearningToSeeInTheDark/Sony/learning-to-see-in-the-dark-sony.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "license-plate-recognition-barrier-0007": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/optical_character_recognition/license_plate_recognition/tf/license-plate-recognition-barrier-0007.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "mask_rcnn_inception_v2_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/instance_segmentation/mask_rcnn/mask_rcnn_inception_v2_coco/tf/mask_rcnn_inception_v2_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "nasnet-a-large-331": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/nasnet/large/tf/nasnet-a-large-331.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "nasnet-a-mobile-224": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/nasnet/mobile/tf/nasnet-a-mobile-224.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "openpose-pose": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/human_pose_estimation/openpose/pose/tf/openpose-pose.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "optical_character_recognition-text_recognition-tf": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/optical_character_recognition/text_recognition/tf/optical_character_recognition-text_recognition-tf.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "person-vehicle-bike-detection-crossroad-yolov3-1020": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/Security/object_detection/crossroad/1020/tf/person-vehicle-bike-detection-crossroad-yolov3-1020.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "PRNet": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/face_reconstruction/PRNet/tf/PRNet.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "resnet-101": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/resnet/v1/101/tf/resnet-101.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "resnet-152": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/resnet/v1/152/tf/resnet-152.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "resnet-50": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/resnet/v1/50/tf/official/resnet-50.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "resnet-v2-101": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/resnet/v2/101/tf/resnet-v2-101.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "resnet-v2-152": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/resnet/v2/152/tf/resnet-v2-152.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "resnet-v2-50": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/resnet/v2/50/tf/224x224/resnet-v2-50.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "resnet_v2_200": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/Resnet_v2_200/Resnet_v2_200.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "retinanet": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/common/retinanet/tf/retinanet.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "rfcn-resnet101-coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/common/rfcn/rfcn_resnet101_coco/tf/rfcn-resnet101-coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "rmnet_ssd": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/Retail//action_detection/pedestrian/rmnet_ssd/0028_tf/tf/rmnet_ssd.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "squeezenet1_1": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/squeezenet/1.1/tf/squeezenet1_1.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ssd_inception_v2_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ckpt/ssd_inception_v2_coco_2018_01_28/ssd_inception_v2_coco_2018_01_28/ssd_inception_v2_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ssd_resnet50_v1_fpn_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/common/ssd_resnet50/ssd_resnet50_v1_fpn_coco/tf/ssd_resnet50_v1_fpn_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ssd_resnet34_300x300": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ckpt/ssd-resnet34_300x300/ssd_resnet34_300x300.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "TCN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicInHouse/sequence_modelling/tcn/tf/TCN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "text-recognition-0012": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/Retail//text_recognition/bilstm_crnn_bilstm_decoder/0012/tf/text-recognition-0012.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "tiny_yolo_v1": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicInHouse/object_detection/common/yolo/v1_tiny/tf/tiny_yolo_v1.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "tiny_yolo_v2": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicInHouse/object_detection/common/yolo/v2_tiny/tf/tiny_yolo_v2.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "vehicle-attributes-barrier-0103": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_attributes/vehicle_attributes/tf/vehicle-attributes-barrier-0103.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "vehicle-license-plate-detection-barrier-0123": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/barrier/tf/0123/vehicle-license-plate-detection-barrier-0123.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "vgg16-oob": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/vgg/16/tf/vgg16.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "vgg19-oob": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/classification/vgg/19/tf/vgg19.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "vggvox": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/voice_recognition/vggvox/vggvox.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "yolo-v3-tiny": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/yolo/yolo_v3/yolo-v3-tiny/yolo-v3-tiny-tf/yolo-v3-tiny.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "yolo-v2": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/yolo/yolo_v2/tf/yolo-v2.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "yolo-v2-ava-sparse-35-0001": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicCompressed/detection/YOLOv2/fp32_sparsity35/yolo-v2-ava-sparse-35-0001.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "yolo-v2-ava-sparse-70-0001": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicCompressed/detection/YOLOv2/fp32_sparsity70/yolo-v2-ava-sparse-70-0001.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "yolo-v2-tiny-ava-0001": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicCompressed/detection/tinyYOLOv2/fp32_sparsity00/yolo-v2-tiny-ava-0001.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "yolo-v2-tiny-ava-sparse-30-0001": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicCompressed/detection/tinyYOLOv2/fp32_sparsity30/yolo-v2-tiny-ava-sparse-30-0001.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "yolo-v2-tiny-ava-sparse-60-0001": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicCompressed/detection/tinyYOLOv2/fp32_sparsity60/yolo-v2-tiny-ava-sparse-60-0001.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "yolo-v2-tiny-vehicle-detection-0001": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/Security/object_detection/barrier/yolo/yolo-v2-tiny-vehicle-detection-0001/tf/yolo-v2-tiny-vehicle-detection-0001.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "yolo-v3": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/yolo/yolo_v3/tf/yolo-v3.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "DeepLab": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/deeplabv3_mnv2_cityscapes_train/deeplab.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "GraphSage": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/GraphSage/GraphSage.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "WGAN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/oob_gan_models/WGAN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "Vnet": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/vnet/vnet.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "DRAW": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/DRAW/DRAW.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ALBERT": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/ALBERT/ALBERT.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "BERT_BASE": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/BERT_BASE/BERT_BASE.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "BERT_LARGE": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/BERT_LARGE/BERT_LARGE.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "CapsuleNet": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/CapsuleNet/CapsuleNet.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "CharCNN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/CharCNN/CharCNN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "CRNN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/CRNN/crnn.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "DIEN_Deep-Interest-Evolution-Network": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/DIEN/dien.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "dense_vnet_abdominal_ct": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/semantic_segmentation/dense_vnet/tf/dense_vnet_abdominal_ct.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "dilation": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/Dilation/dilation.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "faster_rcnn_inception_resnet_v2_atrous_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/common/faster_rcnn/faster_rcnn_inception_resnet_v2_atrous_coco/tf/faster_rcnn_inception_resnet_v2_atrous_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "faster_rcnn_inception_resnet_v2_atrous_lowproposals_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ckpt/faster_rcnn_inception_resnet_v2_atrous_lowproposals_coco_2018_01_28/faster_rcnn_inception_resnet_v2_atrous_lowproposals_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "faster_rcnn_nas_coco_2018_01_28": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ckpt/faster_rcnn_nas_coco_2018_01_28/faster_rcnn_nas_coco_2018_01_28.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "faster_rcnn_nas_lowproposals_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/object_detection/common/faster_rcnn/faster_rcnn_nas_lowproposals_coco/tf/faster_rcnn_nas_lowproposals_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "GAN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/oob_gan_models/GAN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "gmcnn-places2": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/image_inpainting/gmcnn/tf/gmcnn-places2.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "LSGAN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/oob_gan_models/LSGAN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "mask_rcnn_inception_resnet_v2_atrous_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/instance_segmentation/mask_rcnn/mask_rcnn_inception_resnet_v2_atrous_coco/tf/mask_rcnn_inception_resnet_v2_atrous_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "NCF-1B": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/ncf_trained_movielens_1m/NCF-1B.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "R-FCN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/R-FCN/rfcn_resnet101_coco_2018_01_28/R-FCN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "TextCNN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/TextCNN/TextCNN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "TextRNN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/TextRNN/TextRNN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "Transformer-LT": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/transformer_lt_official_fp32_pretrained_model/graph/Transformer-LT.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ACGAN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/oob_gan_models/ACGAN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "BEGAN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/oob_gan_models/BEGAN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "CGAN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/oob_gan_models/CGAN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "DRAGAN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/oob_gan_models/DRAGAN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "EBGAN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/oob_gan_models/EBGAN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "infoGAN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/oob_gan_models/infoGAN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "mask_rcnn_resnet101_atrous_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/instance_segmentation/mask_rcnn/mask_rcnn_resnet101_atrous_coco/tf/mask_rcnn_resnet101_atrous_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "mask_rcnn_resnet50_atrous_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/instance_segmentation/mask_rcnn/mask_rcnn_resnet50_atrous_coco/tf/mask_rcnn_resnet50_atrous_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "person-vehicle-bike-detection-crossroad-yolov3-1024": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/Security/object_detection/crossroad/1024/tf/person-vehicle-bike-detection-crossroad-yolov3-1024.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "srgan": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/image_processing/srgan/tf/srgan.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ssd_resnet34_fp32_1200x1200_pretrained_model": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/SSD-ResNet34_1200x1200/ssd_resnet34_fp32_1200x1200_pretrained_model.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "unet-3d-isensee_2017": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicInHouse/volumetric_segmentation/unet/3d/isensee_2017/tf/unet-3d-isensee_2017.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "unet-3d-origin": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/PublicInHouse/volumetric_segmentation/unet/3d/origin/tf/unet-3d-origin.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "WGAN_GP": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/oob_gan_models/WGAN_GP.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "wide_deep": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/wide_deep/wide_deep.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "DynamicMemory": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/checkpoint_dynamic_memory_network/DynamicMemory.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "EntityNet": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/checkpoint_entity_network2/EntityNet.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "Seq2seqAttn": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/Seq2seqAttn/Seq2seqAttn.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "show_and_tell": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/show_and_tell/Show_and_tell.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "SqueezeNet": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/SqueezeNet-tf/SqueezeNet.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ssd_resnet34_1200x1200": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/ssd_resnet34_model/ssd_resnet34_1200x1200.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "deepspeech": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/speech_to_text/deepspeech/v1/tf/deepspeech.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "TextRCNN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/TextRCNN/TextRCNN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "U-Net": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/unet/unet.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "wavenet": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/wavenet/wavenet.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "HierAtteNet": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/checkpoint_hier_atten_title/text_hier_atten_title_desc_checkpoint_MHA/HierAtteNet.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "SphereFace": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/SphereFace/SphereFace.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ResNet-50_v1_5": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/ResNet50_v1_5/model_dir/ResNet-50_v1.5.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ResNeXt_50": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/ResNext_50/ResNext_50.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "MiniGo": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/MiniGo/MiniGo.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ResNeXt_101": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/ResNext_101/ResNext_101.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "COVID-Net": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/COVID-Net/COVID-Net.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "mnist_keras": { "model_src_dir": "image_recognition/keras_models/mnist/quantization/qat", @@ -1977,470 +1678,366 @@ "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/3D-Unet/3DUNet.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "adv_inception_v3": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/adv_inception_v3/adv_inception_v3.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "CenterNet": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/CenterNet/CenterNet.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "context_rcnn_resnet101_snapshot_serenget": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ckpt/context_rcnn_resnet101_snapshot_serengeti_2020_06_10/context_rcnn_resnet101_snapshot_serenget.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "EfficientDet-D0-512x512": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/EfficientDet/efficientdet-d0/EfficientDet-D0-512x512.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "EfficientDet-D1-640x640": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/EfficientDet/efficientdet-d1/EfficientDet-D1-640x640.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "EfficientDet-D2-768x768": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/EfficientDet/efficientdet-d2/EfficientDet-D2-768x768.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "EfficientDet-D3-896x896": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/EfficientDet/efficientdet-d3/EfficientDet-D3-896x896.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "EfficientDet-D4-1024x1024": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/EfficientDet/efficientdet-d4/EfficientDet-D4-1024x1024.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "EfficientDet-D5-1280x1280": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/EfficientDet/efficientdet-d5/EfficientDet-D5-1280x1280.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "EfficientDet-D6-1280x1280": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/EfficientDet/efficientdet-d6/EfficientDet-D6-1280x1280.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "EfficientDet-D7-1536x1536": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/EfficientDet/efficientdet-d7/EfficientDet-D7-1536x1536.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ens3_adv_inception_v3": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/ens3_inception_v3/ens3_adv_inception_v3.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "Evolution_ensemble": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/simple_net/Evolution_ensemble.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "faster_rcnn_inception_resnet_v2_atrous_lowproposals_oid": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/faster_rcnn_inception_resnet_v2_atrous_lowproposals_oid/faster_rcnn_inception_resnet_v2_atrous_lowproposals_oid.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "faster_rcnn_inception_resnet_v2_atrous_oid": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/faster_rcnn_inception_resnet_v2_atrous_oid/faster_rcnn_inception_resnet_v2_atrous_oid.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "faster_rcnn_resnet101_snapshot_serengeti": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/faster_rcnn_resnet101_snapshot_serengeti/faster_rcnn_resnet101_snapshot_serengeti.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "key-value-memory-networks": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/key-value-memory-networks/key-value-memory-networks.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "MANN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/MANN/MANN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "NCF": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/NCF/NCF.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "NetVLAD": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/NetVLAD/NetVLAD.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "NeuMF": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/NeuMF/NeuMF.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ssd_mobilenet_v1_0_75_depth_300x300_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/ssd_mobilenet_v1_0.75_depth_300x300_coco/ssd_mobilenet_v1_0.75_depth_300x300_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ssd_mobilenet_v1_ppn_shared_box_predictor_300x300_coco": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/ssd_mobilenet_v1_ppn_shared_box_predictor_300x300_coco/ssd_mobilenet_v1_ppn_shared_box_predictor_300x300_coco.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ssd_resnet_101_fpn_oidv4": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ckpt/ssd_resnet101_v1_fpn/ssd_resnet_101_fpn_oidv4.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "SSD_ResNet50_V1_FPN_640x640_RetinaNet50": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ckpt/ssd_resnet50_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03/ssd_resnet50_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03/SSD_ResNet50_V1_FPN_640x640_RetinaNet50.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "vehicle-license-plate-detection-barrier-0106": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/vehicle-license-plate-detection-barrier-0106/vehicle-license-plate-detection-barrier-0106.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "YOLOv4": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/yolov4/YOLOv4.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "CBAM": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/CBAM/CBAM.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "NTM-One-Shot": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/NTM-One-Shot/model/NTM-One-Shot.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "KeypointNet": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/keypoint/KeypointNet.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "DCGAN": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/dcgan/DCGAN.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "pose-ae-multiperson": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/human_pose_estimation/pose-ae/multiperson/tf/pose-ae-multiperson.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "pose-ae-refinement": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ov/all_tf_models/human_pose_estimation/pose-ae/refinement/tf/pose-ae-refinement.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "WD": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/WD/wide_deep_saved_models/", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ResNest50": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/ResNest/ResNest50/", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ResNest101": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/ResNest/ResNest101/", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "ResNest50-3D": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/ResNest/ResNest50-3D/", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "GPT2": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/GPT-2/gpt-2/models/124M/GPT_2_124M-Generated_LPOT_OOB_Model/", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "Attention_OCR": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/attention_ocr/model.ckpt-399731_freeze.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "DLRM": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/DLRM/DLRM-Generated_LPOT_OOB_Model.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "centernet_hg104": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/ckpt/centernet_hg104_1024x1024_coco17/saved_model/", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "DETR": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/DETR/DETR.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "Elmo": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/elmo/model/elmo.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "Time_series_LSTM": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/time_series_LSTM/time_series_lstm.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "Unet": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/oob/Unet/checkpoint/", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "adversarial_text": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/mlp/adversarial_text/imdb_pretrain/model.ckpt-1135_freeze.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "AttRec": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/AttRec/AttRec.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "Parallel_WaveNet": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/Parallel_WaveNet/", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "PNASNet-5": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/PNASNet-5/model/", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "VAE-CF": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/VAE-CF/data/binary/ml_20m/", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "Deep_Speech_2": { "model_src_dir": "oob_models/quantization/ptq", "dataset_location": "", "input_model": "/tf_dataset/tensorflow/tf_oob_models/dpg/Deep_Speech2/Deep_Speech_2-Generated_LPOT_OOB_Model.pb", - "yaml": "config.yaml", - "strategy": "basic", - "batch_size": 1, - "new_benchmark": false + "main_script": "tf_benchmark.py", + "batch_size": 1 }, "yolo_v3": { "model_src_dir": "object_detection/yolo_v3/quantization/ptq", @@ -2455,10 +2052,8 @@ "model_src_dir": "semantic_image_segmentation/3dunet-mlperf/quantization/ptq", "dataset_location": "/tf_dataset2/models/tensorflow/3dunet/build", "input_model": "/tf_dataset2/models/tensorflow/3dunet/3dunet_dynamic_ndhwc.pb", - "yaml": "3dunet-mlperf.yaml", - "strategy": "basic", - "batch_size": 100, - "new_benchmark": false + "main_script": "run_accuracy.py", + "batch_size": 100 }, "transformer_lt_mlperf": { "model_src_dir": "nlp/transformer_lt_mlperf/quantization/ptq", diff --git a/examples/README.md b/examples/README.md index 5060651251e..d3e1f2526d3 100644 --- a/examples/README.md +++ b/examples/README.md @@ -36,175 +36,175 @@ Intel® Neural Compressor validated examples with multiple compression technique ResNet50 V1.0 Image Recognition Post-Training Static Quantization - pb + pb ResNet50 V1.5 Image Recognition Post-Training Static Quantization - pb + pb ResNet101 Image Recognition Post-Training Static Quantization - pb + pb MobileNet V1 Image Recognition Post-Training Static Quantization - pb + pb MobileNet V2 Image Recognition Post-Training Static Quantization - pb / keras + pb / keras MobileNet V3 Image Recognition Post-Training Static Quantization - pb + pb Inception V1 Image Recognition Post-Training Static Quantization - pb + pb Inception V2 Image Recognition Post-Training Static Quantization - pb + pb Inception V3 Image Recognition Post-Training Static Quantization - pb + pb Inception V4 Image Recognition Post-Training Static Quantization - pb + pb Inception ResNet V2 Image Recognition Post-Training Static Quantization - pb + pb VGG16 Image Recognition Post-Training Static Quantization - pb / keras + pb / keras VGG19 Image Recognition Post-Training Static Quantization - pb / keras + pb / keras ResNet V2 50 Image Recognition Post-Training Static Quantization - pb / keras + pb / keras ResNet V2 101 Image Recognition Post-Training Static Quantization - pb / keras + pb / keras ResNet V2 152 Image Recognition Post-Training Static Quantization - pb + pb DenseNet121 Image Recognition Post-Training Static Quantization - pb + pb DenseNet161 Image Recognition Post-Training Static Quantization - pb + pb DenseNet169 Image Recognition Post-Training Static Quantization - pb + pb EfficientNet B0 Image Recognition Post-Training Static Quantization - ckpt + ckpt MNIST Image Recognition Quantization-Aware Training - keras + keras ResNet50 Image Recognition Post-Training Static Quantization - keras + keras ResNet50 Fashion Image Recognition Post-Training Static Quantization - keras + keras ResNet101 Image Recognition Post-Training Static Quantization - keras + keras Inception V3 Image Recognition Post-Training Static Quantization - keras + keras Inception Resnet V2 Image Recognition Post-Training Static Quantization - keras + keras Xception Image Recognition Post-Training Static Quantization - keras + keras ResNet V2 Image Recognition Quantization-Aware Training - keras + keras EfficientNet V2 B0 Image Recognition Post-Training Static Quantization - SavedModel + SavedModel BERT base MRPC @@ -216,13 +216,13 @@ Intel® Neural Compressor validated examples with multiple compression technique BERT large SQuAD (Model Zoo) Natural Language Processing Post-Training Static Quantization - pb + pb BERT large SQuAD Natural Language Processing Post-Training Static Quantization - pb + pb DistilBERT base @@ -246,49 +246,49 @@ Intel® Neural Compressor validated examples with multiple compression technique SSD ResNet50 V1 Object Detection Post-Training Static Quantization - pb / ckpt + pb / ckpt SSD MobileNet V1 Object Detection Post-Training Static Quantization - pb / ckpt + pb / ckpt Faster R-CNN Inception ResNet V2 Object Detection Post-Training Static Quantization - pb / SavedModel + pb / SavedModel Faster R-CNN ResNet101 Object Detection Post-Training Static Quantization - pb / SavedModel + pb / SavedModel Faster R-CNN ResNet50 Object Detection Post-Training Static Quantization - pb + pb Mask R-CNN Inception V2 Object Detection Post-Training Static Quantization - pb / ckpt + pb / ckpt SSD ResNet34 Object Detection Post-Training Static Quantization - pb + pb YOLOv3 Object Detection Post-Training Static Quantization - pb + pb Wide & Deep @@ -300,7 +300,7 @@ Intel® Neural Compressor validated examples with multiple compression technique Arbitrary Style Transfer Style Transfer Post-Training Static Quantization - ckpt + ckpt @@ -322,21 +322,21 @@ Intel® Neural Compressor validated examples with multiple compression technique Image Recognition Unstructured Magnitude - pb + pb ResNet V2 Image Recognition Unstructured Magnitude - pb + pb ViT Image Recognition Unstructured Magnitude - ckpt + ckpt @@ -358,7 +358,7 @@ Intel® Neural Compressor validated examples with multiple compression technique DenseNet201 Image Recognition Knowledge Distillation - pb + pb diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/README.md b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/README.md deleted file mode 100644 index 1c9b6b455d9..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/README.md +++ /dev/null @@ -1,277 +0,0 @@ -Step-by-Step -============ - -This document is used to list steps of reproducing TensorFlow Object Detection models tuning results. This example can run on Intel CPUs and GPUs. -Currently, we've enabled below models. - * ssd_resnet50_v1 - * ssd_resnet34 - * ssd_mobilenet_v1 - * fastrcnn_inception_resnet_v2 - * fastrcnn_resnet101 - * fastrcnn_resnet50 - * maskrcnn_inception_v2 -## Prerequisite - - -### 1. Installation -Recommend python 3.6 or higher version. - -```shell -# Install Intel® Neural Compressor -pip install neural-compressor -``` - -### 2. Install Intel Tensorflow -```shell -pip install intel-tensorflow -``` -> Note: Supported Tensorflow [Version](../../../../../../README.md#supported-frameworks). - -### 3. Installation Dependency packages -```shell -cd examples/tensorflow/object_detection/tensorflow_models/quantization/ptq -pip install -r requirements.txt -``` - -### 4. Install Protocol Buffer Compiler - -`Protocol Buffer Compiler` in version higher than 3.0.0 is necessary ingredient for automatic COCO dataset preparation. To install please follow -[Protobuf installation instructions](https://grpc.io/docs/protoc-installation/#install-using-a-package-manager). - -### 5. Install Intel Extension for Tensorflow - -#### Quantizing the model on Intel GPU -Intel Extension for Tensorflow is mandatory to be installed for quantizing the model on Intel GPUs. - -```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) - -#### 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. - -```shell -pip install --upgrade intel-extension-for-tensorflow[cpu] -``` - -### 6. Prepare Dataset - -#### Automatic dataset download - -> **_Note: `prepare_dataset.sh` script works with TF version 1.x._** - -Run the `prepare_dataset.sh` script located in `examples/tensorflow/object_detection/tensorflow_models/quantization/ptq`. - -Usage: -```shell -cd examples/tensorflow/object_detection/tensorflow_models/quantization/ptq -. prepare_dataset.sh -``` - -This script will download the *train*, *validation* and *test* COCO datasets. Furthermore it will convert them to -tensorflow records using the `https://github.com/tensorflow/models.git` dedicated script. - -#### Manual dataset download -Download CoCo Dataset from [Official Website](https://cocodataset.org/#download). - -### 7. Download Model - -#### Automated approach -Run the `prepare_model.py` script located in `examples/tensorflow/object_detection/tensorflow_models/quantization/ptq`. - -``` -usage: prepare_model.py [-h] [--model_name {ssd_resnet50_v1,ssd_mobilenet_v1}] - [--model_path MODEL_PATH] - -Prepare pre-trained model for COCO object detection - -optional arguments: - -h, --help show this help message and exit - --model_name {ssd_resnet50_v1,ssd_mobilenet_v1} - model to download, default is ssd_resnet50_v1 - --model_path MODEL_PATH - directory to put models, default is ./model -``` - -#### Manual approach - -##### ssd_resnet50_v1 -```shell -wget http://download.tensorflow.org/models/object_detection/ssd_resnet50_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03.tar.gz -tar -xvzf ssd_resnet50_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03.tar.gz -C /tmp -``` - -##### ssd_mobilenet_V1 - -```shell -wget http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2018_01_28.tar.gz -tar -xvzf ssd_mobilenet_v1_coco_2018_01_28.tar.gz -``` - -##### faster_rcnn_inception_resnet_v2 - -```shell -wget http://download.tensorflow.org/models/object_detection/faster_rcnn_inception_v2_coco_2018_01_28.tar.gz -tar -xvzf faster_rcnn_inception_v2_coco_2018_01_28.tar.gz -``` - -##### faster_rcnn_resnet101 - -```shell -wget http://download.tensorflow.org/models/object_detection/faster_rcnn_resnet101_coco_2018_01_28.tar.gz -tar -xvzf faster_rcnn_resnet101_coco_2018_01_28.tar.gz -``` - -##### faster_rcnn_resnet50 - -```shell -wget https://storage.googleapis.com/intel-optimized-tensorflow/models/faster_rcnn_resnet50_fp32_coco_pretrained_model.tar.gz -tar -xvf faster_rcnn_resnet50_fp32_coco_pretrained_model.tar.gz -``` - -##### mask_rcnn_inception_v2 - -```shell -wget http://download.tensorflow.org/models/object_detection/mask_rcnn_inception_v2_coco_2018_01_28.tar.gz -tar -xvzf mask_rcnn_inception_v2_coco_2018_01_28.tar.gz -``` - -##### ssd_resnet34 -```shell -wget https://storage.googleapis.com/intel-optimized-tensorflow/models/v1_8/ssd_resnet34_fp32_1200x1200_pretrained_model.pb -``` -You need to install intel-tensorflow==2.4.0 to enable ssd_resnet34 model. - -## Run Command - -Now we support both pb and ckpt formats. - -### For PB model - - ```shell - # The cmd of running ssd_resnet50_v1 - bash run_tuning.sh --config=ssd_resnet50_v1.yaml --input_model=/tmp/ssd_resnet50_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03/frozen_inference_graph.pb --output_model=./tensorflow-ssd_resnet50_v1-tune.pb - ``` - -### For ckpt model - - ```shell - # The cmd of running ssd_resnet50_v1 - bash run_tuning.sh --config=ssd_resnet50_v1.yaml --input_model=/tmp/ssd_resnet50_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03/ --output_model=./tensorflow-ssd_resnet50_v1-tune.pb - ``` -> Note -> -> 1. Make sure to add dataset_location=/path/to/dataset/coco_val.record in config file: "ssd_resnet50_v1.yaml" -> -> 2. For ssd_resnet34 model, anno_path of evaluation/accuracy/metric/COCOmAP in config file should be "label_map.yaml" - -Details of enabling Intel® Neural Compressor on ssd_resnet50_v1 for Tensorflow. -========================= - -This is a tutorial of how to enable ssd_resnet50_v1 model with Intel® Neural Compressor. -## User Code Analysis -1. User specifies fp32 *model*, calibration dataset *q_dataloader*, evaluation dataset *eval_dataloader* and metric in tuning.metric field of model-specific yaml config file. - -2. User specifies fp32 *model*, calibration dataset *q_dataloader* and a custom *eval_func* which encapsulates the evaluation dataset and metric by itself. - -For ssd_resnet50_v1, we applied the latter one because our philosophy is to enable the model with minimal changes. Hence we need to make two changes on the original code. The first one is to implement the q_dataloader and make necessary changes to *eval_func*. - - -### q_dataloader Part Adaption -Specifically, we need to add one generator to iterate the dataset per Intel® Neural Compressor requirements. The easiest way is to implement *__iter__* interface. Below function will yield the images to feed the model as input. - -```python -def __iter__(self): - """Enable the generator for q_dataloader - - Yields: - [Tensor]: images - """ - data_graph = tf.Graph() - with data_graph.as_default(): - self.input_images, self.bbox, self.label, self.image_id = self.get_input( - ) - - self.data_sess = tf.compat.v1.Session(graph=data_graph, - config=self.config) - for i in range(COCO_NUM_VAL_IMAGES): - input_images = self.data_sess.run([self.input_images]) - yield input_images -``` - -### Evaluation Part Adaption -The Class model_infer has the run_accuracy function which actually could be re-used as the eval_func. - -Compare with the original version, we added the additional parameter **input_graph** as the Intel® Neural Compressor would call this interface with the graph to be evaluated. The following code snippet also need to be added into the run_accuracy function to update the class members like self.input_tensor and self.output_tensors. -```python -if input_graph: - graph_def = get_graph_def(self.args.input_graph, self.output_layers) - input_graph = tf.Graph() - with input_graph.as_default(): - tf.compat.v1.import_graph_def(graph_def, name='') - - self.infer_graph = input_graph - # Need to reset the input_tensor/output_tensor - self.input_tensor = self.infer_graph.get_tensor_by_name( - self.input_layer + ":0") - self.output_tensors = [ - self.infer_graph.get_tensor_by_name(x + ":0") - for x in self.output_layers - ] -``` - -### Write Yaml config file -In examples directory, there is a ssd_resnet50_v1.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 ssd_resnet50_v1_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. - -```yaml -model: # mandatory. used to specify model specific information. - name: ssd_resnet50_v1 - framework: tensorflow # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image_tensor - outputs: num_detections,detection_boxes,detection_scores,detection_classes - -device: cpu # optional. default value is cpu, other value is gpu. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 100 # optional. default value is 100. used to set how many samples should be used in calibration. - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - weight: - algorithm: minmax - op_wise: { - 'FeatureExtractor/resnet_v1_50/fpn/bottom_up_block5/Conv2D': { - 'activation': {'dtype': ['fp32']}, - }, - 'WeightSharedConvolutionalBoxPredictor_2/ClassPredictionTower/conv2d_0/Conv2D': { - 'activation': {'dtype': ['fp32']}, - } - } - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - max_trials: 100 # optional. max tune times. default value is 100. combine with timeout field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. -``` -Here we set the input tensor and output tensors name into *inputs* and *outputs* field. Meanwhile, we set mAp target as tolerating 0.01 relative mAp of baseline. The default tuning strategy is basic strategy. The timeout 0 means early stop as well as a tuning config meet accuracy target. - -### Code update - -After prepare step is done, we just need update infer_detections.py like below. -```python -from neural_compressor.experimental import Quantization,common - -quantizer = Quantization(args.config) -quantizer.model = common.Model(args.input_graph) -quantizer.calib_dataloader = infer -quantizer.eval_dataloader = infer -quantizer.eval_func = infer.accuracy_check -q_model = quantizer.fit() -``` - -The quantizer.fit() function will return a best quantized model during timeout constrain. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_inception_resnet_v2.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_inception_resnet_v2.yaml deleted file mode 100644 index 2452828cee3..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_inception_resnet_v2.yaml +++ /dev/null @@ -1,77 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: faster_rcnn_inception_resnet_v2 - framework: tensorflow # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image_tensor - outputs: num_detections,detection_boxes,detection_scores,detection_classes - -device: cpu # optional. default value is cpu, other value is gpu. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 10, 50, 100, 200 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 600 - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - weight: - granularity: per_tensor - algorithm: minmax - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAPv2: - output_index_mapping: - num_detections: 0 - boxes: 1 - scores: 2 - classes: 3 - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 600 - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - Resize: - size: 600 -tuning: - accuracy_criterion: - absolute: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_inception_resnet_v2_itex.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_inception_resnet_v2_itex.yaml deleted file mode 100644 index 24039f9700d..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_inception_resnet_v2_itex.yaml +++ /dev/null @@ -1,77 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: faster_rcnn_inception_resnet_v2 - framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image_tensor - outputs: num_detections,detection_boxes,detection_scores,detection_classes - -device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu]. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 10, 50, 100, 200 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 600 - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - weight: - granularity: per_tensor - algorithm: minmax - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAPv2: - output_index_mapping: - num_detections: 0 - boxes: 1 - scores: 2 - classes: 3 - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 600 - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - Resize: - size: 600 -tuning: - accuracy_criterion: - absolute: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_resnet101.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_resnet101.yaml deleted file mode 100644 index a879c83451d..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_resnet101.yaml +++ /dev/null @@ -1,71 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: faster_rcnn_resnet101 - framework: tensorflow # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image_tensor - outputs: num_detections,detection_boxes,detection_scores,detection_classes - -device: cpu # optional. default value is cpu, other value is gpu. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 10, 50, 100, 200 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 600 - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAPv2: - output_index_mapping: - num_detections: 0 - boxes: 1 - scores: 2 - classes: 3 - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 600 - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - Resize: - size: 600 -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_resnet101_itex.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_resnet101_itex.yaml deleted file mode 100644 index e7ab49ab0dc..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_resnet101_itex.yaml +++ /dev/null @@ -1,71 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: faster_rcnn_resnet101 - framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image_tensor - outputs: num_detections,detection_boxes,detection_scores,detection_classes - -device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu]. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 10, 50, 100, 200 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 600 - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAPv2: - output_index_mapping: - num_detections: 0 - boxes: 1 - scores: 2 - classes: 3 - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 600 - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - Resize: - size: 600 -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_resnet50.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_resnet50.yaml deleted file mode 100644 index 91f07504f4a..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_resnet50.yaml +++ /dev/null @@ -1,73 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -version: 1.0 - -model: # mandatory. used to specify model specific information. - name: faster_rcnn_resnet50 - framework: tensorflow # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image_tensor - outputs: num_detections,detection_boxes,detection_scores,detection_classes - -device: cpu # optional. default value is cpu, other value is gpu. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 10, 50, 100, 200 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 600 - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAPv2: - output_index_mapping: - num_detections: 0 - boxes: 1 - scores: 2 - classes: 3 - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 600 - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - Resize: - size: 600 -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_resnet50_itex.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_resnet50_itex.yaml deleted file mode 100644 index 61254dfd224..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/faster_rcnn_resnet50_itex.yaml +++ /dev/null @@ -1,73 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -version: 1.0 - -model: # mandatory. used to specify model specific information. - name: faster_rcnn_resnet50 - framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image_tensor - outputs: num_detections,detection_boxes,detection_scores,detection_classes - -device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu]. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 10, 50, 100, 200 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 600 - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAPv2: - output_index_mapping: - num_detections: 0 - boxes: 1 - scores: 2 - classes: 3 - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 600 - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - Resize: - size: 600 -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/label_map.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/label_map.yaml deleted file mode 100644 index 1fbc9263dc9..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/label_map.yaml +++ /dev/null @@ -1,80 +0,0 @@ -person: 1 -bicycle: 2 -car: 3 -motorcycle: 4 -airplane: 5 -bus: 6 -train: 7 -truck: 8 -boat: 9 -traffic light: 10 -fire hydrant: 11 -stop sign: 12 -parking meter: 13 -bench: 14 -bird: 15 -cat: 16 -dog: 17 -horse: 18 -sheep: 19 -cow: 20 -elephant: 21 -bear: 22 -zebra: 23 -giraffe: 24 -backpack: 25 -umbrella: 26 -handbag: 27 -tie: 28 -suitcase: 29 -frisbee: 30 -skis: 31 -snowboard: 32 -sports ball: 33 -kite: 34 -baseball bat: 35 -baseball glove: 36 -skateboard: 37 -surfboard: 38 -tennis racket: 39 -bottle: 40 -wine glass: 41 -cup: 42 -fork: 43 -knife: 44 -spoon: 45 -bowl: 46 -banana: 47 -apple: 48 -sandwich: 49 -orange: 50 -broccoli: 51 -carrot: 52 -hot dog: 53 -pizza: 54 -donut: 55 -cake: 56 -chair: 57 -couch: 58 -potted plant: 59 -bed: 60 -dining table: 61 -toilet: 62 -tv: 63 -laptop: 64 -mouse: 65 -remote: 66 -keyboard: 67 -cell phone: 68 -microwave: 69 -oven: 70 -toaster: 71 -sink: 72 -refrigerator: 73 -book: 74 -clock: 75 -vase: 76 -scissors: 77 -teddy bear: 78 -hair drier: 79 -toothbrush: 80 diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/main.py b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/main.py deleted file mode 100644 index 3d2713107f6..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/main.py +++ /dev/null @@ -1,59 +0,0 @@ -# -# -*- coding: utf-8 -*- -# -# Copyright (c) 2020 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# - -from __future__ import division -import time -import numpy as np -import tensorflow as tf -from argparse import ArgumentParser - -class eval_object_detection_optimized_graph(object): - - def __init__(self): - arg_parser = ArgumentParser(description='Parse args') - - arg_parser.add_argument('-g', - "--input-graph", - help='Specify the input graph.', - dest='input_graph') - arg_parser.add_argument('--config', type=str, default='') - arg_parser.add_argument('--output_model', type=str, default='') - arg_parser.add_argument('--mode', type=str, default='performance') - arg_parser.add_argument('--tune', action='store_true', default=False) - arg_parser.add_argument('--benchmark', dest='benchmark', - action='store_true', help='run benchmark') - self.args = arg_parser.parse_args() - - def run(self): - if self.args.tune: - from neural_compressor.experimental import Quantization - quantizer = Quantization(self.args.config) - quantizer.model = self.args.input_graph - q_model = quantizer.fit() - q_model.save(self.args.output_model) - - if self.args.benchmark: - from neural_compressor.experimental import Benchmark - evaluator = Benchmark(self.args.config) - evaluator.model = self.args.input_graph - evaluator(self.args.mode) - -if __name__ == "__main__": - evaluate_opt_graph = eval_object_detection_optimized_graph() - evaluate_opt_graph.run() diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/mask_rcnn_inception_v2.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/mask_rcnn_inception_v2.yaml deleted file mode 100644 index c89ac397954..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/mask_rcnn_inception_v2.yaml +++ /dev/null @@ -1,82 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: mask_rcnn_inception_v2 - framework: tensorflow # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image_tensor - outputs: num_detections,detection_boxes,detection_scores,detection_classes - -device: cpu # optional. default value is cpu, other value is gpu. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 50 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation dataset TFRecord - filter: - LabelBalance: - size: 1 - #op_wise: { - # 'FirstStageFeatureExtractor/InceptionV2/InceptionV2/Conv2d_1a_7x7/separable_conv2d': { - # 'activation': {'dtype': ['fp32']}, - # } - # } - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAPv2: - output_index_mapping: - num_detections: 0 - boxes: 1 - scores: 2 - classes: 3 - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 1 - dataset: - COCORecord: - root: /path/to/evaluation/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - ResizeWithRatio: - min_dim: 800 - max_dim: 1356 - padding: False - - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - ResizeWithRatio: - min_dim: 800 - max_dim: 1356 - padding: True - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 2%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/mask_rcnn_inception_v2_itex.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/mask_rcnn_inception_v2_itex.yaml deleted file mode 100644 index a253f9e1a27..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/mask_rcnn_inception_v2_itex.yaml +++ /dev/null @@ -1,82 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: mask_rcnn_inception_v2 - framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image_tensor - outputs: num_detections,detection_boxes,detection_scores,detection_classes - -device: cpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu]. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 50 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation dataset TFRecord - filter: - LabelBalance: - size: 1 - #op_wise: { - # 'FirstStageFeatureExtractor/InceptionV2/InceptionV2/Conv2d_1a_7x7/separable_conv2d': { - # 'activation': {'dtype': ['fp32']}, - # } - # } - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAPv2: - output_index_mapping: - num_detections: 0 - boxes: 1 - scores: 2 - classes: 3 - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 1 - dataset: - COCORecord: - root: /path/to/evaluation/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - ResizeWithRatio: - min_dim: 800 - max_dim: 1356 - padding: False - - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - ResizeWithRatio: - min_dim: 800 - max_dim: 1356 - padding: True - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 2%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/prepare_dataset.sh b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/prepare_dataset.sh deleted file mode 100644 index 3cc0cc16f80..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/prepare_dataset.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/bin/bash -# set -x - -DATA_DIR="${PWD}/data" -DATA_NAME="val2017" -DATA_URL_LIST='http://images.cocodataset.org/zips/val2017.zip http://images.cocodataset.org/annotations/annotations_trainval2017.zip' -PACKAGES_LIST='val2017.zip annotations_trainval2017.zip' -VAL_IMAGE_DIR=$DATA_DIR/val2017 -TRAIN_ANNOTATIONS_FILE=$DATA_DIR/annotations/empty.json -VAL_ANNOTATIONS_FILE=$DATA_DIR/annotations/instances_val2017.json -TESTDEV_ANNOTATIONS_FILE=$DATA_DIR/annotations/empty.json -OUTPUT_DIR=$DATA_DIR - -help() -{ - cat <<- EOF - - Desc: Prepare dataset for Tensorflow COCO object detection. - - -h --help help info - - --dataset_location set dataset location, default is ./data - -EOF - exit 0 -} - -function main { - init_params "$@" - download_dataset - convert_to_tf_record -} - -# init params -function init_params { - - for var in "$@" - do - case $var in - --dataset_location=*) - DATA_DIR=$(echo "$var" |cut -f2 -d=) - ;; - -h|--help) help - ;; - *) - echo "Error: No such parameter: ${var}" - exit 1 - ;; - esac - done - -} - -# removes files that will not be used anymore -function remove_zipped_packages { - for package in $PACKAGES_LIST; do - rm "$package" - done -} - -function download_tf_models_repo { - if [ ! -d models ]; then - git clone https://github.com/tensorflow/models.git - fi - cd models || exit - git checkout 7a9934df2afdf95be9405b4e9f1f2480d748dc40 - cd .. -} - -function divide_tf_records_by_dataset { - if [ ! -d "${DATA_DIR}/tf_test2017" ]; then - mkdir "${DATA_DIR}/tf_test2017" - fi - if [ ! -d "${DATA_DIR}/tf_train2017" ]; then - mkdir "${DATA_DIR}/tf_train2017" - fi - if [ ! -d "${DATA_DIR}/tf_val2017" ]; then - mkdir "${DATA_DIR}/tf_val2017" - fi - mv ${DATA_DIR}/coco_testdev.record* ${DATA_DIR}/tf_test2017 - mv ${DATA_DIR}/coco_train.record* ${DATA_DIR}/tf_train2017 - mv ${DATA_DIR}/coco_val.record* ${DATA_DIR}/tf_val2017 -} - -function convert { - cd models/research - protoc object_detection/protos/*.proto --python_out=. - export PYTHONPATH=$PYTHONPATH:$(pwd) - export PYTHONPATH=$PYTHONPATH:$(pwd)/slim - python ./object_detection/dataset_tools/create_coco_tf_record.py --logtostderr \ - --train_image_dir=empty_dir \ - --val_image_dir="${VAL_IMAGE_DIR}" \ - --test_image_dir=empty_dir \ - --train_annotations_file="${TRAIN_ANNOTATIONS_FILE}" \ - --val_annotations_file="${VAL_ANNOTATIONS_FILE}" \ - --testdev_annotations_file="${TESTDEV_ANNOTATIONS_FILE}" \ - --output_dir="${OUTPUT_DIR}" -} - -function convert_to_tf_record { - download_tf_models_repo - convert - divide_tf_records_by_dataset -} - -# download_dataset -function download_dataset { - if [ ! -d "${DATA_DIR}" ]; then - mkdir "${DATA_DIR}" - fi - - cd "${DATA_DIR}" || exit - if [ ! -f "${VAL_IMAGE_DIR}" ]; then - - for dataset_dowload_link in $DATA_URL_LIST; do - wget "$dataset_dowload_link" - done - for package in $PACKAGES_LIST; do - unzip -o "$package" - done - remove_zipped_packages - if [ ! -d empty_dir ]; then - mkdir empty_dir - fi - - cd annotations || exit - echo "{ \"images\": {}, \"categories\": {}}" > empty.json - cd .. - else - echo "Dataset ${DATA_NAME} is exist!" - fi - - cd ../ -} - -main "$@" diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/prepare_model.py b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/prepare_model.py deleted file mode 100644 index 51882cf0bfe..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/prepare_model.py +++ /dev/null @@ -1,99 +0,0 @@ -import os -import argparse -import enum -import tarfile -import abc - - -class SupportedModels(enum.Enum): - """ - Enumeration containing supported models - """ - ssd_resnet50_v1 = 'ssd_resnet50_v1' - ssd_mobilnet_v1 = 'ssd_mobilenet_v1' - - -class Model(abc.ABC): - """ - Base model class used to obtain the model (and perform any necessary operations to make it usable) - """ - - @abc.abstractmethod - def get_pretrained_model(self, destination): - """ - Base method for obtaining a ready to use model - Args: - destination: path to where the file should be stored - """ - pass - - -class SsdMobilenetV1(Model): - """ Concrete implementation of the Model base class for ssd_mobilenet_v1""" - - def get_pretrained_model(self, destination): - """ - Obtains a ready to use ssd_mobilenet_v1 model file. - Args: - destination: path to where the file should be stored - """ - url = 'http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2018_01_28.tar.gz' - os.system("curl -o ssd_mobilenet_v1_coco_2018_01_28.tar.gz {0}".format(url)) - with tarfile.open("ssd_mobilenet_v1_coco_2018_01_28.tar.gz") as tar: - if not os.path.exists(destination): - os.makedirs(destination) - tar.extractall(destination) - - -class SsdResnet50(Model): - """ Concrete implementation of the Model base class for ssd_resnet_50""" - - def get_pretrained_model(self, destination): - """ - Obtains a ready to use ssd_resnet_50 model file. - Args: - destination: path to where the file should be stored - """ - url = "http://download.tensorflow.org/models/object_detection/" \ - "ssd_resnet50_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03.tar.gz" - os.system("curl -o ssd_resnet50_v1.tar.gz {0}".format(url)) - with tarfile.open("ssd_resnet50_v1.tar.gz") as tar: - if not os.path.exists(destination): - os.makedirs(destination) - tar.extractall(destination) - - -def get_model(model: SupportedModels) -> Model: - """ - Factory method that returns the requested model object - Args: - model: model from SupportedModels enumeration - - Returns: Concrete object inheriting the Model base class - - """ - if model == SupportedModels.ssd_resnet50_v1: - return SsdResnet50() - if model == SupportedModels.ssd_mobilnet_v1: - return SsdMobilenetV1() - else: - raise AttributeError("The model {0} is not supported. Supported models: {1}" - .format(model_name, SupportedModels.__members__.keys())) - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Prepare pre-trained model for COCO object detection') - parser.add_argument('--model_name', type=str, default='ssd_resnet50_v1', - help='model to download, default is ssd_resnet50_v1', - choices=["ssd_resnet50_v1", "ssd_mobilenet_v1"]) - parser.add_argument('--model_path', type=str, default='./model', help='directory to put models, default is ./model') - - args = parser.parse_args() - model_name = args.model_name - model_path = args.model_path - try: - model = get_model(SupportedModels(model_name)) - model.get_pretrained_model(model_path) - except AttributeError: - print("The model {0} is not supported. Supported models: {1}" - .format(model_name, SupportedModels.__members__.keys())) diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/requirements.txt b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/requirements.txt deleted file mode 100644 index 865df0f3a6b..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -Cython -contextlib2 -pillow>=8.2.0 -lxml>=4.6.2 -matplotlib -numpy>=1.17.4 -pycocotools -protobuf diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/run_benchmark.sh b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/run_benchmark.sh deleted file mode 100644 index fc59d4b83e4..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/run_benchmark.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -set -x - -function main { - - init_params "$@" - run_benchmark - -} - -# init params -function init_params { - for var in "$@" - do - case $var in - --config=*) - config=$(echo $var |cut -f2 -d=) - ;; - --input_model=*) - input_model=$(echo $var |cut -f2 -d=) - ;; - --mode=*) - mode=$(echo $var |cut -f2 -d=) - ;; - esac - done - -} - - -# run_tuning -function run_benchmark { - - python main.py \ - --input-graph ${input_model} \ - --config ${config} \ - --mode ${mode} \ - --benchmark -} - -main "$@" diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/run_tuning.sh b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/run_tuning.sh deleted file mode 100644 index 23e86e2dc42..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/run_tuning.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -set -x - -function main { - - init_params "$@" - - run_tuning - -} - -# init params -function init_params { - - for var in "$@" - do - case $var in - --config=*) - config=$(echo "$var" |cut -f2 -d=) - ;; - --input_model=*) - input_model=$(echo "$var" |cut -f2 -d=) - ;; - --output_model=*) - output_model=$(echo "$var" |cut -f2 -d=) - ;; - esac - done - -} - -# run_tuning -function run_tuning { - python main.py \ - --input-graph "${input_model}" \ - --config ${config} \ - --output_model "${output_model}" \ - --tune -} - -main "$@" diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_mobilenet_v1.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_mobilenet_v1.yaml deleted file mode 100644 index ded63da480e..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_mobilenet_v1.yaml +++ /dev/null @@ -1,74 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: ssd_mobilenet_v1 - framework: tensorflow # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image_tensor - outputs: num_detections,detection_boxes,detection_scores,detection_classes - -device: cpu # optional. default value is cpu, other value is gpu. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 10, 50, 100, 200 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - weight: - algorithm: minmax - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAPv2: - output_index_mapping: - num_detections: 0 - boxes: 1 - scores: 2 - classes: 3 - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 300 - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - Resize: - size: 300 -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_mobilenet_v1_itex.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_mobilenet_v1_itex.yaml deleted file mode 100644 index c312ecc348f..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_mobilenet_v1_itex.yaml +++ /dev/null @@ -1,74 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: ssd_mobilenet_v1 - framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image_tensor - outputs: num_detections,detection_boxes,detection_scores,detection_classes - -device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu]. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 10, 50, 100, 200 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - weight: - algorithm: minmax - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAPv2: - output_index_mapping: - num_detections: 0 - boxes: 1 - scores: 2 - classes: 3 - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 300 - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - Resize: - size: 300 -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_resnet34.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_resnet34.yaml deleted file mode 100644 index e4e1b978277..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_resnet34.yaml +++ /dev/null @@ -1,90 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: ssd_resnet34 - framework: tensorflow # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image - outputs: detection_bboxes,detection_scores,detection_classes - -device: cpu # optional. default value is cpu, other value is gpu. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 100 # optional. default value is the size of whole dataset. used to set how many portions of calibration dataset is used. exclusive with iterations field. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 1 - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation raw image folder - transform: - Rescale: {} - Normalize: - mean: [0.485, 0.456, 0.406] - std: [0.229, 0.224, 0.225] - Resize: - size: 1200 - - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - weight: - algorithm: minmax - granularity: per_channel - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAP: - anno_path: /path/to/annotation - - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 1 - dataset: - COCORecord: - root: /path/to/evaluation/dataset/ # NOTE: modify to coco2017 validation raw image datafolder - transform: - Rescale: {} - Normalize: - mean: [0.485, 0.456, 0.406] - std: [0.229, 0.224, 0.225] - Resize: - size: 1200 - - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 1 - dataset: - COCORecord: - root: /path/to/evaluation/dataset/ - transform: - Rescale: {} - Normalize: - mean: [0.485, 0.456, 0.406] - std: [0.229, 0.224, 0.225] - Resize: - size: 1200 - -tuning: - accuracy_criterion: - absolute: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_resnet34_itex.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_resnet34_itex.yaml deleted file mode 100644 index caa95464a5e..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_resnet34_itex.yaml +++ /dev/null @@ -1,90 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: ssd_resnet34 - framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image - outputs: detection_bboxes,detection_scores,detection_classes - -device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu]. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 100 # optional. default value is the size of whole dataset. used to set how many portions of calibration dataset is used. exclusive with iterations field. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 1 - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation raw image folder - transform: - Rescale: {} - Normalize: - mean: [0.485, 0.456, 0.406] - std: [0.229, 0.224, 0.225] - Resize: - size: 1200 - - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - weight: - algorithm: minmax - granularity: per_channel - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAP: - anno_path: /path/to/annotation - - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 1 - dataset: - COCORecord: - root: /path/to/evaluation/dataset/ # NOTE: modify to coco2017 validation raw image datafolder - transform: - Rescale: {} - Normalize: - mean: [0.485, 0.456, 0.406] - std: [0.229, 0.224, 0.225] - Resize: - size: 1200 - - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 1 - dataset: - COCORecord: - root: /path/to/evaluation/dataset/ - transform: - Rescale: {} - Normalize: - mean: [0.485, 0.456, 0.406] - std: [0.229, 0.224, 0.225] - Resize: - size: 1200 - -tuning: - accuracy_criterion: - absolute: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_resnet50_v1.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_resnet50_v1.yaml deleted file mode 100644 index 7ea3c76f660..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_resnet50_v1.yaml +++ /dev/null @@ -1,79 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: ssd_resnet50_v1 - framework: tensorflow # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image_tensor - outputs: num_detections,detection_boxes,detection_scores,detection_classes - -device: cpu # optional. default value is cpu, other value is gpu. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 100 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 640 - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - weight: - algorithm: minmax - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAPv2: - output_index_mapping: - num_detections: 0 - boxes: 1 - scores: 2 - classes: 3 - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 640 - - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - Resize: - size: 640 - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - max_trials: 100 # optional. max tune times. default value is 100. combine with timeout field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_resnet50_v1_itex.yaml b/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_resnet50_v1_itex.yaml deleted file mode 100644 index faff3306989..00000000000 --- a/examples/tensorflow/object_detection/tensorflow_models/quantization/ptq/ssd_resnet50_v1_itex.yaml +++ /dev/null @@ -1,79 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: ssd_resnet50_v1 - framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: image_tensor - outputs: num_detections,detection_boxes,detection_scores,detection_classes - -device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu]. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 100 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - dataset: - COCORecord: - root: /path/to/calibration/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 640 - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - weight: - algorithm: minmax - -evaluation: # optional. used to config evaluation process. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - COCOmAPv2: - output_index_mapping: - num_detections: 0 - boxes: 1 - scores: 2 - classes: 3 - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset # NOTE: modify to coco2017 validation dataset TFRecord - transform: - Resize: - size: 640 - - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - Resize: - size: 640 - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - max_trials: 100 # optional. max tune times. default value is 100. combine with timeout field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/README.md b/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/README.md deleted file mode 100644 index fa82967ce42..00000000000 --- a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/README.md +++ /dev/null @@ -1,99 +0,0 @@ -This document describes the step-by-step to reproduce Yolo-v3 tuning result with Neural Compressor. This example can run on Intel CPUs and GPUs. - -## Prerequisite - - -### 1. Installation -Recommend python 3.6 or higher version. - -```shell -# Install Intel® Neural Compressor -pip install neural-compressor -``` - -### 2. Install Intel Tensorflow -```shell -pip install intel-tensorflow -``` -> Note: Only supported Tensorflow 1.x versions. - -### 3. Installation Dependency packages -```shell -cd examples/tensorflow/object_detection/yolo_v3/quantization/ptq -pip install -r requirements.txt -``` - -### 4. Install Intel Extension for Tensorflow -#### Quantizing the model on Intel GPU -Intel Extension for Tensorflow is mandatory to be installed for quantizing the model on Intel GPUs. - -```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) - -#### 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. - -```shell -pip install --upgrade intel-extension-for-tensorflow[cpu] -``` - -### 5. Downloaded Yolo-v3 model -```shell -git clone https://github.com/mystic123/tensorflow-yolo-v3.git -cd tensorflow-yolo-v3 -``` - -### 6. Download COCO Class Names File -```shell -wget https://raw.githubusercontent.com/pjreddie/darknet/master/data/coco.names -``` - -### 7. Download Model Weights (Full): -```shell -wget https://pjreddie.com/media/files/yolov3.weights -``` - -### 8. Generate PB: -```shell -python convert_weights_pb.py --class_names coco.names --weights_file yolov3.weights --data_format NHWC --size 416 --output_graph yolov3.pb -``` - -### 9. Prepare Dataset - -#### Automatic dataset download - -> **_Note: `prepare_dataset.sh` script works with TF version 1.x._** - -Run the `prepare_dataset.sh` script located in `examples/tensorflow/object_detection/yolo_v3/quantization/ptq`. - -Usage: -```shell -cd examples/tensorflow/object_detection/yolo_v3/quantization/ptq -. prepare_dataset.sh -``` - -This script will download the *train*, *validation* and *test* COCO datasets. Furthermore it will convert them to -tensorflow records using the `https://github.com/tensorflow/models.git` dedicated script. - -#### Manual dataset download -Download CoCo Dataset from [Official Website](https://cocodataset.org/#download). - -## Get Quantized Yolo-v3 model with Neural Compressor - -### 1.Config the yolo_v3.yaml with the valid cocoraw data path or the yolo_v3_itex.yaml if using the Intel Extension for Tensorflow. - -### 2.Config the yaml file -In examples directory, there is a yolo_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 yolo_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. - -### 3.Run below command one by one. -Usage -```shell -cd examples/tensorflow/object_detection/yolo_v3/quantization/ptq -``` -```python -python infer_detections.py --input_graph /path/to/yolov3_fp32.pb --config ./yolo_v3.yaml --output_graph /path/to/save/yolov3_tuned3.pb -``` - -Finally, the program will generate the quantized Yolo-v3 model with relative 1% loss. diff --git a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/coco_constants.py b/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/coco_constants.py deleted file mode 100644 index 8c91524da25..00000000000 --- a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/coco_constants.py +++ /dev/null @@ -1,6 +0,0 @@ -COCO_NUM_VAL_IMAGES = 4952 -LABEL_MAP = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, - 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, - 61, 62, 63, 64, 65, 67, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, - 84, 85, 86, 87, 88, 89, 90] diff --git a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/infer_detections.py b/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/infer_detections.py deleted file mode 100644 index e2d961be896..00000000000 --- a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/infer_detections.py +++ /dev/null @@ -1,154 +0,0 @@ -import time -import numpy as np -import tensorflow as tf - -from absl import app, flags - -from tensorflow.python.client import timeline -from coco_constants import LABEL_MAP -from utils import read_graph, non_max_suppression - -flags.DEFINE_integer('batch_size', 1, "batch size") - -flags.DEFINE_string("ground_truth", None, "ground truth file") - -flags.DEFINE_string("input_graph", None, "input graph") - -flags.DEFINE_string("output_graph", None, "input graph") - -flags.DEFINE_string("config", None, "Neural Compressor config file") - -flags.DEFINE_float("conf_threshold", 0.5, "confidence threshold") - -flags.DEFINE_float("iou_threshold", 0.4, "IoU threshold") - -flags.DEFINE_integer("num_intra_threads", 0, "number of intra threads") - -flags.DEFINE_integer("num_inter_threads", 1, "number of inter threads") - -flags.DEFINE_boolean("benchmark", False, "benchmark mode") - -flags.DEFINE_boolean("profiling", False, "Signal of profiling") - -FLAGS = flags.FLAGS - - -class NMS(): - def __init__(self, conf_threshold, iou_threshold): - self.conf_threshold = conf_threshold - self.iou_threshold = iou_threshold - - def __call__(self, sample): - preds, labels = sample - if not isinstance(preds, np.ndarray): - preds = np.array(preds) - filtered_boxes = non_max_suppression(preds, - self.conf_threshold, - self.iou_threshold) - - det_boxes = [] - det_scores = [] - det_classes = [] - for cls, bboxs in filtered_boxes.items(): - det_classes.extend([LABEL_MAP[cls + 1]] * len(bboxs)) - for box, score in bboxs: - rect_pos = box.tolist() - y_min, x_min = rect_pos[1], rect_pos[0] - y_max, x_max = rect_pos[3], rect_pos[2] - height, width = 416, 416 - det_boxes.append( - [y_min / height, x_min / width, y_max / height, x_max / width]) - det_scores.append(score) - - if len(det_boxes) == 0: - det_boxes = np.zeros((0, 4)) - det_scores = np.zeros((0, )) - det_classes = np.zeros((0, )) - - return [np.array([det_boxes]), np.array([det_scores]), np.array([det_classes])], labels - - -def create_tf_config(): - config = tf.compat.v1.ConfigProto() - config.intra_op_parallelism_threads = FLAGS.num_intra_threads - config.inter_op_parallelism_threads = FLAGS.num_inter_threads - return config - - -def run_benchmark(): - config = create_tf_config() - - graph_def = read_graph(FLAGS.input_graph) - - tf.import_graph_def(graph_def, name='') - - input_tensor = tf.compat.v1.get_default_graph().get_tensor_by_name('inputs:0') - output_tensor = tf.compat.v1.get_default_graph().get_tensor_by_name('output_boxes:0') - - dummy_data_shape = list(input_tensor.shape) - dummy_data_shape[0] = FLAGS.batch_size - dummy_data = np.random.random(dummy_data_shape).astype(np.float32) - - if FLAGS.profiling != True: - num_warmup = 200 - total_iter = 1000 - else: - num_warmup = 20 - total_iter = 100 - - total_time = 0.0 - - with tf.compat.v1.Session(config=config) as sess: - print("Running warm-up") - for i in range(num_warmup): - sess.run(output_tensor, {input_tensor: dummy_data}) - print("Warm-up complete") - - for i in range(1, total_iter + 1): - start_time = time.time() - sess.run(output_tensor, {input_tensor: dummy_data}) - end_time = time.time() - - if i % 10 == 0: - print( - "Steps = {0}, {1:10.6f} samples/sec".format(i, FLAGS.batch_size / duration)) - - duration = end_time - start_time - total_time += duration - - if FLAGS.profiling: - options = tf.compat.v1.RunOptions( - trace_level=tf.compat.v1.RunOptions.FULL_TRACE) - run_metadata = tf.compat.v1.RunMetadata() - - sess.run(output_tensor, {input_tensor: dummy_data}, - options=options, run_metadata=run_metadata) - - fetched_timeline = timeline.Timeline(run_metadata.step_stats) - chrome_trace = fetched_timeline.generate_chrome_trace_format() - with open("timeline_%s.json" % (time.time()), 'w') as f: - f.write(chrome_trace) - - throughput = total_iter * FLAGS.batch_size / total_time - print("Batch size = {}".format(FLAGS.batch_size)) - print("Latency: {} ms".format(1 / throughput * 1000)) - print("Throughput: {} samples/sec".format(throughput)) - - -def main(_): - if FLAGS.benchmark: - run_benchmark() - else: - FLAGS.batch_size = 1 - from neural_compressor.experimental import Quantization, common - quantizer = Quantization(FLAGS.config) - quantizer.model = common.Model(FLAGS.input_graph) - kwargs = {'conf_threshold': FLAGS.conf_threshold, - 'iou_threshold': FLAGS.iou_threshold} - quantizer.postprocess = common.Postprocess(NMS, 'NMS', **kwargs) - q_model = quantizer.fit() - q_model.save(FLAGS.output_graph) - - -if __name__ == '__main__': - app.run(main) diff --git a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/prepare_dataset.sh b/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/prepare_dataset.sh deleted file mode 100644 index 3cc0cc16f80..00000000000 --- a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/prepare_dataset.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/bin/bash -# set -x - -DATA_DIR="${PWD}/data" -DATA_NAME="val2017" -DATA_URL_LIST='http://images.cocodataset.org/zips/val2017.zip http://images.cocodataset.org/annotations/annotations_trainval2017.zip' -PACKAGES_LIST='val2017.zip annotations_trainval2017.zip' -VAL_IMAGE_DIR=$DATA_DIR/val2017 -TRAIN_ANNOTATIONS_FILE=$DATA_DIR/annotations/empty.json -VAL_ANNOTATIONS_FILE=$DATA_DIR/annotations/instances_val2017.json -TESTDEV_ANNOTATIONS_FILE=$DATA_DIR/annotations/empty.json -OUTPUT_DIR=$DATA_DIR - -help() -{ - cat <<- EOF - - Desc: Prepare dataset for Tensorflow COCO object detection. - - -h --help help info - - --dataset_location set dataset location, default is ./data - -EOF - exit 0 -} - -function main { - init_params "$@" - download_dataset - convert_to_tf_record -} - -# init params -function init_params { - - for var in "$@" - do - case $var in - --dataset_location=*) - DATA_DIR=$(echo "$var" |cut -f2 -d=) - ;; - -h|--help) help - ;; - *) - echo "Error: No such parameter: ${var}" - exit 1 - ;; - esac - done - -} - -# removes files that will not be used anymore -function remove_zipped_packages { - for package in $PACKAGES_LIST; do - rm "$package" - done -} - -function download_tf_models_repo { - if [ ! -d models ]; then - git clone https://github.com/tensorflow/models.git - fi - cd models || exit - git checkout 7a9934df2afdf95be9405b4e9f1f2480d748dc40 - cd .. -} - -function divide_tf_records_by_dataset { - if [ ! -d "${DATA_DIR}/tf_test2017" ]; then - mkdir "${DATA_DIR}/tf_test2017" - fi - if [ ! -d "${DATA_DIR}/tf_train2017" ]; then - mkdir "${DATA_DIR}/tf_train2017" - fi - if [ ! -d "${DATA_DIR}/tf_val2017" ]; then - mkdir "${DATA_DIR}/tf_val2017" - fi - mv ${DATA_DIR}/coco_testdev.record* ${DATA_DIR}/tf_test2017 - mv ${DATA_DIR}/coco_train.record* ${DATA_DIR}/tf_train2017 - mv ${DATA_DIR}/coco_val.record* ${DATA_DIR}/tf_val2017 -} - -function convert { - cd models/research - protoc object_detection/protos/*.proto --python_out=. - export PYTHONPATH=$PYTHONPATH:$(pwd) - export PYTHONPATH=$PYTHONPATH:$(pwd)/slim - python ./object_detection/dataset_tools/create_coco_tf_record.py --logtostderr \ - --train_image_dir=empty_dir \ - --val_image_dir="${VAL_IMAGE_DIR}" \ - --test_image_dir=empty_dir \ - --train_annotations_file="${TRAIN_ANNOTATIONS_FILE}" \ - --val_annotations_file="${VAL_ANNOTATIONS_FILE}" \ - --testdev_annotations_file="${TESTDEV_ANNOTATIONS_FILE}" \ - --output_dir="${OUTPUT_DIR}" -} - -function convert_to_tf_record { - download_tf_models_repo - convert - divide_tf_records_by_dataset -} - -# download_dataset -function download_dataset { - if [ ! -d "${DATA_DIR}" ]; then - mkdir "${DATA_DIR}" - fi - - cd "${DATA_DIR}" || exit - if [ ! -f "${VAL_IMAGE_DIR}" ]; then - - for dataset_dowload_link in $DATA_URL_LIST; do - wget "$dataset_dowload_link" - done - for package in $PACKAGES_LIST; do - unzip -o "$package" - done - remove_zipped_packages - if [ ! -d empty_dir ]; then - mkdir empty_dir - fi - - cd annotations || exit - echo "{ \"images\": {}, \"categories\": {}}" > empty.json - cd .. - else - echo "Dataset ${DATA_NAME} is exist!" - fi - - cd ../ -} - -main "$@" diff --git a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/requirements.txt b/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/requirements.txt deleted file mode 100644 index 865df0f3a6b..00000000000 --- a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -Cython -contextlib2 -pillow>=8.2.0 -lxml>=4.6.2 -matplotlib -numpy>=1.17.4 -pycocotools -protobuf diff --git a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/run_benchmark.sh b/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/run_benchmark.sh deleted file mode 100644 index 47682835a2c..00000000000 --- a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/run_benchmark.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -set -x - -function main { - - init_params "$@" - run_benchmark - -} - -# init params -function init_params { - for var in "$@" - do - case $var in - --config=*) - config=$(echo $var |cut -f2 -d=) - ;; - --input_model=*) - input_model=$(echo $var |cut -f2 -d=) - ;; - esac - done - -} - - -# run_tuning -function run_benchmark { - python infer_detections.py \ - --input_graph ${input_model} \ - --config ${config} \ - --benchmark -} - -main "$@" diff --git a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/run_tuning.sh b/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/run_tuning.sh deleted file mode 100644 index 120725a1110..00000000000 --- a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/run_tuning.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -set -x - -function main { - - init_params "$@" - run_benchmark - -} - -# init params -function init_params { - for var in "$@" - do - case $var in - --config=*) - config=$(echo $var |cut -f2 -d=) - ;; - --input_model=*) - input_model=$(echo $var |cut -f2 -d=) - ;; - --output_model=*) - output_model=$(echo $var |cut -f2 -d=) - ;; - esac - done - -} - - -# run tuning -function run_benchmark { - python infer_detections.py \ - --input_graph ${input_model} \ - --config ${config} \ - --output_graph ${output_model} -} - -main "$@" diff --git a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/yolo_v3.yaml b/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/yolo_v3.yaml deleted file mode 100644 index 91197b50762..00000000000 --- a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/yolo_v3.yaml +++ /dev/null @@ -1,85 +0,0 @@ -model: # mandatory. neural_compressor uses this model name and framework name to decide where to save tuning history and deploy yaml. - name: yolo_v3 - framework: tensorflow # mandatory. supported values are tensorflow, pytorch, or mxnet; allow new framework backend extension. - inputs: inputs - outputs: output_boxes - -device: cpu # optional. default value is cpu, other value is gpu. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 2 # optional. default value is the size of whole dataset. used to set how many portions of calibration dataset is used. exclusive with iterations field. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 1 - dataset: - COCORecord: - root: /path/to/calibration/dataset - filter: - LabelBalance: - size: 1 - transform: - ParseDecodeCoco: - ResizeWithRatio: - min_dim: 416 - max_dim: 416 - padding: True - - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - weight: - granularity: per_channel - op_wise: { # optional. tuning constraints on op-wise for advance user to reduce tuning space. - 'detector/yolo-v3/Conv_6/Conv2D': { - 'activation': {'dtype': ['fp32']}, - }, - 'detector/yolo-v3/Conv_14/Conv2D': { - 'activation': {'dtype': ['fp32']}, - }, - 'detector/yolo-v3/Conv_22/Conv2D': { - 'activation': {'dtype': ['fp32']}, - } - } - -evaluation: # optional. used to config evaluation process. - accuracy: - metric: - COCOmAP: - map_key: 'DetectionBoxes_Precision/mAP@.50IOU' - dataloader: - batch_size: 1 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - ParseDecodeCoco: {} - ResizeWithRatio: - min_dim: 416 - max_dim: 416 - padding: True - constant_value: 128 - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - ParseDecodeCoco: - ResizeWithRatio: - min_dim: 416 - max_dim: 416 - padding: True - constant_value: 128 - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/yolo_v3_itex.yaml b/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/yolo_v3_itex.yaml deleted file mode 100644 index 6a8c4483d9b..00000000000 --- a/examples/tensorflow/object_detection/yolo_v3/quantization/ptq/yolo_v3_itex.yaml +++ /dev/null @@ -1,85 +0,0 @@ -model: # mandatory. neural_compressor uses this model name and framework name to decide where to save tuning history and deploy yaml. - name: yolo_v3 - framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, or mxnet; allow new framework backend extension. - inputs: inputs - outputs: output_boxes - -device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu]. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 2 # optional. default value is the size of whole dataset. used to set how many portions of calibration dataset is used. exclusive with iterations field. - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 1 - dataset: - COCORecord: - root: /path/to/calibration/dataset - filter: - LabelBalance: - size: 1 - transform: - ParseDecodeCoco: - ResizeWithRatio: - min_dim: 416 - max_dim: 416 - padding: True - - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - weight: - granularity: per_channel - op_wise: { # optional. tuning constraints on op-wise for advance user to reduce tuning space. - 'detector/yolo-v3/Conv_6/Conv2D': { - 'activation': {'dtype': ['fp32']}, - }, - 'detector/yolo-v3/Conv_14/Conv2D': { - 'activation': {'dtype': ['fp32']}, - }, - 'detector/yolo-v3/Conv_22/Conv2D': { - 'activation': {'dtype': ['fp32']}, - } - } - -evaluation: # optional. used to config evaluation process. - accuracy: - metric: - COCOmAP: - map_key: 'DetectionBoxes_Precision/mAP@.50IOU' - dataloader: - batch_size: 1 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - ParseDecodeCoco: {} - ResizeWithRatio: - min_dim: 416 - max_dim: 416 - padding: True - constant_value: 128 - performance: - iteration: 100 - configs: - cores_per_instance: 28 - num_of_instance: 1 - kmp_blocktime: 1 - dataloader: - batch_size: 10 - dataset: - COCORecord: - root: /path/to/evaluation/dataset - transform: - ParseDecodeCoco: - ResizeWithRatio: - min_dim: 416 - max_dim: 416 - padding: True - constant_value: 128 - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/oob_models/quantization/ptq/README.md b/examples/tensorflow/oob_models/quantization/ptq/README.md index 4ca0886f7ce..dea9f15724d 100644 --- a/examples/tensorflow/oob_models/quantization/ptq/README.md +++ b/examples/tensorflow/oob_models/quantization/ptq/README.md @@ -6,11 +6,12 @@ This document is used to list steps of reproducing Intel Optimized TensorFlow OO # Prerequisite ## 1. Installation - Recommend python 3.6 or higher version. + Recommend python 3.8 or higher version. ```bash # Install Intel® Neural Compressor pip install neural-compressor + # Install Intel® Tensorflow pip install intel-tensorflow ``` > Note: Supported Tensorflow [Version](../../../../../README.md#supported-frameworks). @@ -22,7 +23,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. @@ -86,8 +88,16 @@ List models names can get with open_model_zoo: | ssd_inception_v2_coco | http://download.tensorflow.org/models/object_detection/ssd_inception_v2_coco_2018_01_28.tar.gz | | ssd-resnet34 300x300 | https://storage.googleapis.com/intel-optimized-tensorflow/models/v1_6/ssd_resnet34_fp32_bs1_pretrained_model.pb | -## 5. Config the yaml file -In examples directory, there is a config.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 config_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. +## 5. 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 ## run tuning @@ -99,5 +109,5 @@ In examples directory, there is a config.yaml for tuning the model on Intel CPUs ## run benchmarking ```bash -./run_benchmark.sh --topology=${model_topology} --dataset_location= --input_model=${model_path} --mode=benchmark --batch_size=1 --iters=200 +./run_benchmark.sh --topology=${model_topology} --dataset_location= --input_model=${model_path} --mode=benchmark --batch_size=1 ``` diff --git a/examples/tensorflow/oob_models/quantization/ptq/config.yaml b/examples/tensorflow/oob_models/quantization/ptq/config.yaml deleted file mode 100644 index 86e26e1ff8c..00000000000 --- a/examples/tensorflow/oob_models/quantization/ptq/config.yaml +++ /dev/null @@ -1,38 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: oob_models - framework: tensorflow # mandatory. supported values are tensorflow, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: input - outputs: output - -device: cpu # optional. default value is cpu, other value is gpu. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 1 # optional. default value is 100. used to set how many samples should be used in calibration. - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - weight: - algorithm: minmax - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/oob_models/quantization/ptq/config_itex.yaml b/examples/tensorflow/oob_models/quantization/ptq/config_itex.yaml deleted file mode 100644 index 44db3b3910c..00000000000 --- a/examples/tensorflow/oob_models/quantization/ptq/config_itex.yaml +++ /dev/null @@ -1,38 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: oob_models - framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: input - outputs: output - -device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu]. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 1 # optional. default value is 100. used to set how many samples should be used in calibration. - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - weight: - algorithm: minmax - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/oob_models/quantization/ptq/dataloaders.py b/examples/tensorflow/oob_models/quantization/ptq/dataloaders.py index 59abb70aec9..282f878f419 100644 --- a/examples/tensorflow/oob_models/quantization/ptq/dataloaders.py +++ b/examples/tensorflow/oob_models/quantization/ptq/dataloaders.py @@ -1,3 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2022 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + from neural_compressor.experimental.data.dataloaders.fetcher import FETCHERS from neural_compressor.experimental.data.dataloaders.sampler import BatchSampler from neural_compressor.experimental.data.dataloaders.default_dataloader import DefaultDataLoader diff --git a/examples/tensorflow/oob_models/quantization/ptq/find_outputs.py b/examples/tensorflow/oob_models/quantization/ptq/find_outputs.py index f5b9eba9336..e0eed505a37 100644 --- a/examples/tensorflow/oob_models/quantization/ptq/find_outputs.py +++ b/examples/tensorflow/oob_models/quantization/ptq/find_outputs.py @@ -1,8 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2022 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== import argparse -import os -import sys -import re from utils import * from neural_compressor.utils import logger diff --git a/examples/tensorflow/oob_models/quantization/ptq/model_detail.py b/examples/tensorflow/oob_models/quantization/ptq/model_detail.py index 8c5f2d1770d..f4520264cd2 100644 --- a/examples/tensorflow/oob_models/quantization/ptq/model_detail.py +++ b/examples/tensorflow/oob_models/quantization/ptq/model_detail.py @@ -1,3 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2022 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + from utils import * import numpy as np diff --git a/examples/tensorflow/oob_models/quantization/ptq/run_benchmark.sh b/examples/tensorflow/oob_models/quantization/ptq/run_benchmark.sh index efd68dde04d..f549d719b41 100755 --- a/examples/tensorflow/oob_models/quantization/ptq/run_benchmark.sh +++ b/examples/tensorflow/oob_models/quantization/ptq/run_benchmark.sh @@ -35,21 +35,16 @@ function init_params { --iters=*) iters=$(echo ${var} |cut -f2 -d=) ;; - *) - echo "Error: No such parameter: ${var}" - exit 1 - ;; esac done } function define_mode { - if [[ ${mode} == "accuracy" ]]; then echo "For TF OOB models, there is only benchmark mode!, num iter is: ${iters}" exit 1 - elif [[ ${mode} == "benchmark" ]]; then + elif [[ ${mode} == "performance" ]]; then mode_cmd=" --benchmark " else echo "Error: No such mode: ${mode}" diff --git a/examples/tensorflow/oob_models/quantization/ptq/run_tuning.sh b/examples/tensorflow/oob_models/quantization/ptq/run_tuning.sh index a183dbb52e6..e0facd08d4f 100755 --- a/examples/tensorflow/oob_models/quantization/ptq/run_tuning.sh +++ b/examples/tensorflow/oob_models/quantization/ptq/run_tuning.sh @@ -163,7 +163,6 @@ function set_args { function run_tuning { input="input" output="predict" - yaml='./config.yaml' extra_cmd+=' --num_warmup 10 -n 500 ' if [[ "${models_need_name[@]}" =~ " ${topology} " ]]; then @@ -190,7 +189,6 @@ function run_tuning { python tf_benchmark.py \ --model_path ${input_model} \ --output_path ${output_model} \ - --yaml ${yaml} \ --tune \ ${extra_cmd} diff --git a/examples/tensorflow/oob_models/quantization/ptq/tf_benchmark.py b/examples/tensorflow/oob_models/quantization/ptq/tf_benchmark.py index 1c352ef713a..54b74fc9e76 100644 --- a/examples/tensorflow/oob_models/quantization/ptq/tf_benchmark.py +++ b/examples/tensorflow/oob_models/quantization/ptq/tf_benchmark.py @@ -1,10 +1,27 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2022 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + import os import sys import time import logging import argparse import math -import yaml import numpy as np from tensorflow.python.client import timeline @@ -153,24 +170,6 @@ def run_benchmark(model_details, args, find_graph_def): print("Latency: {:.3f} ms".format(latency)) print("Throughput: {:.2f} fps".format(throughput)) -def _write_inputs_outputs_to_yaml(yaml_path, output_yaml_path, inputs, outputs): - # deal with the inputs/outputs at yaml - with open(yaml_path, 'r') as f: - content = yaml.safe_load(f) - - tmp_i = '' - tmp_o = '' - for item in inputs: - tmp_i = tmp_i + str(item) + ',' - for item in outputs: - tmp_o = tmp_o + str(item) + ',' - content['model'].update({'inputs': tmp_i[:-1]}) - content['model'].update({'outputs': tmp_o[:-1]}) - print(content) - - with open(output_yaml_path, 'w') as nf: - yaml.dump(content, nf) - def oob_collate_data_func(batch): """Puts each data field into a pd frame with outer dimension batch size""" elem = batch[0] @@ -330,12 +329,20 @@ def __iter__(self): # tune if args.tune: # os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - from neural_compressor.experimental import Quantization, common inputs = model_detail['input'] outputs = model_detail['output'] - _write_inputs_outputs_to_yaml(args.yaml, "./config_tmp.yaml", list(inputs.keys()), outputs) - quantizer = Quantization("./config_tmp.yaml") + from neural_compressor.data.dataloaders.dataloader import DataLoader + from neural_compressor.quantization import fit + from neural_compressor.config import PostTrainingQuantConfig + from neural_compressor.utils.utility import set_random_seed + + set_random_seed(9527) + config = PostTrainingQuantConfig( + inputs=list(inputs.keys()), + outputs=outputs, + calibration_sampling_size=[1]) + # generate dummy data if model_detail.get('sparse_d_shape'): sparse_input_names = [list(i.keys()) for i in model_detail['sparse_d_shape'].values()] @@ -343,16 +350,19 @@ def __iter__(self): for i in range(1, len(sparse_input_names)): sparse_input_seq += sparse_input_names[i] input_dense_shape = [tuple(list(i.values())[0]) for i in model_detail['sparse_d_shape'].values()] - dataset = quantizer.dataset(dataset_type='sparse_dummy_v2', + from neural_compressor.data import Datasets + dataset = Datasets('tensorflow')['sparse_dummy_v2']( dense_shape=input_dense_shape, label_shape=[[1] for _ in range(len(input_dense_shape))], sparse_ratio=[1-1/np.multiply(*i) for i in input_dense_shape]) seq_idxs = [sparse_input_seq.index(i) for i in inputs.keys()] - quantizer.calib_dataloader = common.DataLoader(dataset=dataset, - batch_size=1, - collate_fn=oob_collate_sparse_func) + calib_dataloader = DataLoader(framework='tensorflow', + dataset=dataset, + batch_size=1, + collate_fn=oob_collate_sparse_func) else: - dataset = quantizer.dataset(dataset_type='dummy', + from neural_compressor.data import Datasets + dataset = Datasets('tensorflow')['dummy']( shape=inputs_shape, low=low, high=high, dtype=inputs_dtype, @@ -361,14 +371,17 @@ def __iter__(self): if args.model_name and args.model_name in dataloader_dict.keys(): Dataloader = dataloader_dict[args.model_name] else: - Dataloader = common.DataLoader - quantizer.calib_dataloader = Dataloader(dataset=dataset, - batch_size=args.batch_size, - collate_fn=oob_collate_data_func \ - if model_detail.get('model_name')!='DLRM' \ - else oob_dlrm_collate_func) - quantizer.model = args.model_path - q_model = quantizer.fit() + Dataloader = DataLoader + calib_dataloader = Dataloader(framework='tensorflow', + dataset=dataset, + batch_size=args.batch_size, + collate_fn=oob_collate_data_func \ + if model_detail.get('model_name')!='DLRM' \ + else oob_dlrm_collate_func) + q_model = fit( + model=args.model_path, + conf=config, + calib_dataloader=calib_dataloader) q_model.save(args.output_path) # benchmark diff --git a/examples/tensorflow/oob_models/quantization/ptq/tf_savemodel_benchmark.py b/examples/tensorflow/oob_models/quantization/ptq/tf_savemodel_benchmark.py index a3e9d0a3d7a..cd8473914fa 100644 --- a/examples/tensorflow/oob_models/quantization/ptq/tf_savemodel_benchmark.py +++ b/examples/tensorflow/oob_models/quantization/ptq/tf_savemodel_benchmark.py @@ -1,6 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2022 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + import os -import cv2 -import sys import time import argparse import numpy as np @@ -12,7 +28,7 @@ def get_dynamic_inputshape(model_dir,dshape): - # judge object_detection model + # judge object_detection model path = model_dir.split('/') is_detection = False for item in path: @@ -100,7 +116,7 @@ def savemodel_valid(meta_graph): flag=False for op in set(all_op_types): if op in valid_op: - flag=True + flag=True return flag def run_benchmark(args): diff --git a/examples/tensorflow/oob_models/quantization/ptq/utils.py b/examples/tensorflow/oob_models/quantization/ptq/utils.py index 57fba066fc6..0a1fd51215c 100644 --- a/examples/tensorflow/oob_models/quantization/ptq/utils.py +++ b/examples/tensorflow/oob_models/quantization/ptq/utils.py @@ -1,7 +1,23 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2022 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + import os -import sys import numpy as np -from google.protobuf import text_format from tensorflow.python.framework import graph_util from tensorflow.python.platform import gfile @@ -25,7 +41,7 @@ def generate_data(input_shape, input_dtype="float32", return np.random.randn(batch_size).astype(input_dtype) dummy_input = np.random.randn(*input_shape).astype(input_dtype) # handle the case that the shape of the input is one-dimensional - if newaxis == False: + if newaxis is False: return np.repeat(dummy_input, batch_size, axis=0) return np.repeat(dummy_input[np.newaxis, :], batch_size, axis=0) @@ -42,7 +58,7 @@ def freeze_graph(input_checkpoint, output_graph, output_node_names): with tf.compat.v1.Session() as sess: saver.restore(sess, input_checkpoint) - output_graph_def = graph_util.convert_variables_to_constants( + output_graph_def = graph_util.convert_variables_to_constants( sess=sess, input_graph_def=sess.graph_def, output_node_names=output_node_names) @@ -50,7 +66,7 @@ def freeze_graph(input_checkpoint, output_graph, output_node_names): with tf.io.gfile.GFile(output_graph, "wb") as f: f.write(output_graph_def.SerializeToString()) print("convert done!!") - print("%d ops in the final graph." % len(output_graph_def.node)) + print("%d ops in the final graph." % len(output_graph_def.node)) return output_graph_def @@ -92,7 +108,7 @@ def write_graph(out_graph_def, out_graph_file): :return: None. """ if not isinstance(out_graph_def, tf.compat.v1.GraphDef): - raise ValueError( + raise ValueError( 'out_graph_def is not instance of TensorFlow GraphDef.') if out_graph_file and not os.path.exists(os.path.dirname(out_graph_file)): raise ValueError('"output_graph" directory does not exists.') diff --git a/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/README.md b/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/README.md index ae21ba36de6..40661ab8f8d 100644 --- a/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/README.md +++ b/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/README.md @@ -24,7 +24,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. @@ -73,15 +74,23 @@ Two .tfrecords files are generated and will be used later on: wget https://storage.googleapis.com/intel-optimized-tensorflow/models/v1_6/wide_deep_fp32_pretrained_model.pb ``` -### 8. Config the yaml file -In examples directory, there is a wide_deep_large_ds.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 wide_deep_large_ds_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. +### 8. 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", + ... + ) +``` ### 9. Run Command # The cmd of running WnD ```shell bash run_tuning.sh --dataset_location=/path/to/datasets --input_model=/path/to/wide_deep_fp32_pretrained_model.pb --output_model=./wnd_int8_opt.pb bash run_benchmark.sh --dataset_location=/path/to/datasets --input_model=./wnd_int8_opt.pb --mode=accuracy --batch_size=500 - bash run_benchmark.sh --dataset_location=/path/to/datasets --input_model=./wnd_int8_opt.pb --mode=benchmark --batch_size=500 + bash run_benchmark.sh --dataset_location=/path/to/datasets --input_model=./wnd_int8_opt.pb --mode=performance --batch_size=500 ``` ### Other This example takes the reference from https://github.com/IntelAI/models/tree/master/benchmarks/recommendation/tensorflow/wide_deep_large_ds. diff --git a/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/inference.py b/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/inference.py index 839ab874692..63444ea727e 100644 --- a/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/inference.py +++ b/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/inference.py @@ -107,6 +107,9 @@ def _parse_function(proto): dataset = dataset.prefetch(batch_size*10) return dataset +def evaluation_func(model, measurer=None): + evaluate_opt_graph.eval_inference(model) + class eval_classifier_optimized_graph: """Evaluate image classifier with optimized TensorFlow graph""" @@ -178,24 +181,37 @@ def auto_tune(self): Returns: graph: it will return a quantized pb """ - from neural_compressor.experimental import Quantization + from neural_compressor.quantization import fit + from neural_compressor.config import PostTrainingQuantConfig + from neural_compressor.utils.utility import set_random_seed infer_graph = load_graph(self.args.input_graph) - quantizer = Quantization(self.args.config) + set_random_seed(9527) + + config = PostTrainingQuantConfig( + inputs=["new_numeric_placeholder", "new_categorical_placeholder"], + outputs=["import/head/predictions/probabilities"], + calibration_sampling_size=[2000], + op_name_list={ + 'import/dnn/hiddenlayer_0/MatMul': { + 'activation': {'dtype': ['uint8'], 'algorithm': ['minmax'], 'scheme':['asym']}, + } + }) + if self.args.calib_data: - quantizer.model = infer_graph - quantizer.calib_dataloader = Dataloader(self.args.calib_data, self.args.batch_size) - quantizer.eval_func = self.eval_inference - q_model = quantizer.fit() + q_model = fit( + model=infer_graph, + conf=config, + calib_dataloader=Dataloader(self.args.calib_data, self.args.batch_size), + eval_func=self.eval_inference) return q_model - else: - print("Please provide calibration dataset!") + print("Please provide calibration dataset!") def eval_inference(self, infer_graph): print("Run inference") if isinstance(infer_graph, tf.compat.v1.GraphDef): - graph = tf.Graph() + graph = tf.Graph() with graph.as_default(): - tf.import_graph_def(infer_graph, name='') + tf.import_graph_def(infer_graph, name='') infer_graph = graph data_config = tf.compat.v1.ConfigProto() @@ -297,8 +313,12 @@ def run(self): q_model.save(self.args.output_graph) if self.args.benchmark: - infer_graph = load_graph(self.args.input_graph) - self.eval_inference(infer_graph) + from neural_compressor.benchmark import fit + from neural_compressor.config import BenchmarkConfig + conf = BenchmarkConfig(iteration=100, cores_per_instance=4, num_of_instance=7) + fit(self.args.input_graph, conf, + b_dataloader=Dataloader(self.args.eval_data, self.args.batch_size), + b_func=evaluation_func) class Dataloader(object): def __init__(self, data_location, batch_size): diff --git a/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/run_benchmark.sh b/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/run_benchmark.sh index d0cab565bb4..045d3a261aa 100644 --- a/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/run_benchmark.sh +++ b/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/run_benchmark.sh @@ -15,9 +15,6 @@ function init_params { for var in "$@" do case $var in - --topology=*) - topology=$(echo $var |cut -f2 -d=) - ;; --dataset_location=*) dataset_location=$(echo $var |cut -f2 -d=) ;; @@ -30,13 +27,6 @@ function init_params { --batch_size=*) batch_size=$(echo $var |cut -f2 -d=) ;; - --iters=*) - iters=$(echo ${var} |cut -f2 -d=) - ;; - *) - echo "Error: No such parameter: ${var}" - exit 1 - ;; esac done @@ -45,8 +35,8 @@ function init_params { function define_mode { if [[ ${mode} == "accuracy" ]]; then mode_cmd=" --benchmark --accuracy_only" - elif [[ ${mode} == "benchmark" ]]; then - mode_cmd=" --steps ${iters} --benchmark" + elif [[ ${mode} == "performance" ]]; then + mode_cmd=" --benchmark" else echo "Error: No such mode: ${mode}" exit 1 diff --git a/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/run_tuning.sh b/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/run_tuning.sh index 0f0a24bd456..175651a44b3 100644 --- a/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/run_tuning.sh +++ b/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/run_tuning.sh @@ -14,9 +14,6 @@ function init_params { for var in "$@" do case $var in - --topology=*) - topology=$(echo $var |cut -f2 -d=) - ;; --dataset_location=*) dataset_location=$(echo $var |cut -f2 -d=) ;; @@ -45,7 +42,6 @@ function run_tuning { --accuracy_only \ --batch_size 1000 \ --output_graph ${output_model} \ - --config wide_deep_large_ds.yaml \ --tune } diff --git a/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/wide_deep_large_ds.yaml b/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/wide_deep_large_ds.yaml deleted file mode 100644 index f464c17260d..00000000000 --- a/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/wide_deep_large_ds.yaml +++ /dev/null @@ -1,42 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: wide_deep_large_ds - framework: tensorflow # mandatory. supported values are tensorflow, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: new_numeric_placeholder,new_categorical_placeholder - outputs: import/head/predictions/probabilities # optional. inputs and outputs fields are only required for tensorflow backend. - -device: cpu # optional. default value is cpu, other value is gpu. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 2000 # optional. default value is 100. used to set how many samples should be used in calibration. - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - op_wise: { - 'import/dnn/hiddenlayer_0/MatMul': { - 'activation': {'dtype': ['uint8'], 'algorithm': ['minmax'], 'scheme':['asym']}, - } - } - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - max_trials: 100 # optional. max tune times. default value is 100. combine with timeout field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/wide_deep_large_ds_itex.yaml b/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/wide_deep_large_ds_itex.yaml deleted file mode 100644 index 59a9d2e6ee3..00000000000 --- a/examples/tensorflow/recommendation/wide_deep_large_ds/quantization/ptq/wide_deep_large_ds_itex.yaml +++ /dev/null @@ -1,42 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -model: # mandatory. used to specify model specific information. - name: wide_deep_large_ds - framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: new_numeric_placeholder,new_categorical_placeholder - outputs: import/head/predictions/probabilities # optional. inputs and outputs fields are only required for tensorflow backend. - -device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu]. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 2000 # optional. default value is 100. used to set how many samples should be used in calibration. - model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - activation: - algorithm: minmax - op_wise: { - 'import/dnn/hiddenlayer_0/MatMul': { - 'activation': {'dtype': ['uint8'], 'algorithm': ['minmax'], 'scheme':['asym']}, - } - } - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - max_trials: 100 # optional. max tune times. default value is 100. combine with timeout field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/3dunet-mlperf.yaml b/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/3dunet-mlperf.yaml deleted file mode 100644 index 2d973ab66e9..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/3dunet-mlperf.yaml +++ /dev/null @@ -1,34 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -version: 1.0 - -device: cpu # optional. default value is cpu, other value is gpu. - -model: - name: 3dunet-mlperf - framework: tensorflow - -quantization: - calibration: - sampling_size: 40 - -tuning: - accuracy_criterion: - relative: 0.01 - exit_policy: - timeout: 0 - max_trials: 100 - random_seed: 9527 diff --git a/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/3dunet-mlperf_itex.yaml b/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/3dunet-mlperf_itex.yaml deleted file mode 100644 index 801aec72d52..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/3dunet-mlperf_itex.yaml +++ /dev/null @@ -1,34 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -version: 1.0 - -device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu]. - -model: - name: 3dunet-mlperf - framework: tensorflow_itex - -quantization: - calibration: - sampling_size: 40 - -tuning: - accuracy_criterion: - relative: 0.01 - exit_policy: - timeout: 0 - max_trials: 100 - random_seed: 9527 diff --git a/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/README.md b/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/README.md index cab2e7e39dc..e4d95f5c5fd 100644 --- a/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/README.md +++ b/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/README.md @@ -25,7 +25,9 @@ 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. @@ -49,13 +51,21 @@ pip install --upgrade intel-extension-for-tensorflow[cpu] ### 6. Prepare Calibration set The calibration set is the forty images listed in brats_cal_images_list.txt. They are randomly selected from Fold 0, Fold 2, Fold 3, and Fold 4 of BraTS 2019 Training Dataset. -### 7. Config the yaml file -In examples directory, there is a 3dunet-mlperf.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 3dunet-mlperf_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. +### 7. 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", + ... + ) +``` ### 8. Test command * `export nnUNet_preprocessed=/build/preprocessed_data` * `export nnUNet_raw_data_base=/build/raw_data` * `export RESULTS_FOLDER=/build/result` -* `pip install requirements.txt` +* `pip install -r requirements.txt` * `python run_accuracy.py --input-model= --data-location= --calib-preprocess= --iters=100 --batch-size=1 --mode=benchmark --bfloat16 0` diff --git a/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/run_accuracy.py b/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/run_accuracy.py index 7ed1dca741d..43136535cf7 100644 --- a/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/run_accuracy.py +++ b/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/run_accuracy.py @@ -64,8 +64,6 @@ def get_args(): arg_parser.add_argument('-o', "--output-model", help='Specify the output graph.', dest='output_model') - arg_parser.add_argument('--config', - help='Specify the yaml config file.') arg_parser.add_argument('-c', "--calib-preprocess", help='Specify calibration preprocess dir.', dest='calib_preprocess') @@ -128,14 +126,14 @@ def eval_func(graph): file_name = preprocessed_files[test_data_index] with open(os.path.join(preprocessed_data_dir, "{:}.pkl".format(file_name)), "rb") as f: data = pickle.load(f)[0] - if args.mode == 'benchmark' and i < args.iters: + if args.mode == 'performance' and i < args.iters: time_start = time.time() predictions[i] = sess.run(output_tensor, feed_dict={input_tensor: data[np.newaxis, ...]})[0].astype(np.float32) duration = time.time() - time_start time_list.append(duration) else: predictions[i] = sess.run(output_tensor, feed_dict={input_tensor: data[np.newaxis, ...]})[0].astype(np.float32) - if args.mode == 'benchmark': + if args.mode == 'performance': latency = np.array(time_list[warmup: ]).mean() / args.batch_size print('Batch size = {}'.format(args.batch_size)) print('Latency: {:.3f} ms'.format(latency * 1000)) @@ -201,19 +199,32 @@ def __len__(self): return self.count - from neural_compressor.experimental import Quantization, common args = get_args() print(args) graph = load_graph(args.input_model) if args.mode == 'tune': - quantizer = Quantization(args.config) - quantizer.calib_dataloader = common.DataLoader(CalibrationDL()) - quantizer.model = common.Model(graph) - quantizer.eval_func = eval_func - q_model = quantizer.fit() + from neural_compressor.data.dataloaders.dataloader import DataLoader + from neural_compressor.quantization import fit + from neural_compressor.config import PostTrainingQuantConfig + from neural_compressor.utils.utility import set_random_seed + set_random_seed(9527) + config = PostTrainingQuantConfig(calibration_sampling_size=[40]) + + q_model = fit( + model=graph, + conf=config, + calib_dataloader=DataLoader(framework='tensorflow', dataset=CalibrationDL()), + eval_dataloader=DataLoader(framework='tensorflow', dataset=CalibrationDL()), + eval_func=eval_func) try: q_model.save(args.output_model) except Exception as e: print("Failed to save model due to {}".format(str(e))) else: - eval_func(graph) + from neural_compressor.data.dataloaders.dataloader import DataLoader + from neural_compressor.benchmark import fit + from neural_compressor.config import BenchmarkConfig + conf = BenchmarkConfig(cores_per_instance=4, num_of_instance=7) + fit(graph, conf, + b_dataloader=DataLoader(framework='tensorflow', dataset=CalibrationDL()), + b_func=eval_func) diff --git a/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/run_benchmark.sh b/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/run_benchmark.sh index 77d20e3b9fe..fd466c5f8d0 100644 --- a/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/run_benchmark.sh +++ b/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/run_benchmark.sh @@ -19,9 +19,6 @@ function init_params { for var in "$@" do case $var in - --topology=*) - topology=$(echo $var |cut -f2 -d=) - ;; --mode=*) mode=$(echo $var |cut -f2 -d=) ;; @@ -34,12 +31,6 @@ function init_params { --batch_size=*) batch_size=$(echo $var |cut -f2 -d=) ;; - --iters=*) - iters=$(echo ${var} |cut -f2 -d=) - ;; - --bfloat16=*) - bfloat16=$(echo ${var} |cut -f2 -d=) - ;; *) echo "Error: No such parameter: ${var}" exit 1 @@ -62,7 +53,6 @@ function run_benchmark { --input-model=${input_model} \ --data-location=${dataset_location} \ --calib-preprocess=${BUILD_DIR}/calib_preprocess \ - --iters=${iters} \ --batch-size=${batch_size} \ --mode=${mode} \ ${extra_cmd} diff --git a/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/run_tuning.sh b/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/run_tuning.sh index 218d91e49c8..749b0c09c2b 100644 --- a/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/run_tuning.sh +++ b/examples/tensorflow/semantic_image_segmentation/3dunet-mlperf/quantization/ptq/run_tuning.sh @@ -17,9 +17,6 @@ function init_params { for var in "$@" do case $var in - --topology=*) - topology=$(echo $var |cut -f2 -d=) - ;; --dataset_location=*) dataset_location=$(echo $var |cut -f2 -d=) ;; @@ -40,13 +37,11 @@ function init_params { # run_tuning function run_tuning { - config=$topology'.yaml' python run_accuracy.py \ --input-model=${input_model} \ --output-model=${output_model} \ --data-location=${dataset_location} \ --calib-preprocess=${BUILD_DIR}/calib_preprocess \ - --config=${config} \ --mode=tune } diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/README.md b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/README.md deleted file mode 100644 index 1bca85e202b..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/README.md +++ /dev/null @@ -1,183 +0,0 @@ -Step-by-Step -============ - -This document list steps of reproducing Intel Optimized TensorFlow image recognition models tuning results via Neural Compressor. -This example can run on Intel CPUs and GPUs. - -> **Note**: -> Most of those models are both supported in Intel optimized TF 1.15.x and Intel optimized TF 2.x. -> [Version support](../../../../../../README.md#supported-frameworks) -# Prerequisite - -### 1. Installation - Recommend python 3.6 or higher version. - - ```shell - cd examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq - pip install -r requirements.txt - ``` - -### 2. Install Intel Tensorflow -```shell -pip install intel-tensorflow -``` -> Note: Supported Tensorflow [Version](../../../../../../README.md#supported-frameworks). - -### 3. Install Intel Extension for Tensorflow -#### Quantizing the model on Intel GPU -Intel Extension for Tensorflow is mandatory to be installed for quantizing the model on Intel GPUs. - -```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) - -#### 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. - -```shell -pip install --upgrade intel-extension-for-tensorflow[cpu] -``` - -### 4. Prepare Dataset -Please use the script under the folder `datasets` to download and convert PASCAL VOC 2012 semantic segmentation dataset to TFRecord. Refer to [Running DeepLab on PASCAL VOC 2012 Semantic Segmentation Dataset](https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/pascal.md#running-deeplab-on-pascal-voc-2012-semantic-segmentation-dataset) for more details. -```shell -# From the examples/tensorflow/semantic_image_segmentation/deeplab/datasets directory. -sh download_and_convert_voc2012.sh -``` - -### 5. Prepare pre-trained model -Refer to [Export trained deeplab model to frozen inference graph](https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/export_model.md#export-trained-deeplab-model-to-frozen-inference-graph) for more details. - -1. Download the checkpoint file -```shell -wget http://download.tensorflow.org/models/deeplabv3_pascal_train_aug_2018_01_04.tar.gz -tar -xvf deeplabv3_pascal_train_aug_2018_01_04.tar.gz -``` -2. Export to a frozen graph -```shell -git clone https://github.com/tensorflow/models.git -cd models/research/ -export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim - -python deeplab/export_model.py \ - --checkpoint_path=/PATH/TO/deeplabv3_pascal_train_aug/model.ckpt \ - --export_path=/PATH/TO/deeplab_export.pb \ - --model_variant="xception_65" \ - --logtostderr \ - --eval_split="val" \ - --model_variant="xception_65" \ - --atrous_rates=6 \ - --atrous_rates=12 \ - --atrous_rates=18 \ - --output_stride=16 \ - --decoder_output_stride=4 \ - --eval_crop_size="513,513" \ - --dataset="pascal_voc_seg" -``` - -# Run -```shell -cd examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq -bash run_tuning.sh --config=deeplab.yaml --input_model=/PATH/TO/deeplab_export.pb --output_model=./nc_deeplab.pb -``` - - -Examples of enabling Intel® Neural Compressor auto tuning on Deeplab model for tensorflow -======================================================= - -This is a tutorial of how to enable deeplab model with Intel® Neural Compressor. - -# User Code Analysis - -Intel® Neural Compressor supports two usages: - -1. User specifies fp32 "model", yaml configured calibration dataloader in calibration field and evaluation dataloader in evaluation field, metric in tuning.metric field of model-specific yaml config file. - -> *Note*: -> you should change the model-specific yaml file dataset path to your own dataset path - -2. User specifies fp32 "model", calibration dataset "q_dataloader" and a custom "eval_func" which encapsulates the evaluation dataset and metric by itself. - -We provide Deeplab model pretrained on PASCAL VOC 2012, Using mIOU as metric which is built-in supported by Intel® Neural Compressor. - -### Write Yaml config file - -In examples directory, there is a deeplab.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 deeplab_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. - -```yaml -# deeplab.yaml -device: cpu # optional. default value is cpu, other value is gpu. -model: # mandatory. neural_compressor uses this model name and framework name to decide where to save tuning history and deploy yaml. - name: deeplab - framework: tensorflow # mandatory. supported values are tensorflow, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 50, 100 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: - batch_size: 1 - dataset: - VOCRecord: - root: /path/to/pascal_voc_seg/tfrecord # NOTE: modify to calibration - transform: - ParseDecodeVoc: {} - - -evaluation: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - mIOU: - num_classes: 21 # built-in metrics are topk, map, f1, allow user to register new metric. - dataloader: - batch_size: 1 - dataset: - VOCRecord: - root: /path/to/pascal_voc_seg/tfrecord # NOTE: modify to evaluation dataset location if needed - transform: - ParseDecodeVoc: {} - performance: # optional. used to benchmark performance of passing model. - iteration: 100 - configs: - cores_per_instance: 4 - num_of_instance: 6 - dataloader: - batch_size: 1 - dataset: - VOCRecord: - root: /path/to/pascal_voc_seg/tfrecord # NOTE: modify to evaluation dataset location if needed - transform: - ParseDecodeVoc: {} - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. - - -``` - -Here we choose topk which is built-in metric and set accuracy criterion as tolerating 0.01 relative accuracy loss of baseline. The default tuning strategy is basic strategy. The timeout 0 means early stop as long as a tuning config meet accuracy target. - -### Tune - -After completed preparation steps, we just need to add below tuning part in `eval_classifier_optimized_graph` class. - -```python -from neural_compressor.experimental import Quantization, common -quantizer = Quantization(self.args.config) -quantizer.model = common.Model(self.args.input_graph) -q_model = quantizer.fit() -q_model.save(self.args.output_graph) -``` - -### Benchmark -```python -from neural_compressor.experimental import Benchmark, common -evaluator = Benchmark(self.args.config) -evaluator.model = common.Model(self.args.input_graph) -evaluator(self.args.mode) -``` - diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/__init__.py b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/build_ade20k_data.py b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/build_ade20k_data.py deleted file mode 100644 index fc04ed0db04..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/build_ade20k_data.py +++ /dev/null @@ -1,123 +0,0 @@ -# Lint as: python2, python3 -# Copyright 2018 The TensorFlow Authors All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== - -"""Converts ADE20K data to TFRecord file format with Example protos.""" - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -import math -import os -import random -import sys -import build_data -from six.moves import range -import tensorflow as tf - -FLAGS = tf.app.flags.FLAGS - -tf.app.flags.DEFINE_string( - 'train_image_folder', - './ADE20K/ADEChallengeData2016/images/training', - 'Folder containing trainng images') -tf.app.flags.DEFINE_string( - 'train_image_label_folder', - './ADE20K/ADEChallengeData2016/annotations/training', - 'Folder containing annotations for trainng images') - -tf.app.flags.DEFINE_string( - 'val_image_folder', - './ADE20K/ADEChallengeData2016/images/validation', - 'Folder containing validation images') - -tf.app.flags.DEFINE_string( - 'val_image_label_folder', - './ADE20K/ADEChallengeData2016/annotations/validation', - 'Folder containing annotations for validation') - -tf.app.flags.DEFINE_string( - 'output_dir', './ADE20K/tfrecord', - 'Path to save converted tfrecord of Tensorflow example') - -_NUM_SHARDS = 4 - - -def _convert_dataset(dataset_split, dataset_dir, dataset_label_dir): - """Converts the ADE20k dataset into into tfrecord format. - - Args: - dataset_split: Dataset split (e.g., train, val). - dataset_dir: Dir in which the dataset locates. - dataset_label_dir: Dir in which the annotations locates. - - Raises: - RuntimeError: If loaded image and label have different shape. - """ - - img_names = tf.gfile.Glob(os.path.join(dataset_dir, '*.jpg')) - random.shuffle(img_names) - seg_names = [] - for f in img_names: - # get the filename without the extension - basename = os.path.basename(f).split('.')[0] - # cover its corresponding *_seg.png - seg = os.path.join(dataset_label_dir, basename+'.png') - seg_names.append(seg) - - num_images = len(img_names) - num_per_shard = int(math.ceil(num_images / _NUM_SHARDS)) - - image_reader = build_data.ImageReader('jpeg', channels=3) - label_reader = build_data.ImageReader('png', channels=1) - - for shard_id in range(_NUM_SHARDS): - output_filename = os.path.join( - FLAGS.output_dir, - '%s-%05d-of-%05d.tfrecord' % (dataset_split, shard_id, _NUM_SHARDS)) - with tf.python_io.TFRecordWriter(output_filename) as tfrecord_writer: - start_idx = shard_id * num_per_shard - end_idx = min((shard_id + 1) * num_per_shard, num_images) - for i in range(start_idx, end_idx): - sys.stdout.write('\r>> Converting image %d/%d shard %d' % ( - i + 1, num_images, shard_id)) - sys.stdout.flush() - # Read the image. - image_filename = img_names[i] - image_data = tf.gfile.FastGFile(image_filename, 'rb').read() - height, width = image_reader.read_image_dims(image_data) - # Read the semantic segmentation annotation. - seg_filename = seg_names[i] - seg_data = tf.gfile.FastGFile(seg_filename, 'rb').read() - seg_height, seg_width = label_reader.read_image_dims(seg_data) - if height != seg_height or width != seg_width: - raise RuntimeError('Shape mismatched between image and label.') - # Convert to tf example. - example = build_data.image_seg_to_tfexample( - image_data, img_names[i], height, width, seg_data) - tfrecord_writer.write(example.SerializeToString()) - sys.stdout.write('\n') - sys.stdout.flush() - - -def main(unused_argv): - tf.gfile.MakeDirs(FLAGS.output_dir) - _convert_dataset( - 'train', FLAGS.train_image_folder, FLAGS.train_image_label_folder) - _convert_dataset('val', FLAGS.val_image_folder, FLAGS.val_image_label_folder) - - -if __name__ == '__main__': - tf.app.run() diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/build_cityscapes_data.py b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/build_cityscapes_data.py deleted file mode 100644 index 53c11e30310..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/build_cityscapes_data.py +++ /dev/null @@ -1,198 +0,0 @@ -# Lint as: python2, python3 -# Copyright 2018 The TensorFlow Authors All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== - -"""Converts Cityscapes data to TFRecord file format with Example protos. - -The Cityscapes dataset is expected to have the following directory structure: - - + cityscapes - - build_cityscapes_data.py (current working directiory). - - build_data.py - + cityscapesscripts - + annotation - + evaluation - + helpers - + preparation - + viewer - + gtFine - + train - + val - + test - + leftImg8bit - + train - + val - + test - + tfrecord - -This script converts data into sharded data files and save at tfrecord folder. - -Note that before running this script, the users should (1) register the -Cityscapes dataset website at https://www.cityscapes-dataset.com to -download the dataset, and (2) run the script provided by Cityscapes -`preparation/createTrainIdLabelImgs.py` to generate the training groundtruth. - -Also note that the tensorflow model will be trained with `TrainId' instead -of `EvalId' used on the evaluation server. Thus, the users need to convert -the predicted labels to `EvalId` for evaluation on the server. See the -vis.py for more details. - -The Example proto contains the following fields: - - image/encoded: encoded image content. - image/filename: image filename. - image/format: image file format. - image/height: image height. - image/width: image width. - image/channels: image channels. - image/segmentation/class/encoded: encoded semantic segmentation content. - image/segmentation/class/format: semantic segmentation file format. -""" -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -import glob -import math -import os.path -import re -import sys -import build_data -from six.moves import range -import tensorflow as tf - -FLAGS = tf.app.flags.FLAGS - -tf.app.flags.DEFINE_string('cityscapes_root', - './cityscapes', - 'Cityscapes dataset root folder.') - -tf.app.flags.DEFINE_string( - 'output_dir', - './tfrecord', - 'Path to save converted SSTable of TensorFlow examples.') - - -_NUM_SHARDS = 10 - -# A map from data type to folder name that saves the data. -_FOLDERS_MAP = { - 'image': 'leftImg8bit', - 'label': 'gtFine', -} - -# A map from data type to filename postfix. -_POSTFIX_MAP = { - 'image': '_leftImg8bit', - 'label': '_gtFine_labelTrainIds', -} - -# A map from data type to data format. -_DATA_FORMAT_MAP = { - 'image': 'png', - 'label': 'png', -} - -# Image file pattern. -_IMAGE_FILENAME_RE = re.compile('(.+)' + _POSTFIX_MAP['image']) - - -def _get_files(data, dataset_split): - """Gets files for the specified data type and dataset split. - - Args: - data: String, desired data ('image' or 'label'). - dataset_split: String, dataset split ('train_fine', 'val_fine', 'test_fine') - - Returns: - A list of sorted file names or None when getting label for - test set. - """ - if dataset_split == 'train_fine': - split_dir = 'train' - elif dataset_split == 'val_fine': - split_dir = 'val' - elif dataset_split == 'test_fine': - split_dir = 'test' - else: - raise RuntimeError("Split {} is not supported".format(dataset_split)) - pattern = '*%s.%s' % (_POSTFIX_MAP[data], _DATA_FORMAT_MAP[data]) - search_files = os.path.join( - FLAGS.cityscapes_root, _FOLDERS_MAP[data], split_dir, '*', pattern) - filenames = glob.glob(search_files) - return sorted(filenames) - - -def _convert_dataset(dataset_split): - """Converts the specified dataset split to TFRecord format. - - Args: - dataset_split: The dataset split (e.g., train_fine, val_fine). - - Raises: - RuntimeError: If loaded image and label have different shape, or if the - image file with specified postfix could not be found. - """ - image_files = _get_files('image', dataset_split) - label_files = _get_files('label', dataset_split) - - num_images = len(image_files) - num_labels = len(label_files) - num_per_shard = int(math.ceil(num_images / _NUM_SHARDS)) - - if num_images != num_labels: - raise RuntimeError("The number of images and labels doesn't match: {} {}".format(num_images, num_labels)) - - image_reader = build_data.ImageReader('png', channels=3) - label_reader = build_data.ImageReader('png', channels=1) - - for shard_id in range(_NUM_SHARDS): - shard_filename = '%s-%05d-of-%05d.tfrecord' % ( - dataset_split, shard_id, _NUM_SHARDS) - output_filename = os.path.join(FLAGS.output_dir, shard_filename) - with tf.python_io.TFRecordWriter(output_filename) as tfrecord_writer: - start_idx = shard_id * num_per_shard - end_idx = min((shard_id + 1) * num_per_shard, num_images) - for i in range(start_idx, end_idx): - sys.stdout.write('\r>> Converting image %d/%d shard %d' % ( - i + 1, num_images, shard_id)) - sys.stdout.flush() - # Read the image. - image_data = tf.gfile.FastGFile(image_files[i], 'rb').read() - height, width = image_reader.read_image_dims(image_data) - # Read the semantic segmentation annotation. - seg_data = tf.gfile.FastGFile(label_files[i], 'rb').read() - seg_height, seg_width = label_reader.read_image_dims(seg_data) - if height != seg_height or width != seg_width: - raise RuntimeError('Shape mismatched between image and label.') - # Convert to tf example. - re_match = _IMAGE_FILENAME_RE.search(image_files[i]) - if re_match is None: - raise RuntimeError('Invalid image filename: ' + image_files[i]) - filename = os.path.basename(re_match.group(1)) - example = build_data.image_seg_to_tfexample( - image_data, filename, height, width, seg_data) - tfrecord_writer.write(example.SerializeToString()) - sys.stdout.write('\n') - sys.stdout.flush() - - -def main(unused_argv): - # Only support converting 'train_fine', 'val_fine' and 'test_fine' sets for now. - for dataset_split in ['train_fine', 'val_fine', 'test_fine']: - _convert_dataset(dataset_split) - - -if __name__ == '__main__': - tf.app.run() diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/build_data.py b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/build_data.py deleted file mode 100644 index 45628674dbf..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/build_data.py +++ /dev/null @@ -1,161 +0,0 @@ -# Copyright 2018 The TensorFlow Authors All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== - -"""Contains common utility functions and classes for building dataset. - -This script contains utility functions and classes to converts dataset to -TFRecord file format with Example protos. - -The Example proto contains the following fields: - - image/encoded: encoded image content. - image/filename: image filename. - image/format: image file format. - image/height: image height. - image/width: image width. - image/channels: image channels. - image/segmentation/class/encoded: encoded semantic segmentation content. - image/segmentation/class/format: semantic segmentation file format. -""" -import collections -import six -import tensorflow as tf - -FLAGS = tf.app.flags.FLAGS - -tf.app.flags.DEFINE_enum('image_format', 'png', ['jpg', 'jpeg', 'png'], - 'Image format.') - -tf.app.flags.DEFINE_enum('label_format', 'png', ['png'], - 'Segmentation label format.') - -# A map from image format to expected data format. -_IMAGE_FORMAT_MAP = { - 'jpg': 'jpeg', - 'jpeg': 'jpeg', - 'png': 'png', -} - - -class ImageReader(object): - """Helper class that provides TensorFlow image coding utilities.""" - - def __init__(self, image_format='jpeg', channels=3): - """Class constructor. - - Args: - image_format: Image format. Only 'jpeg', 'jpg', or 'png' are supported. - channels: Image channels. - """ - with tf.Graph().as_default(): - self._decode_data = tf.placeholder(dtype=tf.string) - self._image_format = image_format - self._session = tf.Session() - if self._image_format in ('jpeg', 'jpg'): - self._decode = tf.image.decode_jpeg(self._decode_data, - channels=channels) - elif self._image_format == 'png': - self._decode = tf.image.decode_png(self._decode_data, - channels=channels) - - def read_image_dims(self, image_data): - """Reads the image dimensions. - - Args: - image_data: string of image data. - - Returns: - image_height and image_width. - """ - image = self.decode_image(image_data) - return image.shape[:2] - - def decode_image(self, image_data): - """Decodes the image data string. - - Args: - image_data: string of image data. - - Returns: - Decoded image data. - - Raises: - ValueError: Value of image channels not supported. - """ - image = self._session.run(self._decode, - feed_dict={self._decode_data: image_data}) - if len(image.shape) != 3 or image.shape[2] not in (1, 3): - raise ValueError('The image channels not supported.') - - return image - - -def _int64_list_feature(values): - """Returns a TF-Feature of int64_list. - - Args: - values: A scalar or list of values. - - Returns: - A TF-Feature. - """ - if not isinstance(values, collections.Iterable): - values = [values] - - return tf.train.Feature(int64_list=tf.train.Int64List(value=values)) - - -def _bytes_list_feature(values): - """Returns a TF-Feature of bytes. - - Args: - values: A string. - - Returns: - A TF-Feature. - """ - def norm2bytes(value): - return value.encode() if isinstance(value, str) and six.PY3 else value - - return tf.train.Feature( - bytes_list=tf.train.BytesList(value=[norm2bytes(values)])) - - -def image_seg_to_tfexample(image_data, filename, height, width, seg_data): - """Converts one image/segmentation pair to tf example. - - Args: - image_data: string of image data. - filename: image filename. - height: image height. - width: image width. - seg_data: string of semantic segmentation data. - - Returns: - tf example of one image/segmentation pair. - """ - return tf.train.Example(features=tf.train.Features(feature={ - 'image/encoded': _bytes_list_feature(image_data), - 'image/filename': _bytes_list_feature(filename), - 'image/format': _bytes_list_feature( - _IMAGE_FORMAT_MAP[FLAGS.image_format]), - 'image/height': _int64_list_feature(height), - 'image/width': _int64_list_feature(width), - 'image/channels': _int64_list_feature(3), - 'image/segmentation/class/encoded': ( - _bytes_list_feature(seg_data)), - 'image/segmentation/class/format': _bytes_list_feature( - FLAGS.label_format), - })) diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/build_voc2012_data.py b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/build_voc2012_data.py deleted file mode 100644 index f0bdecb6a0f..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/build_voc2012_data.py +++ /dev/null @@ -1,146 +0,0 @@ -# Lint as: python2, python3 -# Copyright 2018 The TensorFlow Authors All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== - -"""Converts PASCAL VOC 2012 data to TFRecord file format with Example protos. - -PASCAL VOC 2012 dataset is expected to have the following directory structure: - - + pascal_voc_seg - - build_data.py - - build_voc2012_data.py (current working directory). - + VOCdevkit - + VOC2012 - + JPEGImages - + SegmentationClass - + ImageSets - + Segmentation - + tfrecord - -Image folder: - ./VOCdevkit/VOC2012/JPEGImages - -Semantic segmentation annotations: - ./VOCdevkit/VOC2012/SegmentationClass - -list folder: - ./VOCdevkit/VOC2012/ImageSets/Segmentation - -This script converts data into sharded data files and save at tfrecord folder. - -The Example proto contains the following fields: - - image/encoded: encoded image content. - image/filename: image filename. - image/format: image file format. - image/height: image height. - image/width: image width. - image/channels: image channels. - image/segmentation/class/encoded: encoded semantic segmentation content. - image/segmentation/class/format: semantic segmentation file format. -""" -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -import math -import os.path -import sys -import build_data -from six.moves import range -import tensorflow as tf - -FLAGS = tf.app.flags.FLAGS - -tf.app.flags.DEFINE_string('image_folder', - './VOCdevkit/VOC2012/JPEGImages', - 'Folder containing images.') - -tf.app.flags.DEFINE_string( - 'semantic_segmentation_folder', - './VOCdevkit/VOC2012/SegmentationClassRaw', - 'Folder containing semantic segmentation annotations.') - -tf.app.flags.DEFINE_string( - 'list_folder', - './VOCdevkit/VOC2012/ImageSets/Segmentation', - 'Folder containing lists for training and validation') - -tf.app.flags.DEFINE_string( - 'output_dir', - './tfrecord', - 'Path to save converted SSTable of TensorFlow examples.') - - -_NUM_SHARDS = 4 - - -def _convert_dataset(dataset_split): - """Converts the specified dataset split to TFRecord format. - - Args: - dataset_split: The dataset split (e.g., train, test). - - Raises: - RuntimeError: If loaded image and label have different shape. - """ - dataset = os.path.basename(dataset_split)[:-4] - sys.stdout.write('Processing ' + dataset) - filenames = [x.strip('\n') for x in open(dataset_split, 'r')] - num_images = len(filenames) - num_per_shard = int(math.ceil(num_images / _NUM_SHARDS)) - - image_reader = build_data.ImageReader('jpeg', channels=3) - label_reader = build_data.ImageReader('png', channels=1) - - for shard_id in range(_NUM_SHARDS): - output_filename = os.path.join( - FLAGS.output_dir, - '%s-%05d-of-%05d.tfrecord' % (dataset, shard_id, _NUM_SHARDS)) - with tf.python_io.TFRecordWriter(output_filename) as tfrecord_writer: - start_idx = shard_id * num_per_shard - end_idx = min((shard_id + 1) * num_per_shard, num_images) - for i in range(start_idx, end_idx): - sys.stdout.write('\r>> Converting image %d/%d shard %d' % ( - i + 1, len(filenames), shard_id)) - sys.stdout.flush() - # Read the image. - image_filename = os.path.join( - FLAGS.image_folder, filenames[i] + '.' + FLAGS.image_format) - image_data = tf.gfile.GFile(image_filename, 'rb').read() - height, width = image_reader.read_image_dims(image_data) - # Read the semantic segmentation annotation. - seg_filename = os.path.join( - FLAGS.semantic_segmentation_folder, - filenames[i] + '.' + FLAGS.label_format) - seg_data = tf.gfile.GFile(seg_filename, 'rb').read() - seg_height, seg_width = label_reader.read_image_dims(seg_data) - if height != seg_height or width != seg_width: - raise RuntimeError('Shape mismatched between image and label.') - # Convert to tf example. - example = build_data.image_seg_to_tfexample( - image_data, filenames[i], height, width, seg_data) - tfrecord_writer.write(example.SerializeToString()) - sys.stdout.write('\n') - sys.stdout.flush() - - -def main(unused_argv): - dataset_splits = tf.gfile.Glob(os.path.join(FLAGS.list_folder, '*.txt')) - for dataset_split in dataset_splits: - _convert_dataset(dataset_split) - - -if __name__ == '__main__': - tf.app.run() diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/convert_cityscapes.sh b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/convert_cityscapes.sh deleted file mode 100644 index ddc39fb11dd..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/convert_cityscapes.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash -# Copyright 2018 The TensorFlow Authors All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -# -# Script to preprocess the Cityscapes dataset. Note (1) the users should -# register the Cityscapes dataset website at -# https://www.cityscapes-dataset.com/downloads/ to download the dataset, -# and (2) the users should download the utility scripts provided by -# Cityscapes at https://github.com/mcordts/cityscapesScripts. -# -# Usage: -# bash ./convert_cityscapes.sh -# -# The folder structure is assumed to be: -# + datasets -# - build_cityscapes_data.py -# - convert_cityscapes.sh -# + cityscapes -# + cityscapesscripts (downloaded scripts) -# + gtFine -# + leftImg8bit -# - -# Exit immediately if a command exits with a non-zero status. -set -e - -CURRENT_DIR=$(pwd) -WORK_DIR="." - -# Root path for Cityscapes dataset. -CITYSCAPES_ROOT="${WORK_DIR}/cityscapes" - -export PYTHONPATH="${CITYSCAPES_ROOT}:${PYTHONPATH}" - -# Create training labels. -python "${CITYSCAPES_ROOT}/cityscapesscripts/preparation/createTrainIdLabelImgs.py" - -# Build TFRecords of the dataset. -# First, create output directory for storing TFRecords. -OUTPUT_DIR="${CITYSCAPES_ROOT}/tfrecord" -mkdir -p "${OUTPUT_DIR}" - -BUILD_SCRIPT="${CURRENT_DIR}/build_cityscapes_data.py" - -echo "Converting Cityscapes dataset..." -python "${BUILD_SCRIPT}" \ - --cityscapes_root="${CITYSCAPES_ROOT}" \ - --output_dir="${OUTPUT_DIR}" \ diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/data_generator.py b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/data_generator.py deleted file mode 100644 index d84e66f9c48..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/data_generator.py +++ /dev/null @@ -1,350 +0,0 @@ -# Lint as: python2, python3 -# Copyright 2018 The TensorFlow Authors All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -"""Wrapper for providing semantic segmentaion data. - -The SegmentationDataset class provides both images and annotations (semantic -segmentation and/or instance segmentation) for TensorFlow. Currently, we -support the following datasets: - -1. PASCAL VOC 2012 (http://host.robots.ox.ac.uk/pascal/VOC/voc2012/). - -PASCAL VOC 2012 semantic segmentation dataset annotates 20 foreground objects -(e.g., bike, person, and so on) and leaves all the other semantic classes as -one background class. The dataset contains 1464, 1449, and 1456 annotated -images for the training, validation and test respectively. - -2. Cityscapes dataset (https://www.cityscapes-dataset.com) - -The Cityscapes dataset contains 19 semantic labels (such as road, person, car, -and so on) for urban street scenes. - -3. ADE20K dataset (http://groups.csail.mit.edu/vision/datasets/ADE20K) - -The ADE20K dataset contains 150 semantic labels both urban street scenes and -indoor scenes. - -References: - M. Everingham, S. M. A. Eslami, L. V. Gool, C. K. I. Williams, J. Winn, - and A. Zisserman, The pascal visual object classes challenge a retrospective. - IJCV, 2014. - - M. Cordts, M. Omran, S. Ramos, T. Rehfeld, M. Enzweiler, R. Benenson, - U. Franke, S. Roth, and B. Schiele, "The cityscapes dataset for semantic urban - scene understanding," In Proc. of CVPR, 2016. - - B. Zhou, H. Zhao, X. Puig, S. Fidler, A. Barriuso, A. Torralba, "Scene Parsing - through ADE20K dataset", In Proc. of CVPR, 2017. -""" - -import collections -import os -import tensorflow as tf -from deeplab import common -from deeplab import input_preprocess - -# Named tuple to describe the dataset properties. -DatasetDescriptor = collections.namedtuple( - 'DatasetDescriptor', - [ - 'splits_to_sizes', # Splits of the dataset into training, val and test. - 'num_classes', # Number of semantic classes, including the - # background class (if exists). For example, there - # are 20 foreground classes + 1 background class in - # the PASCAL VOC 2012 dataset. Thus, we set - # num_classes=21. - 'ignore_label', # Ignore label value. - ]) - -_CITYSCAPES_INFORMATION = DatasetDescriptor( - splits_to_sizes={'train_fine': 2975, - 'train_coarse': 22973, - 'trainval_fine': 3475, - 'trainval_coarse': 23473, - 'val_fine': 500, - 'test_fine': 1525}, - num_classes=19, - ignore_label=255, -) - -_PASCAL_VOC_SEG_INFORMATION = DatasetDescriptor( - splits_to_sizes={ - 'train': 1464, - 'train_aug': 10582, - 'trainval': 2913, - 'val': 1449, - }, - num_classes=21, - ignore_label=255, -) - -_ADE20K_INFORMATION = DatasetDescriptor( - splits_to_sizes={ - 'train': 20210, # num of samples in images/training - 'val': 2000, # num of samples in images/validation - }, - num_classes=151, - ignore_label=0, -) - -_DATASETS_INFORMATION = { - 'cityscapes': _CITYSCAPES_INFORMATION, - 'pascal_voc_seg': _PASCAL_VOC_SEG_INFORMATION, - 'ade20k': _ADE20K_INFORMATION, -} - -# Default file pattern of TFRecord of TensorFlow Example. -_FILE_PATTERN = '%s-*' - - -def get_cityscapes_dataset_name(): - return 'cityscapes' - - -class Dataset(object): - """Represents input dataset for deeplab model.""" - - def __init__(self, - dataset_name, - split_name, - dataset_dir, - batch_size, - crop_size, - min_resize_value=None, - max_resize_value=None, - resize_factor=None, - min_scale_factor=1., - max_scale_factor=1., - scale_factor_step_size=0, - model_variant=None, - num_readers=1, - is_training=False, - should_shuffle=False, - should_repeat=False): - """Initializes the dataset. - - Args: - dataset_name: Dataset name. - split_name: A train/val Split name. - dataset_dir: The directory of the dataset sources. - batch_size: Batch size. - crop_size: The size used to crop the image and label. - min_resize_value: Desired size of the smaller image side. - max_resize_value: Maximum allowed size of the larger image side. - resize_factor: Resized dimensions are multiple of factor plus one. - min_scale_factor: Minimum scale factor value. - max_scale_factor: Maximum scale factor value. - scale_factor_step_size: The step size from min scale factor to max scale - factor. The input is randomly scaled based on the value of - (min_scale_factor, max_scale_factor, scale_factor_step_size). - model_variant: Model variant (string) for choosing how to mean-subtract - the images. See feature_extractor.network_map for supported model - variants. - num_readers: Number of readers for data provider. - is_training: Boolean, if dataset is for training or not. - should_shuffle: Boolean, if should shuffle the input data. - should_repeat: Boolean, if should repeat the input data. - - Raises: - ValueError: Dataset name and split name are not supported. - """ - if dataset_name not in _DATASETS_INFORMATION: - raise ValueError('The specified dataset is not supported yet.') - self.dataset_name = dataset_name - - splits_to_sizes = _DATASETS_INFORMATION[dataset_name].splits_to_sizes - - if split_name not in splits_to_sizes: - raise ValueError('data split name %s not recognized' % split_name) - - if model_variant is None: - tf.logging.warning('Please specify a model_variant. See ' - 'feature_extractor.network_map for supported model ' - 'variants.') - - self.split_name = split_name - self.dataset_dir = dataset_dir - self.batch_size = batch_size - self.crop_size = crop_size - self.min_resize_value = min_resize_value - self.max_resize_value = max_resize_value - self.resize_factor = resize_factor - self.min_scale_factor = min_scale_factor - self.max_scale_factor = max_scale_factor - self.scale_factor_step_size = scale_factor_step_size - self.model_variant = model_variant - self.num_readers = num_readers - self.is_training = is_training - self.should_shuffle = should_shuffle - self.should_repeat = should_repeat - - self.num_of_classes = _DATASETS_INFORMATION[self.dataset_name].num_classes - self.ignore_label = _DATASETS_INFORMATION[self.dataset_name].ignore_label - - def _parse_function(self, example_proto): - """Function to parse the example proto. - - Args: - example_proto: Proto in the format of tf.Example. - - Returns: - A dictionary with parsed image, label, height, width and image name. - - Raises: - ValueError: Label is of wrong shape. - """ - - # Currently only supports jpeg and png. - # Need to use this logic because the shape is not known for - # tf.image.decode_image and we rely on this info to - # extend label if necessary. - def _decode_image(content, channels): - return tf.cond( - tf.image.is_jpeg(content), - lambda: tf.image.decode_jpeg(content, channels), - lambda: tf.image.decode_png(content, channels)) - - features = { - 'image/encoded': - tf.FixedLenFeature((), tf.string, default_value=''), - 'image/filename': - tf.FixedLenFeature((), tf.string, default_value=''), - 'image/format': - tf.FixedLenFeature((), tf.string, default_value='jpeg'), - 'image/height': - tf.FixedLenFeature((), tf.int64, default_value=0), - 'image/width': - tf.FixedLenFeature((), tf.int64, default_value=0), - 'image/segmentation/class/encoded': - tf.FixedLenFeature((), tf.string, default_value=''), - 'image/segmentation/class/format': - tf.FixedLenFeature((), tf.string, default_value='png'), - } - - parsed_features = tf.parse_single_example(example_proto, features) - - image = _decode_image(parsed_features['image/encoded'], channels=3) - - label = None - if self.split_name != common.TEST_SET: - label = _decode_image( - parsed_features['image/segmentation/class/encoded'], channels=1) - - image_name = parsed_features['image/filename'] - if image_name is None: - image_name = tf.constant('') - - sample = { - common.IMAGE: image, - common.IMAGE_NAME: image_name, - common.HEIGHT: parsed_features['image/height'], - common.WIDTH: parsed_features['image/width'], - } - - if label is not None: - if label.get_shape().ndims == 2: - label = tf.expand_dims(label, 2) - elif label.get_shape().ndims == 3 and label.shape.dims[2] == 1: - pass - else: - raise ValueError('Input label shape must be [height, width], or ' - '[height, width, 1].') - - label.set_shape([None, None, 1]) - - sample[common.LABELS_CLASS] = label - - return sample - - def _preprocess_image(self, sample): - """Preprocesses the image and label. - - Args: - sample: A sample containing image and label. - - Returns: - sample: Sample with preprocessed image and label. - - Raises: - ValueError: Ground truth label not provided during training. - """ - image = sample[common.IMAGE] - label = sample[common.LABELS_CLASS] - - original_image, image, label = input_preprocess.preprocess_image_and_label( - image=image, - label=label, - crop_height=self.crop_size[0], - crop_width=self.crop_size[1], - min_resize_value=self.min_resize_value, - max_resize_value=self.max_resize_value, - resize_factor=self.resize_factor, - min_scale_factor=self.min_scale_factor, - max_scale_factor=self.max_scale_factor, - scale_factor_step_size=self.scale_factor_step_size, - ignore_label=self.ignore_label, - is_training=self.is_training, - model_variant=self.model_variant) - - sample[common.IMAGE] = image - - if not self.is_training: - # Original image is only used during visualization. - sample[common.ORIGINAL_IMAGE] = original_image - - if label is not None: - sample[common.LABEL] = label - - # Remove common.LABEL_CLASS key in the sample since it is only used to - # derive label and not used in training and evaluation. - sample.pop(common.LABELS_CLASS, None) - - return sample - - def get_one_shot_iterator(self): - """Gets an iterator that iterates across the dataset once. - - Returns: - An iterator of type tf.data.Iterator. - """ - - files = self._get_all_files() - - dataset = ( - tf.data.TFRecordDataset(files, num_parallel_reads=self.num_readers) - .map(self._parse_function, num_parallel_calls=self.num_readers) - .map(self._preprocess_image, num_parallel_calls=self.num_readers)) - - if self.should_shuffle: - dataset = dataset.shuffle(buffer_size=100) - - if self.should_repeat: - dataset = dataset.repeat() # Repeat forever for training. - else: - dataset = dataset.repeat(1) - - dataset = dataset.batch(self.batch_size).prefetch(self.batch_size) - return dataset.make_one_shot_iterator() - - def _get_all_files(self): - """Gets all the files to read data from. - - Returns: - A list of input files. - """ - file_pattern = _FILE_PATTERN - file_pattern = os.path.join(self.dataset_dir, - file_pattern % self.split_name) - return tf.gfile.Glob(file_pattern) diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/data_generator_test.py b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/data_generator_test.py deleted file mode 100644 index f4425d01da0..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/data_generator_test.py +++ /dev/null @@ -1,115 +0,0 @@ -# Lint as: python2, python3 -# Copyright 2018 The TensorFlow Authors All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -"""Tests for deeplab.datasets.data_generator.""" - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import collections - -from six.moves import range -import tensorflow as tf - -from deeplab import common -from deeplab.datasets import data_generator - -ImageAttributes = collections.namedtuple( - 'ImageAttributes', ['image', 'label', 'height', 'width', 'image_name']) - - -class DatasetTest(tf.test.TestCase): - - # Note: training dataset cannot be tested since there is shuffle operation. - # When disabling the shuffle, training dataset is operated same as validation - # dataset. Therefore it is not tested again. - def testPascalVocSegTestData(self): - dataset = data_generator.Dataset( - dataset_name='pascal_voc_seg', - split_name='val', - dataset_dir= - 'deeplab/testing/pascal_voc_seg', - batch_size=1, - crop_size=[3, 3], # Use small size for testing. - min_resize_value=3, - max_resize_value=3, - resize_factor=None, - min_scale_factor=0.01, - max_scale_factor=2.0, - scale_factor_step_size=0.25, - is_training=False, - model_variant='mobilenet_v2') - - self.assertAllEqual(dataset.num_of_classes, 21) - self.assertAllEqual(dataset.ignore_label, 255) - - num_of_images = 3 - with self.test_session() as sess: - iterator = dataset.get_one_shot_iterator() - - for i in range(num_of_images): - batch = iterator.get_next() - batch, = sess.run([batch]) - image_attributes = _get_attributes_of_image(i) - self.assertEqual(batch[common.HEIGHT][0], image_attributes.height) - self.assertEqual(batch[common.WIDTH][0], image_attributes.width) - self.assertEqual(batch[common.IMAGE_NAME][0], - image_attributes.image_name.encode()) - - # All data have been read. - with self.assertRaisesRegexp(tf.errors.OutOfRangeError, ''): - sess.run([iterator.get_next()]) - - -def _get_attributes_of_image(index): - """Gets the attributes of the image. - - Args: - index: Index of image in all images. - - Returns: - Attributes of the image in the format of ImageAttributes. - - Raises: - ValueError: If index is of wrong value. - """ - if index == 0: - return ImageAttributes( - image=None, - label=None, - height=366, - width=500, - image_name='2007_000033') - elif index == 1: - return ImageAttributes( - image=None, - label=None, - height=335, - width=500, - image_name='2007_000042') - elif index == 2: - return ImageAttributes( - image=None, - label=None, - height=333, - width=500, - image_name='2007_000061') - else: - raise ValueError('Index can only be 0, 1 or 2.') - - -if __name__ == '__main__': - tf.test.main() diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/download_and_convert_ade20k.sh b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/download_and_convert_ade20k.sh deleted file mode 100644 index 3614ae42c16..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/download_and_convert_ade20k.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash -# Copyright 2018 The TensorFlow Authors All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -# -# Script to download and preprocess the ADE20K dataset. -# -# Usage: -# bash ./download_and_convert_ade20k.sh -# -# The folder structure is assumed to be: -# + datasets -# - build_data.py -# - build_ade20k_data.py -# - download_and_convert_ade20k.sh -# + ADE20K -# + tfrecord -# + ADEChallengeData2016 -# + annotations -# + training -# + validation -# + images -# + training -# + validation - -# Exit immediately if a command exits with a non-zero status. -set -e - -CURRENT_DIR=$(pwd) -WORK_DIR="./ADE20K" -mkdir -p "${WORK_DIR}" -cd "${WORK_DIR}" - -# Helper function to download and unpack ADE20K dataset. -download_and_uncompress() { - local BASE_URL=${1} - local FILENAME=${2} - - if [ ! -f "${FILENAME}" ]; then - echo "Downloading ${FILENAME} to ${WORK_DIR}" - wget -nd -c "${BASE_URL}/${FILENAME}" - fi - echo "Uncompressing ${FILENAME}" - unzip "${FILENAME}" -} - -# Download the images. -BASE_URL="http://data.csail.mit.edu/places/ADEchallenge" -FILENAME="ADEChallengeData2016.zip" - -download_and_uncompress "${BASE_URL}" "${FILENAME}" - -cd "${CURRENT_DIR}" - -# Root path for ADE20K dataset. -ADE20K_ROOT="${WORK_DIR}/ADEChallengeData2016" - -# Build TFRecords of the dataset. -# First, create output directory for storing TFRecords. -OUTPUT_DIR="${WORK_DIR}/tfrecord" -mkdir -p "${OUTPUT_DIR}" - -echo "Converting ADE20K dataset..." -python ./build_ade20k_data.py \ - --train_image_folder="${ADE20K_ROOT}/images/training/" \ - --train_image_label_folder="${ADE20K_ROOT}/annotations/training/" \ - --val_image_folder="${ADE20K_ROOT}/images/validation/" \ - --val_image_label_folder="${ADE20K_ROOT}/annotations/validation/" \ - --output_dir="${OUTPUT_DIR}" diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/download_and_convert_voc2012.sh b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/download_and_convert_voc2012.sh deleted file mode 100644 index 3126f729dec..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/download_and_convert_voc2012.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/bash -# Copyright 2018 The TensorFlow Authors All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -# -# Script to download and preprocess the PASCAL VOC 2012 dataset. -# -# Usage: -# bash ./download_and_convert_voc2012.sh -# -# The folder structure is assumed to be: -# + datasets -# - build_data.py -# - build_voc2012_data.py -# - download_and_convert_voc2012.sh -# - remove_gt_colormap.py -# + pascal_voc_seg -# + VOCdevkit -# + VOC2012 -# + JPEGImages -# + SegmentationClass -# - -# Exit immediately if a command exits with a non-zero status. -set -e - -CURRENT_DIR=$(pwd) -WORK_DIR="./pascal_voc_seg" -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -mkdir -p "${WORK_DIR}" -cd "${WORK_DIR}" - -# Helper function to download and unpack VOC 2012 dataset. -download_and_uncompress() { - local BASE_URL=${1} - local FILENAME=${2} - - if [ ! -f "${FILENAME}" ]; then - echo "Downloading ${FILENAME} to ${WORK_DIR}" - wget -nd -c "${BASE_URL}/${FILENAME}" - fi - echo "Uncompressing ${FILENAME}" - sudo apt install unzip - unzip "${FILENAME}" -} - -# Download the images. -BASE_URL="https://data.deepai.org/" -FILENAME="PascalVOC2012.zip" - -download_and_uncompress "${BASE_URL}" "${FILENAME}" - -cd "${CURRENT_DIR}" - -# Root path for PASCAL VOC 2012 dataset. -PASCAL_ROOT="${WORK_DIR}/VOC2012" - -# Remove the colormap in the ground truth annotations. -SEG_FOLDER="${PASCAL_ROOT}/SegmentationClass" -SEMANTIC_SEG_FOLDER="${PASCAL_ROOT}/SegmentationClassRaw" - -echo "Removing the color map in ground truth annotations..." -python3 "${SCRIPT_DIR}/remove_gt_colormap.py" \ - --original_gt_folder="${SEG_FOLDER}" \ - --output_dir="${SEMANTIC_SEG_FOLDER}" - -# Build TFRecords of the dataset. -# First, create output directory for storing TFRecords. -OUTPUT_DIR="${WORK_DIR}/tfrecord" -mkdir -p "${OUTPUT_DIR}" - -IMAGE_FOLDER="${PASCAL_ROOT}/JPEGImages" -LIST_FOLDER="${PASCAL_ROOT}/ImageSets/Segmentation" - -echo "Converting PASCAL VOC 2012 dataset..." -python3 "${SCRIPT_DIR}/build_voc2012_data.py" \ - --image_folder="${IMAGE_FOLDER}" \ - --semantic_segmentation_folder="${SEMANTIC_SEG_FOLDER}" \ - --list_folder="${LIST_FOLDER}" \ - --image_format="jpg" \ - --output_dir="${OUTPUT_DIR}" diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/remove_gt_colormap.py b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/remove_gt_colormap.py deleted file mode 100644 index 900570038ed..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/datasets/remove_gt_colormap.py +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright 2018 The TensorFlow Authors All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== - -"""Removes the color map from segmentation annotations. - -Removes the color map from the ground truth segmentation annotations and save -the results to output_dir. -""" -import glob -import os.path -import numpy as np - -from PIL import Image - -import tensorflow as tf - -FLAGS = tf.compat.v1.flags.FLAGS - -tf.compat.v1.flags.DEFINE_string('original_gt_folder', - './VOCdevkit/VOC2012/SegmentationClass', - 'Original ground truth annotations.') - -tf.compat.v1.flags.DEFINE_string('segmentation_format', 'png', 'Segmentation format.') - -tf.compat.v1.flags.DEFINE_string('output_dir', - './VOCdevkit/VOC2012/SegmentationClassRaw', - 'folder to save modified ground truth annotations.') - - -def _remove_colormap(filename): - """Removes the color map from the annotation. - - Args: - filename: Ground truth annotation filename. - - Returns: - Annotation without color map. - """ - return np.array(Image.open(filename)) - - -def _save_annotation(annotation, filename): - """Saves the annotation as png file. - - Args: - annotation: Segmentation annotation. - filename: Output filename. - """ - pil_image = Image.fromarray(annotation.astype(dtype=np.uint8)) - with tf.io.gfile.GFile(filename, mode='w') as f: - pil_image.save(f, 'PNG') - - -def main(unused_argv): - # Create the output directory if not exists. - if not tf.io.gfile.isdir(FLAGS.output_dir): - tf.io.gfile.makedirs(FLAGS.output_dir) - - annotations = glob.glob(os.path.join(FLAGS.original_gt_folder, - '*.' + FLAGS.segmentation_format)) - for annotation in annotations: - raw_annotation = _remove_colormap(annotation) - filename = os.path.basename(annotation)[:-4] - _save_annotation(raw_annotation, - os.path.join( - FLAGS.output_dir, - filename + '.' + FLAGS.segmentation_format)) - - -if __name__ == '__main__': - tf.compat.v1.app.run() diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/deeplab.yaml b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/deeplab.yaml deleted file mode 100644 index 98b362456f5..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/deeplab.yaml +++ /dev/null @@ -1,65 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -device: cpu # optional. default value is cpu, other value is gpu. - -model: # mandatory. neural_compressor uses this model name and framework name to decide where to save tuning history and deploy yaml. - name: deeplab - framework: tensorflow # mandatory. supported values are tensorflow, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: ImageTensor - outputs: SemanticPredictions - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 50, 100 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: - dataset: - VOCRecord: - root: /path/to/pascal_voc_seg/tfrecord # NOTE: modify to calibration dataset location if needed - transform: - ParseDecodeVoc: {} - - -evaluation: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - mIOU: - num_classes: 21 # built-in metrics are topk, map, f1, allow user to register new metric. - dataloader: - batch_size: 1 - dataset: - VOCRecord: - root: /path/to/pascal_voc_seg/tfrecord # NOTE: modify to evaluation dataset location if needed - transform: - ParseDecodeVoc: {} - performance: # optional. used to benchmark performance of passing model. - iteration: 100 - configs: - cores_per_instance: 4 - num_of_instance: 6 - dataloader: - batch_size: 1 - dataset: - VOCRecord: - root: /path/to/pascal_voc_seg/tfrecord # NOTE: modify to evaluation dataset location if needed - transform: - ParseDecodeVoc: {} - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/deeplab_itex.yaml b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/deeplab_itex.yaml deleted file mode 100644 index 5f5ae67361d..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/deeplab_itex.yaml +++ /dev/null @@ -1,65 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu]. - -model: # mandatory. neural_compressor uses this model name and framework name to decide where to save tuning history and deploy yaml. - name: deeplab - framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: ImageTensor - outputs: SemanticPredictions - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - sampling_size: 50, 100 # optional. default value is 100. used to set how many samples should be used in calibration. - dataloader: - dataset: - VOCRecord: - root: /path/to/pascal_voc_seg/tfrecord # NOTE: modify to calibration dataset location if needed - transform: - ParseDecodeVoc: {} - - -evaluation: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization. - metric: - mIOU: - num_classes: 21 # built-in metrics are topk, map, f1, allow user to register new metric. - dataloader: - batch_size: 1 - dataset: - VOCRecord: - root: /path/to/pascal_voc_seg/tfrecord # NOTE: modify to evaluation dataset location if needed - transform: - ParseDecodeVoc: {} - performance: # optional. used to benchmark performance of passing model. - iteration: 100 - configs: - cores_per_instance: 4 - num_of_instance: 6 - dataloader: - batch_size: 1 - dataset: - VOCRecord: - root: /path/to/pascal_voc_seg/tfrecord # NOTE: modify to evaluation dataset location if needed - transform: - ParseDecodeVoc: {} - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/main.py b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/main.py deleted file mode 100644 index 7628672b5b9..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/main.py +++ /dev/null @@ -1,70 +0,0 @@ -# -# -*- coding: utf-8 -*- -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import time -import numpy as np -from argparse import ArgumentParser -import tensorflow as tf -tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) -tf.compat.v1.disable_eager_execution() - -class eval_classifier_optimized_graph: - """Evaluate image classifier with optimized TensorFlow graph""" - - def __init__(self): - - arg_parser = ArgumentParser(description='Parse args') - - arg_parser.add_argument('-g', "--input-graph", - help='Specify the input graph for the transform tool', - dest='input_graph') - - arg_parser.add_argument("--output-graph", - help='Specify tune result model save dir', - dest='output_graph') - - arg_parser.add_argument("--config", default=None, help="tuning config") - - arg_parser.add_argument('--benchmark', dest='benchmark', action='store_true', help='run benchmark') - - arg_parser.add_argument('--mode', dest='mode', default='performance', help='benchmark mode') - - arg_parser.add_argument('--tune', dest='tune', action='store_true', help='use neural_compressor to tune.') - - self.args = arg_parser.parse_args() - - def run(self): - """ This is neural_compressor function include tuning and benchmark option """ - - if self.args.tune: - from neural_compressor.experimental import Quantization, common - quantizer = Quantization(self.args.config) - quantizer.model = common.Model(self.args.input_graph) - q_model = quantizer.fit() - q_model.save(self.args.output_graph) - - if self.args.benchmark: - from neural_compressor.experimental import Benchmark, common - evaluator = Benchmark(self.args.config) - evaluator.model = common.Model(self.args.input_graph) - evaluator(self.args.mode) - -if __name__ == "__main__": - - evaluate_opt_graph = eval_classifier_optimized_graph() - evaluate_opt_graph.run() diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/requirements.txt b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/requirements.txt deleted file mode 100644 index 16ea87a7151..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -intel-tensorflow -neural-compressor diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/run_benchmark.sh b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/run_benchmark.sh deleted file mode 100644 index 2304baaea20..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/run_benchmark.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -set -x - -function main { - - init_params "$@" - run_benchmark - -} - -# init params -function init_params { - for var in "$@" - do - case $var in - --config=*) - config=$(echo $var |cut -f2 -d=) - ;; - --input_model=*) - input_model=$(echo $var |cut -f2 -d=) - ;; - --mode=*) - mode=$(echo $var |cut -f2 -d=) - ;; - esac - done - -} - -# run_tuning -function run_benchmark { - - python main.py \ - --input-graph ${input_model} \ - --config ${config} \ - --mode ${mode} \ - --benchmark -} - -main "$@" diff --git a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/run_tuning.sh b/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/run_tuning.sh deleted file mode 100644 index 5ecbd6b31ea..00000000000 --- a/examples/tensorflow/semantic_image_segmentation/deeplab/quantization/ptq/run_tuning.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -set -x - -function main { - init_params "$@" - run_tuning - -} - -# init params -function init_params { - - for var in "$@" - do - case $var in - --config=*) - config=$(echo $var |cut -f2 -d=) - ;; - --input_model=*) - input_model=$(echo $var |cut -f2 -d=) - ;; - --output_model=*) - output_model=$(echo $var |cut -f2 -d=) - ;; - esac - done - -} - -# run_tuning -function run_tuning { - python main.py \ - --input-graph ${input_model} \ - --output-graph ${output_model} \ - --config ${config} \ - --tune -} - -main "$@" diff --git a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/README.md b/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/README.md deleted file mode 100644 index d6b6d3c9698..00000000000 --- a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/README.md +++ /dev/null @@ -1,150 +0,0 @@ -Step-by-Step -============ - -This document is used to list steps of reproducing TensorFlow style transfer Intel® Neural Compressor tuning zoo result. -This example can run on Intel CPUs and GPUs. - -## Prerequisite - -### 1. Installation -```shell -# Install Intel® Neural Compressor -pip install neural-compressor -``` -### 2. Install Intel Tensorflow -```shell -pip install intel-tensorflow -``` -> Note: Supported Tensorflow [Version](../../../../../../README.md#supported-frameworks). - -### 3. Install Additional Dependency packages -```shell -cd examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq -pip install -r requirements.txt -``` - -### 4. Install Intel Extension for Tensorflow -#### Quantizing the model on Intel GPU -Intel Extension for Tensorflow is mandatory to be installed for quantizing the model on Intel GPUs. - -```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) - -#### 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. - -```shell -pip install --upgrade intel-extension-for-tensorflow[cpu] -``` - -### 5. Prepare Dataset -There are two folders named style_images and content_images -you can use these two folders to generated stylized images for test -you can also prepare your own style_images or content_images - -### 6. Prepare Pretrained model - -#### Automated approach -Run the `prepare_model.py` script located in `LowPrecisionInferenceTool/examples/tensorflow/style_transfer`. - -``` -usage: prepare_model.py [-h] [--model_path MODEL_PATH] - -optional arguments: - -h, --help show this help message and exit - --model_path MODEL_PATH directory to put models, default is ./model -``` - -#### Manual approach - -```shell -wget https://storage.googleapis.com/download.magenta.tensorflow.org/models/arbitrary_style_transfer.tar.gz -tar -xvzf arbitrary_style_transfer.tar.gz ./model -``` - -## Run Command - ```shell - python style_tune.py --output_dir=./result --style_images_paths=./style_images --content_images_paths=./content_images --input_model=./model/model.ckpt - ``` -### Quantize with neural_compressor -#### 1. Tune model with neural_compressor - ```shell - bash run_tuning.sh --dataset_location=style_images/,content_images/ --input_model=./model/model.ckpt --output_model=saved_model - ``` -#### 2. check benchmark of tuned model - ```shell - bash run_benchmark.sh --dataset_location=style_images/,content_images/ --input_model=saved_model.pb --batch_size=1 - ``` - -Details of enabling Intel® Neural Compressor on style transfer for Tensorflow. -========================= - -This is a tutorial of how to enable style_transfer model with Intel® Neural Compressor. -## User Code Analysis -1. User specifies fp32 *model*, calibration dataset *q_dataloader*, evaluation dataset *eval_dataloader* and metric in tuning.metric field of model-specific yaml config file. - -2. User specifies fp32 *model*, calibration dataset *q_dataloader* and a custom *eval_func* which encapsulates the evaluation dataset and metric by itself. - -For style_transfer, we applied the latter one because we don't have metric for style transfer model.The first one is to implement the q_dataloader and implement a fake *eval_func*. As neural_compressor have implement a style_transfer dataset, so only eval_func should be prepared after load the graph - -### Evaluation Part Adaption -As style transfer don't have a metric to measure the accuracy, we only implement a fake eval_func -```python -def eval_func(model): - return 1. -``` - -### Write Yaml config file -In examples directory, there is a conf.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 conf_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. - -```yaml -device: cpu # NOTE: optional. default value is cpu, other value is gpu. - -model: - name: style_transfer - framework: tensorflow - inputs: import/style_input,import/content_input - outputs: import/transformer/expand/conv3/conv/Sigmoid - -quantization: - calibration: - dataloader: - batch_size: 2 - dataset: - style_transfer: - content_folder: ./content_images/ # NOTE: modify to content images path if needed - style_folder: ./style_images/ # NOTE: modify to style images path if needed - -evaluation: - accuracy: - dataloader: - batch_size: 2 - dataset: - style_transfer: - content_folder: ./content_images/ # NOTE: modify to content images path if needed - style_folder: ./style_images/ # NOTE: modify to style images path if needed - -tuning: - accuracy_criterion: - relative: 0.01 - exit_policy: - timeout: 0 - random_seed: 9527 -``` -Here we set the input tensor and output tensors name into *inputs* and *outputs* field. In this case we only calibration and quantize the model without tune the accuracy - -### Code update - -After prepare step is done, we just need add 2 lines to get the quantized model. -```python -from neural_compressor.experimental import Quantization - -quantizer = Quantization(args.config) -quantizer.model = graph -quantizer.eval_func = eval_func -q_model = quantizer.fit() -``` - -The Intel® Neural Compressor quantizer.fit() function will return a best quantized model during timeout constrain. diff --git a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/conf.yaml b/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/conf.yaml deleted file mode 100644 index 89664a00e35..00000000000 --- a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/conf.yaml +++ /dev/null @@ -1,48 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -device: cpu # optional. default value is cpu, other value is gpu. - -model: # mandatory. used to specify model specific information. - name: style_transfer - framework: tensorflow # mandatory. supported values are tensorflow, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: style_input,content_input # optional. inputs and outputs fields are only required for tensorflow backend. - outputs: transformer/expand/conv3/conv/Sigmoid - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 2 - dataset: - style_transfer: - content_folder: ./content_images/ # NOTE: modify to content images path if needed - style_folder: ./style_images/ # NOTE: modify to style images path if needed - -evaluation: - performance: - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 2 - dataset: - style_transfer: - content_folder: ./content_images/ # NOTE: modify to content images path if needed - style_folder: ./style_images/ # NOTE: modify to style images path if needed - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - max_trials: 100 # optional. max tune times. default value is 100. combine with timeout field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/conf_itex.yaml b/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/conf_itex.yaml deleted file mode 100644 index 23a38a18893..00000000000 --- a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/conf_itex.yaml +++ /dev/null @@ -1,48 +0,0 @@ -# -# Copyright (c) 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu]. - -model: # mandatory. used to specify model specific information. - name: style_transfer - framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension. - inputs: style_input,content_input # optional. inputs and outputs fields are only required for tensorflow backend. - outputs: transformer/expand/conv3/conv/Sigmoid - -quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. - calibration: - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 2 - dataset: - style_transfer: - content_folder: ./content_images/ # NOTE: modify to content images path if needed - style_folder: ./style_images/ # NOTE: modify to style images path if needed - -evaluation: - performance: - dataloader: # optional. if not specified, user need construct a q_dataloader in code for neural_compressor.Quantization. - batch_size: 2 - dataset: - style_transfer: - content_folder: ./content_images/ # NOTE: modify to content images path if needed - style_folder: ./style_images/ # NOTE: modify to style images path if needed - -tuning: - accuracy_criterion: - relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. - exit_policy: - timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit. - max_trials: 100 # optional. max tune times. default value is 100. combine with timeout field to decide when to exit. - random_seed: 9527 # optional. random seed for deterministic tuning. diff --git a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/content_images/colva_beach_sq.jpg b/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/content_images/colva_beach_sq.jpg deleted file mode 100644 index 5f6c5a6beb5..00000000000 Binary files a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/content_images/colva_beach_sq.jpg and /dev/null differ diff --git a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/content_images/golden_gate_sq.jpg b/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/content_images/golden_gate_sq.jpg deleted file mode 100644 index 248d9fd31f9..00000000000 Binary files a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/content_images/golden_gate_sq.jpg and /dev/null differ diff --git a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/prepare_model.py b/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/prepare_model.py deleted file mode 100644 index 74182ad5f37..00000000000 --- a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/prepare_model.py +++ /dev/null @@ -1,33 +0,0 @@ -import os -import argparse -import enum -import tarfile -import abc - -def get_pretrained_model(destination): - """ - Obtains a ready to use style_transfer model file. - Args: - destination: path to where the file should be stored - """ - url = "https://storage.googleapis.com/download.magenta.tensorflow.org/models/ \ - arbitrary_style_transfer.tar.gz" - - os.system("curl -o arbitrary_style_transfer.tar.gz {0}".format(url)) - with tarfile.open("arbitrary_style_transfer.tar.gz") as tar: - if not os.path.exists(destination): - os.makedirs(destination) - tar.extractall(destination) - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Prepare pre-trained model for style transfer model') - parser.add_argument('--model_path', type=str, default='./model', help='directory to put models, default is ./model') - - args = parser.parse_args() - model_path = args.model_path - try: - get_pretrained_model(model_path) - except AttributeError: - print("The model fetched failed.") - diff --git a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/requirements.txt b/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/requirements.txt deleted file mode 100644 index 1e5d462dcd4..00000000000 --- a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -scikit-image -Pillow>=8.2.0 diff --git a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/run_benchmark.sh b/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/run_benchmark.sh deleted file mode 100644 index 9582fc5c6f0..00000000000 --- a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/run_benchmark.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash -set -x - -function main { - - init_params "$@" - run_benchmark - -} - -# init params -function init_params { - iters=100 - for var in "$@" - do - case $var in - --topology=*) - topology=$(echo $var |cut -f2 -d=) - ;; - --dataset_location=*) - dataset_location=$(echo $var |cut -f2 -d=) - ;; - --input_model=*) - input_model=$(echo $var |cut -f2 -d=) - ;; - --mode=*) - mode=$(echo $var |cut -f2 -d=) - ;; - --batch_size=*) - batch_size=$(echo $var |cut -f2 -d=) - ;; - --iters=*) - iters=$(echo ${var} |cut -f2 -d=) - ;; - *) - echo "Error: No such parameter: ${var}" - exit 1 - ;; - esac - done - -} - - -# run_tuning -function run_benchmark { - style_images=$(echo ${dataset_location} | awk -F ',' '{print $1}') - content_images=$(echo ${dataset_location} | awk -F ',' '{print $2}') - echo "$style_images, $content_images" - - python style_tune.py \ - --input_model "${input_model}" \ - --style_images_paths "${style_images}" \ - --content_images_paths "${content_images}" \ - --config "./conf.yaml" \ - --batch_size "${batch_size}" \ - --tune=False \ - --output_model "${output_model}" - -} - -main "$@" diff --git a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/run_tuning.sh b/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/run_tuning.sh deleted file mode 100644 index d5adc1060bb..00000000000 --- a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/run_tuning.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash -# set -x - -function main { - - init_params "$@" - - run_tuning - -} - -# init params -function init_params { - - for var in "$@" - do - case $var in - --topology=*) - topology=$(echo $var |cut -f2 -d=) - ;; - --dataset_location=*) - dataset_location=$(echo "$var" |cut -f2 -d=) - ;; - --input_model=*) - input_model=$(echo "$var" |cut -f2 -d=) - ;; - --output_model=*) - output_model=$(echo "$var" |cut -f2 -d=) - ;; - esac - done - -} - -# run_tuning -function run_tuning { - style_images=$(echo ${dataset_location} | awk -F ',' '{print $1}') - content_images=$(echo ${dataset_location} | awk -F ',' '{print $2}') - echo "$style_images, $content_images" - - python style_tune.py \ - --input_model "${input_model}" \ - --style_images_paths "${style_images}" \ - --content_images_paths "${content_images}" \ - --config "./conf.yaml" \ - --tune=True \ - --output_model "${output_model}" -} - -main "$@" diff --git a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/style_images/kanagawa_great_wave.jpg b/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/style_images/kanagawa_great_wave.jpg deleted file mode 100644 index 5af5a0eff59..00000000000 Binary files a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/style_images/kanagawa_great_wave.jpg and /dev/null differ diff --git a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/style_images/zigzag_colorful.jpg b/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/style_images/zigzag_colorful.jpg deleted file mode 100644 index bb0c46ea1de..00000000000 Binary files a/examples/tensorflow/style_transfer/arbitrary_style_transfer/quantization/ptq/style_images/zigzag_colorful.jpg and /dev/null differ