Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
b8b80474
Commit
b8b80474
authored
Jun 28, 2017
by
Aleksandr Rybnikov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed python sample for googlenet in dnn
parent
dcf3d988
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
15 deletions
+4
-15
googlenet_python.py
samples/dnn/googlenet_python.py
+4
-15
No files found.
samples/dnn/googlenet_python.py
View file @
b8b80474
...
...
@@ -4,31 +4,21 @@ import cv2
from
cv2
import
dnn
import
timeit
def
prepare_image
(
img
):
img
=
cv2
.
resize
(
img
,
(
224
,
224
))
#convert interleaved image (RGBRGB) to planar(RRGGBB)
blob
=
np
.
moveaxis
(
img
,
2
,
0
)
blob
=
np
.
reshape
(
blob
.
astype
(
np
.
float32
),
(
-
1
,
3
,
224
,
224
))
return
blob
def
timeit_forward
(
net
):
print
(
"OpenCL:"
,
cv2
.
ocl
.
useOpenCL
())
print
(
"Runtime:"
,
timeit
.
timeit
(
lambda
:
net
.
forward
(),
number
=
10
))
def
get_class_list
():
with
open
(
'synset_words.txt'
,
'rt'
)
as
f
:
return
[
x
[
x
.
find
(
" "
)
+
1
:]
for
x
in
f
]
return
[
x
[
x
.
find
(
" "
)
+
1
:]
for
x
in
f
]
blob
=
prepare_image
(
cv2
.
imread
(
'space_shuttle.jpg'
))
blob
=
dnn
.
blobFromImage
(
cv2
.
imread
(
'space_shuttle.jpg'
),
1
,
(
224
,
224
),
(
104
,
117
,
123
))
print
(
"Input:"
,
blob
.
shape
,
blob
.
dtype
)
cv2
.
ocl
.
setUseOpenCL
(
True
)
#Disable OCL if you want
net
=
dnn
.
readNetFromCaffe
(
'bvlc_googlenet.prototxt'
,
'bvlc_googlenet.caffemodel'
)
net
.
set
Blob
(
".data"
,
blob
)
net
.
forward
()
net
.
set
Input
(
blob
)
prob
=
net
.
forward
()
#timeit_forward(net) #Uncomment to check performance
prob
=
net
.
getBlob
(
"prob"
)
print
(
"Output:"
,
prob
.
shape
,
prob
.
dtype
)
classes
=
get_class_list
()
print
(
"Best match"
,
classes
[
prob
.
argmax
()])
\ No newline at end of file
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