2

I'm pretty new to all this business of machine learning and image categorisation. I'm using pybrain as my primary neural network modelisation tool.

My problem is the following. I have 100x100 images that have 0,1,2,3 items and I would like the machine to tell me how much elements are in a new 100x100 image.

I made a training set of 25 elements (just to see if I could get something out of that). I realise that this number is very very small relatively to the required test set but gathering training data would be very expensive (doable but expensive).

Here is how i made the training set

    onlyfiles = [f for f in filter(lambda x: x[-3:] == "png", onlyfiles)]
    input = np.zeros(shape=(len(onlyfiles), 10000))
    output = np.zeros(shape=(len(onlyfiles), 1))

    row = 0
    for file in onlyfiles:
        img = Image.open(path+file)
        pix = img.load()
        for x in range(100):
            for y in range(100):
                input[row, 100*x+y] = pix[x, y][2]
        output[row,0] = output_mapping[file]
        row += 1

I only used the pix[x,y][2] (blue color) because the zone is lightened by blue light.

So I generated the classification data set

    ds = ClassificationDataSet(10000,1,nb_classes=4)
    for k in range(len(X)):
        ds.addSample(np.ravel(input[k]),output[k])

    temp_testdata, temp_traindata = ds.splitWithProportion(0.25)

    tstdata = ClassificationDataSet(10000,1,nb_classes=4)
    trndata = ClassificationDataSet(10000,1,nb_classes=4)

    for k in range(len(temp_testdata)):
        tstdata.addSample(temp_testdata.getSample(k)[0],temp_testdata.getSample(k)[1])

    for k in range(len(temp_traindata)):
        trndata.addSample(temp_traindata.getSample(k)[0],temp_traindata.getSample(k)[1])

created the network

    fnn = buildNetwork(trndata.indim, 1, trndata.outdim, outclass=SoftmaxLayer)
    trainer = BackpropTrainer(fnn,dataset=trndata, momentum=0.1, learningrate=0.01, verbose= True, weightdecay=0.01)

trained the network

    trainer.trainEpochs (50)

and tried to push some data back in the

    fnn.activateOnDataset(tstdata)

and here it is what I got

    Out[186]: 
    array([[ 0.20086945,  0.46216524,  0.30707544,  0.02988986],
           [ 0.20086945,  0.46216524,  0.30707544,  0.02988986],
           [ 0.20086945,  0.46216524,  0.30707544,  0.02988986],
           [ 0.20086945,  0.46216524,  0.30707544,  0.02988986],
           [ 0.20086945,  0.46216524,  0.30707544,  0.02988986],
           [ 0.20086945,  0.46216524,  0.30707544,  0.02988986]])

From that I understand that my neural network would give Class "2" for all tstdata samples. I'm surprised. I was expecting crappy results, but I did not expect the very same 6 outputs...

And for the sake of checking out, here it is the "sum" of all pixel for each of those 5 samples showing that my 5 samples are indeed different...

    In[199]: np.sum(tstdata.data['input'],1)
    Out[198]: array([ 1170985.,  1115688.,  1173766.,  1125111.,  1152222.,  1132945.])

I even had thrown bunches of 0 and 1 as "fake" sample and the numbers did not change!

Any idea why all my trails have the very same output?

Thanks a lot!

gboffi
  • 22,939
  • 8
  • 54
  • 85
MastaJeet
  • 91
  • 6
  • Can it be the amount of feature that causes this problem? I increased the number of training data to 100 and same problem. I tried to use grayscale and number were not all identical. very very close, but not identical. interresting. – MastaJeet Dec 07 '15 at 22:51

0 Answers0