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
ModelZoo
ResNet50_onnxruntime
Commits
85570d57
Commit
85570d57
authored
Nov 07, 2023
by
yangql
Browse files
Update Python/Classifier.py
parent
36700b06
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
Python/Classifier.py
Python/Classifier.py
+16
-2
No files found.
Python/Classifier.py
View file @
85570d57
...
@@ -42,7 +42,7 @@ def Preprocessing(pathOfImage):
...
@@ -42,7 +42,7 @@ def Preprocessing(pathOfImage):
norm_img_data
=
norm_img_data
.
reshape
(
1
,
3
,
224
,
224
).
astype
(
'float32'
)
norm_img_data
=
norm_img_data
.
reshape
(
1
,
3
,
224
,
224
).
astype
(
'float32'
)
return
norm_img_data
return
norm_img_data
def
postprocess
(
scores
):
def
postprocess
(
scores
,
pathOfImage
):
'''
'''
Postprocessing with mxnet gluon
Postprocessing with mxnet gluon
The function takes scores generated by the network and returns the class IDs in decreasing order
The function takes scores generated by the network and returns the class IDs in decreasing order
...
@@ -54,6 +54,9 @@ def postprocess(scores):
...
@@ -54,6 +54,9 @@ def postprocess(scores):
a
=
np
.
argsort
(
preds
)[::
-
1
]
a
=
np
.
argsort
(
preds
)[::
-
1
]
print
(
'class=%s ; probability=%f'
%
(
labels
[
a
[
0
]],
preds
[
a
[
0
]]))
print
(
'class=%s ; probability=%f'
%
(
labels
[
a
[
0
]],
preds
[
a
[
0
]]))
text
=
'class=%s '
%
(
labels
[
a
[
0
]])
saveimage
(
pathOfImage
,
text
)
def
ort_seg_dcu
(
model_path
,
image
):
def
ort_seg_dcu
(
model_path
,
image
):
#创建sess_options
#创建sess_options
...
@@ -73,6 +76,17 @@ def ort_seg_dcu(model_path,image):
...
@@ -73,6 +76,17 @@ def ort_seg_dcu(model_path,image):
return
scores
return
scores
def
saveimage
(
pathOfImage
,
text
):
iimage
=
cv2
.
imread
(
pathOfImage
,
cv2
.
IMREAD_COLOR
)
font
=
cv2
.
FONT_HERSHEY_SIMPLEX
font_scale
=
0.5
font_color
=
(
255
,
0
,
0
)
font_thickness
=
1
text_position
=
(
5
,
10
)
cv2
.
putText
(
iimage
,
text
,
text_position
,
font
,
font_scale
,
font_color
,
font_thickness
)
cv2
.
imwrite
(
"./output_image.jpg"
,
iimage
)
cv2
.
destroyAllWindows
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
pathOfImage
=
"../Resource/Images/ImageNet_01.jpg"
pathOfImage
=
"../Resource/Images/ImageNet_01.jpg"
...
@@ -83,4 +97,4 @@ if __name__ == '__main__':
...
@@ -83,4 +97,4 @@ if __name__ == '__main__':
result
=
ort_seg_dcu
(
model_path
,
image
)
result
=
ort_seg_dcu
(
model_path
,
image
)
# 解析分类结果
# 解析分类结果
postprocess
(
result
)
postprocess
(
result
,
pathOfImage
)
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