README.md 2.48 KB
Newer Older
Your Name's avatar
Your Name committed
1
# Convolutional Recurrent Neural Network(CRNN)
shizhm's avatar
shizhm committed
2

Your Name's avatar
Your Name committed
3
4
5
6
7
8
9
10
## 模型介绍

CRNN是文本识别领域的一种经典算法,该算法的主要思想是认为文本识别需要对序列进行预测,所以采用了预测序列常用的RNN网络。算法通过CNN提取图片特征,然后采用RNN对序列进行预测,最终使用CTC方法得到最终结果。

## 模型结构

CRNN模型的主要结构包括基于CNN的图像特征提取模块以及基于双向LSTM的文字序列特征提取模块。

shizhm's avatar
shizhm committed
11
## Python版本推理
liucong's avatar
liucong committed
12

shizhm's avatar
shizhm committed
13
下面介绍如何运行Python代码示例,Python示例的详细说明见Doc目录下的Tutorial_Python.md。
liucong's avatar
liucong committed
14

shizhm's avatar
shizhm committed
15
### 下载镜像
Your Name's avatar
Your Name committed
16

liucong's avatar
liucong committed
17
下载MIGraphX镜像: 
Your Name's avatar
Your Name committed
18
19

```python
liucong's avatar
liucong committed
20
docker pull sugonhub/migraphx:3.2.1-centos7.6-dtk-23.04.1-py38
Your Name's avatar
Your Name committed
21
22
```

shizhm's avatar
shizhm committed
23
24
25
26
27
28
29
### 设置Python环境变量

```
export PYTHONPATH=/opt/dtk/lib:$PYTHONPATH
```

### 安装依赖
liucong's avatar
liucong committed
30
31
32
33
34

CRNN工程的Python推理示例仅提供静态推理,可使用如下命令运行:

```
# 进入python示例目录
shizhm's avatar
shizhm committed
35
cd <path_to_crnn_migraphx>/Python
liucong's avatar
liucong committed
36
37
38

# 安装依赖
pip install -r requirements.txt
shizhm's avatar
shizhm committed
39
40
41
42
43
```

### 运行示例

在Python目录下执行如下命令运行该示例程序:
liucong's avatar
liucong committed
44

shizhm's avatar
shizhm committed
45
```
liucong's avatar
liucong committed
46
47
48
python Crnn_infer_migraphx.py 
```

shizhm's avatar
shizhm committed
49
文本识别结果为:
liucong's avatar
liucong committed
50
51
52
53
54
55
56

```
a-----v--a-i-l-a-bb-l-e--- => available
```

## C++版本推理

shizhm's avatar
shizhm committed
57
58
59
60
下面介绍如何运行C++代码示例,C++示例的详细说明见Doc目录下的Tutorial_Cpp.md。

### 下载镜像

liucong's avatar
liucong committed
61
下载MIGraphX镜像: 
liucong's avatar
liucong committed
62

shizhm's avatar
shizhm committed
63
```
liucong's avatar
liucong committed
64
docker pull sugonhub/migraphx:3.2.1-centos7.6-dtk-23.04.1-py38
shizhm's avatar
shizhm committed
65
```
liucong's avatar
liucong committed
66

Your Name's avatar
Your Name committed
67

shizhm's avatar
shizhm committed
68
### 构建工程
Your Name's avatar
Your Name committed
69
70

```
Your Name's avatar
Your Name committed
71
rbuild build -d depend
Your Name's avatar
Your Name committed
72
73
```

Your Name's avatar
Your Name committed
74
75
76
77
### 设置环境变量

将依赖库依赖加入环境变量LD_LIBRARY_PATH,在~/.bashrc中添加如下语句:

Your Name's avatar
Your Name committed
78
```
shizhm's avatar
shizhm committed
79
export LD_LIBRARY_PATH=<path_to_crnn_migraphx>/depend/lib64/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
80
81
```

Your Name's avatar
Your Name committed
82
然后执行:
Your Name's avatar
Your Name committed
83
84

```
Your Name's avatar
Your Name committed
85
86
87
source ~/.bashrc
```

shizhm's avatar
shizhm committed
88
### 运行示例
Your Name's avatar
Your Name committed
89

shizhm's avatar
shizhm committed
90
91
92
93
94
95
96
97
98
成功编译CRNN工程后,执行如下命令运行该示例:

```
# 进入crnn migraphx工程根目录
cd <path_to_crnn_migraphx> 

# 进入build目录
cd build/
```
Your Name's avatar
Your Name committed
99
100
101
102

1. 静态推理

```
liucong's avatar
liucong committed
103
./CRNN 0
Your Name's avatar
Your Name committed
104
105
```

Your Name's avatar
Your Name committed
106
静态推理示例输入样本图像为:
Your Name's avatar
Your Name committed
107

Your Name's avatar
Your Name committed
108
![text0](./Resource/Images/CrnnDynamicPic/text0.jpg)
Your Name's avatar
Your Name committed
109
110
111
112
113
114
115

文本识别结果为:

```
a-----v--a-i-l-a-bb-l-e--- => available
```

Your Name's avatar
Your Name committed
116
117
118
119
120
121
2. 动态shape推理

```
# 开启环境变量
export MIGRAPHX_DYNAMIC_SHAPE=1

shizhm's avatar
shizhm committed
122
# 执行动态推理示例程序
liucong's avatar
liucong committed
123
./CRNN 1
Your Name's avatar
Your Name committed
124
125
126
127
128
129
130
131
132
133
134
```

文本识别结果:

```
available
migraphx
waiting
recognition
```

shizhm's avatar
shizhm committed
135
## 源码仓库及问题反馈
Your Name's avatar
Your Name committed
136
137
138
139
140
141

​		https://developer.hpccube.com/codes/modelzoo/crnn_migraphx

## 参考

​		https://github.com/meijieru/crnn.pytorch