Mmodlist Now

This guide covers the conceptual, practical, and edge-case behaviors of mmodlist in dlib's MMOD system.

#include <dlib/image_processing.h> using namespace dlib;

# Convert simple rectangle list to mmodlist with default label 0 def to_mmodlist(rect_list, label=0): return [dlib.mmod_rect(r, label=label, ignore=False) for r in rect_list] Reverse conversion (strip labels/ignore): mmodlist

mmodlist = detector.run(image) # returns mmod_rects rects = [m.rect for m in mmodlist] # just boxes labels = [m.label for m in mmodlist] # class predictions ignored = [m.ignore for m in mmodlist] # usually False for output | Problem | Likely cause | |--------|---------------| | Training crashes with “empty mmodlist” | An image has zero mmod_rect s. That’s allowed, but check that your dataset isn't entirely empty. | | Loss stays high | ignore=True used incorrectly on positive samples. | | Detector outputs wrong class | Mismatch between training labels and test-time expectations. | | Memory explosion | Too many mmod_rect s per image (e.g., 1000+ small objects). Use ignore for tiny or edge objects. | 8. mmodlist in C++ (for custom dlib extensions) If you work with dlib’s C++ API:

options = dlib.simple_object_detector_training_options() options.C = 1 options.num_threads = 8 options.add_left_right_image_flips = True This guide covers the conceptual, practical, and edge-case

options = dlib.simple_object_detector_training_options() options.add_left_right_image_flips = True options.C = 5 options.num_threads = 4 options.be_verbose = True detector = dlib.train_simple_object_detector(images, boxes_per_image, options) Save the detector detector.save("mmod_detector.svm")

Under the hood, train_simple_object_detector converts mmodlist into the internal MMOD loss format. The ignore flag is critical for hard examples: | | Loss stays high | ignore=True used

for xml_file in glob.glob("annotations/*.xml"): # Load dlib's XML format (which uses mmod_rect internally) rects = dlib.load_image_dataset(images, xml_file, "image") # rects is already list of mmod_rect mmodlists.append(rects)