在窗口中的张量流中添加操作

Adding an op in tensorflow in windows

本文关键字:添加 操作 张量流 窗口      更新时间:2023-10-16

我目前正在尝试优化Tensorflow的word2vec实现,使其像原始gensim word2vec实现一样工作。但是,这里的教程

https://github.com/tensorflow/models/blob/master/tutorials/embedding/word2vec.py, 要求我首先向张量流添加新的操作。

我已经将存储库克隆到我的桌面,tensorflow/tensorflow-master和tensorflow/models-master都在一个名为tensorflow的目录中。 我尝试编译位于模型主/教程/嵌入中的 word2vec_ops.cc 和 word2vec_kernels.cc 文件(它们定义了新操作的实现和接口)

它给了我以下错误消息 -

In file included from word2vec_kernels.cc:16:0:
tensorflow/core/framework/op.h:23:54: fatal error: 
tensorflow/core/framework/op_def_builder.h: No such file or directory
compilation terminated.

我还将 tensorflow-master/tensorflow/文件夹复制到 models-master/tutorials/embedding/中,以便所有必需的头文件都在同一个目录中(请参阅 github 存储库以供参考,我在 windows 上有类似的目录树:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core)

原始编译程序:

TF_CFLAGS=( $(python -c 'import tensorflow as tf; print(" 
".join(tf.sysconfig.get_compile_flags()))') )
TF_LFLAGS=( $(python -c 'import tensorflow as tf; print(" 
".join(tf.sysconfig.get_link_flags()))') )
g++ -std=c++11 -shared word2vec_ops.cc word2vec_kernels.cc -o 
word2vec_ops.so -fPIC ${TF_CFLAGS[@]} ${TF_LFLAGS[@]} -O2 - 
D_GLIBCXX_USE_CXX11_ABI=0

这一系列命令在 Windows 终端中不起作用(显然)。所以我还在代码本身中定义了标志

flags.DEFINE_string("save_path", 'C:UsersDesktoplog_dirgensim22', 
"Directory to write the model and "
"training summaries.")
flags.DEFINE_string("train_data", 'cmpl.txt', "Training text file. "
"E.g., unzipped file 
http://mattmahoney.net/dc/text8.zip.")
flags.DEFINE_string(
"eval_data", 'questions-words.txt', "File consisting of analogies of four 
tokens."
"embedding 2 - embedding 1 + embedding 3 should be close "
"to embedding 4."
"See README.md for how to get 'questions-words.txt'.")

,所以我不需要将它们传递给 sys.argv(),(所以前两个 命令不是必需的),但是,仍然使用anaconda mingw,我无法构建实现的动态库。

我已经通过使用适用于Linux的Windows子系统找到了解决方案。因此,不是双启动或虚拟环境, 在搜索框中的窗口中,键入"打开/关闭Windows功能"并选中-> Windows子系统for linux
的框,然后Windows要求您重新启动系统,您可以在其上安装任何相关的终端(我安装了Ubuntu 18.04)。

接下来,设置非常简单,您只需设置用户名和pwd,就可以了。

您可以通过以下方式访问窗口上的任何文件

cd /mnt/c/

因此,我将我的工作目录加载到C盘上并使用了该系统,作为Linux。 虽然这是一个非常迂回的解决方案,但它是临时工作的。