shackenberg / Minimal-Bag-of-Visual-Words-Image-Classifier

Implementation of a content based image classifier using the bag of visual words approach in Python together with Lowe's SIFT and Libsvm.
236 stars 94 forks source link

memory error #14

Open Jivnesh opened 8 years ago

Jivnesh commented 8 years ago

I am using this classifier for 4 class classification over 23,0000 image set. After calculation of SIFT feature I get a error Traceback (most recent call last): File "learn.py", line 129, in all_features_array = dict2numpy(all_features) File "learn.py", line 61, in dict2numpy array = zeros((nkeys * PRE_ALLOCATION_BUFFER, 128)) MemoryError What could be reason? What is the solution for this?

shackenberg commented 8 years ago

Hi, Jivnes, this 'MemoryError' indicates that the script runs out of memory. Try with much less images like 1000, and see if it works.

Rich700000000000 commented 8 years ago

Hey, I just tried it on only 1,765 images and got the same error. What's happening?

shackenberg commented 8 years ago

And if you use even less images? When does it start working?

Rich700000000000 commented 8 years ago

There has to be a lot of images for good image classification results. Neural nets use hundreds of images, and even for something simple such as HAAR cascades you need many, many images:

It is unclear exactly how many of each kind of image are needed. For Urban Challenge 2008 we used 1000 positive and 1000 negative images whereas the previous project Grippered Bandit used 5000. The result for the Grippered Bandit project was that their classifier was much more accurate than ours.

This is an issue that needs to be fixed in the code.

shackenberg commented 8 years ago

Dear Rich, thanks for reminding me to update the readme.md. It seems like

As the name suggests, this is only a minimal example to illustrate the general workings of such a system.

is not clear enough.

Rich700000000000 commented 8 years ago

Oh.

But even still, I would like to see if there's a way to fix this. What does this function:

def dict2numpy(dict):
    nkeys = len(dict)
    array = zeros((nkeys * PRE_ALLOCATION_BUFFER, 128))
    pivot = 0
    for key in dict.keys():
    value = dict[key]
    nelements = value.shape[0]
    while pivot + nelements > array.shape[0]:
        padding = zeros_like(array)
        array = vstack((array, padding))
    array[pivot:pivot + nelements] = value
    pivot += nelements
    array = resize(array, (pivot, 128))
    return array

Do? Why do you need to use memory operations in the first place?