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
PaddleOCR_migraphx
Commits
6878b65f
Commit
6878b65f
authored
Jun 08, 2023
by
shizhm
Browse files
完善代码和文档
parent
97c70f1a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
98 deletions
+58
-98
CMakeLists.txt
CMakeLists.txt
+3
-3
Python/PaddleOCR_infer_migraphx.py
Python/PaddleOCR_infer_migraphx.py
+3
-2
README.md
README.md
+20
-11
Src/Sample.cpp
Src/Sample.cpp
+0
-41
Src/Sample.h
Src/Sample.h
+0
-11
Src/main.cpp
Src/main.cpp
+32
-30
No files found.
CMakeLists.txt
View file @
6878b65f
...
...
@@ -2,7 +2,7 @@
cmake_minimum_required
(
VERSION 3.5
)
# 设置项目名
project
(
MIGraphX_Samples
)
project
(
PaddleOCR_VLPR
)
# 设置编译器
set
(
CMAKE_CXX_COMPILER g++
)
...
...
@@ -37,7 +37,7 @@ link_libraries(${LIBRARY})
# 添加源文件
set
(
SOURCE_FILES
${
CMAKE_CURRENT_SOURCE_DIR
}
/Src/main.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/Src/Sample.cpp
#
${CMAKE_CURRENT_SOURCE_DIR}/Src/Sample.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/Src/PaddleOCR/VLPR/clipper.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/Src/PaddleOCR/VLPR/OcrDB.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/Src/PaddleOCR/VLPR/utility.cpp
...
...
@@ -47,4 +47,4 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/Src/main.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/Src/Utility/Filesystem.cpp
)
# 添加可执行目标
add_executable
(
MIGraphX_Samples
${
SOURCE_FILES
}
)
add_executable
(
PaddleOCR_VLPR
${
SOURCE_FILES
}
)
Python/PaddleOCR_infer_migraphx.py
View file @
6878b65f
...
...
@@ -271,7 +271,7 @@ class process_pred(object):
else
:
conf_list
.
append
(
1
)
text
=
''
.
join
(
char_list
)
result_list
.
append
(
(
text
,
round
(
np
.
mean
(
conf_list
),
2
))
)
result_list
.
append
(
text
)
return
result_list
def
__call__
(
self
,
preds
,
label
=
None
):
...
...
@@ -533,7 +533,8 @@ if __name__=='__main__':
start
=
time
.
time
()
ocr_sys
=
det_rec_functions
(
image
)
dt_boxes
=
ocr_sys
.
get_boxes
()
results_info
=
ocr_sys
.
recognition_img
(
dt_boxes
)
results
=
ocr_sys
.
recognition_img
(
dt_boxes
)
results_info
=
results
[
0
][
0
]
print
(
'net forward time: {:.4f}'
.
format
(
time
.
time
()
-
start
))
print
(
"############# OCR Results #############"
)
...
...
README.md
View file @
6878b65f
...
...
@@ -8,7 +8,9 @@
DBnet是一种基于分割的文本检测方法,相比传统分割方法需要设定固定阈值,该模型将二值化操作插入到分割网络中进行联合优化,通过网络学习可以自适应的预测图像中每一个像素点的阈值,能够在像素水平很好的检测自然场景下不同形状的文字。SVTR是一种端到端的文本识别模型,通过单个视觉模型就可以一站式解决特征提取和文本转录两个任务,同时也保证了更快的推理速度。百度PaddleOCR开源项目提供了车牌识别的预训练模型,本示例使用PaddleOCR提供的蓝绿黄牌识别模型进行推理。
## 构建安装
## C++版本推理
### 拉取镜像
在光源可拉取推理的docker镜像,PaddleOCR工程推荐的镜像如下:
...
...
@@ -19,7 +21,7 @@ docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0
### 安装Opencv依赖
```
python
cd
<
path_to_migraphx
_samples
>
cd
<
path_to_
paddleocr_
migraphx
>
sh
.
/
3
rdParty
/
InstallOpenCVDependences
.
sh
```
...
...
@@ -59,9 +61,7 @@ export LD_LIBRARY_PATH=<path_to_migraphx_samples>/depend/lib/:$LD_LIBRARY_PATH
source ~/.bashrc
```
## 推理
### C++版本推理
### 运行示例
成功编译PaddleOCR车牌识别工程后,在build目录下输入如下命令运行该示例:
...
...
@@ -70,18 +70,22 @@ source ~/.bashrc
export MIGRAPHX_DYNAMIC_SHAPE=1
# 运行示例
./
MIGraphX 0
./
PaddleOCR_VLPR
```
PaddleOCR车牌识别结果为:
```
[
皖AD19906
, 0.999067]
皖AD19906
```
### python版本推理
## python版本推理
PaddleOCR工程同时提供了python推理示例。
### 环境配置
PaddleOCR工程同时提供了python推理示例,可使用如下命令运行
:
python推理示例推荐使用C++版本示例同一镜像,python依赖安装
:
```
# 进入python示例目录
...
...
@@ -89,15 +93,20 @@ cd ./Python
# 安装依赖
pip install -r requirements.txt
```
### 运行示例
# 运行程序
环境配置成功之后,可在当前目录执行如下指令运行程序推理:
```
python PaddleOCR_infer_migraphx.py
```
PaddleOCR车牌识别结果为:
```
[[('
皖AD19906
', 0.99)]]
皖AD19906
```
## 历史版本
...
...
Src/Sample.cpp
deleted
100644 → 0
View file @
97c70f1a
#include <Sample.h>
#include <opencv2/dnn.hpp>
#include <SimpleLog.h>
#include <Filesystem.h>
#include <VLPR.h>
#include <fstream>
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
::
dnn
;
using
namespace
migraphx
;
using
namespace
migraphxSamples
;
void
Sample_VLPR
()
{
// 创建PaddleOCR车牌识别
VLPR
vlpr
;
InitializationParameterOfDB
initParamOfDB
;
InitializationParameterOfSVTR
initParamOfSVTR
;
vlpr
.
Initialize
(
initParamOfDB
,
initParamOfSVTR
);
// 读取测试图片
cv
::
Mat
Image
=
cv
::
imread
(
"../Resource/Images/vlpr.jpg"
,
1
);
// 推理
std
::
vector
<
std
::
string
>
recTexts
;
std
::
vector
<
float
>
recTextScores
;
double
time1
=
getTickCount
();
vlpr
.
Infer
(
Image
,
recTexts
,
recTextScores
);
double
time2
=
getTickCount
();
double
elapsedTime
=
(
time2
-
time1
)
*
1000
/
getTickFrequency
();
LOG_INFO
(
stdout
,
"inference time:%f ms
\n
"
,
elapsedTime
);
// 打印结果
for
(
int
i
=
0
;
i
<
recTexts
.
size
();
i
++
)
{
printf
(
"VLPR Result:[%s, %f]
\n
"
,
recTexts
[
i
].
c_str
(),
recTextScores
[
i
]);
}
}
\ No newline at end of file
Src/Sample.h
deleted
100644 → 0
View file @
97c70f1a
// 示例程序
#ifndef __SAMPLE_H__
#define __SAMPLE_H__
// VLPR sample
void
Sample_VLPR
();
#endif
\ No newline at end of file
Src/main.cpp
View file @
6878b65f
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Sample.h>
#include <opencv2/dnn.hpp>
#include <SimpleLog.h>
#include <Filesystem.h>
#include <VLPR.h>
#include <fstream>
using
namespace
std
;
using
namespace
cv
;
using
namespace
migraphx
;
using
namespace
migraphxSamples
;
void
MIGraphXSamplesUsage
(
char
*
programName
)
{
printf
(
"Usage : %s <index>
\n
"
,
programName
);
printf
(
"index:
\n
"
);
printf
(
"
\t
0) PaddleOCR VLPR sample.
\n
"
);
}
int
main
(
int
argc
,
char
*
argv
[]
)
int
main
()
{
if
(
argc
<
2
||
argc
>
2
)
{
MIGraphXSamplesUsage
(
argv
[
0
]);
return
-
1
;
}
if
(
!
strncmp
(
argv
[
1
],
"-h"
,
2
))
// 创建PaddleOCR车牌识别
VLPR
vlpr
;
InitializationParameterOfDB
initParamOfDB
;
InitializationParameterOfSVTR
initParamOfSVTR
;
vlpr
.
Initialize
(
initParamOfDB
,
initParamOfSVTR
);
// 读取测试图片
cv
::
Mat
Image
=
cv
::
imread
(
"../Resource/Images/2.jpg"
,
1
);
// 推理
std
::
vector
<
std
::
string
>
recTexts
;
std
::
vector
<
float
>
recTextScores
;
double
time1
=
getTickCount
();
vlpr
.
Infer
(
Image
,
recTexts
,
recTextScores
);
double
time2
=
getTickCount
();
double
elapsedTime
=
(
time2
-
time1
)
*
1000
/
getTickFrequency
();
LOG_INFO
(
stdout
,
"inference time:%f ms
\n
"
,
elapsedTime
);
// 打印结果
for
(
int
i
=
0
;
i
<
recTexts
.
size
();
i
++
)
{
MIGraphXSamplesUsage
(
argv
[
0
]);
return
0
;
}
switch
(
*
argv
[
1
])
{
case
'0'
:
{
Sample_VLPR
();
break
;
}
default
:
{
MIGraphXSamplesUsage
(
argv
[
0
]);
break
;
}
printf
(
"VLPR Result:%s
\n
"
,
recTexts
[
i
].
c_str
());
}
return
0
;
}
\ No newline at end of file
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