Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

c++ - Adding custom TensorFlow OP

I am trying to use the Tensorflow implementation of compact bilinear pooling by ronghanghu since it's used in the implementation of the "Learning Rich Features for Image Manipulation Detection" paper. ronghanghu uses TensorFlow version 1.12.0 with CUDA 8.0 and g++ 5.4.0 to build sequential_batch_fft.so. However, they do say we can rebuild the sequential_batch_fft.so using a different version of Tensorflow (in my case 2.4.0) with a different compiler (g++ 7.5.0) and a different CUDA version (11.0). When I try to build sequential_batch_fft.so using the commands in compile.sh below

TF_INC=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())')
TF_LIB=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_lib())')

# Use 0 if the TensorFlow binary is built with GCC 4.x
# see https://docs.computecanada.ca/wiki/GCC_C%2B%2B_Dual_ABI for details
USE_CXX11_ABI=0

nvcc -std=c++11 -c -o sequential_batch_fft_kernel.cu.o 
sequential_batch_fft_kernel.cu.cc 
-D_GLIBCXX_USE_CXX11_ABI=$USE_CXX11_ABI -DNDEBUG 
-L$TF_LIB -ltensorflow_framework 
-I $TF_INC -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC

g++ -std=c++11 -shared -o ./build/sequential_batch_fft.so 
sequential_batch_fft_kernel.cu.o 
sequential_batch_fft.cc 
-D_GLIBCXX_USE_CXX11_ABI=$USE_CXX11_ABI -DNDEBUG 
-L$TF_LIB -ltensorflow_framework 
-I $TF_INC -fPIC 
-lcudart -lcufft -L/usr/local/cuda/lib64

rm -rf sequential_batch_fft_kernel.cu.o

the only output I get in the terminal is this. compile.sh output

The problem is nothing else happens beyond that. No errors reported and it doesn't end the build. Left it for hours and still nothing. I am completely clueless as to why this is. I later decided to try doing one of the examples provided by TensorFlow on adding_an_op and I got the same result. What could be the problem here? It's really confusing for me because there are no errors just a never-ending program.

question from:https://stackoverflow.com/questions/65599567/adding-custom-tensorflow-op

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Turns out the problem was with the tensorflow_framework.so. Was able to fix this by creating a symbolic link ln -s libtensorflow_framework.so.2 libtensorflow_framework.so in ../site-packages/tensorflow. Also, I think my project path was not suitable as it contains spaces. Not so sure about this one but when I used TensorFlow installed on a path with no spaces everything worked fine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...