tensorflow windows 创建自己的插件 [英] tensorflow windows create own plugin

查看:20
本文介绍了tensorflow windows 创建自己的插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从源代码中使用 Visual Studio 2015 在 Windows 10 上成功构建了 tensorflow+gpu.

I have tensorflow+gpu successfully built on windows 10 with visual studio 2015, from the source code.

结果,我得到了 tensorflow.dlltensorflow.lib.我有 CUDA8.0cudnn 5.0;配备 gtx 1080 gpu.

As a result, I get tensorflow.dll and tensorflow.lib. I have CUDA8.0 and cudnn 5.0; with a gtx 1080 gpu equipped.

然而,我的问题不是关于构建和编译 tensorflow.这是关于创建 tensorflow 插件.

However, my question is not about building and compiling tensorflow. It's about creating tensorflow plugins.

我按照教程构建了我自己的插件".然后我尝试编译一个windows .dll;所以windows不会自动为我导出符号.然后我先编译一个静态库并使用你的工具

I followed the tutorial to construct my own "plug-in". and then I tried to compile a windows .dll; so windows would not export symbols automatically for me . then I compile a static lib first and used your tools

/tensorflow/contrib/cmake/tools/create_def_file.py

为我创建一个 .def 文件,并最终用它来编译 .dll.

to create a .def file for me and eventually used that to compile the .dll.

但是,在我的python代码中,当我尝试

However, in my python code, when I tried to

correlation = tf.load_op_library(correlation.dll) 

我打电话给

correlation.correlation()

使用REGISTER_OP("Correlation")注册相关性;它仍然告诉我

with Correlation registered using REGISTER_OP("Correlation"); It still tells me

AttributeError: module '7b088d8b906b36d3e50721b0adbaaa6a' 没有属性 'correlation'

AttributeError: module '7b088d8b906b36d3e50721b0adbaaa6a' has no attribute 'correlation'

我认为这只是 windows(或 cl 编译器)的问题,也许 REGISTER_OP("Correlation") 所做的只是编译器没有发现,

I think this is just a windows (or cl compiler) issue, maybe what REGISTER_OP("Correlation") did is just not picked up by the compiler,

那么我可以做些什么来使这在 Windows 上发生??

so is there any thing I can do to make this happen on windows??

推荐答案

Windows 不支持通过 tf.load_op_library() 加载自定义操作库(至少在 TensorFlow 1.8 中).解决方法是将您的自定义操作添加到 TensorFlow 库本身中.以tensorflow\tensorflow\core\user_ops\fact.cc中实现的tf.user_ops.my_fact为例:

Loading custom op libraries via tf.load_op_library() is not supported on Windows (at least with TensorFlow 1.8). The workaround is to add your custom op into the TensorFlow library itself. Follow the example of tf.user_ops.my_fact implemented in tensorflow\tensorflow\core\user_ops\fact.cc:

  1. 将您的 C++ 实现放在 tensorflow\tensorflow\core\user_ops 中
  2. 在 tensorflow\tensorflow\python\user_ops 中添加 python 绑定
  3. 编译 TensorFlow(阅读https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/cmake)
  4. 将 Conda 环境中的 tensorflow 目录替换为张量流\张量流\contrib\cmake\build\tf_python\tensorflow
  5. 您的新 op 函数将导入 tf.user_ops

这篇关于tensorflow windows 创建自己的插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆