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
yolov7_migraphx
Commits
acfc7adf
Commit
acfc7adf
authored
Nov 15, 2023
by
liucong
Browse files
修改yolov7工程格式
parent
073a717a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
58 deletions
+16
-58
Doc/Tutorial_Cpp.md
Doc/Tutorial_Cpp.md
+10
-20
Doc/Tutorial_Python.md
Doc/Tutorial_Python.md
+1
-8
Python/YoloV7_infer_migraphx.py
Python/YoloV7_infer_migraphx.py
+3
-12
Src/YOLOV7.cpp
Src/YOLOV7.cpp
+2
-14
Src/main.cpp
Src/main.cpp
+0
-4
No files found.
Doc/Tutorial_Cpp.md
View file @
acfc7adf
...
...
@@ -22,18 +22,8 @@ ErrorCode DetectorYOLOV7::Initialize(InitializationParameterOfDetector initializ
LOG_INFO(stdout,"succeed to load model: %s\n",GetFileName(modelPath).c_str());
// 获取模型输入/输出节点信息
std::cout<<"inputs:"<<std::endl;
std::unordered_map<std::string, migraphx::shape> inputs=net.get_inputs();
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];
...
...
@@ -53,7 +43,7 @@ ErrorCode DetectorYOLOV7::Initialize(InitializationParameterOfDetector initializ
// 编译模型
migraphx::compile_options options;
options.device_id=0; // 设置GPU设备,默认为0号设备
options.device_id=0;
// 设置GPU设备,默认为0号设备
options.offload_copy=true; // 设置offload_copy
net.compile(gpuTarget,options);
LOG_INFO(stdout,"succeed to compile model: %s\n",GetFileName(modelPath).c_str());
...
...
@@ -77,13 +67,13 @@ ErrorCode DetectorYOLOV7::Detect(const cv::Mat &srcImage, std::vector<ResultOfDe
// 预处理并转换为NCHW
cv
::
Mat
inputBlob
;
blobFromImage
(
srcImage
,
//输入数据
inputBlob
,
//输出数据
1
/
255.0
,
//缩放系数,这里为1/255.0
inputSize
,
//YOLOV7输入尺寸(640,640)
Scalar
(
0
,
0
,
0
),
// 均值,这里不需要减均值,所以设置为0.0
true
,
//转换RB通道
false
);
blobFromImage
(
srcImage
,
//
输入数据
inputBlob
,
//
输出数据
1
/
255.0
,
//
缩放系数,这里为1/255.0
inputSize
,
//
YOLOV7输入尺寸(640,640)
Scalar
(
0
,
0
,
0
),
// 均值,这里不需要减均值,所以设置为0.0
true
,
//
转换RB通道
false
);
...
}
```
...
...
@@ -221,8 +211,8 @@ ErrorCode DetectorYOLOV7::Detect(const cv::Mat &srcImage, std::vector<ResultOfDe
//保存每个最终预测anchor的坐标值、置信度分数、类别ID
ResultOfDetection result;
result.boundingBox=box;
result.confidence=confidence;// confidence
result.classID=classID; // label
result.confidence=confidence;
// confidence
result.classID=classID;
// label
result.className=className;
resultsOfDetection.push_back(result);
}
...
...
Doc/Tutorial_Python.md
View file @
acfc7adf
...
...
@@ -49,18 +49,11 @@ class YOLOv7:
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
self.inputName =
"images"
self.inputName =
self.model.get_parameter_names()[0]
# 获取模型的输入尺寸
inputShape = inputShape=inputs[self.inputName].lens()
...
...
Python/YoloV7_infer_migraphx.py
View file @
acfc7adf
...
...
@@ -19,18 +19,11 @@ class YOLOv7:
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
self
.
inputName
=
"images"
self
.
inputName
=
self
.
model
.
get_parameter_names
()[
0
]
# 获取模型的输入尺寸
inputShape
=
inputShape
=
inputs
[
self
.
inputName
].
lens
()
...
...
@@ -44,12 +37,10 @@ class YOLOv7:
# 模型编译
self
.
model
.
compile
(
t
=
migraphx
.
get_target
(
"gpu"
),
device_id
=
0
)
# device_id: 设置GPU设备,默认为0号设备
print
(
"Success to compile"
)
# 执行推理
print
(
"Start to inference"
)
start
=
time
.
time
()
result
=
self
.
model
.
run
({
self
.
inputName
:
input_img
})
print
(
'net forward time: {:.4f}'
.
format
(
time
.
time
()
-
start
))
# 模型输出结果后处理
boxes
,
scores
,
class_ids
=
self
.
process_output
(
result
)
...
...
Src/YOLOV7.cpp
View file @
acfc7adf
...
...
@@ -15,16 +15,14 @@ DetectorYOLOV7::DetectorYOLOV7()
DetectorYOLOV7
::~
DetectorYOLOV7
()
{
configurationFile
.
release
();
}
ErrorCode
DetectorYOLOV7
::
Initialize
(
InitializationParameterOfDetector
initializationParameterOfDetector
)
{
// 读取配置文件
std
::
string
configFilePath
=
initializationParameterOfDetector
.
configFilePath
;
if
(
Exists
(
configFilePath
)
==
false
)
if
(
!
Exists
(
configFilePath
))
{
LOG_ERROR
(
stdout
,
"no configuration file!
\n
"
);
return
CONFIG_FILE_NOT_EXIST
;
...
...
@@ -47,7 +45,7 @@ ErrorCode DetectorYOLOV7::Initialize(InitializationParameterOfDetector initializ
useFP16
=
(
bool
)(
int
)
netNode
[
"UseFP16"
];
// 加载模型
if
(
Exists
(
modelPath
)
==
false
)
if
(
!
Exists
(
modelPath
))
{
LOG_ERROR
(
stdout
,
"%s not exist!
\n
"
,
modelPath
.
c_str
());
return
MODEL_NOT_EXIST
;
...
...
@@ -56,18 +54,8 @@ ErrorCode DetectorYOLOV7::Initialize(InitializationParameterOfDetector initializ
LOG_INFO
(
stdout
,
"succeed to load model: %s
\n
"
,
GetFileName
(
modelPath
).
c_str
());
// 获取模型输入/输出节点信息
std
::
cout
<<
"inputs:"
<<
std
::
endl
;
std
::
unordered_map
<
std
::
string
,
migraphx
::
shape
>
inputs
=
net
.
get_inputs
();
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
];
...
...
Src/main.cpp
View file @
acfc7adf
...
...
@@ -24,11 +24,7 @@ int main()
// 推理
std
::
vector
<
migraphxSamples
::
ResultOfDetection
>
predictions
;
double
time1
=
cv
::
getTickCount
();
detector
.
Detect
(
srcImage
,
predictions
);
double
time2
=
cv
::
getTickCount
();
double
elapsedTime
=
(
time2
-
time1
)
*
1000
/
cv
::
getTickFrequency
();
LOG_INFO
(
stdout
,
"inference time:%f ms
\n
"
,
elapsedTime
);
// 获取推理结果
LOG_INFO
(
stdout
,
"========== Detection Results ==========
\n
"
);
...
...
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