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
5e550a26
Commit
5e550a26
authored
Jun 25, 2016
by
Davis King
Browse files
Added some more comments
parent
034e0e19
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
2 deletions
+7
-2
examples/dnn_imagenet_ex.cpp
examples/dnn_imagenet_ex.cpp
+7
-2
No files found.
examples/dnn_imagenet_ex.cpp
View file @
5e550a26
...
@@ -121,7 +121,11 @@ int main(int argc, char** argv) try
...
@@ -121,7 +121,11 @@ int main(int argc, char** argv) try
anet_type
net
;
anet_type
net
;
deserialize
(
"resnet34_1000_imagenet_classifier.dnn"
)
>>
net
>>
labels
;
deserialize
(
"resnet34_1000_imagenet_classifier.dnn"
)
>>
net
>>
labels
;
// Make a network with softmax as the final layer. We don't have to do this
// if we just want to output the single best prediction, since the anet_type
// already does this. But if we instead want to get the probability of each
// class as output we need to replace the last layer of the network with a
// softmax layer, which we do as follows:
softmax
<
anet_type
::
subnet_type
>
snet
;
softmax
<
anet_type
::
subnet_type
>
snet
;
snet
.
subnet
()
=
net
.
subnet
();
snet
.
subnet
()
=
net
.
subnet
();
...
@@ -131,7 +135,7 @@ int main(int argc, char** argv) try
...
@@ -131,7 +135,7 @@ int main(int argc, char** argv) try
dlib
::
rand
rnd
;
dlib
::
rand
rnd
;
image_window
win
;
image_window
win
;
//
r
ead images from the command prompt and print the top 5 best labels for each.
//
R
ead images from the command prompt and print the top 5 best labels for each.
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
{
load_image
(
img
,
argv
[
i
]);
load_image
(
img
,
argv
[
i
]);
...
@@ -143,6 +147,7 @@ int main(int argc, char** argv) try
...
@@ -143,6 +147,7 @@ int main(int argc, char** argv) try
matrix
<
float
,
1
,
1000
>
p
=
sum_rows
(
mat
(
snet
(
images
.
begin
(),
images
.
end
())))
/
num_crops
;
matrix
<
float
,
1
,
1000
>
p
=
sum_rows
(
mat
(
snet
(
images
.
begin
(),
images
.
end
())))
/
num_crops
;
win
.
set_image
(
img
);
win
.
set_image
(
img
);
// Print the 5 most probable labels
for
(
int
k
=
0
;
k
<
5
;
++
k
)
for
(
int
k
=
0
;
k
<
5
;
++
k
)
{
{
unsigned
long
predicted_label
=
index_of_max
(
p
);
unsigned
long
predicted_label
=
index_of_max
(
p
);
...
...
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