如何在theano中运行多个模型

时间:2018-12-08 06:30:01

标签: theano theano-cuda

我正在使用MLP运行theano代码,我想知道是否可以运行具有相同结构的6个模型,并获得输出并一起更新,如下所示:

import numpy as np
import theano
import theano.tensor as T
from numpy.random import RandomState
from functools import reduce

inputs = []
outputs = []
updatess = []
for i in range(6):
    W = []
    input = T.matrix('x1')
    W_values1 = np.random.randn(1000,250)
    W1 = theano.shared(value=W_values1.astype(theano.config.floatX), borrow=True)
    b_values1 = np.zeros((250,), dtype=theano.config.floatX)
    b1 = theano.shared(value=b_values1.astype(theano.config.floatX),
                                 name='%s_b' % ('b'), borrow=True)
    output1 = T.dot(input, W1) + b1
    W.append(W1)
    L1 = abs(W1).sum()
    L2_sqr = (W1 ** 2).sum()

    reg_cost = (0.001 * L1 + 0.000001 * L2_sqr)

    reg_gparams = [T.grad(reg_cost, p) for p in W]
    updates = [(param, param - 0.001*gparam) for param, gparam in zip(
                                                 W, reg_gparams)]

    inputs.append(input)
    outputs.append(output1)
    updatess.append(updates)

for input, output, updates in zip([inputs], outputs, updatess):
    take_step = theano.function(input, 
                        outputs=output, 
                        updates=updates)

但是我得到如下错误:

UnusedInputError: theano.function was asked to create a function computing outputs given cert
ain inputs, but the provided input variable at index 1 is not part of the computational graph 
needed to compute the outputs: x1.
To make this error into a warning, you can pass the parameter on_unused_input='warn' to thean
o.function. To disable it completely, use on_unused_input='ignore'.

是什么意思?我该如何解决?

0 个答案:

没有答案