在google colab上将新操作添加到tensorflow

时间:2019-01-08 08:59:39

标签: tensorflow word2vec google-colaboratory embedding

我正在尝试在Google colab上编译一些.cc文件(如herehere所示),但是找不到包含的op.h文件 编译时出现以下错误:

word2vec_ops.cc:16:10: fatal error: tensorflow/core/framework/op.h: No such file or directory
#include "tensorflow/core/framework/op.h"
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
word2vec_kernels.cc:16:10: fatal error: tensorflow/core/framework/op.h: No such file or directory
#include "tensorflow/core/framework/op.h"
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

1 个答案:

答案 0 :(得分:0)

您可以使用以下gcc命令在Google colab上编译.cc文件:

$ gcc -Wl,-R/path/to/lib -I/path/to/include -L/path/to/lib -o myAppName mycode.c -llibapp2

通过

查找您的库包含路径
import tensorflow as tf
tf.sysconfig.get_include()

示例:

!g++ -std=c++11 -I /usr/local/lib/python3.6/dist-packages/tensorflow_core/include -shared word2vec_ops.cc word2vec_kernels.cc -o word2vec_ops.so -fPIC ${TF_CFLAGS[@]} ${TF_LFLAGS[@]} -O2```