2014-05-14 3 views
0

Theano와 함께 전달 전파를 코딩하려고했습니다.Theano를 사용하여 forward_propagation을 계산하십시오.

class hiddenLayer(): 
    """ Hidden Layer class 
    """ 
    def __init__(self, n_in, n_out): 
     rng = np.random 
     self.W = shared(np.asarray(rng.uniform(low=-np.sqrt(6./(n_in + n_out)), 
               high=np.sqrt(6./(n_in + n_out)), 
               size=(n_in, n_out)), 
            dtype=T.config.floatX), 
         name='W') 
     self.b = shared(np.zeros(n_out, dtype=T.config.floatX), name='b') 
     self.x = T.dvector('x') 
     self.a = T.tanh(T.dot(self.x, self.W) + self.b) 
     self.W_sum = shared(np.zeros([n_in, n_out]), name='W_sum') 
     self.gw = 0 
     self.gb = 0 

내가 hiddenLayer의 목록을 설정하려는 theano 가져 오기 기능에서 NP 로 수입 NumPy와 공유 theano 가져 오기에서 T 로

수입 theano.tensor : 나는 다음과 같이 클래스 이름 hiddenLayer을 정의 현재의 hiddenLayer는 다음 hiddenLayer의 입력입니다. 마지막으로 나는 함수 앞으로의 이름이 오류가 발생하고 코드는 다음과 같다 구입 정의 :

def init_network(n_in, n_out, sl, x, y): 
    l = [] 
    for i in range(sl): 
     l.append(hiddenLayer(n_in, n_out)) 
    for i in range(sl): 
     if i == 0: 
      l[i].x = x 
     elif i < sl-1: 
      l[i].x = l[i-1].a 
     else: 
      l[i].x = l[i-1].a 
      y = l[i].a 
    return x, y, l 

x = T.dvector('x') 
y = T.dvector('y') 
x, y, l = init_network(3, 3, 3, x, y) 
forward = function(inputs=[x], outputs=y) 

오류 메시지는 다음과 같습니다과 어떻게 해결하는 문제가 무엇인지 왜

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

당신이 말해 수 그것? 감사합니다

답변

1

문제는 두 번째 루프에서 l.x를 무시하는 것입니다. 너는 그렇게 할 수 없다. self12가 에서 사용되면, 그 결과는 self.x의 현재 인스턴스를 기반으로합니다. 그래서 당신이 그것을 오버라이드 할 때, 그것은 새로운 x에 다른 것들을 재현하지 않습니다.

입력시 x를 으로 전달해야합니다. 없음이면 작성하십시오. 이것은 첫 번째 레이어입니다. 다른 쪽의 경우 이전 레이어 출력이어야합니다.

def __init__(self, n_in, n_out, x=None): 
    if x is not None: 
     self.x = x 
    else: 
     x = T.dvector('x') 
관련 문제