MCPcopy Create free account
hub / github.com/davisking/dlib / train_detection_network

Function train_detection_network

examples/dnn_instance_segmentation_train_ex.cpp:191–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191det_bnet_type train_detection_network(
192 const std::vector<truth_image>& truth_images,
193 unsigned int det_minibatch_size
194)
195{
196 const double initial_learning_rate = 0.1;
197 const double weight_decay = 0.0001;
198 const double momentum = 0.9;
199 const double min_detector_window_overlap_iou = 0.65;
200
201 const int target_size = 70;
202 const int min_target_size = 30;
203
204 mmod_options options(
205 extract_mmod_rect_vectors(truth_images),
206 target_size, min_target_size,
207 min_detector_window_overlap_iou
208 );
209
210 options.overlaps_ignore = test_box_overlap(0.5, 0.9);
211
212 det_bnet_type det_net(options);
213
214 det_net.subnet().layer_details().set_num_filters(options.detector_windows.size());
215
216 dlib::pipe<det_training_sample> data(200);
217 auto f = [&data, &truth_images, target_size, min_target_size](time_t seed)
218 {
219 dlib::rand rnd(time(0) + seed);
220 matrix<rgb_pixel> input_image;
221
222 random_cropper cropper;
223 cropper.set_seed(time(0));
224 cropper.set_chip_dims(350, 350);
225
226 // Usually you want to give the cropper whatever min sizes you passed to the
227 // mmod_options constructor, or very slightly smaller sizes, which is what we do here.
228 cropper.set_min_object_size(target_size - 2, min_target_size - 2);
229 cropper.set_max_rotation_degrees(2);
230
231 det_training_sample temp;
232
233 while (data.is_enabled())
234 {
235 // Pick a random input image.
236 const auto random_index = rnd.get_random_32bit_number() % truth_images.size();
237 const auto& truth_image = truth_images[random_index];
238
239 // Load the input image.
240 load_image(input_image, truth_image.info.image_filename);
241
242 // Get a random crop of the input.
243 const auto mmod_rects = extract_mmod_rects(truth_image.truth_instances);
244 cropper(input_image, mmod_rects, temp.input_image, temp.mmod_rects);
245
246 disturb_colors(temp.input_image, rnd);
247
248 // Push the result to be used by the trainer.

Callers 1

mainFunction · 0.85

Calls 15

extract_mmod_rectsFunction · 0.85
disturb_colorsFunction · 0.85
moveFunction · 0.85
set_chip_dimsMethod · 0.80
set_min_object_sizeMethod · 0.80
set_learning_rateMethod · 0.80
get_learning_rateMethod · 0.80

Tested by

no test coverage detected