繁体   English   中英

我正在尝试将CNN用于非图像的数据

[英]I'm trying to use CNN with data that aren't images

正在使用的代码是来自http://deeplearning.net/tutorial/lenet.html#lenet的CNN,但我无法理解我需要更改以接受其他类型的数据。 我使用的文件具有相同的MNIST格式,但要小得多,这是使用的数据https://archive.ics.uci.edu/ml/datasets/Iris

这些是我改变的两个部分:

Batch_size,nkers,n_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.

可能答案很简单,但是我在一周左右看这段代码并没有出现在我脑海中

CNN中的C代表卷积。 为了执行卷积,您需要将变量组合在一起形成某种空间/时间/以任何方式连续的范围,群体结构在其上保持,例如空间翻译,时间翻译,旋转或更奇特的东西。 对于您正在使用的数据,情况并非如此,因此使用CNN没有多大意义。 (这并不能阻止你尝试在2D空间中安排变量并查看出来的内容,但它看起来并没有用。)如果你想做NN,坚持完全连接的并开始评估逻辑回归。

暂无
暂无

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

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