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_migraphx
Commits
e6a8bf6a
Commit
e6a8bf6a
authored
Jan 08, 2025
by
liucong
Browse files
修改python示例程序
parent
25e4f86c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
20 deletions
+34
-20
Python/Classifier_io_binding.py
Python/Classifier_io_binding.py
+34
-20
No files found.
Python/Classifier_io_binding.py
View file @
e6a8bf6a
...
@@ -62,32 +62,46 @@ def ort_seg_dcu(model_path,image):
...
@@ -62,32 +62,46 @@ def ort_seg_dcu(model_path,image):
provider_options
=
[{
'device_id'
:
'0'
,
'migraphx_fp16_enable'
:
'true'
}]
provider_options
=
[{
'device_id'
:
'0'
,
'migraphx_fp16_enable'
:
'true'
}]
dcu_session
=
ort
.
InferenceSession
(
model_path
,
providers
=
[
'MIGraphXExecutionProvider'
],
provider_options
=
provider_options
)
dcu_session
=
ort
.
InferenceSession
(
model_path
,
providers
=
[
'MIGraphXExecutionProvider'
],
provider_options
=
provider_options
)
output_data
=
np
.
empty
(
dcu_session
.
get_outputs
()[
0
].
shape
).
astype
(
np
.
float32
)
images
=
[
image
]
input_nodes
=
dcu_session
.
get_inputs
()
input_names
=
[
i_n
.
name
for
i_n
in
input_nodes
]
output_nodes
=
dcu_session
.
get_outputs
()
output_names
=
[
o_n
.
name
for
o_n
in
output_nodes
]
inputData
=
{}
input_dict
=
{}
outputData
=
{}
for
i_d
,
i_n
in
zip
(
images
,
input_names
):
inputData
[
dcu_session
.
get_inputs
()[
0
].
name
]
=
ort
.
OrtValue
.
ortvalue_from_numpy
(
image
,
device_type
=
'cuda'
)
input_dict
[
i_n
]
=
i_d
outputData
[
dcu_session
.
get_outputs
()[
0
].
name
]
=
ort
.
OrtValue
.
ortvalue_from_numpy
(
output_data
,
device_type
=
'cuda'
)
io_binding
=
dcu_session
.
io_binding
()
io_binding
=
dcu_session
.
io_binding
()
io_binding
.
bind_input
(
name
=
dcu_session
.
get_inputs
()[
0
].
name
,
device_type
=
inputData
[
dcu_session
.
get_inputs
()[
0
].
name
].
device_name
(),
device_id
=
0
,
element_type
=
np
.
float32
,
shape
=
inputData
[
dcu_session
.
get_inputs
()[
0
].
name
].
shape
(),
buffer_ptr
=
inputData
[
dcu_session
.
get_inputs
()[
0
].
name
].
data_ptr
())
io_binding
.
bind_output
(
inputData
=
{}
name
=
dcu_session
.
get_outputs
()[
0
].
name
,
for
key
in
input_dict
.
keys
():
device_type
=
outputData
[
dcu_session
.
get_outputs
()[
0
].
name
].
device_name
(),
inputData
[
key
]
=
ort
.
OrtValue
.
ortvalue_from_numpy
(
input_dict
[
key
],
device_type
=
'cuda'
)
device_id
=
0
,
io_binding
.
bind_input
(
element_type
=
np
.
float32
,
name
=
key
,
shape
=
outputData
[
dcu_session
.
get_outputs
()[
0
].
name
].
shape
(),
device_type
=
inputData
[
key
].
device_name
(),
buffer_ptr
=
outputData
[
dcu_session
.
get_outputs
()[
0
].
name
].
data_ptr
())
device_id
=
0
,
element_type
=
np
.
float32
,
shape
=
inputData
[
key
].
shape
(),
buffer_ptr
=
inputData
[
key
].
data_ptr
())
outputData
=
{}
output_data
=
{}
for
index
,
o_n
in
enumerate
(
output_names
):
output_data
[
o_n
]
=
np
.
empty
(
dcu_session
.
get_outputs
()[
index
].
shape
).
astype
(
np
.
float32
)
outputData
[
o_n
]
=
ort
.
OrtValue
.
ortvalue_from_numpy
(
output_data
[
o_n
],
device_type
=
'cuda'
)
io_binding
.
bind_output
(
name
=
o_n
,
device_type
=
outputData
[
o_n
].
device_name
(),
device_id
=
0
,
element_type
=
np
.
float32
,
shape
=
outputData
[
o_n
].
shape
(),
buffer_ptr
=
outputData
[
o_n
].
data_ptr
())
dcu_session
.
run_with_iobinding
(
io_binding
)
dcu_session
.
run_with_iobinding
(
io_binding
)
scores
=
np
.
array
(
io_binding
.
copy_outputs_to_cpu
()[
0
])
result
=
io_binding
.
copy_outputs_to_cpu
()[
0
]
scores
=
np
.
array
(
result
)
print
(
"ort result.shape:"
,
scores
.
shape
)
print
(
"ort result.shape:"
,
scores
.
shape
)
return
scores
return
scores
...
...
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