"tensorflow/core/framework/common_shape_fns.h: No such file or directory" 在 tensorflow 中添加自定义操作时
"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)的使用,并使用直接命令构建它。
- 添加 cpp 文件。
# create empty file and copy and paste code
! touch ./xor_op.cc
或者使用魔法操作,
%%writefile xor_op.cc
#And contents of the file
- 从 TensorFlow 获取编译标志。
tf.sysconfig.get_compile_flags()
# output: ['-I/usr/local/lib/python3.7/dist-packages/tensorflow/include',
# '-D_GLIBCXX_USE_CXX11_ABI=0']
- 从 TensorFlow 获取链接标志。
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 in 指出了这一点。
我正在尝试使用此 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)的使用,并使用直接命令构建它。
- 添加 cpp 文件。
# create empty file and copy and paste code
! touch ./xor_op.cc
或者使用魔法操作,
%%writefile xor_op.cc
#And contents of the file
- 从 TensorFlow 获取编译标志。
tf.sysconfig.get_compile_flags()
# output: ['-I/usr/local/lib/python3.7/dist-packages/tensorflow/include',
# '-D_GLIBCXX_USE_CXX11_ABI=0']
- 从 TensorFlow 获取链接标志。
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 in