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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With