Commit 527e26df authored by Davis King's avatar Davis King

Added max runtime option to object detector trainer API in python.

parent 7d3fac55
......@@ -177,6 +177,8 @@ process take significantly longer, so be patient when using it."
process take significantly longer, so be patient when using it.
!*/
)
.def_readwrite("max_runtime_seconds", &type::max_runtime_seconds,
"Don't let the solver run for longer than this many seconds.")
.def_readwrite("C", &type::C,
"C is the usual SVM C regularization parameter. So it is passed to \n\
structural_object_detection_trainer::set_c(). Larger values of C \n\
......@@ -407,13 +409,23 @@ ensures \n\
bunch of other simple_object_detectors. It essentially packs them together \n\
so that when you run the detector it's like calling run_multiple(). Except \n\
in this case the non-max suppression is applied to them all as a group. So \n\
unlike run_multiple(), each detector competes in the non-max suppression."
unlike run_multiple(), each detector competes in the non-max suppression. \n\
\n\
Also, the non-max suppression settings used for this whole thing are \n\
the settings used by detectors[0]. So if you have a preference, \n\
put the detector that uses the type of non-max suppression you like first \n\
in the list."
/*!
This version of the constructor builds a simple_object_detector from a
bunch of other simple_object_detectors. It essentially packs them together
so that when you run the detector it's like calling run_multiple(). Except
in this case the non-max suppression is applied to them all as a group. So
unlike run_multiple(), each detector competes in the non-max suppression.
Also, the non-max suppression settings used for this whole thing are
the settings used by detectors[0]. So if you have a preference,
put the detector that uses the type of non-max suppression you like first
in the list.
!*/
)
.def(py::init(&load_object_from_file<type>),
......
......@@ -36,6 +36,7 @@ namespace dlib
epsilon = 0.01;
upsample_limit = 2;
nuclear_norm_regularization_strength = 0;
max_runtime_seconds = 86400*365*100; // 100 years
}
bool be_verbose;
......@@ -46,7 +47,7 @@ namespace dlib
double epsilon;
unsigned long upsample_limit;
double nuclear_norm_regularization_strength;
double max_runtime_seconds;
};
inline std::string print_simple_object_detector_training_options(const simple_object_detector_training_options& o)
......@@ -59,6 +60,7 @@ namespace dlib
<< "detection_window_size=" << o.detection_window_size << ", "
<< "C=" << o.C << ", "
<< "epsilon=" << o.epsilon << ", "
<< "max_runtime_seconds=" << o.max_runtime_seconds << ", "
<< "upsample_limit=" << o.upsample_limit << ", "
<< "nuclear_norm_regularization_strength=" << o.nuclear_norm_regularization_strength
<< ")";
......@@ -162,6 +164,8 @@ namespace dlib
throw error("Invalid C value given to train_simple_object_detector(), C must be > 0.");
if (options.epsilon <= 0)
throw error("Invalid epsilon value given to train_simple_object_detector(), epsilon must be > 0.");
if (options.max_runtime_seconds <= 0)
throw error("Invalid max_runtime_seconds value given to train_simple_object_detector(), max_runtime_seconds must be > 0.");
if (options.nuclear_norm_regularization_strength < 0)
throw error("Invalid nuclear_norm_regularization_strength value given to train_simple_object_detector(), it must be must be >= 0.");
......@@ -184,6 +188,7 @@ namespace dlib
trainer.set_num_threads(options.num_threads);
trainer.set_c(options.C);
trainer.set_epsilon(options.epsilon);
trainer.set_max_runtime(std::chrono::milliseconds((int64_t)std::round(options.max_runtime_seconds*1000)));
if (options.be_verbose)
{
std::cout << "Training with C: " << options.C << std::endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment