Search code examples
pythonsvm

'int' object is not subscriptable : HOG SVM object detection in Python


I'm working on an object detection project, while using HOG skimage and SVM. I'm trying to save all my positive windows in a list using my SVM model that I trained, but I'm facing an error : 'int' object is not subscriptable on this line : detect = model_.predict([features_window[i]])

def detection_image(image):
    coordonnees,HOG_features = fenetre_coulissante_HOG(image)
    features_window = []
    #We will now loop through all the features collected by the HOG on each of the sliding windows
    #We will predict from our model whether we consider the window as positive or negative: whether or not it contains our object
    
    for features_window in range(len(HOG_features)):
        #For all the windows considered positive of our model we will record their coordinates
        detect = model_.predict([features_window[i]])
        if detect[0] == 1:
            features_window.append((coordonnees[:i]))
    
    
    return features_window

Solution

  • The problem lies on that line:

    for features_window in range(len(HOG_features))
    

    Inside the loop, it will turn the features variable into an integer, instead of the list it originally was. If you change it to for i in ... it will solve the problem, but will cause a problem with features_window[i], because features_window is an empty collection; maybe you're intending to use HOG_features[i], instead?