我正在阅读jpg图像,然后将它们重塑成张量。我将这些图像转换为float32:
def load(folder,table):
X=[]
train = pd.read_csv(table)
for i,img_id in enumerate(train['Image']):
img = io.imread(folder+img_id[2:])
X.append(img)
X = np.array(X)/255.
X = X.astype(np.float32)
X = X.reshape(-1, 1, 225, 225)
return X
但是,我得到了这个错误。
TypeError: ('Bad input argument to theano function with name "/Users/mas/PycharmProjects/Whale/nolearn_convnet/Zahraa5/lib/python2.7/site-packages/nolearn/lasagne/base.py:435" at index 1(0-based)', 'TensorType(int32, vector) cannot store a value of dtype float32 without risking loss of precision. If you do not mind this loss, you can: 1) explicitly cast your data to int32, or 2) set "allow_input_downcast=True" when calling "function".', array([[ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., 0., 0.],
...,
[ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., 0., 0.]], dtype=float32))
发布于 2016-01-12 09:13:59
这是一个交叉邮寄到theano-用户邮件列表。
道格在那提供了一个答案:
您使用的theano变量被定义为整数,但传入一个浮点数,因此错误'TensorType(int32,vector)无法存储dtype float 32的值.‘。您可以修改数据加载代码以将其转换为int32,也可以将符号变量更改为支持float32的代码。
所以在某个地方,你有一条看起来像:
x = T.ivector()
或
x = T.vector(dtype='int32')
看起来你需要把这个改变成
x = T.tensor4()
其中,dtype
被更改为相等的theano.config.floatX
,而维数被更改为4,以匹配X
的四维空间性质。
发布于 2016-01-24 11:36:11
如果您没有搞清楚,我也有一个类似的错误,下面是我修复它的方法:将您的y转换为int32。X值可以是浮动的,但y必须是int32在诺尔学习中进行分类。
https://stackoverflow.com/questions/34748720
复制