Comments (14)
from deeplearningbook.
@innovation-cat 您好!这段代码来自您那本书的第29页2.3.2节Logistic回归。请问该如何修正这个错误呢?
from deeplearningbook.
from deeplearningbook.
@innovation-cat 您好!第29页的完整代码如下
import numpy as np
import theano
import theano.tensor as TN, M = 1000, 78
X = np.random.randn(N, M)
Y = np.random.randint(low=0, high=2, size=N)train_X = theano.shared(value = X)
train_Y = theano.shared(value = Y)batch_size = 100
w_value = np.random.randn(M)w = theano.shared(value=w_value, name='w')
b = theano.shared(value=0.0, name='b')x = T.dmatrix('x')
y = T.ivector('y')index = T.iscalar('index')
output = 1.0 / (1.0 + T.exp(-T.dot(x, w)-b))
predict = output > 0.5loss = -y * T.log(output) - (1-y)*T.log(1-output)
cost = T.mean(loss)+0.001*(w**2).sum()
gw, gb = T.grad(cost, [w, b])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]}
)
from deeplearningbook.
这个运行后并没有报错误
from deeplearningbook.
Hi @innovation-cat 我刚又用Python3.5运行了一遍,依然有错误提示。
/usr/bin/python3.5 demo_01.py
Using cuDNN version 6021 on context None
Mapped name None to device cuda0: GeForce GTX 970 (0000:01:00.0)
Traceback (most recent call last):
File "/home/xxx/demo_01.py", line 33, in
y : train_Y[index * batch_size : (index + 1) * batch_size]})
File "/usr/local/lib/python3.5/dist-packages/Theano-0.10.0.dev1-py3.5.egg/theano/compile/function.py", line 325, in function
output_keys=output_keys)
File "/usr/local/lib/python3.5/dist-packages/Theano-0.10.0.dev1-py3.5.egg/theano/compile/pfunc.py", line 449, in pfunc
no_default_updates=no_default_updates)
File "/usr/local/lib/python3.5/dist-packages/Theano-0.10.0.dev1-py3.5.egg/theano/compile/pfunc.py", line 219, in rebuild_collect_shared
cloned_v = clone_v_get_shared_updates(v, copy_inputs_over)
File "/usr/local/lib/python3.5/dist-packages/Theano-0.10.0.dev1-py3.5.egg/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
clone_v_get_shared_updates(i, copy_inputs_over)
File "/usr/local/lib/python3.5/dist-packages/Theano-0.10.0.dev1-py3.5.egg/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
clone_v_get_shared_updates(i, copy_inputs_over)
File "/usr/local/lib/python3.5/dist-packages/Theano-0.10.0.dev1-py3.5.egg/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
clone_v_get_shared_updates(i, copy_inputs_over)
File "/usr/local/lib/python3.5/dist-packages/Theano-0.10.0.dev1-py3.5.egg/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
clone_v_get_shared_updates(i, copy_inputs_over)
File "/usr/local/lib/python3.5/dist-packages/Theano-0.10.0.dev1-py3.5.egg/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates
clone_v_get_shared_updates(i, copy_inputs_over)
File "/usr/local/lib/python3.5/dist-packages/Theano-0.10.0.dev1-py3.5.egg/theano/compile/pfunc.py", line 96, in clone_v_get_shared_updates
[clone_d[i] for i in owner.inputs], strict=rebuild_strict)
File "/usr/local/lib/python3.5/dist-packages/Theano-0.10.0.dev1-py3.5.egg/theano/gof/graph.py", line 239, in clone_with_new_inputs
new_inputs[i] = curr.type.filter_variable(new)
File "/usr/local/lib/python3.5/dist-packages/Theano-0.10.0.dev1-py3.5.egg/theano/tensor/type.py", line 234, in filter_variable
self=self))
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).
Process finished with exit code 1
from deeplearningbook.
我分别在python2.7+theano0.8和python3.6+theano0.9两个环境运行过,代码并没有报错,我看了你用的是theano0.10dev,这个版本还是一个测试版本,估计起码明年才正式发布,试试安装0.8或者0.9,不要用0.10,这个版本可能还不稳定
from deeplearningbook.
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不太熟,请问这个类型转换应怎么写?
from deeplearningbook.
from deeplearningbook.
Hi @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
实现这个转换?谢谢!
from deeplearningbook.
from deeplearningbook.
Hi @innovation-cat 谢谢您的回复。请问下TensorType(int64, vector) (of Variable Subtensor{int32:int32:}.0)
具体是指y : train_Y[index * batch_size : (index + 1) * batch_size]}
中的哪个变量?如果是y
的话,我在y
的定义语句之后加上y=T.cast(y, 'int32')
也不起作用。
from deeplearningbook.
不是说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
from deeplearningbook.
@innovation-cat 是版本bug的说法有道理,我之前把train_Y
的定义修改为train_Y = theano.shared(value=Y, allow_downcast=True)
也还是会报这个错误,谢谢!
from deeplearningbook.
Related Issues (2)
- run out of memory error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deeplearningbook.