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
8a7fb193
Commit
8a7fb193
authored
Dec 03, 2011
by
Davis King
Browse files
Made the feature_extractor interface a little more efficient.
parent
7359ab4b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
4 deletions
+15
-4
dlib/svm/assignment_function.h
dlib/svm/assignment_function.h
+5
-1
dlib/svm/structural_svm_assignment_problem.h
dlib/svm/structural_svm_assignment_problem.h
+10
-3
No files found.
dlib/svm/assignment_function.h
View file @
8a7fb193
...
@@ -126,6 +126,9 @@ namespace dlib
...
@@ -126,6 +126,9 @@ namespace dlib
}
}
cost
.
set_size
(
size
,
size
);
cost
.
set_size
(
size
,
size
);
typedef
typename
feature_extractor
::
feature_vector_type
feature_vector_type
;
feature_vector_type
feats
;
// now fill out the cost assignment matrix
// now fill out the cost assignment matrix
for
(
long
r
=
0
;
r
<
cost
.
nr
();
++
r
)
for
(
long
r
=
0
;
r
<
cost
.
nr
();
++
r
)
{
{
...
@@ -133,7 +136,8 @@ namespace dlib
...
@@ -133,7 +136,8 @@ namespace dlib
{
{
if
(
r
<
(
long
)
lhs
.
size
()
&&
c
<
(
long
)
rhs
.
size
())
if
(
r
<
(
long
)
lhs
.
size
()
&&
c
<
(
long
)
rhs
.
size
())
{
{
cost
(
r
,
c
)
=
dot
(
weights
,
fe
(
lhs
[
r
],
rhs
[
c
]));
fe
.
get_features
(
lhs
[
r
],
rhs
[
c
],
feats
);
cost
(
r
,
c
)
=
dot
(
weights
,
feats
);
}
}
else
else
{
{
...
...
dlib/svm/structural_svm_assignment_problem.h
View file @
8a7fb193
...
@@ -68,12 +68,14 @@ namespace dlib
...
@@ -68,12 +68,14 @@ namespace dlib
psi_type
&
psi
psi_type
&
psi
)
const
)
const
{
{
typename
feature_extractor
::
feature_vector_type
feats
;
psi
=
0
;
psi
=
0
;
for
(
unsigned
long
i
=
0
;
i
<
sample
.
first
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
sample
.
first
.
size
();
++
i
)
{
{
if
(
label
[
i
]
!=
-
1
)
if
(
label
[
i
]
!=
-
1
)
{
{
psi
+=
fe
(
sample
.
first
[
i
],
sample
.
second
[
label
[
i
]]);
fe
.
get_features
(
sample
.
first
[
i
],
sample
.
second
[
label
[
i
]],
feats
);
psi
+=
feats
;
}
}
}
}
}
}
...
@@ -95,11 +97,13 @@ namespace dlib
...
@@ -95,11 +97,13 @@ namespace dlib
)
const
)
const
{
{
psi
.
clear
();
psi
.
clear
();
typename
feature_extractor
::
feature_vector_type
feats
;
for
(
unsigned
long
i
=
0
;
i
<
sample
.
first
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
sample
.
first
.
size
();
++
i
)
{
{
if
(
label
[
i
]
!=
-
1
)
if
(
label
[
i
]
!=
-
1
)
{
{
append_to_sparse_vect
(
psi
,
fe
(
sample
.
first
[
i
],
sample
.
second
[
label
[
i
]]));
fe
.
get_features
(
sample
.
first
[
i
],
sample
.
second
[
label
[
i
]],
feats
);
append_to_sparse_vect
(
psi
,
feats
);
}
}
}
}
}
}
...
@@ -137,6 +141,8 @@ namespace dlib
...
@@ -137,6 +141,8 @@ namespace dlib
}
}
cost
.
set_size
(
size
,
size
);
cost
.
set_size
(
size
,
size
);
typename
feature_extractor
::
feature_vector_type
feats
;
// now fill out the cost assignment matrix
// now fill out the cost assignment matrix
for
(
long
r
=
0
;
r
<
cost
.
nr
();
++
r
)
for
(
long
r
=
0
;
r
<
cost
.
nr
();
++
r
)
{
{
...
@@ -146,7 +152,8 @@ namespace dlib
...
@@ -146,7 +152,8 @@ namespace dlib
{
{
if
(
c
<
(
long
)
samples
[
idx
].
second
.
size
())
if
(
c
<
(
long
)
samples
[
idx
].
second
.
size
())
{
{
cost
(
r
,
c
)
=
dot
(
current_solution
,
fe
(
samples
[
idx
].
first
[
r
],
samples
[
idx
].
second
[
c
]));
fe
.
get_features
(
samples
[
idx
].
first
[
r
],
samples
[
idx
].
second
[
c
],
feats
);
cost
(
r
,
c
)
=
dot
(
current_solution
,
feats
);
// add in the loss since this corresponds to an incorrect prediction.
// add in the loss since this corresponds to an incorrect prediction.
if
(
c
!=
labels
[
idx
][
r
])
if
(
c
!=
labels
[
idx
][
r
])
...
...
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