I've a question regarding embedding python into a C++ application. The setup is as follows: I have a large C++ application which generates some data (renders images in real-time) and displays them. I have also trained a neural network in python using tensorflow which will accept these images.
My idea was to embed python and send data as a numpy array, predict using the neural network and get back another processed numpy array to display (in C++). I've made some basic tests without tensorflow on python side to get a feel for embedding python in c and such and it seems to work.
However, once i place "import tensorflow" into any python script that I want to import, I'll get a NULL from PyImport_ImportModule in c++ part.
e.g.
import numpy as np
def foo(img):
return np.clip(img * 2.0, 0, 255).astype(np.uint8)
works fine. But the following doesn't:
import numpy as np
import tensorflow as tf #this causes the fail
def foo(img):
return np.clip(img * 2.0, 0, 255).astype(np.uint8)
In the second case, I still get the message in stdout from tensorflow that it has found cuda etc, but then the module import fails.
My setup is on Windows 10 x64, Anaconda Python 3.5, tensorflow-0.12 and CUDA 8. Has anyone ran across a similar problem? Other modules that I've tested (numpy, pil, scipy) seem to load fine.
If it looks like it cannot be resolved, I'll resort to IPC of some sort between the c++ part and python.
I've resolved the issue. I needed to set argc and argv with PySys_SetArgv. I've uncovered this using PyErr_Occurred() and PyErr_Print() right after the failed import to see the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With