0

전체 스 니펫을 게시하지 않아서 죄송합니다. 코드가 너무 커서 확산되어 있으므로 문제가 될 수 있습니다. 내가 가진이 :Theano의 function() 함수는 그래프에 내 'givens` 값이 필요 없다고보고합니다.

train = theano.function([X], output, updates=update_G, 
         givens={train_mode=:np.cast['int32'](1)}) 

내 이해

test = theano.function([X], output, updates=update_G, 
         givens={train_mode=:np.cast['int32'](0)}) 

, 출력을 계산하는 데 필요한 곳 ​​ givens 것 입력 train_mode (즉 1/ 0)의 값입니다.

 ... 
    network2 = Net2() 
    # This is sort of a dummy variable so I don't get a NameError when this 
    # is called before `theano.function()` is called. Not sure if this is the 
    # right way to do this. 
    train_mode = T.iscalar('train_mode') 
    output = loss(network1.get_outputs(network2.get_outputs(X, train_mode=train_mode)),something).mean() 

.... 
class Net2(): 
     def get_outputs(self, x, train_mode): 
      from theano.ifelse import ifelse 
      import theano.tensor as T 
      my_flag = ifelse(T.eq(train_mode, 1), 1, 0) 
      return something if my_flag else something_else 

그래서 train_mode가 중첩 된 기능 중 하나의 인수로 사용하고, 내가 원하는만큼 traintest 사이에 말을 사용

output이의 라인에서 계산 그들을 약간 다르게 처리 할 수 ​​있습니다.

내가 이것을 실행하려고하면

그러나,이 오류가 얻을 : 나는 givens 매개 변수를 삭제하면

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 1 is not part of the computational 
graph needed to compute the outputs: <TensorType(int32, scalar)>.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'.  

, 오류가, 그래서 내 이해 Theano 내 train_mode이 계산에 필요하지 않다고 생각 사라집니다 function(). 그들의 제안에 따라 on_unusued_input='ignore'을 사용할 수는 있지만 사용하지 않을 경우 내 train_mode을 무시할 것입니다. 내가 잘못 돌아가고 있니? 나는 기본적으로 방울이있는 신경망을 훈련시키고 싶지만, 평가할 때 드롭 아웃을 사용하지 않는다.

답변

0

왜 "="기호를 사용합니까? 나는 train_mode를 읽을 수 없게 만들었다. 나의 코드는 다음과 같이 쓰면 잘 작동한다고 생각한다 : givens = {train_mode:1}

+0

죄송합니다.'= :'는 오타였습니다. 유형을 일관되게 유지하기 위해 캐스팅을 수행하지만, 컴퓨터에 다시 연결하면 시도하지 않아도됩니다. – confused00