# API usage sample for classification task¶

This sample demonstrates the use of the Post-training Optimization Tool API for the task of quantizing a classification model. The MobilenetV2 model from TensorFlow* is used for this purpose. A custom DataLoader is created to load the ImageNet classification dataset and the implementation of Accuracy at top-1 metric is used for the model evaluation.

## How to prepare the data¶

To run this sample, you need to download the validation part of the ImageNet image database and place it in a separate folder, which will be later referred 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 Sample¶

In the instructions below, the Post-Training Optimization Tool directory <POT_DIR> is referred to:

• <ENV>/lib/python<version>/site-packages/ in the case of PyPI installation, where <ENV> is a Python* environment where OpenVINO is installed and <version> is a Python* version, e.g. 3.6.

• <INSTALL_DIR>/deployment_tools/tools/post_training_optimization_toolkit in the case of OpenVINO distribution package. <INSTALL_DIR> is the directory where Intel Distribution of OpenVINO toolkit is installed.

1. To get started, follow the Installation Guide.

2. Launch Model Downloader tool to download mobilenet-v2-1.0-224 model from the Open Model Zoo repository.

python3 ./downloader.py --name mobilenet-v2-1.0-224
3. Launch Model Converter tool to generate Intermediate Representation (IR) files for the model:

python3 ./converter.py --name mobilenet-v2-1.0-224 --mo <PATH_TO_MODEL_OPTIMIZER>/mo.py
4. Launch the sample script:

python3 <POT_DIR>/compression/api/samples/classification/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.