Commit 16ae5eac authored by Davis King's avatar Davis King

Added functions to the interface that allow a user to control the relative

loss from a false alarm vs. a missed detection.
parent aa88a574
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#ifndef DLIB_STRUCTURAL_SVM_ObJECT_DETECTION_PROBLEM_H__ #ifndef DLIB_STRUCTURAL_SVM_ObJECT_DETECTION_PROBLEM_H__
#define DLIB_STRUCTURAL_SVM_ObJECT_DETECTION_PROBLEM_H__ #define DLIB_STRUCTURAL_SVM_ObJECT_DETECTION_PROBLEM_H__
#include "structural_svm_object_detection_problem_abstract.h"
#include "../matrix.h" #include "../matrix.h"
#include "structural_svm_problem_threaded.h" #include "structural_svm_problem_threaded.h"
#include <sstream> #include <sstream>
...@@ -33,7 +34,9 @@ namespace dlib ...@@ -33,7 +34,9 @@ namespace dlib
boxes_overlap(overlap_tester), boxes_overlap(overlap_tester),
images(images_), images(images_),
rects(truth_rects), rects(truth_rects),
overlap_eps(0.5) overlap_eps(0.5),
loss_per_false_alarm(1),
loss_per_missed_target(1)
{ {
// make sure requires clause is not broken // make sure requires clause is not broken
DLIB_ASSERT(is_learning_problem(images_, truth_rects) && DLIB_ASSERT(is_learning_problem(images_, truth_rects) &&
...@@ -62,7 +65,7 @@ namespace dlib ...@@ -62,7 +65,7 @@ namespace dlib
{ {
// make sure requires clause is not broken // make sure requires clause is not broken
DLIB_ASSERT(0 < eps && eps < 1, DLIB_ASSERT(0 < eps && eps < 1,
"\t structural_svm_object_detection_problem::set_overlap_eps(eps)" "\t void structural_svm_object_detection_problem::set_overlap_eps(eps)"
<< "\n\t Invalid inputs were given to this function " << "\n\t Invalid inputs were given to this function "
<< "\n\t eps: " << eps << "\n\t eps: " << eps
<< "\n\t this: " << this << "\n\t this: " << this
...@@ -77,6 +80,48 @@ namespace dlib ...@@ -77,6 +80,48 @@ namespace dlib
return overlap_eps; return overlap_eps;
} }
double get_loss_per_missed_target (
) const
{
return loss_per_missed_target;
}
void set_loss_per_missed_target (
double loss
)
{
// make sure requires clause is not broken
DLIB_ASSERT(loss > 0,
"\t void structural_svm_object_detection_problem::set_loss_per_missed_target(loss)"
<< "\n\t Invalid inputs were given to this function "
<< "\n\t loss: " << loss
<< "\n\t this: " << this
);
loss_per_missed_target = loss;
}
double get_loss_per_false_alarm (
) const
{
return loss_per_false_alarm;
}
void set_loss_per_false_alarm (
double loss
)
{
// make sure requires clause is not broken
DLIB_ASSERT(loss > 0,
"\t void structural_svm_object_detection_problem::set_loss_per_false_alarm(loss)"
<< "\n\t Invalid inputs were given to this function "
<< "\n\t loss: " << loss
<< "\n\t this: " << this
);
loss_per_false_alarm = loss;
}
private: private:
virtual long get_num_dimensions ( virtual long get_num_dimensions (
) const ) const
...@@ -161,8 +206,6 @@ namespace dlib ...@@ -161,8 +206,6 @@ namespace dlib
std::vector<std::pair<double, rectangle> > dets; std::vector<std::pair<double, rectangle> > dets;
const double thresh = current_solution(scanner.get_num_dimensions()); const double thresh = current_solution(scanner.get_num_dimensions());
const double loss_per_false_alarm = 1;
const double loss_per_missed_target = 1;
scanner.load(images[idx]); scanner.load(images[idx]);
scanner.detect(current_solution, dets, thresh-loss_per_false_alarm); scanner.detect(current_solution, dets, thresh-loss_per_false_alarm);
...@@ -309,6 +352,8 @@ namespace dlib ...@@ -309,6 +352,8 @@ namespace dlib
unsigned long max_num_dets; unsigned long max_num_dets;
double overlap_eps; double overlap_eps;
double loss_per_false_alarm;
double loss_per_missed_target;
}; };
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
// Copyright (C) 2011 Davis E. King (davis@dlib.net) // Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license. // License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_STRUCTURAL_SVM_ObJECT_DETECTION_PROBLEM_ABSTRACT_H__ #undef DLIB_STRUCTURAL_SVM_ObJECT_DETECTION_PROBLEM_ABSTRACT_H__
#define DLIB_STRUCTURAL_SVM_ObJECT_DETECTION_PROBLEM_ABSTRACT_H__ #ifdef DLIB_STRUCTURAL_SVM_ObJECT_DETECTION_PROBLEM_ABSTRACT_H__
#include "../matrix.h" #include "../matrix.h"
#include "structural_svm_problem_threaded_abstract.h" #include "structural_svm_problem_threaded_abstract.h"
...@@ -45,15 +45,18 @@ namespace dlib ...@@ -45,15 +45,18 @@ namespace dlib
per image and the measure of loss is different from what is described in per image and the measure of loss is different from what is described in
the paper. the paper.
In particular, the loss is the number of false detections plus the number In particular, the loss is measured as follows:
of missed targets. A detection is considered a false detection if it doesn't let FA == the number of false alarms produced by a labeling of an image.
overlap with any of the ground truth rectangles or if it is a duplicate let MT == the number of targets missed by a labeling of an image.
detection of a truth rectangle. A detection "misses a target" if it doesn't Then the loss for a particular labeling is the quantity:
overlap with the truth rectangle for any target. Finally, for the purposes FA*get_loss_per_false_alarm() + MT*get_loss_per_missed_target()
of calculating loss, overlap is determined using the following formula,
rectangles A and B overlap if and only if: A detection is considered a false alarm if it doesn't overlap with any
of the ground truth rectangles or if it is a duplicate detection of a
truth rectangle. Finally, for the purposes of calculating loss, overlap
is determined using the following formula, rectangles A and B overlap
if and only if:
A.intersect(B).area()/(A+B).area() > get_overlap_eps() A.intersect(B).area()/(A+B).area() > get_overlap_eps()
!*/ !*/
public: public:
...@@ -81,6 +84,8 @@ namespace dlib ...@@ -81,6 +84,8 @@ namespace dlib
- This object will use num_threads threads during the optimization - This object will use num_threads threads during the optimization
procedure. You should set this parameter equal to the number of procedure. You should set this parameter equal to the number of
available processing cores on your machine. available processing cores on your machine.
- #get_loss_per_missed_target() == 1
- #get_loss_per_false_alarm() == 1
!*/ !*/
void set_overlap_eps ( void set_overlap_eps (
...@@ -101,6 +106,43 @@ namespace dlib ...@@ -101,6 +106,43 @@ namespace dlib
as overlapping with a ground truth rectangle. as overlapping with a ground truth rectangle.
!*/ !*/
double get_loss_per_missed_target (
) const;
/*!
ensures
- returns the amount of loss experienced for failing to detect one of the
targets.
!*/
void set_loss_per_missed_target (
double loss
);
/*!
requires
- loss > 0
ensures
- #get_loss_per_missed_target() == loss
!*/
double get_loss_per_false_alarm (
) const;
/*!
ensures
- returns the amount of loss experienced for emitting a false alarm detection.
Or in other words, the loss for generating a detection that doesn't correspond
to one of the truth rectangles.
!*/
void set_loss_per_false_alarm (
double loss
);
/*!
requires
- loss > 0
ensures
- #get_loss_per_false_alarm() == loss
!*/
}; };
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
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