Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
06dc489c
Commit
06dc489c
authored
Dec 26, 2011
by
Davis King
Browse files
Added some more tests and also fixed the existing ones to work
given the recent changes to the object detection tools.
parent
c2ad9698
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
6 deletions
+45
-6
dlib/test/object_detector.cpp
dlib/test/object_detector.cpp
+45
-6
No files found.
dlib/test/object_detector.cpp
View file @
06dc489c
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
// License: Boost Software License See LICENSE.txt for the full license.
// License: Boost Software License See LICENSE.txt for the full license.
#include <dlib/statistics.h>
#include <sstream>
#include <sstream>
#include <string>
#include <string>
#include <cstdlib>
#include <cstdlib>
...
@@ -37,6 +38,42 @@ namespace
...
@@ -37,6 +38,42 @@ namespace
a
.
img
.
swap
(
b
.
img
);
a
.
img
.
swap
(
b
.
img
);
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_array_type
,
typename
detector_type
>
void
validate_some_object_detector_stuff
(
const
image_array_type
&
images
,
detector_type
&
detector
)
{
for
(
unsigned
long
i
=
0
;
i
<
images
.
size
();
++
i
)
{
std
::
vector
<
rectangle
>
dets
=
detector
(
images
[
i
]);
std
::
vector
<
std
::
pair
<
double
,
rectangle
>
>
dets2
;
detector
(
images
[
i
],
dets2
);
matrix
<
double
,
0
,
1
>
psi
(
detector
.
get_w
().
size
());
const
double
thresh
=
detector
.
get_w
()(
detector
.
get_w
().
size
()
-
1
);
DLIB_TEST
(
dets
.
size
()
==
dets2
.
size
());
for
(
unsigned
long
j
=
0
;
j
<
dets
.
size
();
++
j
)
{
DLIB_TEST
(
dets
[
j
]
==
dets2
[
j
].
second
);
psi
=
0
;
detector
.
get_scanner
().
get_feature_vector
(
dets
[
j
],
psi
);
const
double
check_score
=
dot
(
psi
,
detector
.
get_w
())
-
thresh
;
DLIB_TEST
(
std
::
abs
(
check_score
-
dets2
[
j
].
first
)
<
1e-10
);
}
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
class
very_simple_feature_extractor
:
noncopyable
class
very_simple_feature_extractor
:
noncopyable
...
@@ -229,10 +266,11 @@ namespace
...
@@ -229,10 +266,11 @@ namespace
image_scanner_type
scanner
;
image_scanner_type
scanner
;
const
rectangle
object_box
=
compute_box_dimensions
(
1
,
35
*
35
);
const
rectangle
object_box
=
compute_box_dimensions
(
1
,
35
*
35
);
scanner
.
add_detection_template
(
object_box
,
create_grid_detection_template
(
object_box
,
2
,
2
));
scanner
.
add_detection_template
(
object_box
,
create_grid_detection_template
(
object_box
,
2
,
2
));
setup_hashed_features
(
scanner
,
images
,
9
);
structural_object_detection_trainer
<
image_scanner_type
>
trainer
(
scanner
);
structural_object_detection_trainer
<
image_scanner_type
>
trainer
(
scanner
);
trainer
.
set_num_threads
(
4
);
trainer
.
set_num_threads
(
4
);
trainer
.
set_overlap_tester
(
test_box_overlap
(
0
));
trainer
.
set_overlap_tester
(
test_box_overlap
(
0
,
0
));
const
object_detector
<
image_scanner_type
>
detector
=
trainer
.
train
(
images
,
object_locations
);
object_detector
<
image_scanner_type
>
detector
=
trainer
.
train
(
images
,
object_locations
);
matrix
<
double
>
res
=
test_object_detection_function
(
detector
,
images
,
object_locations
);
matrix
<
double
>
res
=
test_object_detection_function
(
detector
,
images
,
object_locations
);
dlog
<<
LINFO
<<
"Test detector (precision,recall): "
<<
res
;
dlog
<<
LINFO
<<
"Test detector (precision,recall): "
<<
res
;
...
@@ -247,6 +285,8 @@ namespace
...
@@ -247,6 +285,8 @@ namespace
matrix
<
double
>
res
=
test_object_detection_function
(
detector
,
images
,
object_locations
);
matrix
<
double
>
res
=
test_object_detection_function
(
detector
,
images
,
object_locations
);
dlog
<<
LINFO
<<
"Test detector (precision,recall): "
<<
res
;
dlog
<<
LINFO
<<
"Test detector (precision,recall): "
<<
res
;
DLIB_TEST
(
sum
(
res
)
==
2
);
DLIB_TEST
(
sum
(
res
)
==
2
);
validate_some_object_detector_stuff
(
images
,
detector
);
}
}
}
}
...
@@ -270,8 +310,7 @@ namespace
...
@@ -270,8 +310,7 @@ namespace
scanner
.
set_max_pyramid_levels
(
1
);
scanner
.
set_max_pyramid_levels
(
1
);
structural_object_detection_trainer
<
image_scanner_type
>
trainer
(
scanner
);
structural_object_detection_trainer
<
image_scanner_type
>
trainer
(
scanner
);
trainer
.
set_num_threads
(
0
);
trainer
.
set_num_threads
(
0
);
trainer
.
set_overlap_tester
(
test_box_overlap
(
0
));
object_detector
<
image_scanner_type
>
detector
=
trainer
.
train
(
images
,
object_locations
);
const
object_detector
<
image_scanner_type
>
detector
=
trainer
.
train
(
images
,
object_locations
);
matrix
<
double
>
res
=
test_object_detection_function
(
detector
,
images
,
object_locations
);
matrix
<
double
>
res
=
test_object_detection_function
(
detector
,
images
,
object_locations
);
dlog
<<
LINFO
<<
"Test detector (precision,recall): "
<<
res
;
dlog
<<
LINFO
<<
"Test detector (precision,recall): "
<<
res
;
...
@@ -290,6 +329,7 @@ namespace
...
@@ -290,6 +329,7 @@ namespace
matrix
<
double
>
res
=
test_object_detection_function
(
detector
,
images
,
object_locations
);
matrix
<
double
>
res
=
test_object_detection_function
(
detector
,
images
,
object_locations
);
dlog
<<
LINFO
<<
"Test detector (precision,recall): "
<<
res
;
dlog
<<
LINFO
<<
"Test detector (precision,recall): "
<<
res
;
DLIB_TEST
(
sum
(
res
)
==
2
);
DLIB_TEST
(
sum
(
res
)
==
2
);
validate_some_object_detector_stuff
(
images
,
detector
);
}
}
}
}
...
@@ -362,8 +402,7 @@ namespace
...
@@ -362,8 +402,7 @@ namespace
scanner
.
set_max_pyramid_levels
(
1
);
scanner
.
set_max_pyramid_levels
(
1
);
structural_object_detection_trainer
<
image_scanner_type
>
trainer
(
scanner
);
structural_object_detection_trainer
<
image_scanner_type
>
trainer
(
scanner
);
trainer
.
set_num_threads
(
4
);
trainer
.
set_num_threads
(
4
);
trainer
.
set_overlap_tester
(
test_box_overlap
(
0
));
object_detector
<
image_scanner_type
>
detector
=
trainer
.
train
(
images
,
object_locations
);
const
object_detector
<
image_scanner_type
>
detector
=
trainer
.
train
(
images
,
object_locations
);
matrix
<
double
>
res
=
test_object_detection_function
(
detector
,
images
,
object_locations
);
matrix
<
double
>
res
=
test_object_detection_function
(
detector
,
images
,
object_locations
);
dlog
<<
LINFO
<<
"Test detector (precision,recall): "
<<
res
;
dlog
<<
LINFO
<<
"Test detector (precision,recall): "
<<
res
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment