Reusing compiled Theano functions

徘徊边缘 提交于 2019-11-30 04:24:30

问题


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.

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

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


回答1:


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.

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 links against the python lib and requires numpy to be installed. But this isn't ready for broad usage.

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

So what is your goal?

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



来源:https://stackoverflow.com/questions/21112016/reusing-compiled-theano-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!