From 1e1f4efbafd8571cd6c4849c7f4e9debdd0d000c Mon Sep 17 00:00:00 2001 From: Davis King Date: Thu, 28 Mar 2013 19:21:52 -0400 Subject: [PATCH] Gave load_image_dataset() the ability to skip images that don't have any ground truth boxes. --- dlib/data_io/load_image_dataset.h | 14 +++++++++---- dlib/data_io/load_image_dataset_abstract.h | 24 +++++++++++++--------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/dlib/data_io/load_image_dataset.h b/dlib/data_io/load_image_dataset.h index fdb6945bb..c955cdefb 100644 --- a/dlib/data_io/load_image_dataset.h +++ b/dlib/data_io/load_image_dataset.h @@ -28,7 +28,8 @@ namespace dlib array& images, std::vector >& object_locations, const std::string& filename, - const std::string& label + const std::string& label, + bool skip_empty_images = false ) { images.clear(); @@ -47,11 +48,10 @@ namespace dlib dataset data; load_image_dataset_metadata(data, filename); - images.resize(data.images.size()); + image_type img; std::vector rects; for (unsigned long i = 0; i < data.images.size(); ++i) { - load_image(images[i], data.images[i].filename); rects.clear(); for (unsigned long j = 0; j < data.images[i].boxes.size(); ++j) { @@ -60,7 +60,13 @@ namespace dlib rects.push_back(data.images[i].boxes[j].rect); } } - object_locations.push_back(rects); + + if (!skip_empty_images || rects.size() != 0) + { + object_locations.push_back(rects); + load_image(img, data.images[i].filename); + images.push_back(img); + } } set_current_dir(old_working_dir); diff --git a/dlib/data_io/load_image_dataset_abstract.h b/dlib/data_io/load_image_dataset_abstract.h index c31ff14c1..4800095b4 100644 --- a/dlib/data_io/load_image_dataset_abstract.h +++ b/dlib/data_io/load_image_dataset_abstract.h @@ -23,25 +23,29 @@ namespace dlib array& images, std::vector >& object_locations, const std::string& filename, - const std::string& label + const std::string& label, + bool skip_empty_images = false ); /*! requires - image_type == is an implementation of array2d/array2d_kernel_abstract.h - pixel_traits is defined ensures - - This routine loads the images and their associated object boxes from - the image metadata file indicated by filename. This metadata file - should be in the XML format used by the save_image_dataset_metadata() - routine. - - #images.size() == the number of images in the metadata file + - This routine loads the images and their associated object boxes from the + image metadata file indicated by filename. This metadata file should be in + the XML format used by the save_image_dataset_metadata() routine. + - #images.size() == The number of images loaded from the metadata file. This + is all the images listed in the file unless skip_empty_images is set to true. - #images.size() == #object_locations.size() - - This routine is capable of loading any image format which can be read - by the load_image() routine. + - This routine is capable of loading any image format which can be read by the + load_image() routine. - for all valid i: - - #images[i] == a copy of the ith image from the dataset + - #images[i] == a copy of the i-th image from the dataset - #object_locations[i] == a vector of all the rectangles associated with - #images[i]. + #images[i]. + - if (skip_empty_images == true) then + - #object_locations[i].size() != 0 + (i.e. only images with detection boxes in them will be loaded.) - if (labels != "") then - only boxes with the given label will be loaded into object_locations. - else