0
votes

I am trying to train CNN (Sklearn Neural Network). I am having 4 images of 128 x 128 pixels. shape -> (4, 128, 128) I am reading images like -

in1 = misc.imread('../data/Train_Data/train-1.jpg', mode='L', flatten=True)/255. in2 = misc.imread('../data/Train_Data/train-2.jpg', mode='L', flatten=True)/255. in3 = misc.imread('../data/Train_Data/train-3.jpg', mode='L', flatten=True)/255. in4 = misc.imread('../data/Train_Data/train-4.jpg', mode='L', flatten=True)/255.

Then numpy array is created like this -

X_train = [in1,in2,in3,in4]
X_train = np.array(X_train)

Same as for label and test set .

Then I am training my CNN -

nn = Classifier(
    layers=[
        Convolution('Rectifier', channels=12, kernel_shape=(3, 3), border_mode='full'),
        Convolution('Rectifier', channels=8, kernel_shape=(3, 3), border_mode='valid'),
        Layer('Rectifier', units=64),
        Layer('Softmax')],
    learning_rate=0.002,
    valid_size=0.2,
    n_stable=10,
    verbose=True)


nn.fit(X_train, y_train)

It throws error as -

Traceback (most recent call last): File "/home/zaverichintan/PycharmProjects/WBC_identification/neural/trial.py", line 91, in nn.fit(X_train, y_train) File "/home/zaverichintan/miniconda2/lib/python2.7/site-packages/sknn/mlp.py", line 383, in fit ys = [lb.fit_transform(y[:,i]) for i, lb in enumerate(self.label_binarizers)] File "/home/zaverichintan/miniconda2/lib/python2.7/site-packages/sklearn/base.py", line 494, in fit_transform return self.fit(X, **fit_params).transform(X) File "/home/zaverichintan/miniconda2/lib/python2.7/site-packages/sklearn/preprocessing/label.py", line 335, in transform sparse_output=self.sparse_output) File "/home/zaverichintan/miniconda2/lib/python2.7/site-packages/sklearn/preprocessing/label.py", line 497, in label_binarize y = column_or_1d(y) File "/home/zaverichintan/miniconda2/lib/python2.7/site-packages/sklearn/utils/validation.py", line 563, in column_or_1d raise ValueError("bad input shape {0}".format(shape)) ValueError: bad input shape (4, 128)

1

1 Answers

-1
votes

your in1, in2,....inN are 2D arrays that are 128x128 you have to convert them all to 1D arrays of 16384. in1.shape should print (16384,) and X_train.shape should print (4,16384). You can use numpy arrays and apply the [reshape][1] function. https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html