Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
8c27a29e
Commit
8c27a29e
authored
Feb 21, 2014
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Just renamed variables and simplified a few things. No real changes.
parent
63eb621a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
141 additions
and
98 deletions
+141
-98
cross_validate_track_association_trainer.h
dlib/svm/cross_validate_track_association_trainer.h
+15
-15
cross_validate_track_association_trainer_abstract.h
dlib/svm/cross_validate_track_association_trainer_abstract.h
+4
-4
structural_track_association_trainer.h
dlib/svm/structural_track_association_trainer.h
+46
-29
structural_track_association_trainer_abstract.h
dlib/svm/structural_track_association_trainer_abstract.h
+21
-33
svm.h
dlib/svm/svm.h
+21
-7
svm_abstract.h
dlib/svm/svm_abstract.h
+34
-10
No files found.
dlib/svm/cross_validate_track_association_trainer.h
View file @
8c27a29e
...
@@ -15,11 +15,11 @@ namespace dlib
...
@@ -15,11 +15,11 @@ namespace dlib
template
<
template
<
typename
track_association_function
,
typename
track_association_function
,
typename
detection_type
,
typename
detection_type
,
typename
detection_id
_type
typename
label
_type
>
>
void
test_track_association_function
(
void
test_track_association_function
(
const
track_association_function
&
assoc
,
const
track_association_function
&
assoc
,
const
std
::
vector
<
std
::
vector
<
std
::
pair
<
detection_type
,
detection_id
_type
>
>
>&
samples
,
const
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label
_type
>
>
>&
samples
,
unsigned
long
&
total_dets
,
unsigned
long
&
total_dets
,
unsigned
long
&
correctly_associated_dets
unsigned
long
&
correctly_associated_dets
)
)
...
@@ -30,7 +30,7 @@ namespace dlib
...
@@ -30,7 +30,7 @@ namespace dlib
using
namespace
impl
;
using
namespace
impl
;
std
::
vector
<
track_type
>
tracks
;
std
::
vector
<
track_type
>
tracks
;
std
::
map
<
detection_id
_type
,
unsigned
long
>
track_idx
;
// tracks[track_idx[id]] == track with ID id.
std
::
map
<
label
_type
,
unsigned
long
>
track_idx
;
// tracks[track_idx[id]] == track with ID id.
for
(
unsigned
long
j
=
0
;
j
<
samples
.
size
();
++
j
)
for
(
unsigned
long
j
=
0
;
j
<
samples
.
size
();
++
j
)
{
{
...
@@ -38,32 +38,32 @@ namespace dlib
...
@@ -38,32 +38,32 @@ namespace dlib
std
::
vector
<
long
>
assignments
=
f
(
get_unlabeled_dets
(
samples
[
j
]),
tracks
);
std
::
vector
<
long
>
assignments
=
f
(
get_unlabeled_dets
(
samples
[
j
]),
tracks
);
std
::
vector
<
bool
>
updated_track
(
tracks
.
size
(),
false
);
std
::
vector
<
bool
>
updated_track
(
tracks
.
size
(),
false
);
// now update all the tracks with the detections that associated to them.
// now update all the tracks with the detections that associated to them.
const
std
::
vector
<
std
::
pair
<
detection_type
,
detection_id
_type
>
>&
dets
=
samples
[
j
];
const
std
::
vector
<
labeled_detection
<
detection_type
,
label
_type
>
>&
dets
=
samples
[
j
];
for
(
unsigned
long
k
=
0
;
k
<
assignments
.
size
();
++
k
)
for
(
unsigned
long
k
=
0
;
k
<
assignments
.
size
();
++
k
)
{
{
// If the detection is associated to tracks[assignments[k]]
// If the detection is associated to tracks[assignments[k]]
if
(
assignments
[
k
]
!=
-
1
)
if
(
assignments
[
k
]
!=
-
1
)
{
{
tracks
[
assignments
[
k
]].
update_track
(
dets
[
k
].
firs
t
);
tracks
[
assignments
[
k
]].
update_track
(
dets
[
k
].
de
t
);
updated_track
[
assignments
[
k
]]
=
true
;
updated_track
[
assignments
[
k
]]
=
true
;
// if this detection was supposed to go to this track
// if this detection was supposed to go to this track
if
(
track_idx
.
count
(
dets
[
k
].
second
)
&&
track_idx
[
dets
[
k
].
second
]
==
assignments
[
k
])
if
(
track_idx
.
count
(
dets
[
k
].
label
)
&&
track_idx
[
dets
[
k
].
label
]
==
assignments
[
k
])
++
correctly_associated_dets
;
++
correctly_associated_dets
;
track_idx
[
dets
[
k
].
second
]
=
assignments
[
k
];
track_idx
[
dets
[
k
].
label
]
=
assignments
[
k
];
}
}
else
else
{
{
track_type
new_track
;
track_type
new_track
;
new_track
.
update_track
(
dets
[
k
].
firs
t
);
new_track
.
update_track
(
dets
[
k
].
de
t
);
tracks
.
push_back
(
new_track
);
tracks
.
push_back
(
new_track
);
// if this detection was supposed to go to a new track
// if this detection was supposed to go to a new track
if
(
track_idx
.
count
(
dets
[
k
].
second
)
==
0
)
if
(
track_idx
.
count
(
dets
[
k
].
label
)
==
0
)
++
correctly_associated_dets
;
++
correctly_associated_dets
;
track_idx
[
dets
[
k
].
second
]
=
tracks
.
size
()
-
1
;
track_idx
[
dets
[
k
].
label
]
=
tracks
.
size
()
-
1
;
}
}
}
}
...
@@ -82,11 +82,11 @@ namespace dlib
...
@@ -82,11 +82,11 @@ namespace dlib
template
<
template
<
typename
track_association_function
,
typename
track_association_function
,
typename
detection_type
,
typename
detection_type
,
typename
detection_id
_type
typename
label
_type
>
>
double
test_track_association_function
(
double
test_track_association_function
(
const
track_association_function
&
assoc
,
const
track_association_function
&
assoc
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
std
::
pair
<
detection_type
,
detection_id
_type
>
>
>
>&
samples
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label
_type
>
>
>
>&
samples
)
)
{
{
unsigned
long
total_dets
=
0
;
unsigned
long
total_dets
=
0
;
...
@@ -105,18 +105,18 @@ namespace dlib
...
@@ -105,18 +105,18 @@ namespace dlib
template
<
template
<
typename
trainer_type
,
typename
trainer_type
,
typename
detection_type
,
typename
detection_type
,
typename
detection_id
_type
typename
label
_type
>
>
double
cross_validate_track_association_trainer
(
double
cross_validate_track_association_trainer
(
const
trainer_type
&
trainer
,
const
trainer_type
&
trainer
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
std
::
pair
<
detection_type
,
detection_id
_type
>
>
>
>&
samples
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label
_type
>
>
>
>&
samples
,
const
long
folds
const
long
folds
)
)
{
{
const
long
num_in_test
=
samples
.
size
()
/
folds
;
const
long
num_in_test
=
samples
.
size
()
/
folds
;
const
long
num_in_train
=
samples
.
size
()
-
num_in_test
;
const
long
num_in_train
=
samples
.
size
()
-
num_in_test
;
std
::
vector
<
std
::
vector
<
std
::
vector
<
std
::
pair
<
detection_type
,
detection_id
_type
>
>
>
>
samples_train
;
std
::
vector
<
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label
_type
>
>
>
>
samples_train
;
long
next_test_idx
=
0
;
long
next_test_idx
=
0
;
unsigned
long
total_dets
=
0
;
unsigned
long
total_dets
=
0
;
...
...
dlib/svm/cross_validate_track_association_trainer_abstract.h
View file @
8c27a29e
...
@@ -14,11 +14,11 @@ namespace dlib
...
@@ -14,11 +14,11 @@ namespace dlib
template
<
template
<
typename
track_association_function
,
typename
track_association_function
,
typename
detection_type
,
typename
detection_type
,
typename
detection_id
_type
typename
label
_type
>
>
double
test_track_association_function
(
double
test_track_association_function
(
const
track_association_function
&
assoc
,
const
track_association_function
&
assoc
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
std
::
pair
<
detection_type
,
detection_id
_type
>
>
>
>&
samples
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label
_type
>
>
>
>&
samples
);
);
/*!
/*!
requires
requires
...
@@ -38,11 +38,11 @@ namespace dlib
...
@@ -38,11 +38,11 @@ namespace dlib
template
<
template
<
typename
trainer_type
,
typename
trainer_type
,
typename
detection_type
,
typename
detection_type
,
typename
detection_id
_type
typename
label
_type
>
>
double
cross_validate_track_association_trainer
(
double
cross_validate_track_association_trainer
(
const
trainer_type
&
trainer
,
const
trainer_type
&
trainer
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
std
::
pair
<
detection_type
,
detection_id
_type
>
>
>
>&
samples
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label
_type
>
>
>
>&
samples
,
const
long
folds
const
long
folds
);
);
/*!
/*!
...
...
dlib/svm/structural_track_association_trainer.h
View file @
8c27a29e
...
@@ -20,16 +20,16 @@ namespace dlib
...
@@ -20,16 +20,16 @@ namespace dlib
{
{
template
<
template
<
typename
detection_type
,
typename
detection_type
,
typename
detection_id
_type
typename
label
_type
>
>
std
::
vector
<
detection_type
>
get_unlabeled_dets
(
std
::
vector
<
detection_type
>
get_unlabeled_dets
(
const
std
::
vector
<
std
::
pair
<
detection_type
,
detection_id
_type
>
>&
dets
const
std
::
vector
<
labeled_detection
<
detection_type
,
label
_type
>
>&
dets
)
)
{
{
std
::
vector
<
detection_type
>
temp
;
std
::
vector
<
detection_type
>
temp
;
temp
.
reserve
(
dets
.
size
());
temp
.
reserve
(
dets
.
size
());
for
(
unsigned
long
i
=
0
;
i
<
dets
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
dets
.
size
();
++
i
)
temp
.
push_back
(
dets
[
i
].
firs
t
);
temp
.
push_back
(
dets
[
i
].
de
t
);
return
temp
;
return
temp
;
}
}
...
@@ -37,21 +37,9 @@ namespace dlib
...
@@ -37,21 +37,9 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
detection_type_
,
typename
detection_id_type_
=
unsigned
long
>
class
structural_track_association_trainer
class
structural_track_association_trainer
{
{
public
:
public
:
typedef
detection_type_
detection_type
;
typedef
typename
detection_type
::
track_type
track_type
;
typedef
detection_id_type_
detection_id_type
;
typedef
std
::
pair
<
detection_type
,
detection_id_type
>
labeled_detection
;
typedef
std
::
vector
<
labeled_detection
>
detections_at_single_time_step
;
typedef
std
::
vector
<
detections_at_single_time_step
>
track_history
;
typedef
track_association_function
<
detection_type
>
trained_function_type
;
structural_track_association_trainer
(
structural_track_association_trainer
(
)
)
...
@@ -159,8 +147,12 @@ namespace dlib
...
@@ -159,8 +147,12 @@ namespace dlib
learn_nonnegative_weights
=
value
;
learn_nonnegative_weights
=
value
;
}
}
template
<
typename
detection_type
,
typename
label_type
>
const
track_association_function
<
detection_type
>
train
(
const
track_association_function
<
detection_type
>
train
(
const
std
::
vector
<
track_history
>&
samples
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label_type
>
>
>
>&
samples
)
const
)
const
{
{
// make sure requires clause is not broken
// make sure requires clause is not broken
...
@@ -170,6 +162,7 @@ namespace dlib
...
@@ -170,6 +162,7 @@ namespace dlib
<<
"
\n\t
is_track_association_problem(samples): "
<<
is_track_association_problem
(
samples
)
<<
"
\n\t
is_track_association_problem(samples): "
<<
is_track_association_problem
(
samples
)
);
);
typedef
typename
detection_type
::
track_type
track_type
;
const
unsigned
long
num_dims
=
find_num_dims
(
samples
);
const
unsigned
long
num_dims
=
find_num_dims
(
samples
);
...
@@ -195,21 +188,30 @@ namespace dlib
...
@@ -195,21 +188,30 @@ namespace dlib
return
track_association_function
<
detection_type
>
(
trainer
.
train
(
assignment_samples
,
labels
));
return
track_association_function
<
detection_type
>
(
trainer
.
train
(
assignment_samples
,
labels
));
}
}
template
<
typename
detection_type
,
typename
label_type
>
const
track_association_function
<
detection_type
>
train
(
const
track_association_function
<
detection_type
>
train
(
const
track_history
&
sample
const
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label_type
>
>
>
&
sample
)
const
)
const
{
{
std
::
vector
<
track_history
>
samples
;
std
::
vector
<
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label_type
>
>
>
>
samples
;
samples
.
push_back
(
sample
);
samples
.
push_back
(
sample
);
return
train
(
samples
);
return
train
(
samples
);
}
}
private
:
private
:
template
<
typename
detection_type
,
typename
label_type
>
static
unsigned
long
find_num_dims
(
static
unsigned
long
find_num_dims
(
const
std
::
vector
<
track_history
>&
samples
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label_type
>
>
>
>&
samples
)
)
{
{
typedef
typename
detection_type
::
track_type
track_type
;
// find a detection_type object so we can call get_similarity_features() and
// find a detection_type object so we can call get_similarity_features() and
// find out how big the feature vectors are.
// find out how big the feature vectors are.
...
@@ -222,9 +224,9 @@ namespace dlib
...
@@ -222,9 +224,9 @@ namespace dlib
if
(
samples
[
i
][
j
].
size
()
>
0
)
if
(
samples
[
i
][
j
].
size
()
>
0
)
{
{
track_type
new_track
;
track_type
new_track
;
new_track
.
update_track
(
samples
[
i
][
j
][
0
].
firs
t
);
new_track
.
update_track
(
samples
[
i
][
j
][
0
].
de
t
);
typename
track_type
::
feature_vector_type
feats
;
typename
track_type
::
feature_vector_type
feats
;
new_track
.
get_similarity_features
(
samples
[
i
][
j
][
0
].
firs
t
,
feats
);
new_track
.
get_similarity_features
(
samples
[
i
][
j
][
0
].
de
t
,
feats
);
return
feats
.
size
();
return
feats
.
size
();
}
}
}
}
...
@@ -234,6 +236,11 @@ namespace dlib
...
@@ -234,6 +236,11 @@ namespace dlib
"No detection objects were given in the call to dlib::structural_track_association_trainer::train()"
);
"No detection objects were given in the call to dlib::structural_track_association_trainer::train()"
);
}
}
template
<
typename
detections_at_single_time_step
,
typename
detection_type
,
typename
track_type
>
static
void
convert_dets_to_association_sets
(
static
void
convert_dets_to_association_sets
(
const
std
::
vector
<
detections_at_single_time_step
>&
det_history
,
const
std
::
vector
<
detections_at_single_time_step
>&
det_history
,
std
::
vector
<
std
::
pair
<
std
::
vector
<
detection_type
>
,
std
::
vector
<
track_type
>
>
>&
data
,
std
::
vector
<
std
::
pair
<
std
::
vector
<
detection_type
>
,
std
::
vector
<
track_type
>
>
>&
data
,
...
@@ -243,10 +250,11 @@ namespace dlib
...
@@ -243,10 +250,11 @@ namespace dlib
if
(
det_history
.
size
()
<
1
)
if
(
det_history
.
size
()
<
1
)
return
;
return
;
typedef
typename
detections_at_single_time_step
::
value_type
::
label_type
label_type
;
std
::
vector
<
track_type
>
tracks
;
std
::
vector
<
track_type
>
tracks
;
// track_labels maps from detection labels to the index in tracks. So track
// track_labels maps from detection labels to the index in tracks. So track
// with detection label X is at tracks[track_labels[X]].
// with detection label X is at tracks[track_labels[X]].
std
::
map
<
detection_id
_type
,
unsigned
long
>
track_labels
;
std
::
map
<
label
_type
,
unsigned
long
>
track_labels
;
add_dets_to_tracks
(
tracks
,
track_labels
,
det_history
[
0
]);
add_dets_to_tracks
(
tracks
,
track_labels
,
det_history
[
0
]);
using
namespace
impl
;
using
namespace
impl
;
...
@@ -258,17 +266,21 @@ namespace dlib
...
@@ -258,17 +266,21 @@ namespace dlib
}
}
}
}
template
<
typename
labeled_detection
,
typename
label_type
>
static
std
::
vector
<
long
>
get_association_labels
(
static
std
::
vector
<
long
>
get_association_labels
(
const
std
::
vector
<
labeled_detection
>&
dets
,
const
std
::
vector
<
labeled_detection
>&
dets
,
const
std
::
map
<
detection_id
_type
,
unsigned
long
>&
track_labels
const
std
::
map
<
label
_type
,
unsigned
long
>&
track_labels
)
)
{
{
std
::
vector
<
long
>
assoc
(
dets
.
size
(),
-
1
);
std
::
vector
<
long
>
assoc
(
dets
.
size
(),
-
1
);
// find out which detections associate to what tracks
// find out which detections associate to what tracks
for
(
unsigned
long
i
=
0
;
i
<
dets
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
dets
.
size
();
++
i
)
{
{
typename
std
::
map
<
detection_id
_type
,
unsigned
long
>::
const_iterator
j
;
typename
std
::
map
<
label
_type
,
unsigned
long
>::
const_iterator
j
;
j
=
track_labels
.
find
(
dets
[
i
].
second
);
j
=
track_labels
.
find
(
dets
[
i
].
label
);
// If this detection matches one of the tracks then record which track it
// If this detection matches one of the tracks then record which track it
// matched with.
// matched with.
if
(
j
!=
track_labels
.
end
())
if
(
j
!=
track_labels
.
end
())
...
@@ -277,9 +289,14 @@ namespace dlib
...
@@ -277,9 +289,14 @@ namespace dlib
return
assoc
;
return
assoc
;
}
}
template
<
typename
track_type
,
typename
label_type
,
typename
labeled_detection
>
static
void
add_dets_to_tracks
(
static
void
add_dets_to_tracks
(
std
::
vector
<
track_type
>&
tracks
,
std
::
vector
<
track_type
>&
tracks
,
std
::
map
<
detection_id
_type
,
unsigned
long
>&
track_labels
,
std
::
map
<
label
_type
,
unsigned
long
>&
track_labels
,
const
std
::
vector
<
labeled_detection
>&
dets
const
std
::
vector
<
labeled_detection
>&
dets
)
)
{
{
...
@@ -288,18 +305,18 @@ namespace dlib
...
@@ -288,18 +305,18 @@ namespace dlib
// first assign the dets to the tracks
// first assign the dets to the tracks
for
(
unsigned
long
i
=
0
;
i
<
dets
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
dets
.
size
();
++
i
)
{
{
const
detection_id_type
&
label
=
dets
[
i
].
second
;
const
label_type
&
label
=
dets
[
i
].
label
;
if
(
track_labels
.
count
(
label
))
if
(
track_labels
.
count
(
label
))
{
{
const
unsigned
long
track_idx
=
track_labels
[
label
];
const
unsigned
long
track_idx
=
track_labels
[
label
];
tracks
[
track_idx
].
update_track
(
dets
[
i
].
firs
t
);
tracks
[
track_idx
].
update_track
(
dets
[
i
].
de
t
);
updated_track
[
track_idx
]
=
true
;
updated_track
[
track_idx
]
=
true
;
}
}
else
else
{
{
// this detection creates a new track
// this detection creates a new track
track_type
new_track
;
track_type
new_track
;
new_track
.
update_track
(
dets
[
i
].
firs
t
);
new_track
.
update_track
(
dets
[
i
].
de
t
);
tracks
.
push_back
(
new_track
);
tracks
.
push_back
(
new_track
);
track_labels
[
label
]
=
tracks
.
size
()
-
1
;
track_labels
[
label
]
=
tracks
.
size
()
-
1
;
}
}
...
...
dlib/svm/structural_track_association_trainer_abstract.h
View file @
8c27a29e
...
@@ -11,45 +11,23 @@ namespace dlib
...
@@ -11,45 +11,23 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
detection_type_
,
typename
detection_id_type_
=
unsigned
long
>
class
structural_track_association_trainer
class
structural_track_association_trainer
{
{
/*!
/*!
REQUIREMENTS ON detection_type_
It must be an object that implements an interface compatible with the
example_detection defined in dlib/svm/track_association_function_abstract.h.
REQUIREMENTS ON detection_id_type_
This can be any type that can be used as the key in a std::map. e.g.
unsigned long, std::string, etc.
WHAT THIS OBJECT REPRESENTS
WHAT THIS OBJECT REPRESENTS
This object is a tool for learning to solve a track association problem. That
This object is a tool for learning to solve a track association problem. That
is, it takes in a set of training data and outputs a track_association_function
is, it takes in a set of training data and outputs a track_association_function
you can use to do detection to track association. The training data takes the
you can use to do detection to track association. The training data takes the
form of a set or sets of "track histories". Each track history is a
form of a set or sets of "track histories". Each track history is a
std::vector where each element contains all the detections from a single time
std::vector where each element contains all the detections from a single time
step. Moreover, each detection is labeled with a detection_id_type_ that
step. Moreover, each detection has a label that uniquely identifies which
uniquely identifies which object (e.g. person or whatever) the detection really
object (e.g. person or whatever) the detection really corresponds to. That is,
corresponds to. That is, the detection_id_type_ values indicate the correct
the labels indicate the correct detection to track associations. The goal of
detection to track associations. The goal of this object is then to produce a
this object is then to produce a track_association_function that can perform a
track_association_function that can perform a correct detection to track
correct detection to track association at each time step.
association at each time step.
!*/
!*/
public
:
public
:
typedef
detection_type_
detection_type
;
typedef
typename
detection_type
::
track_type
track_type
;
typedef
detection_id_type_
detection_id_type
;
typedef
std
::
pair
<
detection_type
,
detection_id_type
>
labeled_detection
;
typedef
std
::
vector
<
labeled_detection
>
detections_at_single_time_step
;
typedef
std
::
vector
<
detections_at_single_time_step
>
track_history
;
typedef
track_association_function
<
detection_type
>
trained_function_type
;
structural_track_association_trainer
(
structural_track_association_trainer
(
);
);
...
@@ -192,15 +170,21 @@ namespace dlib
...
@@ -192,15 +170,21 @@ namespace dlib
- #learns_nonnegative_weights() == value
- #learns_nonnegative_weights() == value
!*/
!*/
template
<
typename
detection_type
,
typename
label_type
>
const
track_association_function
<
detection_type
>
train
(
const
track_association_function
<
detection_type
>
train
(
const
track_history
&
sample
const
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label_type
>
>
>
&
sample
)
const
;
)
const
;
/*!
/*!
requires
requires
- is_track_association_problem(sample
s
) == true
- is_track_association_problem(sample) == true
ensures
ensures
- This function attempts to learn to do track association from the given
- This function attempts to learn to do track association from the given
training data.
training data. Note that we interpret sample as a single track history such
that sample[0] are all detections from the first time step, then sample[1]
are detections from the second time step, and so on.
- returns a function F such that:
- returns a function F such that:
- Executing F(tracks, detections) will try to correctly associate the
- Executing F(tracks, detections) will try to correctly associate the
contents of detections to the contents of tracks and perform track
contents of detections to the contents of tracks and perform track
...
@@ -209,8 +193,12 @@ namespace dlib
...
@@ -209,8 +193,12 @@ namespace dlib
- min(F.get_assignment_function().get_weights()) >= 0
- min(F.get_assignment_function().get_weights()) >= 0
!*/
!*/
template
<
typename
detection_type
,
typename
label_type
>
const
track_association_function
<
detection_type
>
train
(
const
track_association_function
<
detection_type
>
train
(
const
std
::
vector
<
track_history
>&
samples
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label_type
>
>
>
>&
sample
)
const
;
)
const
;
/*!
/*!
requires
requires
...
...
dlib/svm/svm.h
View file @
8c27a29e
...
@@ -307,14 +307,28 @@ namespace dlib
...
@@ -307,14 +307,28 @@ namespace dlib
return
false
;
return
false
;
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
detection_type_
,
typename
label_type_
=
long
>
struct
labeled_detection
{
typedef
detection_type_
detection_type
;
typedef
label_type_
label_type
;
detection_type
det
;
label_type
label
;
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
template
<
typename
detection_type
,
typename
detection_type
,
typename
detection_id
_type
typename
label
_type
>
>
bool
is_track_association_problem
(
bool
is_track_association_problem
(
const
std
::
vector
<
std
::
vector
<
std
::
pair
<
detection_type
,
detection_id
_type
>
>
>&
samples
const
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label
_type
>
>
>&
samples
)
)
{
{
if
(
samples
.
size
()
==
0
)
if
(
samples
.
size
()
==
0
)
...
@@ -329,12 +343,12 @@ namespace dlib
...
@@ -329,12 +343,12 @@ namespace dlib
if
(
num_nonzero_elements
<
2
)
if
(
num_nonzero_elements
<
2
)
return
false
;
return
false
;
// now make sure the
detection_id
_type values are unique within each time step.
// now make sure the
label
_type values are unique within each time step.
for
(
unsigned
long
i
=
0
;
i
<
samples
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
samples
.
size
();
++
i
)
{
{
std
::
set
<
detection_id
_type
>
vals
;
std
::
set
<
label
_type
>
vals
;
for
(
unsigned
long
j
=
0
;
j
<
samples
[
i
].
size
();
++
j
)
for
(
unsigned
long
j
=
0
;
j
<
samples
[
i
].
size
();
++
j
)
vals
.
insert
(
samples
[
i
][
j
].
second
);
vals
.
insert
(
samples
[
i
][
j
].
label
);
if
(
vals
.
size
()
!=
samples
[
i
].
size
())
if
(
vals
.
size
()
!=
samples
[
i
].
size
())
return
false
;
return
false
;
}
}
...
@@ -347,10 +361,10 @@ namespace dlib
...
@@ -347,10 +361,10 @@ namespace dlib
template
<
template
<
typename
detection_type
,
typename
detection_type
,
typename
detection_id
_type
typename
label
_type
>
>
bool
is_track_association_problem
(
bool
is_track_association_problem
(
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
std
::
pair
<
detection_type
,
detection_id
_type
>
>
>
>&
samples
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label
_type
>
>
>
>&
samples
)
)
{
{
for
(
unsigned
long
i
=
0
;
i
<
samples
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
samples
.
size
();
++
i
)
...
...
dlib/svm/svm_abstract.h
View file @
8c27a29e
...
@@ -164,12 +164,36 @@ namespace dlib
...
@@ -164,12 +164,36 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
detection_type_
,
typename
label_type_
=
long
>
struct
labeled_detection
{
/*!
WHAT THIS OBJECT REPRESENTS
This is a simple object, like std::pair, it just holds two objects. It
serves the same purpose as std::pair except that it has informative names
describing its two members and is intended for use with track association
problems.
!*/
typedef
detection_type_
detection_type
;
typedef
label_type_
label_type
;
detection_type
det
;
label_type
label
;
};
// ----------------------------------------------------------------------------------------
template
<
template
<
typename
detection_type
,
typename
detection_type
,
typename
detection_id
_type
typename
label
_type
>
>
bool
is_track_association_problem
(
bool
is_track_association_problem
(
const
std
::
vector
<
std
::
vector
<
std
::
pair
<
detection_type
,
detection_id
_type
>
>
>&
samples
const
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label
_type
>
>
>&
samples
);
);
/*!
/*!
ensures
ensures
...
@@ -185,8 +209,8 @@ namespace dlib
...
@@ -185,8 +209,8 @@ namespace dlib
- samples[i] is a set of labeled detections from the i-th time step.
- samples[i] is a set of labeled detections from the i-th time step.
Each detection has been labeled with its "true object identity".
Each detection has been labeled with its "true object identity".
That is, all the detection throughout the history with the same
That is, all the detection throughout the history with the same
detection_id_type value are detections from the same object and
label_type value are detections from the same object and therefore
therefore
should be associated to the same track.
should be associated to the same track.
Putting this all together, samples is a valid track association learning
Putting this all together, samples is a valid track association learning
problem if and only if the following are all true:
problem if and only if the following are all true:
- samples.size() > 0
- samples.size() > 0
...
@@ -198,18 +222,18 @@ namespace dlib
...
@@ -198,18 +222,18 @@ namespace dlib
or it is impossible to learn anything.
or it is impossible to learn anything.
- for all valid i:
- for all valid i:
- for all valid j and k where j!=k:
- for all valid j and k where j!=k:
- samples[i][j].
second != samples[i][k].second
- samples[i][j].
label != samples[i][k].label
(i.e. the
detection_id_type values must be unique within each
(i.e. the
label_type values must be unique within each time step.
time step. Or in other words, you can't have two detections on
Or in other words, you can't have two detections on the same
the same
object in a single time step.)
object in a single time step.)
!*/
!*/
template
<
template
<
typename
detection_type
,
typename
detection_type
,
typename
detection_id
_type
typename
label
_type
>
>
bool
is_track_association_problem
(
bool
is_track_association_problem
(
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
std
::
pair
<
detection_type
,
detection_id
_type
>
>
>
>&
samples
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
labeled_detection
<
detection_type
,
label
_type
>
>
>
>&
samples
);
);
/*!
/*!
ensures
ensures
...
...
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