Commit 8a7fb193 authored by Davis King's avatar Davis King

Made the feature_extractor interface a little more efficient.

parent 7359ab4b
...@@ -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
{ {
......
...@@ -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])
......
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