Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Train scikit-neuralnetwork on images

I'm trying to train a classifier to recognise different shapes on tags in my images (circles, rectangles and blank - examples down below) and thought that scikit-neuralnetwork might be able to help as I haven't had much success with an SVM. I found the documentation on their site, but am not sure about the format the data I use to train the network should be in.

from sknn.mlp import Classifier, Convolution, Layer

nn = Classifier(
    layers=[
        Convolution("Rectifier", channels=8, kernel_shape=(3,3)),
        Layer("Softmax")],
    learning_rate=0.02,
    n_iter=5)
nn.fit(X_train, y_train)

My grayscale images are 24*24 pixels, so can I have a NumPy array ("X_train") composed of these matrices? That way I don't have to flatten each image into a row that forms my training matrix and I lose all the shape information (which is what was happening when I trained my SVM, LDA, PCA, etc).

enter image description here

like image 924
Jack Simpson Avatar asked Nov 27 '25 20:11

Jack Simpson


2 Answers

No need to flatten a data. Just feed an array of matrices. In your case X_train.shape would be (NUM_OF_EXAMPLES, 24, 24). Take a look at digits example.

like image 107
prudenko Avatar answered Nov 29 '25 09:11

prudenko


You have to use multidimensional representation for each sample in set, numpy allows it.

You can think about following example as about 4 images in training set each with size (2,3)

>>> np.arange(2*3*4).reshape(4,2,3)
array([[[ 0,  1,  2],
        [ 3,  4,  5]],

        [[ 6,  7,  8],
         [ 9, 10, 11]],

        [[12, 13, 14],
         [15, 16, 17]],

        [[18, 19, 20],
         [21, 22, 23]]])
like image 27
Ibraim Ganiev Avatar answered Nov 29 '25 08:11

Ibraim Ganiev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!