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
RetinaFace_migraphx
Commits
474298d4
Commit
474298d4
authored
Nov 15, 2023
by
liucong
Browse files
修改retinaface工程格式
parent
58b5daa5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
31 deletions
+6
-31
Python/RetinaFace_infer_migraphx.py
Python/RetinaFace_infer_migraphx.py
+0
-10
Src/RetinaFace.cpp
Src/RetinaFace.cpp
+6
-17
Src/main.cpp
Src/main.cpp
+0
-4
No files found.
Python/RetinaFace_infer_migraphx.py
View file @
474298d4
...
@@ -61,16 +61,8 @@ if __name__ == '__main__':
...
@@ -61,16 +61,8 @@ if __name__ == '__main__':
model
=
migraphx
.
parse_onnx
(
"./FaceDetector.onnx"
)
model
=
migraphx
.
parse_onnx
(
"./FaceDetector.onnx"
)
# 获取模型输入/输出节点信息
# 获取模型输入/输出节点信息
print
(
"inputs:"
)
inputs
=
model
.
get_inputs
()
inputs
=
model
.
get_inputs
()
for
key
,
value
in
inputs
.
items
():
print
(
"{}:{}"
.
format
(
key
,
value
))
print
(
"outputs:"
)
outputs
=
model
.
get_outputs
()
outputs
=
model
.
get_outputs
()
for
key
,
value
in
outputs
.
items
():
print
(
"{}:{}"
.
format
(
key
,
value
))
inputName
=
model
.
get_parameter_names
()[
0
]
inputName
=
model
.
get_parameter_names
()[
0
]
inputShape
=
inputs
[
inputName
].
lens
()
inputShape
=
inputs
[
inputName
].
lens
()
print
(
"inputName:{0}
\n
inputShape:{1}"
.
format
(
inputName
,
inputShape
))
print
(
"inputName:{0}
\n
inputShape:{1}"
.
format
(
inputName
,
inputShape
))
...
@@ -100,9 +92,7 @@ if __name__ == '__main__':
...
@@ -100,9 +92,7 @@ if __name__ == '__main__':
img
=
img
.
to
(
device
)
img
=
img
.
to
(
device
)
scale
=
scale
.
to
(
device
)
scale
=
scale
.
to
(
device
)
tic
=
time
.
time
()
loc
,
conf
,
landms
=
migraphx_run
(
model
,
args
.
cpu
,
img
)
# forward pass
loc
,
conf
,
landms
=
migraphx_run
(
model
,
args
.
cpu
,
img
)
# forward pass
print
(
'net forward time: {:.4f}'
.
format
(
time
.
time
()
-
tic
))
priorbox
=
PriorBox
(
cfg
,
image_size
=
(
im_height
,
im_width
))
priorbox
=
PriorBox
(
cfg
,
image_size
=
(
im_height
,
im_width
))
priors
=
priorbox
.
forward
()
priors
=
priorbox
.
forward
()
...
...
Src/RetinaFace.cpp
View file @
474298d4
...
@@ -24,6 +24,7 @@ namespace migraphxSamples
...
@@ -24,6 +24,7 @@ namespace migraphxSamples
DetectorRetinaFace
::
DetectorRetinaFace
()
DetectorRetinaFace
::
DetectorRetinaFace
()
{
{
}
}
DetectorRetinaFace
::~
DetectorRetinaFace
()
DetectorRetinaFace
::~
DetectorRetinaFace
()
...
@@ -38,7 +39,7 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
...
@@ -38,7 +39,7 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
{
{
// 读取配置文件
// 读取配置文件
std
::
string
configFilePath
=
initializationParameterOfDetector
.
configFilePath
;
std
::
string
configFilePath
=
initializationParameterOfDetector
.
configFilePath
;
if
(
Exists
(
configFilePath
)
==
false
)
if
(
!
Exists
(
configFilePath
))
{
{
LOG_ERROR
(
stdout
,
"no configuration file!
\n
"
);
LOG_ERROR
(
stdout
,
"no configuration file!
\n
"
);
return
CONFIG_FILE_NOT_EXIST
;
return
CONFIG_FILE_NOT_EXIST
;
...
@@ -63,7 +64,7 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
...
@@ -63,7 +64,7 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
useFP16
=
(
bool
)(
int
)
netNode
[
"UseFP16"
];
useFP16
=
(
bool
)(
int
)
netNode
[
"UseFP16"
];
// 加载模型
// 加载模型
if
(
Exists
(
modelPath
)
==
false
)
if
(
!
Exists
(
modelPath
))
{
{
LOG_ERROR
(
stdout
,
"%s not exist!
\n
"
,
modelPath
.
c_str
());
LOG_ERROR
(
stdout
,
"%s not exist!
\n
"
,
modelPath
.
c_str
());
return
MODEL_NOT_EXIST
;
return
MODEL_NOT_EXIST
;
...
@@ -72,18 +73,8 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
...
@@ -72,18 +73,8 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
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
::
cout
<<
"inputs:"
<<
std
::
endl
;
std
::
unordered_map
<
std
::
string
,
migraphx
::
shape
>
inputs
=
net
.
get_inputs
();
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
();
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
;
inputName
=
inputs
.
begin
()
->
first
;
inputShape
=
inputs
.
begin
()
->
second
;
inputShape
=
inputs
.
begin
()
->
second
;
int
N
=
inputShape
.
lens
()[
0
];
int
N
=
inputShape
.
lens
()[
0
];
...
@@ -105,6 +96,7 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
...
@@ -105,6 +96,7 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
{
{
srcImages
.
push_back
(
srcImage
);
srcImages
.
push_back
(
srcImage
);
}
}
cv
::
Mat
inputBlob
;
cv
::
Mat
inputBlob
;
cv
::
dnn
::
blobFromImages
(
srcImages
,
cv
::
dnn
::
blobFromImages
(
srcImages
,
inputBlob
,
inputBlob
,
...
@@ -113,6 +105,7 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
...
@@ -113,6 +105,7 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
meanValue
,
meanValue
,
swapRB
,
swapRB
,
false
);
false
);
std
::
unordered_map
<
std
::
string
,
migraphx
::
argument
>
inputData
;
std
::
unordered_map
<
std
::
string
,
migraphx
::
argument
>
inputData
;
inputData
[
inputName
]
=
migraphx
::
argument
{
inputShape
,
(
float
*
)
inputBlob
.
data
};
inputData
[
inputName
]
=
migraphx
::
argument
{
inputShape
,
(
float
*
)
inputBlob
.
data
};
std
::
vector
<
std
::
unordered_map
<
std
::
string
,
migraphx
::
argument
>>
calibrationData
=
{
inputData
};
std
::
vector
<
std
::
unordered_map
<
std
::
string
,
migraphx
::
argument
>>
calibrationData
=
{
inputData
};
...
@@ -134,7 +127,7 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
...
@@ -134,7 +127,7 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
// warm up
// warm up
std
::
unordered_map
<
std
::
string
,
migraphx
::
argument
>
inputData
;
std
::
unordered_map
<
std
::
string
,
migraphx
::
argument
>
inputData
;
inputData
[
inputName
]
=
migraphx
::
argument
{
inputShape
};
inputData
[
inputName
]
=
migraphx
::
argument
{
inputShape
};
net
.
eval
(
inputData
);
net
.
eval
(
inputData
);
// log
// log
...
@@ -151,7 +144,6 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
...
@@ -151,7 +144,6 @@ ErrorCode DetectorRetinaFace::Initialize(InitializationParameterOfDetector initi
GetSSDParameter
();
GetSSDParameter
();
return
SUCCESS
;
return
SUCCESS
;
}
}
ErrorCode
DetectorRetinaFace
::
Detect
(
const
cv
::
Mat
&
srcImage
,
std
::
vector
<
ResultOfDetection
>
&
resultsOfDetection
)
ErrorCode
DetectorRetinaFace
::
Detect
(
const
cv
::
Mat
&
srcImage
,
std
::
vector
<
ResultOfDetection
>
&
resultsOfDetection
)
...
@@ -219,7 +211,6 @@ ErrorCode DetectorRetinaFace::Detect(const cv::Mat &srcImage,std::vector<ResultO
...
@@ -219,7 +211,6 @@ ErrorCode DetectorRetinaFace::Detect(const cv::Mat &srcImage,std::vector<ResultO
sort
(
resultsOfDetection
.
begin
(),
resultsOfDetection
.
end
(),
CompareConfidence
);
sort
(
resultsOfDetection
.
begin
(),
resultsOfDetection
.
end
(),
CompareConfidence
);
return
SUCCESS
;
return
SUCCESS
;
}
}
void
DetectorRetinaFace
::
GetSSDParameter
()
void
DetectorRetinaFace
::
GetSSDParameter
()
...
@@ -1129,6 +1120,4 @@ void DetectorRetinaFace::CreateDetectionResults(std::vector<ResultOfDetection> &
...
@@ -1129,6 +1120,4 @@ void DetectorRetinaFace::CreateDetectionResults(std::vector<ResultOfDetection> &
}
}
}
}
}
}
Src/main.cpp
View file @
474298d4
...
@@ -24,11 +24,7 @@ int main()
...
@@ -24,11 +24,7 @@ int main()
// 推理
// 推理
std
::
vector
<
migraphxSamples
::
ResultOfDetection
>
predictions
;
std
::
vector
<
migraphxSamples
::
ResultOfDetection
>
predictions
;
double
time1
=
cv
::
getTickCount
();
detector
.
Detect
(
srcImage
,
predictions
);
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
"
);
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