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
crnn_migraphx
Commits
453f511c
Commit
453f511c
authored
Jun 15, 2023
by
shizhm
Browse files
完善代码格式
parent
165d6c8b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
18 deletions
+15
-18
Src/Crnn.cpp
Src/Crnn.cpp
+15
-17
Src/Crnn.h
Src/Crnn.h
+0
-1
No files found.
Src/Crnn.cpp
View file @
453f511c
#include <Crnn.h>
#include <migraphx/onnx.hpp>
#include <migraphx/gpu/target.hpp>
#include <Filesystem.h>
#include <SimpleLog.h>
...
...
@@ -19,7 +17,7 @@ Crnn::~Crnn()
{
configurationFile
.
release
();
}
ErrorCode
Crnn
::
Initialize
(
InitializationParameterOfOcr
initializationParameterOfOcr
,
bool
dynamic
)
...
...
@@ -50,11 +48,11 @@ ErrorCode Crnn::Initialize(InitializationParameterOfOcr initializationParameterO
}
if
(
dynamic
)
{
{
migraphx
::
onnx_options
onnx_options
;
onnx_options
.
map_input_dims
[
"input"
]
=
{
1
,
1
,
32
,
512
};
net
=
migraphx
::
parse_onnx
(
modelPath
,
onnx_options
);
net
=
migraphx
::
parse_onnx
(
modelPath
,
onnx_options
);
LOG_INFO
(
stdout
,
"succeed to load model: %s
\n
"
,
GetFileName
(
modelPath
).
c_str
());
// 获取模型输入属性
...
...
@@ -76,7 +74,7 @@ ErrorCode Crnn::Initialize(InitializationParameterOfOcr initializationParameterO
migraphx
::
onnx_options
onnx_options
;
onnx_options
.
map_input_dims
[
"input"
]
=
{
1
,
1
,
32
,
100
};
net
=
migraphx
::
parse_onnx
(
modelPath
,
onnx_options
);
net
=
migraphx
::
parse_onnx
(
modelPath
,
onnx_options
);
LOG_INFO
(
stdout
,
"succeed to load model: %s
\n
"
,
GetFileName
(
modelPath
).
c_str
());
// 获取模型输入属性
...
...
@@ -100,14 +98,14 @@ ErrorCode Crnn::Initialize(InitializationParameterOfOcr initializationParameterO
// 编译模型
migraphx
::
compile_options
options
;
options
.
device_id
=
0
;
// 设置GPU设备,默认为0号设备
options
.
offload_copy
=
true
;
net
.
compile
(
gpuTarget
,
options
);
options
.
offload_copy
=
true
;
net
.
compile
(
gpuTarget
,
options
);
LOG_INFO
(
stdout
,
"succeed to compile model: %s
\n
"
,
GetFileName
(
modelPath
).
c_str
());
// warm up
std
::
unordered_map
<
std
::
string
,
migraphx
::
argument
>
inputData
;
inputData
[
inputName
]
=
migraphx
::
argument
{
inputShape
};
net
.
eval
(
inputData
);
net
.
eval
(
inputData
);
return
SUCCESS
;
}
...
...
@@ -122,7 +120,7 @@ ErrorCode Crnn::Infer(const cv::Mat &srcImage, std::vector<char> &resultsChar, b
cv
::
Mat
inputImage
,
inputBlob
;
cv
::
cvtColor
(
srcImage
,
inputImage
,
CV_BGR2GRAY
);
int
height
,
width
,
widthRaw
;
widthRaw
=
inputImage
.
cols
;
if
(
dynamic
)
...
...
@@ -136,12 +134,12 @@ ErrorCode Crnn::Infer(const cv::Mat &srcImage, std::vector<char> &resultsChar, b
height
=
inputImage
.
rows
,
width
=
inputImage
.
cols
;
}
inputBlob
=
cv
::
dnn
::
blobFromImage
(
inputImage
);
for
(
int
i
=
0
;
i
<
width
*
height
;
i
++
)
{
*
((
float
*
)
inputBlob
.
data
+
i
)
=
((
*
((
float
*
)
inputBlob
.
data
+
i
))
/
255.
f
-
0.5
)
/
0.5
;
}
// 创建输入数据
std
::
unordered_map
<
std
::
string
,
migraphx
::
argument
>
inputData
;
if
(
dynamic
)
...
...
@@ -153,13 +151,13 @@ ErrorCode Crnn::Infer(const cv::Mat &srcImage, std::vector<char> &resultsChar, b
{
inputData
[
inputName
]
=
migraphx
::
argument
{
inputShape
,
(
float
*
)
inputBlob
.
data
};
}
// 推理
std
::
vector
<
migraphx
::
argument
>
inferenceResults
=
net
.
eval
(
inputData
);
// 获取推理结果
std
::
vector
<
cv
::
Mat
>
outs
;
migraphx
::
argument
result
=
inferenceResults
[
0
];
migraphx
::
argument
result
=
inferenceResults
[
0
];
// 转换为cv::Mat
migraphx
::
shape
outputShape
=
result
.
get_shape
();
...
...
@@ -168,7 +166,7 @@ ErrorCode Crnn::Infer(const cv::Mat &srcImage, std::vector<char> &resultsChar, b
memcpy
(
out
.
data
,
result
.
data
(),
sizeof
(
float
)
*
outputShape
.
elements
());
outs
.
push_back
(
out
);
std
::
vector
<
int
>
predChars
;
std
::
vector
<
int
>
predChars
;
const
std
::
string
alphabet
=
"-0123456789abcdefghijklmnopqrstuvwxyz"
;
//获取字符索引序列
...
...
@@ -181,7 +179,7 @@ ErrorCode Crnn::Infer(const cv::Mat &srcImage, std::vector<char> &resultsChar, b
int
maxIdx
=
charIdPoint
.
x
;
predChars
.
push_back
(
maxIdx
);
}
//字符转录处理
for
(
uint
i
=
0
;
i
<
predChars
.
size
();
i
++
)
{
...
...
Src/Crnn.h
View file @
453f511c
...
...
@@ -2,7 +2,6 @@
#define __OCR_CRNN_H__
#include <migraphx/program.hpp>
#include <CommonDefinition.h>
namespace
migraphxSamples
...
...
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