Skip to content

Latest commit

 

History

History
220 lines (189 loc) · 9.13 KB

File metadata and controls

220 lines (189 loc) · 9.13 KB

RFCN inference

This document has instructions for running RFCN inference using Intel-optimized TensorFlow.

Dataset

The COCO validation dataset is used in these RFCN quickstart scripts. The inference quickstart scripts use raw images, and the accuracy quickstart scripts require the dataset to be converted into the TF records format. See the COCO dataset for instructions on downloading and preprocessing the COCO validation dataset.

Quick Start Scripts

Script name Description
inference.sh Runs inference on a directory of raw images for 500 steps and outputs performance metrics.
accuracy.sh Processes the TF records to run inference and check accuracy on the results.

Run the model

Setup your environment using the instructions below, depending on if you are using AI Kit:

Setup using AI Kit on Linux Setup without AI Kit on Linux Setup without AI Kit on Windows

To run using AI Kit on Linux you will need:

  • git
  • numactl
  • wget
  • build-essential
  • Cython
  • contextlib2
  • jupyter
  • lxml
  • matplotlib
  • pillow>=9.3.0
  • protobuf-compiler
  • pycocotools
  • Activate the `tensorflow` conda environment
    conda activate tensorflow

To run without AI Kit on Linux you will need:

  • Python 3
  • git
  • numactl
  • wget
  • intel-tensorflow>=2.5.0
  • build-essential
  • Cython
  • contextlib2
  • jupyter
  • lxml
  • matplotlib
  • pillow>=9.3.0
  • protobuf-compiler
  • pycocotools
  • A clone of the Model Zoo repo
    git clone https://github.com/IntelAI/models.git

To run without AI Kit on Windows you will need:

For more information on the required dependencies, see the documentation on prerequisites in the TensorFlow models repo.

Download and extract the pretrained model and set the PRETRAINED_MODEL environment variable to point to the frozen graph file. If you run on Windows, please use a browser to download the pretrained model using the link below. For Linux, run:

# FP32 Pretrained Model
https://storage.googleapis.com/intel-optimized-tensorflow/models/2_10_0/rfcn_frozen_inference_graph.pb
export PRETRAINED_MODEL=$(pwd)/rfcn_frozen_inference_graph.pb

# Int8 Pretrained Model
https://storage.googleapis.com/intel-optimized-tensorflow/models/2_10_0/rfcn_final_fused_pad_and_conv.pb
export PRETRAINED_MODEL=$(pwd)/rfcn_final_fused_pad_and_conv.pb

RFCN uses the object detection code from the TensorFlow Model Garden. Clone this repo with the SHA specified below and apply the patch from the model zoo directory. Set the TF_MODELS_DIR environment variable to the path of your clone of the TF Model Garden.

# Clone the TensorFlow Model Garden
git clone https://github.com/tensorflow/models.git tensorflow-models
cd tensorflow-models
git checkout 6c21084503b27a9ab118e1db25f79957d5ef540b

# Apply the TF2 patch from the model zoo repo directory
git apply --ignore-space-change --ignore-whitespace <model zoo directory>/models/object_detection/tensorflow/rfcn/inference/tf-2.0.patch

# Set the TF_MODELS_DIR env var
export TF_MODELS_DIR=$(pwd)

Run on Linux

Download and install Google Protobuf version 3.3.0, and run protobuf compilation.

cd TF_MODELS_DIR/research
protoc object_detection/protos/*.proto --python_out=.
cd ../..

Once your environment is setup, navigate back to your Model Zoo directory. Ensure that you have set environment variables pointing to the TensorFlow Model Garden repo, the dataset, and output directories, and then run a quickstart script.

To run inference with performance metrics:

# cd to your model zoo directory
cd models

export DATASET_DIR=<path to the coco val2017 raw image directory (ex: /home/user/coco_dataset/val2017)>
export PRECISION=<set the precision to "int8" or "fp32">
export OUTPUT_DIR=<path to the directory where log files will be written>
export TF_MODELS_DIR=<directory where TensorFlow Model Garden is cloned>
# For a custom batch size, set env var `BATCH_SIZE` or it will run with a default value.
export BATCH_SIZE=<customized batch size value>

./quickstart/object_detection/tensorflow/rfcn/inference/cpu/inference.sh

To get accuracy metrics:

# cd to your model zoo directory
cd models

export DATASET_DIR=<path to TF record file (ex: /home/user/coco_output/coco_val.record)>
export PRECISION=<set the precision to "int8" or "fp32">
export OUTPUT_DIR=<path to the directory where log files will be written>
export TF_MODELS_DIR=<directory where TensorFlow Model Garden is cloned>
# For a custom batch size, set env var `BATCH_SIZE` or it will run with a default value.
export BATCH_SIZE=<customized batch size value>

./quickstart/object_detection/tensorflow/rfcn/inference/cpu/accuracy.sh

Run on Windows

  • Download and install Google Protobuf version 3.4.0 for Windows in addition to the above listed dependencies. Download and extract protoc-3.4.0-win32.zip Navigate to the research directory in TF_MODELS_DIR and install Google Protobuf:
set TF_MODELS_DIR=<directory where TensorFlow Model Garden is cloned>
cd %TF_MODELS_DIR%\research
“C:\<user>\protoc-3.4.0-win32\bin\protoc.exe” object_detection/protos/*.proto --python_out=.

After installing the prerequisites and cloning the TensorFlow models repo, and downloading the pretrained model, set the environment variables for the paths to your PRETRAINED_MODEL, an OUTPUT_DIR where log files will be written, TF_MODELS_DIR, and DATASET_DIR for COCO raw dataset directory or tf_records file based on whether you run inference or accuracy scripts. Navigate to your model zoo directory and then run a quickstart script.

# cd to your model zoo directory
cd models

set PRETRAINED_MODEL=<path to the frozen graph downloaded above>
set DATASET_DIR=<path to COCO raw dataset directory or tf_records file based on whether you run inference or accuracy scripts>
set PRECISION=<set the precision to "int8" or "fp32">
set OUTPUT_DIR=<directory where log files will be written>
set TF_MODELS_DIR=<directory where TensorFlow Model Garden is cloned>
# For a custom batch size, set env var `BATCH_SIZE` or it will run with a default value.
set BATCH_SIZE=<customized batch size value>

bash quickstart\object_detection\tensorflow\rfcn\inference\cpu\<script name>.sh

Note: You may use cygpath to convert the Windows paths to Unix paths before setting the environment variables. As an example, if the dataset location on Windows is D:\user\coco_dataset\val2017, convert the Windows path to Unix as shown:

cygpath D:\user\coco_dataset\val2017
/d/user/coco_dataset/val2017

Then, set the DATASET_DIR environment variable set DATASET_DIR=/d/user/coco_dataset/val2017.

Additional Resources