C++ calls the pb model and realizes the prediction of a single image

Environment:
win10
vs2017

After checking the information, three plans are tentatively decided:

  1. C++ calls the written python script
  2. cmake compiles tf source code, c++ calls and realizes offline prediction
  3. Call by finding python modules, classes, methods, and construction parameters

The first solution is implemented. I wrote a classified demo, created a new virtual environment, and packaged the things needed. This package is large, and the entire app integrated into the client is large. If there are other options, I definitely don't choose this one!

Try the second option:

When compiling tensorflow, I found out that NCCL was not installed. Some blogs are really pits. Why are the pits copied intact? The pits of others are also your pits. I especially want to complain! !

NCCL download link : link

https://developer.nvidia.com/nccl
sudo dpkg -i nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
sudo apt update
sudo apt install libnccl2 libnccl-dev
sudo cp /usr/lib/x86_64-linux-gnu/libnccl.so.2 /usr/local/cuda/lib
sudo cp /usr/include/nccl.h /usr/local/cuda/include/

nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb link:
link: https://pan.baidu.com/s/1jl_e4T8XZSMItRifDCAmvQ
extraction code: l9j3

The matters needing attention when compiling tensorflow are:

  1. The tensorflow version I chose 1.10
  2. The default installation address of python3.5: /usr/bin/python3.5
  3. Choose the location of various python libraries according to the version you want to compile
  4. ubuntu16.04 chose gcc-4.8
  5. There seems to be nothing wrong with the others

Several python libraries are installed:

sudo pip3.5 install -U --user pip six numpy wheel mock
sudo pip3.5 install -U --user keras_applications==1.0.5 --no-deps
sudo pip3.5 install -U --user keras_preprocessing==1.0.3 --no-deps

The following is the compilation:
because I want to use cuda to accelerate, I gave an additional parameter. It is said that there are a lot of pits here. I am still compiling this and I am a little worried. At this step, I read many blogs and said not to add sudo, otherwise there will be There are many unexpected errors. I don't like adding sudo when using bazel itself, so I didn't add them. Wait for the result! !
bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

Insert picture description here
The blog has just been published and I saw it successfully! Happy~

Insert picture description here

After verification, the compiled tf can correctly output what you want!
Next, compile and generate the .so file, and compile the C++API library:
bazel build //tensorflow:libtensorflow_cc.so

Insert picture description here
The compilation was successful, and another small goal was achieved! ! !

Um, why do I need to load the complete path for my guide package? Leave a question! !

Insert picture description here
This is too ugly! ! !

Compile the excellent references seen by tensorflow:
https://blog.csdn.net/HappyCtest/article/details/86747306

Guess you like

Origin blog.csdn.net/weixin_43868576/article/details/108219799