All Projects → BIGBALLON → CPP-Call-Tensorflow

BIGBALLON / CPP-Call-Tensorflow

Licence: other
Calling (TensorFlow) Python Program from C++

Programming Languages

C++
36643 projects - #6 most used programming language
python
139335 projects - #7 most used programming language
CMake
9771 projects
Makefile
30231 projects

Projects that are alternatives of or similar to CPP-Call-Tensorflow

messenger
Laravel messenger. A full messenger suite for your new / existing laravel app! Private and group threads between multiple models, with real-time messaging, reactions, attachments, calling, chat bots, and more!
Stars: ✭ 194 (+295.92%)
Mutual labels:  calling
ios-swift-chat-app
Open-source Voice & Video Calling and Text Chat App for Swift (iOS)
Stars: ✭ 111 (+126.53%)
Mutual labels:  calling
q-municate-web
Q-municate Web chat application
Stars: ✭ 66 (+34.69%)
Mutual labels:  calling
connectycube-flutter-call-kit
A Flutter plugin for displaying call screen when the app in the background or terminated.
Stars: ✭ 35 (-28.57%)
Mutual labels:  calling
TUICalling
腾讯云TRTC针对直播、语聊、视频通话等推出的低代码解决方案~
Stars: ✭ 28 (-42.86%)
Mutual labels:  calling
ios-swift-chat-ui-kit
Ready-to-use Chat UI Components for Swift (iOS)
Stars: ✭ 42 (-14.29%)
Mutual labels:  calling

Calling TensorFlow Python Program from C++

This Demo will show how to call an pre-trained imagenet model to predict picture in C++.

├─ prediction.cpp                 % C++ file
├─ vgg_model.py                   % TensorFlow vgg model   
├─ makefile                       % Compile file
├─ little_demo                    % An simple Demo
└─ test_pic/                      % Test pictures
	├─ cat.jpeg     
	├─ puzzle.jpeg
	└─ tiger.jpeg  

The python script

Firstly, we need an python script which let us to load VGG model & use it to do predict op.

You can test the script vgg_model.py by using the following cmd:

(deeplearning) bg@bg-cgi:~/Desktop/C_python$ python3 vgg_model.py 
Using TensorFlow backend.

...
...
...

 Please input picture file to predict: test_pic/cat.jpeg
 Predicted: [('n02124075', 'Egyptian_cat', 0.93183666)]

It will download weight file vgg19_weights_tf_dim_ordering_tf_kernels.h5 and imagenet_class_index.json to ~/.keras/models the first time.

Compile

use Makefile

Using make all to Compile your cpp file.
Make sure your python's version is correct.

bg@bg-cgi:~/.keras/models$ locate Python.h
/usr/include/python2.7/Python.h
/usr/include/python3.5m/Python.h

so I use the following cmd to compile

g++ -std=c++11 -Wall -O3 prediction.cpp -lpython3.5m -L/usr/include/python3.5m/ -I/usr/include/python3.5m/ -o pred_test

use Cmake

I just write a CMakeLists.txt, which can help you to compile your cpp code.
So just use the following cmd:

mkdir build && cd build
cmake ../
make
cd ../ 

Then you will see a executable file classifier, just use ./classifier to run the program.

Usage

Makefile

make all to compile, then ./pred_test to run c++ program.

Cmake

use ./classifier to run the program after building.

Then you can see it works:

 ===========> START CALL PYTHON SCRIPT <===========
 ===========> 1st CALL <===========
 Please input picture file to predict: huhu
 file not exist!
 ===========> 2nd CALL <===========
 Please input picture file to predict: test_pic/cat.jpeg
 Predicted:  [('n02124075', 'Egyptian_cat', 0.93183666)]
 ===========> 3rd CALL <===========
 Please input picture file to predict: test_pic/tiger.jpeg
 Predicted:  [('n02129604', 'tiger', 0.82598984)]
 ===========> 4th CALL <===========
 Please input picture file to predict: test_pic/puzzle.jpeg
 Predicted:  [('n03598930', 'jigsaw_puzzle', 0.99813461)]
 ===========> CALLING FINISHED <===========
(deeplearning) bg@bg-cgi:~/Desktop/C_python$ 

Feel free to contact me if you have any question.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].