简体   繁体   English

Theano教程:UnusedInputError:theano.function

[英]Theano tutorial: UnusedInputError: theano.function

Attempting to teach myself neural nets, I have begun working my way through the Theano tutorials over at deeplearning.net. 为了尝试自学神经网络,我开始在deeplearning.net上通过Theano教程进行学习。 I just encountered an error that I was not expecting as I have literally copied and pasted every line of code from the tutorial. 我刚刚遇到了一个我没有想到的错误,因为我从字面上复制并粘贴了教程中的每一行代码。 I'm sure whatever is wrong is something small and I'm just looking over it but any help would be much appreciated. 我敢肯定,哪里出了毛病都是小问题,我只是在仔细检查,但任何帮助将不胜感激。 Thanks 谢谢

http://deeplearning.net/software/theano/tutorial/examples.html#copying-functions http://deeplearning.net/software/theano/tutorial/examples.html#copying-functions

import theano
import theano.tensor as T
state = theano.shared(0)
inc = T.iscalar('inc')
accumulator = theano.function([inc], state, updates=[(state, state+inc)])
accumulator(10)
print(state.get_value())

new_state = theano.shared(0)
new_accumulator = accumulator.copy(swap={state:new_state})
new_accumulator(100)

print(state.get_value())
print(new_state.get_value())

null_accumulator = accumulator.copy(delete_updates=True)


---------------------------------------------------------------------------
UnusedInputError                          Traceback (most recent call last)
<ipython-input-20-5d1acb597345> in <module>()
----> 1 null_accumulator = accumulator.copy(delete_updates=True)

/home/mcamp/anaconda3/lib/python3.5/site-packages/theano/compile/function_module.py in copy(self, share_memory, swap, delete_updates, name, profile)
    719                                 # can contain inplace. DebugMode check
    720                                 # that.
--> 721                                 accept_inplace=True,
    722                                 ).create(input_storage,
    723                                          storage_map=new_storage_map)

/home/mcamp/anaconda3/lib/python3.5/site-packages/theano/compile/function_module.py in __init__(self, inputs, outputs, mode, accept_inplace, function_builder, profile, on_unused_input, fgraph, output_keys)
   1413 
   1414         # Check if some input variables are unused
-> 1415         self._check_unused_inputs(inputs, outputs, on_unused_input)
   1416 
   1417         # Make a list of (SymbolicInput|SymblicInputKits, indices,

/home/mcamp/anaconda3/lib/python3.5/site-packages/theano/compile/function_module.py in _check_unused_inputs(self, inputs, outputs, on_unused_input)
   1551                 elif on_unused_input == 'raise':
   1552                     raise UnusedInputError(msg % (inputs.index(i),
-> 1553                                                   i.variable, err_msg))
   1554                 else:
   1555                     raise ValueError("Invalid value for keyword "

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: inc.
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'.

I'm also new at theano, and I just ran into this. 我在theano也很新,而我碰到了这个。 It seems to be a bug in the tutorial. 这似乎是本教程中的错误。 The error message suggests using the parameter on_unused_input to suppress the error, but this isn't a keyword argument for copy . 错误消息建议使用参数on_unused_input来抑制错误,但这不是copy的关键字参数。 Apparently it has to be passed to function . 显然必须将其传递给function So if accumulator was created like this: 因此,如果累加器是这样创建的:

accumulator = theano.function([inc], state,
    updates=[(state, state+inc)], on_unused_input='ignore')

then the error goes away. 然后错误消失了。 (This seems to me like a non-ideal solution, having to change a property of the original function.) (在我看来,这是非理想的解决方案,必须更改原始函数的属性。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM