Python I';我试图用CNN提供的数据不是';t图像

Python I';我试图用CNN提供的数据不是';t图像,python,neural-network,theano,Python,Neural Network,Theano,所使用的代码是CNN的,但我很难理解为了接受其他类型的数据我需要更改什么。我使用的文件与MNIST的格式相同,但要小得多,这是正在使用的数据 以下是我更改的两个部分: 批量大小、NKER、n\U epocchs def evaluate_lenet5(learning_rate=0.1, n_epochs=1000, nkerns=[3, 4], batch_size=5): 层的所有参数 layer0_input = x.reshape((batch_size, 1, 2, 2)) lay

所使用的代码是CNN的,但我很难理解为了接受其他类型的数据我需要更改什么。我使用的文件与MNIST的格式相同,但要小得多,这是正在使用的数据

以下是我更改的两个部分:

批量大小、NKER、n\U epocchs

def evaluate_lenet5(learning_rate=0.1, n_epochs=1000, nkerns=[3, 4], batch_size=5):
层的所有参数

layer0_input = x.reshape((batch_size, 1, 2, 2))

layer0 = LeNetConvPoolLayer(rng, input=layer0_input, image_shape=(batch_size, 1, 2, 2), filter_shape=(nkerns[0], 1, 1, 1), poolsize=(2, 2))

layer1 = LeNetConvPoolLayer(rng, input=layer0.output, image_shape=(batch_size, nkerns[0], 2, 2), filter_shape=(nkerns[1], nkerns[0], 1, 1), poolsize=(2, 2))

layer2_input = layer1.output.flatten(2)

layer2 = HiddenLayer(rng, input=layer2_input, n_in=nkerns[1], n_out=15, activation=T.tanh)

layer3 = LogisticRegression(input=layer2.output, n_in=15, n_out=3)
当我执行此代码时,会出现以下错误:

In [4]: %run test_convolutional_mlp.py
... loading data
... building the model
... training
training @ iter =  0
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    173             else:
    174                 filename = fname
--> 175             __builtin__.execfile(filename, *where)

/media/HD Usuario/DeepLearning/Iris Data/test_convolutional_mlp.py in <module>()
    172 
    173 if __name__ == '__main__':
--> 174     evaluate_lenet5()
    175 
    176 

/media/HD Usuario/DeepLearning/Iris Data/test_convolutional_mlp.py in evaluate_lenet5(learning_rate, n_epochs, nkerns, batch_size)
    128             if iter % 100 == 0:
    129                 print 'training @ iter = ', iter
--> 130             cost_ij = train_model(minibatch_index)
    131 
    132             if (iter + 1) % validation_frequency == 0:

/usr/local/lib/python2.7/dist-packages/theano/compile/function_module.pyc in __call__(self, *args, **kwargs)
    586                     # For the CVM

    587                     gof.vm.raise_with_op(self.fn.nodes[self.fn.position_of_error],
--> 588                                          self.fn.thunks[self.fn.position_of_error])
    589                 else:
    590                     # For the c linker


/usr/local/lib/python2.7/dist-packages/theano/compile/function_module.pyc in __call__(self, *args, **kwargs)
    577         t0_fn = time.time()
    578         try:
--> 579             outputs = self.fn()
    580         except Exception:
    581             if hasattr(self.fn, 'position_of_error'):

ValueError: the number of rows in the image (1) at run time is different than at build time (2) for the ConvOp.
Apply node that caused the error: ConvOp{('imshp', (3, 2, 2)),('kshp', (1, 1)),('nkern', 4),('bsize', 5),('dx', 1),('dy', 1),('out_mode', 'valid'),('unroll_batch', 5),('unroll_kern', 2),('unroll_patch', False),('imshp_logical', (3, 2, 2)),('kshp_logical', (1, 1)),('kshp_logical_top_aligned', True)}(Elemwise{Composite{[tanh(add(i0, i1))]}}.0, <TensorType(float64, 4D)>)
Inputs shapes: [(5, 3, 1, 1), (4, 3, 1, 1)]
Inputs strides: [(24, 8, 8, 8), (24, 8, 8, 8)]
Inputs types: [TensorType(float64, 4D), TensorType(float64, 4D)]
Use the Theano flag 'exception_verbosity=high' for a debugprint of this apply node.
[4]中的
:%运行测试\u卷积\u mlp.py
... 加载数据
... 构建模型
... 训练
iter=0时的培训
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
/execfile(fname,*其中)中的usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc
173.其他:
174 filename=fname
-->175 _uu内置_uuu.execfile(文件名,*其中)
/媒体/HD Usuario/DeepLearning/Iris数据/test_convolutional_mlp.py in()
172
173如果uuuu name uuuuu=='\uuuuuuu main\uuuuuuu':
-->174评估_lenet5()
175
176
/媒体/HD Usuario/DeepLearning/Iris数据/test_convolutional_mlp.py in evaluate_lenet5(学习率、n时代、nkerns、批量大小)
128如果iter%100==0:
129印刷“国际热核试验堆培训=”,国际热核试验堆
-->130成本=列车模型(小批量指数)
131
132如果(国际热核实验堆+1)%验证频率==0:
/usr/local/lib/python2.7/dist-packages/theano/compile/function\u module.pyc in_uuuu调用(self,*args,**kwargs)
586#用于CVM
587 gof.vm.raise_with_op(self.fn.nodes[self.fn.position_of_error],
-->588 self.fn.thunks[self.fn.position\u of\u error])
589其他:
590#用于c链接器
/usr/local/lib/python2.7/dist-packages/theano/compile/function\u module.pyc in_uuuu调用(self,*args,**kwargs)
577 t0_fn=时间。时间()
578请尝试:
-->579输出=self.fn()
580例外情况除外:
581如果hasattr(self.fn,“错误位置”):
ValueError:运行时映像(1)中的行数与CONVAP的生成时(2)中的行数不同。
导致错误的应用节点:convolp{('imshp',(3,2,2)),('kshp',(1,1)),('nkern',4),('bsize',5),('dx',1),('dy',1),('out_mode','valid'),('unroll_batch',5),('unroll_kern',2),('unroll_patch',False),('imshp_logical',(3,2,2)),('kshp_logical',1),('kshp_逻辑',(1,1),('kshp)u逻辑上对齐的组合,True),add emwi 0}{1}
输入形状:[(5,3,1,1),(4,3,1,1)]
输入跨步:[(24,8,8,8),(24,8,8,8)]
输入类型:[TensorType(浮点64,4D),TensorType(浮点64,4D)]
对此应用节点的debugprint使用Theano标志“exception\u verbosity=high”。

也许答案真的很简单,但我花了大约一周的时间研究这段代码,我的脑海中没有任何东西出现

CNN中的C代表卷积。为了执行卷积运算,您需要将变量组合在一起,形成某种空间/时间/以任何方式连续的范围,这是一个组结构的基础,例如空间平移、时间平移、旋转或其他更奇特的内容。对于您正在处理的数据,情况并非如此,因此使用CNN没有多大意义。(这并不能阻止您尝试在2D空间中排列变量并查看结果,但它似乎一点用处都没有。)如果您想进行NNs,请坚持使用完全连接的NNs,然后从评估逻辑回归开始。

很抱歉回答得太晚,感谢您的回答,正如你所注意到的,英语不是我的母语,我无法理解这一部分“组合在一起形成某种空间/时间/以任何方式连续的范围的变量,这是一种群体结构”。我忘了提到的另一件事是,我这样做的目的是为了在代码中需要更改什么,以便以后应用kinect提供的数值和其他手工从人们那里收集的数值,有81个Atibuttes可以在CNN上使用吗?您的数据需要有适合卷积()的结构。最不必要的是群体结构。