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
e1ac0b43
Unverified
Commit
e1ac0b43
authored
Nov 17, 2021
by
Adrià Arrufat
Committed by
GitHub
Nov 17, 2021
Browse files
normalize samples for SVM classifier (#2460)
parent
44621a61
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
1 deletion
+7
-1
examples/dnn_self_supervised_learning_ex.cpp
examples/dnn_self_supervised_learning_ex.cpp
+7
-1
No files found.
examples/dnn_self_supervised_learning_ex.cpp
View file @
e1ac0b43
...
@@ -295,6 +295,10 @@ try
...
@@ -295,6 +295,10 @@ try
std
::
vector
<
matrix
<
float
,
0
,
1
>>
features
;
std
::
vector
<
matrix
<
float
,
0
,
1
>>
features
;
cout
<<
"Extracting features for linear classifier..."
<<
endl
;
cout
<<
"Extracting features for linear classifier..."
<<
endl
;
features
=
fnet
(
training_images
,
4
*
batch_size
);
features
=
fnet
(
training_images
,
4
*
batch_size
);
vector_normalizer
<
matrix
<
float
,
0
,
1
>>
normalizer
;
normalizer
.
train
(
features
);
for
(
auto
&
feature
:
features
)
feature
=
normalizer
(
feature
);
// Find the most appropriate C setting using find_max_global.
// Find the most appropriate C setting using find_max_global.
auto
cross_validation_score
=
[
&
](
const
double
c
)
auto
cross_validation_score
=
[
&
](
const
double
c
)
...
@@ -309,7 +313,7 @@ try
...
@@ -309,7 +313,7 @@ try
cout
<<
"confusion matrix:
\n
"
<<
cm
<<
endl
;
cout
<<
"confusion matrix:
\n
"
<<
cm
<<
endl
;
return
accuracy
;
return
accuracy
;
};
};
const
auto
result
=
find_max_global
(
cross_validation_score
,
1e-
4
,
1000
0
,
max_function_calls
(
50
));
const
auto
result
=
find_max_global
(
cross_validation_score
,
1e-
3
,
1000
,
max_function_calls
(
50
));
cout
<<
"Best C: "
<<
result
.
x
(
0
)
<<
endl
;
cout
<<
"Best C: "
<<
result
.
x
(
0
)
<<
endl
;
// Proceed to train the SVM classifier with the best C.
// Proceed to train the SVM classifier with the best C.
...
@@ -346,6 +350,8 @@ try
...
@@ -346,6 +350,8 @@ try
compute_accuracy
(
features
,
training_labels
);
compute_accuracy
(
features
,
training_labels
);
cout
<<
"
\n
testing accuracy"
<<
endl
;
cout
<<
"
\n
testing accuracy"
<<
endl
;
features
=
fnet
(
testing_images
,
4
*
batch_size
);
features
=
fnet
(
testing_images
,
4
*
batch_size
);
for
(
auto
&
feature
:
features
)
feature
=
normalizer
(
feature
);
compute_accuracy
(
features
,
testing_labels
);
compute_accuracy
(
features
,
testing_labels
);
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
...
...
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