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
yolov3_migraphx
Commits
d43928d8
Commit
d43928d8
authored
Sep 07, 2023
by
liucong
Browse files
更新示例工程
parent
ed86689d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
12 deletions
+68
-12
Doc/Tutorial_Cpp.md
Doc/Tutorial_Cpp.md
+27
-4
Doc/Tutorial_Python.md
Doc/Tutorial_Python.md
+13
-2
Python/YoloV3_infer_migraphx.py
Python/YoloV3_infer_migraphx.py
+13
-2
Src/YOLOV3.cpp
Src/YOLOV3.cpp
+15
-4
No files found.
Doc/Tutorial_Cpp.md
View file @
d43928d8
...
@@ -21,10 +21,21 @@ ErrorCode DetectorYOLOV3::Initialize(InitializationParameterOfDetector initializ
...
@@ -21,10 +21,21 @@ ErrorCode DetectorYOLOV3::Initialize(InitializationParameterOfDetector initializ
net = migraphx::parse_onnx(modelPath);
net = migraphx::parse_onnx(modelPath);
LOG_INFO(stdout,"succeed to load model: %s\n",GetFileName(modelPath).c_str());
LOG_INFO(stdout,"succeed to load model: %s\n",GetFileName(modelPath).c_str());
// 获取模型输入属性
// 获取模型输入/输出节点信息
std::pair<std::string, migraphx::shape> inputAttribute=net.get_parameter_shapes();
std::cout<<"inputs:"<<std::endl;
inputName=inputAttribute.first;
std::unordered_map<std::string, migraphx::shape> inputs=net.get_inputs();
inputShape=inputAttribute.second;
for(auto i:inputs)
{
std::cout<<i.first<<":"<<i.second<<std::endl;
}
std::cout<<"outputs:"<<std::endl;
std::unordered_map<std::string, migraphx::shape> outputs=net.get_outputs();
for(auto i:outputs)
{
std::cout<<i.first<<":"<<i.second<<std::endl;
}
inputName=inputs.begin()->first;
inputShape=inputs.begin()->second;
int N=inputShape.lens()[0];
int N=inputShape.lens()[0];
int C=inputShape.lens()[1];
int C=inputShape.lens()[1];
int H=inputShape.lens()[2];
int H=inputShape.lens()[2];
...
@@ -109,6 +120,18 @@ ErrorCode DetectorYOLOV3::Detect(const cv::Mat &srcImage, std::vector<ResultOfDe
...
@@ -109,6 +120,18 @@ ErrorCode DetectorYOLOV3::Detect(const cv::Mat &srcImage, std::vector<ResultOfDe
}
}
```
```
另外,如果想要指定输出节点,可以在eval()方法中通过提供outputNames参数来实现:
```
...
// 推理
std::vector<std::string> outputNames = {"187","121","output"}
std::vector<migraphx::argument> inferenceResults = net.eval(inputData, outputNames);
...
```
如果没有指定outputName参数,则默认输出所有输出节点,此时输出节点的顺序与ONNX中输出节点顺序保持一致,可以通过netron查看ONNX文件的输出节点的顺序。
获取上述信息之后进行anchors筛选,筛选过程分为两个步骤:
获取上述信息之后进行anchors筛选,筛选过程分为两个步骤:
-
第一步根据objectThreshold阈值进行筛选,大于该阈值则判断当前anchor内包含物体,小于该阈值则判断无物体;
-
第一步根据objectThreshold阈值进行筛选,大于该阈值则判断当前anchor内包含物体,小于该阈值则判断无物体;
...
...
Doc/Tutorial_Python.md
View file @
d43928d8
...
@@ -49,11 +49,22 @@ class YOLOv3:
...
@@ -49,11 +49,22 @@ class YOLOv3:
# 解析推理模型
# 解析推理模型
self.model = migraphx.parse_onnx(path)
self.model = migraphx.parse_onnx(path)
# 获取模型输入/输出节点信息
print("inputs:")
inputs = self.model.get_inputs()
for key,value in inputs.items():
print("{}:{}".format(key,value))
print("outputs:")
outputs = self.model.get_outputs()
for key,value in outputs.items():
print("{}:{}".format(key,value))
# 获取模型的输入name
# 获取模型的输入name
self.inputName =
self.model.get_parameter_names()[0]
self.inputName =
"images"
# 获取模型的输入尺寸
# 获取模型的输入尺寸
inputShape =
self.model.get_parameter_shapes()
[self.inputName].lens()
inputShape =
inputShape=inputs
[self.inputName].lens()
self.inputHeight = int(inputShape[2])
self.inputHeight = int(inputShape[2])
self.inputWidth = int(inputShape[3])
self.inputWidth = int(inputShape[3])
```
```
...
...
Python/YoloV3_infer_migraphx.py
View file @
d43928d8
...
@@ -19,11 +19,22 @@ class YOLOv3:
...
@@ -19,11 +19,22 @@ class YOLOv3:
# 解析推理模型
# 解析推理模型
self
.
model
=
migraphx
.
parse_onnx
(
path
)
self
.
model
=
migraphx
.
parse_onnx
(
path
)
# 获取模型输入/输出节点信息
print
(
"inputs:"
)
inputs
=
self
.
model
.
get_inputs
()
for
key
,
value
in
inputs
.
items
():
print
(
"{}:{}"
.
format
(
key
,
value
))
print
(
"outputs:"
)
outputs
=
self
.
model
.
get_outputs
()
for
key
,
value
in
outputs
.
items
():
print
(
"{}:{}"
.
format
(
key
,
value
))
# 获取模型的输入name
# 获取模型的输入name
self
.
inputName
=
self
.
model
.
get_parameter_names
()[
0
]
self
.
inputName
=
"images"
# 获取模型的输入尺寸
# 获取模型的输入尺寸
inputShape
=
self
.
model
.
get_parameter_shapes
()
[
self
.
inputName
].
lens
()
inputShape
=
inputShape
=
inputs
[
self
.
inputName
].
lens
()
self
.
inputHeight
=
int
(
inputShape
[
2
])
self
.
inputHeight
=
int
(
inputShape
[
2
])
self
.
inputWidth
=
int
(
inputShape
[
3
])
self
.
inputWidth
=
int
(
inputShape
[
3
])
print
(
"inputName:{0}
\n
inputShape:{1}"
.
format
(
self
.
inputName
,
inputShape
))
print
(
"inputName:{0}
\n
inputShape:{1}"
.
format
(
self
.
inputName
,
inputShape
))
...
...
Src/YOLOV3.cpp
View file @
d43928d8
...
@@ -55,10 +55,21 @@ ErrorCode DetectorYOLOV3::Initialize(InitializationParameterOfDetector initializ
...
@@ -55,10 +55,21 @@ ErrorCode DetectorYOLOV3::Initialize(InitializationParameterOfDetector initializ
net
=
migraphx
::
parse_onnx
(
modelPath
);
net
=
migraphx
::
parse_onnx
(
modelPath
);
LOG_INFO
(
stdout
,
"succeed to load model: %s
\n
"
,
GetFileName
(
modelPath
).
c_str
());
LOG_INFO
(
stdout
,
"succeed to load model: %s
\n
"
,
GetFileName
(
modelPath
).
c_str
());
// 获取模型输入属性
// 获取模型输入/输出节点信息
std
::
unordered_map
<
std
::
string
,
migraphx
::
shape
>
inputMap
=
net
.
get_parameter_shapes
();
std
::
cout
<<
"inputs:"
<<
std
::
endl
;
inputName
=
inputMap
.
begin
()
->
first
;
std
::
unordered_map
<
std
::
string
,
migraphx
::
shape
>
inputs
=
net
.
get_inputs
();
inputShape
=
inputMap
.
begin
()
->
second
;
for
(
auto
i
:
inputs
)
{
std
::
cout
<<
i
.
first
<<
":"
<<
i
.
second
<<
std
::
endl
;
}
std
::
cout
<<
"outputs:"
<<
std
::
endl
;
std
::
unordered_map
<
std
::
string
,
migraphx
::
shape
>
outputs
=
net
.
get_outputs
();
for
(
auto
i
:
outputs
)
{
std
::
cout
<<
i
.
first
<<
":"
<<
i
.
second
<<
std
::
endl
;
}
inputName
=
inputs
.
begin
()
->
first
;
inputShape
=
inputs
.
begin
()
->
second
;
int
N
=
inputShape
.
lens
()[
0
];
int
N
=
inputShape
.
lens
()[
0
];
int
C
=
inputShape
.
lens
()[
1
];
int
C
=
inputShape
.
lens
()[
1
];
int
H
=
inputShape
.
lens
()[
2
];
int
H
=
inputShape
.
lens
()[
2
];
...
...
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