重用编译的Theano函数 [英] Reusing compiled Theano functions

查看:135
本文介绍了重用编译的Theano函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在Theano中实现了以下函数:

Suppose I have implemented the following function in Theano:

import theano.tensor as T
from theano import function
x = T.dscalar('x')
y = T.dscalar('y')
z = x + y
f = function([x, y], z)

当我尝试运行它时,构建一个计算图形,函数被优化和编译。

When I try to run it a graph of computations is constructed, the function gets optimized and compiled.

如何在Python脚本和/或C ++应用程序中重用这个编译的代码块?

How can I reuse this compiled chunk of code from within a Python script and/or a C++ application?

EDIT:
目标是构建一个深度学习网络,并在最终的C ++应用程序中重用它。

The goal is to construct a deep learning network and reuse it in a final C++ app.

推荐答案

目前不可能。有用户修改了Theano以允许对Theano函数进行酸洗,但是在取消发送的过程中,我们已经重新优化了图形。

Currently this isn't possible. There is user that modified Theano to allow pickling the Theano function, but during unpickling we already re optimize the graph.

有一个Pull请求允许Theano生成一个C ++图书馆。然后,用户可以自己编译它,并将其用作正常的C ++库。 lib链接再次python lib并要求安装numpy。但这还没有准备好广泛使用。

There is a Pull Request that allow Theano to generate a C++ library. The user can then compile it himself and use it as a normal C++ library. The lib link again the python lib and ask that numpy is installed. But this isn't ready for broad usage.

你的目标是什么?同样的编译时间?如果是这样,Theano已经缓存了它编译的c ++模块,所以下次重用它时,编译速度更快。

What is your goal? To same on the compilation time? If so Theano already cache the c++ module that it compile, so the next time it is reused, the compilation is faster. But for big graph, the optimization phase is always redone as told above and this can take a significant time.

那么你的目标是什么?

这是我们正在做的事情。确保使用最新的Theaon版本(0.6),因为它编译速度更快。开发版本os也有点快。

This is something that we are working on. Make sure to use the latest Theaon release (0.6) as it compile faster. The development version os also a little faster.

这篇关于重用编译的Theano函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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