From 4239d3675fe833aa4d145ffb49dd938bdc4c8726 Mon Sep 17 00:00:00 2001 From: Neo Zhang Jianyu Date: Tue, 9 Jan 2024 14:35:27 +0800 Subject: [PATCH] notebook example update to install latest INC & TF, add metric in fit (#1517) --- .../tensorflow/alexnet_mnist/conda_set_env.sh | 0 .../tensorflow/alexnet_mnist/devcloud_setup_env.sh | 0 .../tensorflow/alexnet_mnist/inc_quantize_model.py | 7 ++++++- .../alexnet_mnist/inc_sample_for_tensorflow.ipynb | 12 +----------- .../notebook/tensorflow/alexnet_mnist/pip_set_env.sh | 0 .../tensorflow/alexnet_mnist/requirements.txt | 4 ++-- .../alexnet_mnist/run_in_intel_devcloud.sh | 0 .../notebook/tensorflow/alexnet_mnist/run_jupyter.sh | 0 .../notebook/tensorflow/alexnet_mnist/run_sample.sh | 1 + 9 files changed, 10 insertions(+), 14 deletions(-) mode change 100644 => 100755 examples/notebook/tensorflow/alexnet_mnist/conda_set_env.sh mode change 100644 => 100755 examples/notebook/tensorflow/alexnet_mnist/devcloud_setup_env.sh mode change 100644 => 100755 examples/notebook/tensorflow/alexnet_mnist/pip_set_env.sh mode change 100644 => 100755 examples/notebook/tensorflow/alexnet_mnist/run_in_intel_devcloud.sh mode change 100644 => 100755 examples/notebook/tensorflow/alexnet_mnist/run_jupyter.sh mode change 100644 => 100755 examples/notebook/tensorflow/alexnet_mnist/run_sample.sh diff --git a/examples/notebook/tensorflow/alexnet_mnist/conda_set_env.sh b/examples/notebook/tensorflow/alexnet_mnist/conda_set_env.sh old mode 100644 new mode 100755 diff --git a/examples/notebook/tensorflow/alexnet_mnist/devcloud_setup_env.sh b/examples/notebook/tensorflow/alexnet_mnist/devcloud_setup_env.sh old mode 100644 new mode 100755 diff --git a/examples/notebook/tensorflow/alexnet_mnist/inc_quantize_model.py b/examples/notebook/tensorflow/alexnet_mnist/inc_quantize_model.py index 46655026c48..e41aae86a6d 100644 --- a/examples/notebook/tensorflow/alexnet_mnist/inc_quantize_model.py +++ b/examples/notebook/tensorflow/alexnet_mnist/inc_quantize_model.py @@ -14,6 +14,7 @@ from neural_compressor.config import PostTrainingQuantConfig, AccuracyCriterion, TuningCriterion from neural_compressor.data import DataLoader from neural_compressor.quantization import fit +from neural_compressor import Metric import mnist_dataset @@ -58,11 +59,15 @@ def auto_tune(input_graph_path, batch_size): criterion='relative', tolerable_loss=0.01 ) ) + top1 = Metric(name="topk", k=1) + q_model = fit( model=input_graph_path, conf=config, calib_dataloader=dataloader, - eval_dataloader=dataloader) + eval_dataloader=dataloader, + eval_metric=top1 + ) return q_model diff --git a/examples/notebook/tensorflow/alexnet_mnist/inc_sample_for_tensorflow.ipynb b/examples/notebook/tensorflow/alexnet_mnist/inc_sample_for_tensorflow.ipynb index b187df288dd..b81b0e0b1a6 100644 --- a/examples/notebook/tensorflow/alexnet_mnist/inc_sample_for_tensorflow.ipynb +++ b/examples/notebook/tensorflow/alexnet_mnist/inc_sample_for_tensorflow.ipynb @@ -184,16 +184,6 @@ "!./run_sample.sh" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "d53543c9", - "metadata": {}, - "outputs": [], - "source": [ - "!ls" - ] - }, { "cell_type": "markdown", "id": "b3cb8011-31c4-4a7c-be00-775d2ec940f4", @@ -272,7 +262,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.8.13" }, "nbTranslate": { "displayLangs": [ diff --git a/examples/notebook/tensorflow/alexnet_mnist/pip_set_env.sh b/examples/notebook/tensorflow/alexnet_mnist/pip_set_env.sh old mode 100644 new mode 100755 diff --git a/examples/notebook/tensorflow/alexnet_mnist/requirements.txt b/examples/notebook/tensorflow/alexnet_mnist/requirements.txt index 83d584fd094..bdee80fd626 100644 --- a/examples/notebook/tensorflow/alexnet_mnist/requirements.txt +++ b/examples/notebook/tensorflow/alexnet_mnist/requirements.txt @@ -1,5 +1,5 @@ -neural-compressor==2.0 +neural-compressor runipy notebook matplotlib -tensorflow==2.12.* +tensorflow diff --git a/examples/notebook/tensorflow/alexnet_mnist/run_in_intel_devcloud.sh b/examples/notebook/tensorflow/alexnet_mnist/run_in_intel_devcloud.sh old mode 100644 new mode 100755 diff --git a/examples/notebook/tensorflow/alexnet_mnist/run_jupyter.sh b/examples/notebook/tensorflow/alexnet_mnist/run_jupyter.sh old mode 100644 new mode 100755 diff --git a/examples/notebook/tensorflow/alexnet_mnist/run_sample.sh b/examples/notebook/tensorflow/alexnet_mnist/run_sample.sh old mode 100644 new mode 100755 index 31f990396fa..0c215583162 --- a/examples/notebook/tensorflow/alexnet_mnist/run_sample.sh +++ b/examples/notebook/tensorflow/alexnet_mnist/run_sample.sh @@ -6,6 +6,7 @@ echo "Enable Intel Optimized TensorFlow 2.6.0 and newer by setting environment v echo "That will accelerate training and inference, and it's mandatory requirement of running IntelĀ® Neural Compressor quantize Fp32 model or deploying the quantized model." export TF_ENABLE_ONEDNN_OPTS=1 +export CUDA_VISIBLE_DEVICES=-1 echo "Train Model by Keras/Tensorflow with MNIST" python keras_tf_train_mnist.py