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_migraphx
Commits
1c515e55
Commit
1c515e55
authored
Nov 09, 2023
by
liucong
Browse files
重构C++版本的数据预处理操作
parent
b4a869e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
8 deletions
+16
-8
Src/Classifier.cpp
Src/Classifier.cpp
+14
-8
Src/Classifier.h
Src/Classifier.h
+2
-0
No files found.
Src/Classifier.cpp
View file @
1c515e55
...
...
@@ -193,14 +193,8 @@ ErrorCode Classifier::Initialize(InitializationParameterOfClassifier initializat
}
ErrorCode
Classifier
::
Classify
(
const
std
::
vector
<
cv
::
Mat
>
&
srcImages
,
std
::
vector
<
std
::
vector
<
ResultOfPrediction
>>
&
predictions
)
cv
::
Mat
Classifier
::
Preprocess
(
const
std
::
vector
<
cv
::
Mat
>
&
srcImages
)
{
if
(
srcImages
.
size
()
==
0
||
srcImages
[
0
].
empty
()
||
srcImages
[
0
].
depth
()
!=
CV_8U
)
{
LOG_ERROR
(
stdout
,
"image error!
\n
"
);
return
IMAGE_ERROR
;
}
// 数据预处理
std
::
vector
<
cv
::
Mat
>
image
;
for
(
int
i
=
0
;
i
<
srcImages
.
size
();
++
i
)
...
...
@@ -236,6 +230,18 @@ ErrorCode Classifier::Classify(const std::vector<cv::Mat> &srcImages,std::vector
image2BlobParams
.
mean
=
cv
::
Scalar
(
123.675
,
116.28
,
103.53
);
image2BlobParams
.
swapRB
=
false
;
blobFromImagesWithParams
(
image
,
inputBlob
,
image2BlobParams
);
return
inputBlob
;
}
ErrorCode
Classifier
::
Classify
(
const
std
::
vector
<
cv
::
Mat
>
&
srcImages
,
std
::
vector
<
std
::
vector
<
ResultOfPrediction
>>
&
predictions
)
{
if
(
srcImages
.
size
()
==
0
||
srcImages
[
0
].
empty
()
||
srcImages
[
0
].
depth
()
!=
CV_8U
)
{
LOG_ERROR
(
stdout
,
"image error!
\n
"
);
return
IMAGE_ERROR
;
}
cv
::
Mat
inputBlob
=
Preprocess
(
srcImages
);
// 当offload为true时,不需要内存拷贝
if
(
useoffloadcopy
)
...
...
@@ -282,7 +288,7 @@ ErrorCode Classifier::Classify(const std::vector<cv::Mat> &srcImages,std::vector
else
// 当offload为false时,需要内存拷贝
{
migraphx
::
argument
inputData
=
migraphx
::
argument
{
inputShape
,
(
float
*
)
inputBlob
.
data
};
migraphx
::
argument
inputData
=
migraphx
::
argument
{
inputShape
,
(
float
*
)
inputBlob
.
data
};
// 拷贝到device输入内存
hipMemcpy
(
inputBuffer_Device
,
inputData
.
data
(),
inputShape
.
bytes
(),
hipMemcpyHostToDevice
);
...
...
Src/Classifier.h
View file @
1c515e55
...
...
@@ -17,6 +17,8 @@ public:
ErrorCode
Initialize
(
InitializationParameterOfClassifier
initializationParameterOfClassifier
);
cv
::
Mat
Preprocess
(
const
std
::
vector
<
cv
::
Mat
>
&
srcImages
);
ErrorCode
Classify
(
const
std
::
vector
<
cv
::
Mat
>
&
srcImages
,
std
::
vector
<
std
::
vector
<
ResultOfPrediction
>>
&
predictions
);
private:
...
...
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