简体   繁体   English

pylearn2模型进行预测

[英]predictions using pylearn2 models

I have trained the following CNN model using pylearn2. 我已经使用pylearn2训练了以下CNN模型。

h1
    Input space: Conv2DSpace(shape=(25, 150), num_channels=1, axes=('b', 0, 1, 'c'), dtype=float64)
    Total input dimension: 3750
h2
    Input space: Conv2DSpace(shape=(11, 73), num_channels=8, axes=('b', 'c', 0, 1), dtype=float64)
    Total input dimension: 6424
h3
    Input space: VectorSpace(dim=1024, dtype=float64)
    Total input dimension: 1024
h4
    Input space: VectorSpace(dim=1024, dtype=float64)
    Total input dimension: 1024
y
    Input space: VectorSpace(dim=1024, dtype=float64)
    Total input dimension: 1024

You can observe that input examples to this CNN are gray images of size 25 x150. 您可以观察到此CNN的输入示例是大小为25 x150的灰度图像。 The final number of outputs are 10, that is, the layer 'y' has an output dimension of 10. 输出的最终数量为10,即层y的输出尺寸为10。

My training dataset is created using the CSVDataset in pylearn2, and I'm able to train the model. 我的训练数据集是使用pylearn2中的CSVDataset创建的,并且能够训练模型。

However, I have a problem in making predictions using this model, which I'm trying to do using the predict_csv.py file in scripts/mlp folder. 但是,我在使用此模型进行预测时遇到问题,我正在尝试使用scripts / mlp文件夹中的predict_csv.py文件来进行此操作。

The problem is that predict_csv.py directly loads the test.csv file into a 2d matrix of 1000 x 3750 representing 1000 test examples each having 3750 pixels each. 问题在于,predict_csv.py将test.csv文件直接加载到1000 x 3750的二维矩阵中,该矩阵表示1000个测试示例,每个示例具有3750像素。 However, while predicting theano expects the input to be of the same format as input of layer 'h1'. 但是,在预测theano时,期望输入与“ h1”层的输入具有相同的格式。 The following error occurs: 发生以下错误:

TypeError: ('Bad input argument to theano function with name "../mlp/predict_csv.py:111"  at index 0(0-based)', 'Wrong number of dimensions: expected 4, got 2 with shape (1000, 3750).')

I guess the required format is the ('b', 0, 1, 'c') format of pylearn2. 我猜需要的格式是pylearn2的('b',0,1,'c')格式。

I would really like to know how do we make this transformation from the 2d array to the above required format. 我真的很想知道我们如何将2d数组转换为上面要求的格式。 Or any other way this problem could be dealt with? 还是可以通过其他方式解决此问题?

To solve my problem, I ended up manually converting the 2D set of images (1000 x 3750) to a 4D array with columns as number-of-examples, rows and columns in image, and number-of-channels (1000 x 25 x 150 x 1). 为了解决我的问题,我最终手动将2D图像集(1000 x 3750)转换为4D数组,其中列数为示例,图像中的行和列数为,通道数为(1000 x 25 x 150 x 1)。 It worked fine after this transformation. 在进行此转换后,它运行良好。

I was hoping to find a pylearn2 class or function that directly served my purpose, because while training, pylearn2 is obviously making this change in space itself. 我希望找到一个直接满足我的目的的pylearn2类或函数,因为在训练时,pylearn2显然在改变空间本身。

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

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