# 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):
Under the hood, train_simple_object_detector converts mmodlist into the internal MMOD loss format. The ignore flag is critical for hard examples:
detector = dlib.train_simple_object_detector(images, mmodlists, options) img = dlib.load_rgb_image("test.jpg") dets = detector(img) for det in dets: print(f"Class det.label at det.rect, score det.detection_confidence") mmodlist
1. What is mmodlist ? mmodlist (short for Max-Margin Object Detection List ) is not a standalone class but a specific data format used by dlib’s fhog_object_detector and loss_mmod_ layers. It is a list of mmod_rect objects.
#include <dlib/image_processing.h> using namespace dlib; # Convert simple rectangle list to mmodlist with
This guide covers the conceptual, practical, and edge-case behaviors of mmodlist in dlib's MMOD system.
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: mmodlist (short for Max-Margin Object Detection List )
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)
Friends