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
b87ecad5
Commit
b87ecad5
authored
Dec 18, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved example
parent
fd132304
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
dnn_metric_learning_on_images_ex.cpp
examples/dnn_metric_learning_on_images_ex.cpp
+7
-3
No files found.
examples/dnn_metric_learning_on_images_ex.cpp
View file @
b87ecad5
...
...
@@ -288,8 +288,12 @@ int main(int argc, char** argv)
dlib
::
rand
rnd
(
time
(
0
));
load_mini_batch
(
5
,
5
,
rnd
,
objs
,
images
,
labels
);
// Normally you would use the non-batch-normalized version of the network to do
// testing, which is what we do here.
anet_type
testing_net
=
net
;
// Run all the images through the network to get their vector embeddings.
std
::
vector
<
matrix
<
float
,
0
,
1
>>
embedded
=
net
(
images
);
std
::
vector
<
matrix
<
float
,
0
,
1
>>
embedded
=
testing_
net
(
images
);
// Now, check if the embedding puts images with the same labels near each other and
// images with different labels far apart.
...
...
@@ -304,14 +308,14 @@ int main(int argc, char** argv)
// The loss_metric layer will cause images with the same label to be less
// than net.loss_details().get_distance_threshold() distance from each
// other. So we can use that distance value as our testing threshold.
if
(
length
(
embedded
[
i
]
-
embedded
[
j
])
<
net
.
loss_details
().
get_distance_threshold
())
if
(
length
(
embedded
[
i
]
-
embedded
[
j
])
<
testing_
net
.
loss_details
().
get_distance_threshold
())
++
num_right
;
else
++
num_wrong
;
}
else
{
if
(
length
(
embedded
[
i
]
-
embedded
[
j
])
>=
net
.
loss_details
().
get_distance_threshold
())
if
(
length
(
embedded
[
i
]
-
embedded
[
j
])
>=
testing_
net
.
loss_details
().
get_distance_threshold
())
++
num_right
;
else
++
num_wrong
;
...
...
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