[英]“tensorflow/core/framework/common_shape_fns.h: No such file or directory” when adding custom op in tensorflow
我正在嘗試使用此Tensorflow Doc在Google Colab的 Tensorflow 中添加自定義操作。 但是,在構建時出現此錯誤。
2021-04-05 04:24:26.500483: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-04-05 04:24:29.436586: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
xor_op.cc:2:10: fatal error: tensorflow/core/framework/common_shape_fns.h: No such file or directory
#include "tensorflow/core/framework/common_shape_fns.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
構建命令是,
$ TF_LFLAGS=($(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))'))
$ TF_CFLAGS=($(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))'))
$
$ g++ -std=c++14 -shared xor_op.cc -o xor_op.so -fPIC ${TF_CFLAGS[@]} ${TF_LFLAGS[@]} -O2
知道在這種情況下有什么問題嗎?
使用以下步驟在 Google Colab 中運行它。 基本上,我們將在構建中刪除變量(例如,TF_LFLAGS、TF_CFLAGS)的使用,並使用直接命令構建它。
# create empty file and copy and paste code
! touch ./xor_op.cc
或者使用魔法操作,
%%writefile xor_op.cc
#And contents of the file
tf.sysconfig.get_compile_flags()
# output: ['-I/usr/local/lib/python3.7/dist-packages/tensorflow/include',
# '-D_GLIBCXX_USE_CXX11_ABI=0']
tf.sysconfig.get_link_flags()
# output: ['-L/usr/local/lib/python3.7/dist-packages/tensorflow',
# '-l:libtensorflow_framework.so.2']
! g++ -std=c++14 -shared \
xor_op.cc \
-o xor_op.so \
-fPIC \
-I/usr/local/lib/python3.7/dist-packages/tensorflow/include \
-D_GLIBCXX_USE_CXX11_ABI=0 \
-L/usr/local/lib/python3.7/dist-packages/tensorflow \
-l:libtensorflow_framework.so.2 \
-O2
現在這將創建預期的.so 文件。 gobrewers14在另一個問題的評論部分指出了這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.