Image SVM classifier does not work

Asked

Viewed 95 times

1

Hello, I’m with a program in Python that uses the library Dlib 19.10, the classifier uses an xml file to learn the images and then I run the following code that creates a file. svm for the classification:

import dlib

opcoes = dlib.simple_object_detector_training_options()
opcoes.add_left_right_image_flips = True
opcoes.C = 5

dlib.train_simple_object_detector("recursos/treinamento_casas.xml", "recursos/detector_casas.svm",opcoes)

The first problem happens on line 4 (opcoes.add_left_right_image_flips = True), when it is placed False there is no mistake, the training occurs normally, but when I put True appears the following error:


Traceback (Most recent call last): File "C:/Users/marco/Desktop/Project_de_search/training_casas.py", line 7, in dlib.train_simple_object_detector("resources/training_casas.xml", "features/detector_homes.svm",options) Runtimeerror: An Impossible set of Object Labels was Detected. This is happening because None of the Object Locations checked by the supplied image scanner is a close enough match to one of the Truth boxes in your training dataset. To resolve this you need to either Lower the match_eps, Adjust the Settings of the image scanner so that it is capable of Hitting this Truth box, or Adjust the offending Truth Rectangle so it can be Matched by the Current image scanner. Also, if you are using the scan_fhog_pyramid Object then you could Try using a Finer image Pyramid. Additionally, the scan_fhog_pyramid scans a Fixed Aspect ratio box Across the image when it searches for Objects. So if you are Getting this error and you are using the scan_fhog_pyramid, it’s very likely the problem is that your training dataset contains Truth Rectangles of widely Varying Aspect ratios. The Solution is to make sure your training boxes all have about the same Aspect ratio.

image index 23 match_eps: 0.5 best possible match: 0.496824 Truth rect: [(508, 482) (600, 650) ] Truth rect width/height: 0.550296 Truth rect area:
15717 Nearest Detection template rect: [(492,515) (595, 618)] Nearest Detection template rect width/height: 1 Nearest Detection template rect area: 10816

The second problem occurs in the detection of the objects in the images, the algorithm does not recognize any object in the test images, including not even the images that were used for the training, the algorithm should draw a rectangle on the detected objects and this does not occur. Code snippet:

contador = 0
detectorCasa = dlib.simple_object_detector("recursos/detector_casas.svm")
for imagem in glob.glob(os.path.join("imagens/teste", "*.jpg")):
    img = cv2.imread(imagem)
    objetosDetectados = detectorCasa(img)
    for d in objetosDetectados:
        e, t, d, b = (int(d.left()), int(d.top()), int(d.right()), int(d.bottom()))
        cv2.rectangle(img, (e,t), (d, b), (0,0,255), 2)
        contador += 1

    cv2.imshow("Detector de casas", img)
    cv2.waitKey(0)

The error would be in xml file?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.