Changing file structure of POT Tool Examples section (#20213)
This commit is contained in:
+75
@@ -0,0 +1,75 @@
|
||||
# Post-training Optimization Tool API Examples {#pot_example_README}
|
||||
|
||||
@sphinxdirective
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:hidden:
|
||||
|
||||
Quantizing Image Classification Model <pot_example_classification_README>
|
||||
Quantizing Object Detection Model with Accuracy Control <pot_example_object_detection_README>
|
||||
Quantizing Cascaded Model <pot_example_face_detection_README>
|
||||
Quantizing Semantic Segmentation Model <pot_example_segmentation_README>
|
||||
Quantizing 3D Segmentation Model <pot_example_3d_segmentation_README>
|
||||
Quantizing for GNA Device <pot_example_speech_README>
|
||||
|
||||
|
||||
The Post-training Optimization Tool contains multiple examples that demonstrate how to use its :doc:`API <pot_compression_api_README>`
|
||||
to optimize DL models. All available examples can be found on `GitHub <https://github.com/openvinotoolkit/openvino/tree/master/tools/pot/openvino/tools/pot/api/samples>`__.
|
||||
|
||||
The following examples demonstrate the implementation of ``Engine``, ``Metric``, and ``DataLoader`` interfaces for various use cases:
|
||||
|
||||
1. :doc:`Quantizing Image Classification model <pot_example_classification_README>`
|
||||
|
||||
- Uses a single ``MobilenetV2`` model from TensorFlow
|
||||
- Implements ``DataLoader`` to load .JPEG images and annotations of the Imagenet database
|
||||
- Implements ``Metric`` interface to calculate Accuracy at top-1 metric
|
||||
- Uses DefaultQuantization algorithm for quantization model
|
||||
|
||||
2. :doc:`Quantizing Object Detection Model with Accuracy Control <pot_example_object_detection_README>`
|
||||
|
||||
- Uses asingle ``MobileNetV1 FPN`` model from TensorFlow
|
||||
- Implements ``Dataloader`` to load images of the COCO database
|
||||
- Implements ``Metric`` interface to calculate ``mAP@[.5:.95]`` metric
|
||||
- Uses ``AccuracyAwareQuantization`` algorithm for quantization model
|
||||
|
||||
3. :doc:`Quantizing Semantic Segmentation Model <pot_example_segmentation_README>`
|
||||
|
||||
- Uses a single ``DeepLabV3`` model from TensorFlow
|
||||
- Implements ``DataLoader`` to load .JPEG images and annotations of the Pascal VOC 2012 database
|
||||
- Implements ``Metric`` interface to calculate Mean Intersection Over Union metric
|
||||
- Uses DefaultQuantization algorithm for quantization model
|
||||
|
||||
4. :doc:`Quantizing 3D Segmentation Model <pot_example_3d_segmentation_README>`
|
||||
|
||||
- Uses a single ``Brain Tumor Segmentation`` model from PyTorch
|
||||
- Implements ``DataLoader`` to load images in NIfTI format from the Medical Segmentation Decathlon BRATS 2017 database
|
||||
- Implements ``Metric`` interface to calculate Dice Index metric
|
||||
- Demonstrates how to use image metadata obtained during data loading to post-process the raw model output
|
||||
- Uses DefaultQuantization algorithm for quantization model
|
||||
|
||||
5. :doc:`Quantizing Cascaded model <pot_example_face_detection_README>`
|
||||
|
||||
- Uses a cascaded (composite) ``MTCNN`` model from Caffe that consists of three separate models in an OpenVINO™ Intermediate Representation (IR)
|
||||
- Implements ``Dataloader`` to load .jpg images of the WIDER FACE database
|
||||
- Implements ``Metric`` interface to calculate Recall metric
|
||||
- Implements ``Engine`` class that is inherited from ``IEEngine`` to create a complex staged pipeline to sequentially execute each of the three stages of the MTCNN model, represented by multiple models in IR. It uses engine helpers to set a model in OpenVINO Inference Engine and process raw model output for the correct statistics collection
|
||||
- Uses DefaultQuantization algorithm for quantization model
|
||||
|
||||
6. :doc:`Quantizing for GNA Device <pot_example_speech_README>`
|
||||
|
||||
- Uses models from Kaldi
|
||||
- Implements ``DataLoader`` to load data in .ark format
|
||||
- Uses DefaultQuantization algorithm for quantization model
|
||||
|
||||
After the execution of each example above, the quantized model is placed into the folder ``optimized``. The accuracy validation of the quantized model is performed right after the quantization.
|
||||
|
||||
See the tutorials
|
||||
####################
|
||||
|
||||
* `Quantization of Image Classification model <https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/301-tensorflow-training-openvino>`__
|
||||
* `Quantization of Object Detection model from Model Zoo <https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/111-yolov5-quantization-migration)>`__
|
||||
* `Quantization of Segmentation model for medical data <https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/110-ct-segmentation-quantize>`__
|
||||
* `Quantization of BERT for Text Classification <https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/105-language-quantize-bert>`__
|
||||
|
||||
@endsphinxdirective
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
# Quantizing 3D Segmentation Model {#pot_example_3d_segmentation_README}
|
||||
|
||||
@sphinxdirective
|
||||
|
||||
This example demonstrates the use of the :doc:`Post-training Optimization Tool API <pot_compression_api_README>` for the task of quantizing a 3D segmentation model.
|
||||
The `Brain Tumor Segmentation <https://github.com/openvinotoolkit/open_model_zoo/tree/master/models/public/brain-tumor-segmentation-0002>`__ model from PyTorch is used for this purpose. A custom ``DataLoader`` is created to load images in NIfTI format from the `Medical Segmentation Decathlon BRATS 2017 <http://medicaldecathlon.com/>`__ dataset for 3D semantic segmentation task and the implementation of the Dice Index metric is used for the model evaluation. In addition, this example demonstrates how one can use image metadata obtained during image reading and preprocessing to post-process the model raw output. The code of the example is available on `GitHub <https://github.com/openvinotoolkit/openvino/tree/master/tools/pot/openvino/tools/pot/api/samples/3d_segmentation>`__.
|
||||
|
||||
How to Prepare the Data
|
||||
#######################
|
||||
|
||||
To run this example, you will need to download the Brain Tumors 2017 part of the Medical Segmentation Decathlon image database http://medicaldecathlon.com/.
|
||||
3D MRI data in NIfTI format can be found in the ``imagesTr`` folder, and segmentation masks are in ``labelsTr``.
|
||||
|
||||
How to Run the Example
|
||||
######################
|
||||
|
||||
1. Launch :doc:`Model Downloader <omz_tools_downloader>` tool to download ``brain-tumor-segmentation-0002`` model from the Open Model Zoo repository.
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
omz_downloader --name brain-tumor-segmentation-0002
|
||||
|
||||
|
||||
2. Launch :doc:`Model Converter <omz_tools_downloader>` tool to generate Intermediate Representation (IR) files for the model:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
omz_converter --name brain-tumor-segmentation-0002
|
||||
|
||||
|
||||
3. Launch the example script from the example directory:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
python3 ./3d_segmentation_example.py -m <PATH_TO_IR_XML> -d <BraTS_2017/imagesTr> --mask-dir <BraTS_2017/labelsTr>
|
||||
|
||||
|
||||
Optional: you can specify .bin file of IR directly using the ``-w``, ``--weights`` options.
|
||||
|
||||
@endsphinxdirective
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
# Quantizing Image Classification Model {#pot_example_classification_README}
|
||||
|
||||
@sphinxdirective
|
||||
|
||||
This example demonstrates the use of the :doc:`Post-training Optimization Tool API <pot_compression_api_README>` for the task of quantizing a classification model.
|
||||
The `MobilenetV2 <https://github.com/openvinotoolkit/open_model_zoo/tree/master/models/public/mobilenet-v2-1.0-224>`__ model from TensorFlow is used for this purpose.
|
||||
A custom ``DataLoader`` is created to load the `ImageNet <http://www.image-net.org/>`__ classification dataset and the implementation of Accuracy at top-1 metric is used for the model evaluation. The code of the example is available on `GitHub <https://github.com/openvinotoolkit/openvino/tree/master/tools/pot/openvino/tools/pot/api/samples/classification>`__.
|
||||
|
||||
How to Prepare the Data
|
||||
#######################
|
||||
|
||||
To run this example, you need to `download <https://image-net.org/download.php>`__ the validation part of the ImageNet image database and place it in a separate folder,
|
||||
which will be later referred to as ``<IMAGES_DIR>``. Annotations to images should be stored in a separate .txt file (``<IMAGENET_ANNOTATION_FILE>``) in the format ``image_name label``.
|
||||
|
||||
|
||||
How to Run the Example
|
||||
######################
|
||||
|
||||
1. Launch :doc:`Model Downloader <omz_tools_downloader>` tool to download ``mobilenet-v2-1.0-224`` model from the Open Model Zoo repository.
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
omz_downloader --name mobilenet-v2-1.0-224
|
||||
|
||||
2. Launch :doc:`Model Converter <omz_tools_downloader>` tool to generate Intermediate Representation (IR) files for the model:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
omz_converter --name mobilenet-v2-1.0-224 --mo <PATH_TO_MODEL_OPTIMIZER>/mo.py
|
||||
|
||||
3. Launch the example script from the example directory:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
python3 ./classification_sample.py -m <PATH_TO_IR_XML> -a <IMAGENET_ANNOTATION_FILE> -d <IMAGES_DIR>
|
||||
|
||||
Optional: you can specify .bin file of IR directly using the ``-w``, ``--weights`` options.
|
||||
|
||||
@endsphinxdirective
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
# Quantizing Cascaded Face detection Model {#pot_example_face_detection_README}
|
||||
|
||||
@sphinxdirective
|
||||
|
||||
This example demonstrates the use of the :doc:`Post-training Optimization Tool API <pot_compression_api_README>` for the task of quantizing a face detection model.
|
||||
The `MTCNN <https://github.com/openvinotoolkit/open_model_zoo/tree/master/models/public/mtcnn>`__ model from Caffe is used for this purpose.
|
||||
A custom ``DataLoader`` is created to load the `WIDER FACE <http://shuoyang1213.me/WIDERFACE/>`__ dataset for a face detection task
|
||||
and the implementation of Recall metric is used for the model evaluation. In addition, this example demonstrates how one can implement
|
||||
an engine to infer a cascaded (composite) model that is represented by multiple submodels in an OpenVINO™ Intermediate Representation (IR)
|
||||
and has a complex staged inference pipeline. The code of the example is available on `GitHub <https://github.com/openvinotoolkit/openvino/tree/master/tools/pot/openvino/tools/pot/api/samples/face_detection>`__.
|
||||
|
||||
How to Prepare the Data
|
||||
#######################
|
||||
|
||||
To run this example, you need to download the validation part of the Wider Face dataset http://shuoyang1213.me/WIDERFACE/.
|
||||
Images with faces divided into categories are placed in the ``WIDER_val/images`` folder.
|
||||
Annotations in .txt format containing the coordinates of the face bounding boxes of the
|
||||
validation part of the dataset can be downloaded separately and are located in the ``wider_face_split/wider_face_val_bbx_gt.txt`` file.
|
||||
|
||||
How to Run the Example
|
||||
######################
|
||||
|
||||
1. Launch :doc:`Model Downloader <omz_tools_downloader>` tool to download ``mtcnn`` model from the Open Model Zoo repository.
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
omz_downloader --name mtcnn*
|
||||
|
||||
|
||||
2. Launch :doc:`Model Converter <omz_tools_downloader>` tool to generate Intermediate Representation (IR) files for the model:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
omz_converter --name mtcnn* --mo <PATH_TO_MODEL_OPTIMIZER>/mo.py
|
||||
|
||||
|
||||
3. Launch the example script from the example directory:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
python3 ./face_detection_example.py -pm <PATH_TO_IR_XML_OF_PNET_MODEL>
|
||||
-rm <PATH_TO_IR_XML_OF_RNET_MODEL> -om <PATH_TO_IR_XML_OF_ONET_MODEL> -d <WIDER_val/images> -a <wider_face_split/wider_face_val_bbx_gt.txt>
|
||||
|
||||
|
||||
Optional: you can specify .bin files of corresponding IRs directly using the ``-pw/--pnet-weights``, ``-rw/--rnet-weights`` and ``-ow/--onet-weights`` options.
|
||||
|
||||
@endsphinxdirective
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
# Quantizing Object Detection Model with Accuracy Control {#pot_example_object_detection_README}
|
||||
|
||||
@sphinxdirective
|
||||
|
||||
This example demonstrates the use of the :doc:`Post-training Optimization Toolkit API <pot_compression_api_README>` to quantize an object detection model in the :doc:`accuracy-aware mode <accuracy_aware_README>`. The `MobileNetV1 FPN <https://github.com/openvinotoolkit/open_model_zoo/tree/master/models/public/ssd_mobilenet_v1_fpn_coco>`__ model from TensorFlow for object detection task is used for this purpose. A custom ``DataLoader`` is created to load the `COCO <https://cocodataset.org/>`__ dataset for object detection task and the implementation of mAP COCO is used for the model evaluation. The code of the example is available on `GitHub <https://github.com/openvinotoolkit/openvino/tree/master/tools/pot/openvino/tools/pot/api/samples/object_detection>`__.
|
||||
|
||||
How to prepare the data
|
||||
#######################
|
||||
|
||||
To run this example, you will need to download the validation part of the `COCO <https://cocodataset.org/>`__. The images should be placed in a separate folder, which will be later referred to as ``<IMAGES_DIR>`` and the annotation file ``instances_val2017.json`` later referred to as ``<ANNOTATION_FILE>``.
|
||||
|
||||
How to Run the example
|
||||
######################
|
||||
|
||||
1. Launch :doc:`Model Downloader <omz_tools_downloader>` tool to download ``ssd_mobilenet_v1_fpn_coco`` model from the Open Model Zoo repository.
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
omz_downloader --name ssd_mobilenet_v1_fpn_coco
|
||||
|
||||
|
||||
2. Launch :doc:`Model Converter <omz_tools_downloader>` tool to generate Intermediate Representation (IR) files for the model:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
omz_converter --name ssd_mobilenet_v1_fpn_coco --mo <PATH_TO_MODEL_OPTIMIZER>/mo.py
|
||||
|
||||
|
||||
3. Launch the example script from the example directory:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
python ./object_detection_example.py -m <PATH_TO_IR_XML> -d <IMAGES_DIR> --annotation-path <ANNOTATION_FILE>
|
||||
|
||||
|
||||
* Optional: you can specify .bin file of IR directly using the ``-w``, ``--weights`` options.
|
||||
|
||||
@endsphinxdirective
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
# Quantizing Semantic Segmentation Model {#pot_example_segmentation_README}
|
||||
|
||||
@sphinxdirective
|
||||
|
||||
This example demonstrates the use of the :doc:`Post-training Optimization Tool API <pot_compression_api_README>` for the task of quantizing a segmentation model.
|
||||
The `DeepLabV3 <https://github.com/openvinotoolkit/open_model_zoo/tree/master/models/public/deeplabv3>` model from TensorFlow is used for this purpose.
|
||||
A custom `DataLoader` is created to load the `Pascal VOC 2012 <http://host.robots.ox.ac.uk/pascal/VOC/voc2012/>`__ dataset for semantic segmentation task
|
||||
and the implementation of Mean Intersection Over Union metric is used for the model evaluation. The code of the example is available on `GitHub <https://github.com/openvinotoolkit/openvino/tree/master/tools/pot/openvino/tools/pot/api/samples/segmentation>`__.
|
||||
|
||||
How to Prepare the Data
|
||||
#######################
|
||||
|
||||
To run this example, you will need to download the validation part of the Pascal VOC 2012 image database http://host.robots.ox.ac.uk/pascal/VOC/voc2012/#data.
|
||||
Images are placed in the ``JPEGImages`` folder, ImageSet file with the list of image names for the segmentation task can be found at ``ImageSets/Segmentation/val.txt``
|
||||
and segmentation masks are kept in the ``SegmentationClass`` directory.
|
||||
|
||||
How to Run the Example
|
||||
######################
|
||||
|
||||
1. Launch :doc:`Model Downloader <omz_tools_downloader>` tool to download ``deeplabv3`` model from the Open Model Zoo repository.
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
omz_downloader --name deeplabv3
|
||||
|
||||
|
||||
2. Launch :doc:`Model Converter <omz_tools_downloader>` tool to generate Intermediate Representation (IR) files for the model:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
omz_converter --name deeplabv3 --mo <PATH_TO_MODEL_OPTIMIZER>/mo.py
|
||||
|
||||
|
||||
3. Launch the example script from the example directory:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
python3 ./segmentation_example.py -m <PATH_TO_IR_XML> -d <VOCdevkit/VOC2012/JPEGImages> --imageset-file <VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt> --mask-dir <VOCdevkit/VOC2012/SegmentationClass>
|
||||
|
||||
|
||||
Optional: you can specify .bin file of IR directly using the ``-w``, ``--weights`` options.
|
||||
|
||||
@endsphinxdirective
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
# Quantizing for GNA Device {#pot_example_speech_README}
|
||||
|
||||
@sphinxdirective
|
||||
|
||||
This example demonstrates the use of the :doc:`Post-training Optimization Tool API <pot_compression_api_README>` for the task of quantizing a speech model for :doc:`GNA <openvino_docs_OV_UG_supported_plugins_GNA>` device. Quantization for GNA is different from CPU quantization due to device specifics: GNA supports quantized inputs in INT16 and INT32 (for activations) precision and quantized weights in INT8 and INT16 precision.
|
||||
|
||||
This example contains pre-selected quantization options based on the DefaultQuantization algorithm and created for models from `Kaldi <http://kaldi-asr.org/doc/>`__ framework, and its data format.
|
||||
A custom ``ArkDataLoader`` is created to load the dataset from files with .ark extension for speech analysis task.
|
||||
|
||||
How to Prepare the Data
|
||||
#######################
|
||||
|
||||
To run this example, you will need to use the .ark files for each model input from your ``<DATA_FOLDER>``.
|
||||
For generating data from original formats to .ark, please, follow the `Kaldi data preparation tutorial <https://kaldi-asr.org/doc/data_prep.html>`__.
|
||||
|
||||
How to Run the Example
|
||||
######################
|
||||
|
||||
1. Launch :doc:`model conversion API <openvino_docs_MO_DG_Deep_Learning_Model_Optimizer_DevGuide>` with the necessary options (for details follow the :doc:`instructions for Kaldi <openvino_docs_MO_DG_prepare_model_convert_model_Convert_Model_From_Kaldi>` to generate Intermediate Representation (IR) files for the model:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
mo --input_model <PATH_TO_KALDI_MODEL> [MODEL_CONVERSION_API_PARAMETERS]
|
||||
|
||||
|
||||
2. Launch the example script:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
python3 <POT_DIR>/api/examples/speech/gna_example.py -m <PATH_TO_IR_XML> -w <PATH_TO_IR_BIN> -d <DATA_FOLDER> --input_names [LIST_OF_MODEL_INPUTS] --files_for_input [LIST_OF_INPUT_FILES]
|
||||
|
||||
|
||||
Required parameters:
|
||||
|
||||
- ``-i``, ``--input_names`` option. Defines the list of model inputs;
|
||||
- ``-f``, ``--files_for_input`` option. Defines the list of filenames (.ark) mapped with input names. You should define names without extension, for example: FILENAME_1, FILENAME_2 maps with INPUT_1, INPUT_2.
|
||||
|
||||
Optional parameters:
|
||||
|
||||
- ``-p``, ``--preset`` option. Defines preset for quantization: ``performance`` for INT8 weights, ``accuracy`` for INT16 weights;
|
||||
- ``-s``, ``--subset_size`` option. Defines subset size for calibration;
|
||||
- ``-o``, ``--output`` option. Defines output folder for the quantized model.
|
||||
|
||||
3. Validate your INT8 model using ``./speech_example`` from the Inference Engine examples. Follow the :doc:`speech example description link <openvino_inference_engine_samples_speech_sample_README>` for details.
|
||||
|
||||
@endsphinxdirective
|
||||
+222
@@ -0,0 +1,222 @@
|
||||
# End-to-end Command-line Interface Example {#pot_configs_examples_README}
|
||||
|
||||
@sphinxdirective
|
||||
|
||||
This tutorial describes an example of running post-training quantization for the **MobileNet v2 model from PyTorch** framework,
|
||||
particularly by the DefaultQuantization algorithm.
|
||||
The example covers the following steps:
|
||||
|
||||
- Environment setup
|
||||
- Model preparation and converting it to the OpenVINO™ Intermediate Representation (IR) format
|
||||
- Performance benchmarking of the original full-precision model
|
||||
- Dataset preparation
|
||||
- Accuracy validation of the full-precision model in the IR format
|
||||
- Model quantization by the DefaultQuantization algorithm and accuracy validation of the quantized model
|
||||
- Performance benchmarking of the quantized model
|
||||
|
||||
All the steps are based on the tools and samples of configuration files distributed with the Intel® Distribution of OpenVINO™ toolkit.
|
||||
|
||||
The example has been verified in Ubuntu 18.04 Operating System with Python 3.6 installed.
|
||||
|
||||
In case of issues while running the example, refer to :doc:`POT Frequently Asked Questions <pot_docs_FrequentlyAskedQuestions>` for help.
|
||||
|
||||
Model Preparation
|
||||
####################
|
||||
|
||||
1. Navigate to ``<EXAMPLE_DIR>``.
|
||||
|
||||
2. Download the MobileNet v2 PyTorch model using :doc:`Model Downloader <omz_tools_downloader>` tool from the Open Model Zoo repository:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
omz_downloader --name mobilenet-v2-pytorch
|
||||
|
||||
|
||||
After that, the original full-precision model is located in ``<EXAMPLE_DIR>/public/mobilenet-v2-pytorch/``.
|
||||
|
||||
3. Convert the model to the OpenVINO™ Intermediate Representation (IR) format using :doc:`Model Converter <omz_tools_downloader>` tool:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
omz_converter --name mobilenet-v2-pytorch
|
||||
|
||||
|
||||
After that, the full-precision model in the IR format is located in ``<EXAMPLE_DIR>/public/mobilenet-v2-pytorch/FP32/``.
|
||||
|
||||
For more information about Model Conversion API, refer to its :doc:`documentation <openvino_docs_MO_DG_Deep_Learning_Model_Optimizer_DevGuide>`.
|
||||
|
||||
Performance Benchmarking of Full-Precision Models
|
||||
#################################################
|
||||
|
||||
Check the performance of the full-precision model in the IR format using :doc:`Deep Learning Benchmark <openvino_inference_engine_tools_benchmark_tool_README>` tool:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
benchmark_app -m <EXAMPLE_DIR>/public/mobilenet-v2-pytorch/FP32/mobilenet-v2-pytorch.xml
|
||||
|
||||
Note that the results might be different depending on the characteristics of your machine. On a machine with Intel® Core™ i9-10920X CPU @ 3.50GHz it is like:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
Latency: 4.14 ms
|
||||
Throughput: 1436.55 FPS
|
||||
|
||||
|
||||
Dataset Preparation
|
||||
####################
|
||||
|
||||
To perform the accuracy validation as well as quantization of a model, the dataset should be prepared. This example uses a real dataset called ImageNet.
|
||||
|
||||
To download images:
|
||||
|
||||
1. Go to the `ImageNet <http://www.image-net.org/>`__ homepage.
|
||||
2. If you do not have an account, click the ``Signup`` button in the right upper corner, provide your data, and wait for a confirmation email.
|
||||
3. Log in after receiving the confirmation email or if you already have an account. Go to the ``Download`` tab.
|
||||
4. Select ``Download Original Images``.
|
||||
5. You will be redirected to the ``Terms of Access`` page. If you agree to the Terms, continue by clicking ``Agree and Sign``.
|
||||
6. Click one of the links in the ``Download as one tar file`` section.
|
||||
7. Unpack the downloaded archive into ``<EXAMPLE_DIR>/ImageNet/``.
|
||||
|
||||
Note that the registration process might be quite long.
|
||||
|
||||
Note that the ImageNet size is 50 000 images and takes around 6.5 GB of disk space.
|
||||
|
||||
To download the annotation file:
|
||||
|
||||
1. Download `archive <http://dl.caffe.berkeleyvision.org/caffe_ilsvrc12.tar.gz>`__.
|
||||
2. Unpack ``val.txt`` from the archive into ``<EXAMPLE_DIR>/ImageNet/``.
|
||||
|
||||
After that, the ``<EXAMPLE_DIR>/ImageNet/`` dataset folder should have a lot of image files like ``ILSVRC2012_val_00000001.JPEG`` and the ``val.txt`` annotation file.
|
||||
|
||||
Accuracy Validation of Full-Precision Model in IR Format
|
||||
########################################################
|
||||
|
||||
1. Create a new file in ``<EXAMPLE_DIR>`` and name it ``mobilenet_v2_pytorch.yaml``. This is the Accuracy Checker configuration file.
|
||||
|
||||
2. Put the following text into ``mobilenet_v2_pytorch.yaml`` :
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
models:
|
||||
- name: mobilenet-v2-pytorch
|
||||
|
||||
launchers:
|
||||
- framework: dlsdk
|
||||
device: CPU
|
||||
adapter: classification
|
||||
|
||||
datasets:
|
||||
- name: classification_dataset
|
||||
data_source: ./ImageNet
|
||||
annotation_conversion:
|
||||
converter: imagenet
|
||||
annotation_file: ./ImageNet/val.txt
|
||||
reader: pillow_imread
|
||||
|
||||
preprocessing:
|
||||
- type: resize
|
||||
size: 256
|
||||
aspect_ratio_scale: greater
|
||||
use_pillow: True
|
||||
- type: crop
|
||||
size: 224
|
||||
use_pillow: True
|
||||
- type: bgr_to_rgb
|
||||
|
||||
metrics:
|
||||
- name: accuracy@top1
|
||||
type: accuracy
|
||||
top_k: 1
|
||||
|
||||
- name: accuracy@top5
|
||||
type: accuracy
|
||||
top_k: 5
|
||||
|
||||
|
||||
where ``data_source: ./ImageNet`` is the dataset and ``annotation_file: ./ImageNet/val.txt``
|
||||
is the annotation file prepared in the previous step. For more information about
|
||||
the Accuracy Checker configuration file refer to :doc:`Accuracy Checker Tool documentation <omz_tools_accuracy_checker>`.
|
||||
|
||||
3. Evaluate the accuracy of the full-precision model in the IR format by executing the following command in ``<EXAMPLE_DIR>`` :
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
accuracy_check -c mobilenet_v2_pytorch.yaml -m ./public/mobilenet-v2-pytorch/FP32/
|
||||
|
||||
|
||||
The actual result should be like **71.81%** of the accuracy top-1 metric on VNNI-based CPU.
|
||||
Note that the results might be different on CPUs with different instruction sets.
|
||||
|
||||
|
||||
Model Quantization
|
||||
####################
|
||||
|
||||
1. Create a new file in ``<EXAMPLE_DIR>`` and name it ``mobilenet_v2_pytorch_int8.json``. This is the POT configuration file.
|
||||
|
||||
2. Put the following text into ``mobilenet_v2_pytorch_int8.json`` :
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
{
|
||||
"model": {
|
||||
"model_name": "mobilenet-v2-pytorch",
|
||||
"model": "./public/mobilenet-v2-pytorch/FP32/mobilenet-v2-pytorch.xml",
|
||||
"weights": "./public/mobilenet-v2-pytorch/FP32/mobilenet-v2-pytorch.bin"
|
||||
},
|
||||
"engine": {
|
||||
"config": "./mobilenet_v2_pytorch.yaml"
|
||||
},
|
||||
"compression": {
|
||||
"algorithms": [
|
||||
{
|
||||
"name": "DefaultQuantization",
|
||||
"params": {
|
||||
"preset": "mixed",
|
||||
"stat_subset_size": 300
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
where ``"model": "./public/mobilenet-v2-pytorch/FP32/mobilenet-v2-pytorch.xml"`` and
|
||||
``"weights": "./public/mobilenet-v2-pytorch/FP32/mobilenet-v2-pytorch.bin"`` specify
|
||||
the full-precision model in the IR format, ``"config": "./mobilenet_v2_pytorch.yaml"``
|
||||
is the Accuracy Checker configuration file, and ``"name": "DefaultQuantization"`` is the algorithm name.
|
||||
|
||||
3. Perform model quantization by executing the following command in ``<EXAMPLE_DIR>`` :
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
pot -c mobilenet_v2_pytorch_int8.json -e
|
||||
|
||||
|
||||
The quantized model is placed into the subfolder with your current date and time
|
||||
in the name under the ``./results/mobilenetv2_DefaultQuantization/`` directory.
|
||||
The accuracy validation of the quantized model is performed right after the quantization.
|
||||
The actual result should be like **71.556%** of the accuracy top-1 metric on VNNI-based CPU.
|
||||
Note that the results might be different on CPUs with different instruction sets.
|
||||
|
||||
|
||||
Performance Benchmarking of Quantized Model
|
||||
###########################################
|
||||
|
||||
Check the performance of the quantized model using :doc:`Deep Learning Benchmark <openvino_inference_engine_tools_benchmark_tool_README>` tool:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
benchmark_app -m <INT8_MODEL>
|
||||
|
||||
|
||||
where ``<INT8_MODEL>`` is the path to the quantized model.
|
||||
Note that the results might be different depending on the characteristics of your
|
||||
machine. On a machine with Intel® Core™ i9-10920X CPU @ 3.50GHz it is like:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
Latency: 1.54 ms
|
||||
Throughput: 3814.18 FPS
|
||||
|
||||
|
||||
@endsphinxdirective
|
||||
Reference in New Issue
Block a user