在窗口中的张量流中添加操作
Adding an op in tensorflow in windows
我目前正在尝试优化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。 虽然这是一个非常迂回的解决方案,但它是临时工作的。
- 堆栈粉碎 在我在代码中添加新变量以及一些操作后C++检测到
- 宏如何在Tensorflow中添加新的操作时"REGISTER_OP("ZeroOut")
- 当我尝试在 tensorflow 中添加一个新操作时如何 #include "include/libxsmm.h"?
- 如何使用阻止套接字 API 添加消息发送操作 (smtp) 的进度?
- 静态断言添加操作是否可用
- 在窗口中的张量流中添加操作
- QT从Qmenu删除操作,以后再添加
- 如何添加到由QtConcurrent::map操作的QStringList中?
- 在范围内添加位操作和转换式的枚举 - 圣诞节探索
- 如何在服务exe中添加失败操作
- C++ 用于添加操作的线程安全
- 将操作码添加到现有二进制文件所需的内容
- 向QListWidget添加操作
- 我正在寻找一种在从模型中删除并重新添加修改后的可提取对象后操作 iloextract 对象的方法
- 在Model上添加操作而不向Model中添加代码
- Qt5无法识别快捷方式,除非将操作添加到工具栏中
- 添加C++前缀是否"const"硬件级别执行任何不同操作,或者只是对编码人员的保护?
- c++添加操作菜单
- 具有 2D 数组添加操作的模板
- 添加叠加/操作使用AVFoundation为iPhone