onnxruntime/samples/c_cxx/imagenet
Pranav Sharma f8c3442880
Part 2 of renaming AllocatorInfo to MemoryInfo. (#1804)
* Mention OrtCreateSessionFromArray in C API doc

* Part 2 of renaming AllocatorInfo to MemoryInfo.

* pr comments

* fix comment
2019-09-12 08:19:29 -07:00
..
async_ring_buffer.h Part 2 of renaming AllocatorInfo to MemoryInfo. (#1804) 2019-09-12 08:19:29 -07:00
cached_interpolation.h
CMakeLists.txt
controller.cc
controller.h
data_processing.h Document for the C/C++ samples (#1442) 2019-07-22 16:14:49 -07:00
image_loader.cc Document for the C/C++ samples (#1442) 2019-07-22 16:14:49 -07:00
image_loader.h Document for the C/C++ samples (#1442) 2019-07-22 16:14:49 -07:00
image_loader_libjpeg.cc Document for the C/C++ samples (#1442) 2019-07-22 16:14:49 -07:00
image_loader_wic.cc
jpeg_handle.cc
jpeg_handle.h
jpeg_mem.cc
jpeg_mem.h
local_filesystem.h
local_filesystem_posix.cc
local_filesystem_win.cc
main.cc Don't create the default allocator every single time. Rename API accordingly. Expose Session/Run log severity levels. (#1615) 2019-08-23 10:33:20 -07:00
README.md Document for the C/C++ samples (#1442) 2019-07-22 16:14:49 -07:00
resize_image_cmd.cc
runnable_task.h
single_consumer.h
sync_api.h
sync_api_posix.cc
sync_api_win.cc
taskflow.png Document for the C/C++ samples (#1442) 2019-07-22 16:14:49 -07:00

Overview

taskflow

WARNING: If you want to train the model by yourself, you need at least 500GB disk space and a powerful NVIDIA GPU.

Install tensorflow

Install Python 3.x from python.org, then execute

pip install --upgrade tensorflow

For more information, see Install Tensorflow

Get the Imagenet dataset

We need the ILSVRC-2012-CLS image classification dataset from http://www.image-net.org/.

If you're going to train the model by yourself, then you need the full dataset, which is about 500GB. Otherwise, you only need the validation data set, which is just about 3GB.

For how to get the data, see ImageNet Download faq. Once you get an account, visit http://www.image-net.org/download-images. You will find "Download links to ILSVRC2012 image data" on that page

And also, please download the "imagenet_lsvrc_2015_synsets.txt" and "imagenet_2012_validation_synset_labels.txt" from tensorflow models repo.

Get the model

Please check https://github.com/tensorflow/models/tree/master/research/slim/. You may either train the model by yourself, or just download a pretrained model provided by Google. If you don't know which one to download and try, we suggest you choose the Inception V4 model as a starting point.

After downloading, please uncompress it.

tar -zxvf inception_v4_2016_09_09.tar.gz

The [Inception V4] zip file only contains a single checkpoint file: inception_v4.ckpt. It can't be directly used for inferencing. You need to combine the network definition and the checkpoint. Please follow the steps below:

  1. Export the graph Create an new folder. At there, execute
git clone https://github.com/tensorflow/models .
python research\slim\export_inference_graph.py --model_name=inception_v4 --output_file=grpah.pb
  1. Freeze the graph Run
freeze_graph.exe --input_graph=graph.pb --input_checkpoint=inception_v4.ckpt --output_graph=inception_v4.pb --output_node_names=InceptionV4/Logits/Predictions --input_binary=true

Convert the model to ONNX

pip install --upgrade tf2onnx 
python -m tf2onnx.convert --input inception_v4.pb --inputs input:0 --outputs InceptionV4/Logits/Predictions:0 --opset 10 --output inception_v4.onnx

Run the inferencing

In your build dir of onnxruntime_samples, search for "image_classifier.exe" and run

image_classifier.exe C:\tools\imagnet_validation_data inception_v4.onnx imagenet_lsvrc_2015_synsets.txt imagenet_2012_validation_synset_labels.txt 32

Please replace the file names with the corresponding file paths.

The last parameter is batch size, you may need to adjust it according to your GPU memory size.