| 78 | // ---------------------------------------------------------------------------------------- |
| 79 | |
| 80 | int split_dataset ( |
| 81 | const command_line_parser& parser |
| 82 | ) |
| 83 | { |
| 84 | if (parser.number_of_arguments() != 1) |
| 85 | { |
| 86 | cerr << "The --split option requires you to give one XML file on the command line." << endl; |
| 87 | return EXIT_FAILURE; |
| 88 | } |
| 89 | |
| 90 | const std::string label = parser.option("split").argument(); |
| 91 | |
| 92 | dlib::image_dataset_metadata::dataset data, data_with, data_without; |
| 93 | load_image_dataset_metadata(data, parser[0]); |
| 94 | |
| 95 | data_with.name = data.name; |
| 96 | data_with.comment = data.comment; |
| 97 | data_without.name = data.name; |
| 98 | data_without.comment = data.comment; |
| 99 | |
| 100 | for (unsigned long i = 0; i < data.images.size(); ++i) |
| 101 | { |
| 102 | auto&& temp = data.images[i]; |
| 103 | |
| 104 | bool has_the_label = false; |
| 105 | // check for the label we are looking for |
| 106 | for (unsigned long j = 0; j < temp.boxes.size(); ++j) |
| 107 | { |
| 108 | if (temp.boxes[j].label == label) |
| 109 | { |
| 110 | has_the_label = true; |
| 111 | break; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | if (has_the_label) |
| 116 | data_with.images.push_back(temp); |
| 117 | else |
| 118 | data_without.images.push_back(temp); |
| 119 | } |
| 120 | |
| 121 | |
| 122 | save_image_dataset_metadata(data_with, left_substr(parser[0],".") + "_with_"+label + ".xml"); |
| 123 | save_image_dataset_metadata(data_without, left_substr(parser[0],".") + "_without_"+label + ".xml"); |
| 124 | |
| 125 | return EXIT_SUCCESS; |
| 126 | } |
| 127 | |
| 128 | // ---------------------------------------------------------------------------------------- |
| 129 |
no test coverage detected