-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: ('An update must have the same type as the original shared variable #1
Comments
读者你好,请问这段代码是在哪一个代码文件里呢?这个应该是b的定义问题,b的定义是int64,但updates的时候b - 0.1 *
gb是float,所以类型不匹配
不过我检查了我的代码,没有发现这样的写法呢,所以麻烦告诉我一下是哪一个项目文件哈
谢谢
2017-07-01 18:44 GMT+08:00 Eric <notifications@github.com>:
… train = theano.function( inputs = [index], outputs = cost, updates=[(w, w
- 0.1 * gw), (b, b - 0.1 * gb)], givens = {x : train_X[index * batch_size :
(index + 1) * batch_size], y : train_Y[index * batch_size : (index + 1) *
batch_size]})
------------------------------
TypeError Traceback (most recent call last)
in ()
4 updates=[(w, w - 0.1 * gw), (b, b - 0.1 * gb)],
5 givens = {x : train_X[index * batch_size : (index + 1) * batch_size],
----> 6 y : train_Y[index * batch_size : (index + 1) * batch_size]})
/usr/local/lib/python2.7/dist-packages/Theano-0.10.0.dev1-
py2.7.egg/theano/compile/function.pyc in function(inputs, outputs, mode,
updates, givens, no_default_updates, accept_inplace, name, rebuild_strict,
allow_input_downcast, profile, on_unused_input)
324 on_unused_input=on_unused_input,
325 profile=profile,
--> 326 output_keys=output_keys)
327 # We need to add the flag check_aliased inputs if we have any mutable
or
328 # borrowed used defined inputs
/usr/local/lib/python2.7/dist-packages/Theano-0.10.0.dev1-
py2.7.egg/theano/compile/pfunc.pyc in pfunc(params, outputs, mode,
updates, givens, no_default_updates, accept_inplace, name, rebuild_strict,
allow_input_downcast, profile, on_unused_input, output_keys)
447 rebuild_strict=rebuild_strict,
448 copy_inputs_over=True,
--> 449 no_default_updates=no_default_updates)
450 # extracting the arguments
451 input_variables, cloned_extended_outputs, other_stuff = output_vars
/usr/local/lib/python2.7/dist-packages/Theano-0.10.0.dev1-
py2.7.egg/theano/compile/pfunc.pyc in rebuild_collect_shared(outputs,
inputs, replace, updates, rebuild_strict, copy_inputs_over,
no_default_updates)
206 ' function to remove broadcastable dimensions.')
207
--> 208 raise TypeError(err_msg, err_sug)
209 assert update_val.type == store_into.type
210
TypeError: ('An update must have the same type as the original shared
variable (shared_var=b, shared_var.type=TensorType(int64, scalar),
update_val=Elemwise{sub,no_inplace}.0, update_val.type=TensorType(float64,
scalar)).', 'If the difference is related to the broadcast pattern, you can
call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to
remove broadcastable dimensions.')
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AD4dfYFIK40ek7lSdFVxbLyUJ-VHbNaTks5sJiLwgaJpZM4OLSDL>
.
|
@innovation-cat 您好!这段代码来自您那本书的第29页2.3.2节Logistic回归。请问该如何修正这个错误呢? |
哦,这段代码我没放在github上,你能把您的代码发给我一下吗?或者你看看b的定义,你是不是写成:b = theano.shared(value=0,
name='b') ?
2017-08-04 8:42 GMT+08:00 Eric <notifications@github.com>:
… @innovation-cat <https://github.com/innovation-cat> 您好!这段代码来自您那本书的第29页。
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AD4dfWVMJWxxOAK3Q_PUupeZ72zLlUQRks5sUmjagaJpZM4OLSDL>
.
|
@innovation-cat 您好!第29页的完整代码如下
|
这个运行后并没有报错误 |
Hi @innovation-cat 我刚又用Python3.5运行了一遍,依然有错误提示。 /usr/bin/python3.5 demo_01.py Process finished with exit code 1 |
我分别在python2.7+theano0.8和python3.6+theano0.9两个环境运行过,代码并没有报错,我看了你用的是theano0.10dev,这个版本还是一个测试版本,估计起码明年才正式发布,试试安装0.8或者0.9,不要用0.10,这个版本可能还不稳定 |
Hi @innovation-cat 谢谢!我看到最后一句提示说TypeError: Cannot convert Type TensorType(int64, vector) (of Variable Subtensor{int32:int32:}.0) into Type TensorType(int32, vector). You can try to manually convert Subtensor{int32:int32:}.0 into a TensorType(int32, vector). 请问下这个提示是针对哪条语句的?为什么会有这样的提示?我Theano不太熟,请问这个类型转换应怎么写? |
转换一般用cast,不过这里也可以在function试试添加一行allow_input_downcast=True
改为这样试试看?
train = theano.function(
inputs = [index],
outputs = cost,
updates = [(w, w-0.1*gw), (b, b-0.1*gb)],
givens = {x : train_X[index * batch_size : (index + 1)*batch_size],
y : train_Y[index * batch_size : (index + 1) * batch_size]},
allow_input_downcast=True
)`
2017-08-07 15:25 GMT+08:00 Eric <notifications@github.com>:
… Hi @innovation-cat <https://github.com/innovation-cat>
谢谢!我看到最后一句提示说TypeError: Cannot convert Type TensorType(int64, vector) (of
Variable Subtensor{int32:int32:}.0) into Type TensorType(int32, vector).
You can try to manually convert Subtensor{int32:int32:}.0 into a
TensorType(int32, vector). 我Theano不太熟,请问这个类型转换应怎么写?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AD4dfWBUOevypQ9qvArw-HXa3c9QW1zEks5sVrv0gaJpZM4OLSDL>
.
|
Hi @innovation-cat 加上
这句是由哪个参数引起的? |
换成安装0.9试试,上面你发的代码里面我在0.9和0.8都没有错误,这个错误看来是y : train_Y[index * batch_size :
(index + 1) * batch_size]}这一句引起的
2017-08-07 16:58 GMT+08:00 Eric <notifications@github.com>:
… Hi @innovation-cat <https://github.com/innovation-cat>
加上allow_input_downcast=True后,仍有错误提示,而且提示内容没有变化。请问下
Type TensorType(int64, vector) (of Variable Subtensor{int32:int32:}.0)
into Type TensorType(int32, vector)
这句是由哪个参数引起的?TensorType(int64, vector) (of Variable
Subtensor{int32:int32:}.0)具体是指哪个变量?另外为什么会需要转换成TensorType(int32, vector)
?怎么用cast实现这个转换?谢谢!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AD4dfYr-uM3cUKdCoVvk6miVJqeU6zZYks5sVtHOgaJpZM4OLSDL>
.
|
Hi @innovation-cat 谢谢您的回复。请问下 |
不是说y,而是说train_Y[index * batch_size : (index + 1) * batch_size]的结果是TensorType(int64, vector),但y的定义是TensorType(int32, vector),所以报了这个类型错误,不过这里面 train_Y[index * batch_size : (index + 1) * batch_size]的结果应该也是TensorType(int32, vector),所以应该是版本的bug,不是你的代码有bug |
@innovation-cat 是版本bug的说法有道理,我之前把 |
TypeError Traceback (most recent call last)
in ()
4 updates=[(w, w - 0.1 * gw), (b, b - 0.1 * gb)],
5 givens = {x : train_X[index * batch_size : (index + 1) * batch_size],
----> 6 y : train_Y[index * batch_size : (index + 1) * batch_size]})
/usr/local/lib/python2.7/dist-packages/Theano-0.10.0.dev1-py2.7.egg/theano/compile/function.pyc in function(inputs, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input)
324 on_unused_input=on_unused_input,
325 profile=profile,
--> 326 output_keys=output_keys)
327 # We need to add the flag check_aliased inputs if we have any mutable or
328 # borrowed used defined inputs
/usr/local/lib/python2.7/dist-packages/Theano-0.10.0.dev1-py2.7.egg/theano/compile/pfunc.pyc in pfunc(params, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys)
447 rebuild_strict=rebuild_strict,
448 copy_inputs_over=True,
--> 449 no_default_updates=no_default_updates)
450 # extracting the arguments
451 input_variables, cloned_extended_outputs, other_stuff = output_vars
/usr/local/lib/python2.7/dist-packages/Theano-0.10.0.dev1-py2.7.egg/theano/compile/pfunc.pyc in rebuild_collect_shared(outputs, inputs, replace, updates, rebuild_strict, copy_inputs_over, no_default_updates)
206 ' function to remove broadcastable dimensions.')
207
--> 208 raise TypeError(err_msg, err_sug)
209 assert update_val.type == store_into.type
210
TypeError: ('An update must have the same type as the original shared variable (shared_var=b, shared_var.type=TensorType(int64, scalar), update_val=Elemwise{sub,no_inplace}.0, update_val.type=TensorType(float64, scalar)).', 'If the difference is related to the broadcast pattern, you can call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove broadcastable dimensions.')
The text was updated successfully, but these errors were encountered: