我希望存储中间结果,以避免对一件事进行多次计算。我要找的东西是这样的:
h1_activ = sigmoid(self.bias_visiblie + T.dot(D, self.W))
h1_sample = h1_activ > rnds.uniform((n_samples, self.n_hidden ))
f_h1_sample = theano.function(
inputs=[D],
outputs=h1_sample,
# I'd like to take the result from 'h1_sample' and store it into 'H1_sample'
updates=[(self.H1_sample, ??? )]
)上面的代码当然不会运行,但是有没有办法这样做呢?将中间值存储到共享变量中?
发布于 2016-10-17 15:46:17
您可以在相同的theano.function中编写使用相同中间结果的最终结果。
例如:
h1_activ = sigmoid(self.bias_visiblie + T.dot(D, self.W))
h1_sample = h1_activ > rnds.uniform((n_samples, self.n_hidden ))
# h2_sample use the intermediate result h1_sample.
h2_sample = h1_sample * 2
f_h1_sample = theano.function(
inputs=[D],
outputs=[h1_sample, h2_sample],
)h2_smaple是使用h1_sample的最终结果。
您还可以保存中间结果,并将它们用作另一个theano.function中的输入。
不同的theano.function对应不同的计算图。我认为不同的计算图之间不能共享任何计算。
https://stackoverflow.com/questions/40070098
复制相似问题