문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top