Dlib training error: error about aspect ratio and area size when all conditions are actually true

Viewed 78

I use dlib.train_simple_object_detector to create detector for steel bars in bunch. This is my sample: enter image description here

It has SAME box for every bar (created via Duplicate RectBox in labelImg) and size of box is 122x118 (14396 in area).

This is my training code:

import dlib
import cv2.cv2 as cv2
import os
import time
import sys
from xml.dom import minidom

if len(sys.argv) != 4:
    print("Usage: python train.py /path/to/images/ /path/to/boxes/ /path/to/result.svm")
    print("Images and boxes are named like 1.jpg and 1.xml")
    exit(1)

data = {}

image_indexes = [int(img_name.split(".")[0]) for img_name in os.listdir(sys.argv[1])]

# np.random.shuffle(image_indexes)
image_indexes.sort()

# parse rectangle data
for index in image_indexes:
    if index in [0]:
        continue

    rects = minidom.parse("{}/{}.xml".format(sys.argv[2], index)).getElementsByTagName("bndbox")

    img = cv2.imread(os.path.join(sys.argv[1], str(index) + ".jpg"))

    for rect in rects:
        xmin = int(rect.getElementsByTagName("xmin")[0].firstChild.data)
        xmax = int(rect.getElementsByTagName("xmax")[0].firstChild.data)
        ymin = int(rect.getElementsByTagName("ymin")[0].firstChild.data)
        ymax = int(rect.getElementsByTagName("ymax")[0].firstChild.data)

        dlib_box = dlib.rectangle(left=xmin, top=ymin, right=xmax, bottom=ymax)
        if index in data:
            data[index][1].append(dlib_box)
        else:
            data[index] = (img, [dlib_box])


# train
percent = 0.8
split = int(len(data) * percent)

images = [tuple_value[0] for tuple_value in data.values()]
bounding_boxes = [tuple_value[1] for tuple_value in data.values()]

options = dlib.simple_object_detector_training_options()

options.add_left_right_image_flips = False
options.C = 5
options.num_threads = 16
options.epsilon = 0.01
# options.be_verbose = True

st = time.time()

detector = dlib.train_simple_object_detector(images[:split], bounding_boxes[:split], options)

print("Training complete. Time taken: {:.2f} seconds.".format(time.time() - st))
print("Training Metrics: {}".format(dlib.test_simple_object_detector(images[:split], bounding_boxes[:split], detector)))

detector.save(sys.argv[3])

When I run it with this sample it gives an error:

Error! An impossible set of object boxes was given for training. All the boxes 
need to have a similar aspect ratio and also not be smaller than about 400 
pixels in area.

But it's not true. They definitely have same aspect ratio as they are same boxes and they do have area > 400 (about 14000 actually). Why do this happen?

0 Answers
Related