README.md 2.93 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

shizhm's avatar
shizhm committed
17
在光源中下载MIGraphX镜像: 
Your Name's avatar
Your Name committed
18
19
20
21
22

```python
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0.0-dtk22.10.1
```

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
61
下面介绍如何运行C++代码示例,C++示例的详细说明见Doc目录下的Tutorial_Cpp.md。

### 下载镜像

在光源中下载MIGraphX镜像: 
liucong's avatar
liucong committed
62

shizhm's avatar
shizhm committed
63
64
65
```
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0.0-dtk22.10.1
```
liucong's avatar
liucong committed
66

Your Name's avatar
Your Name committed
67
68
69
70
71
72
73
74
75
76
77
### 安装Opencv依赖

```python
cd <path_to_migraphx_samples>
sh ./3rdParty/InstallOpenCVDependences.sh
```

### 修改CMakeLists.txt

- 如果使用ubuntu系统,需要修改CMakeLists.txt中依赖库路径:
  将"${CMAKE_CURRENT_SOURCE_DIR}/depend/lib64/"修改为"${CMAKE_CURRENT_SOURCE_DIR}/depend/lib/"
Your Name's avatar
Your Name committed
78

Your Name's avatar
Your Name committed
79
- **MIGraphX2.3.0及以上版本需要c++17**
Your Name's avatar
Your Name committed
80

Your Name's avatar
Your Name committed
81
82

### 安装OpenCV并构建工程
Your Name's avatar
Your Name committed
83
84

```
Your Name's avatar
Your Name committed
85
rbuild build -d depend
Your Name's avatar
Your Name committed
86
87
```

Your Name's avatar
Your Name committed
88
89
90
91
92
### 设置环境变量

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

**Centos**:
Your Name's avatar
Your Name committed
93
94

```
shizhm's avatar
shizhm committed
95
export LD_LIBRARY_PATH=<path_to_crnn_migraphx>/depend/lib64/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
96
97
```

Your Name's avatar
Your Name committed
98
99
100
**Ubuntu**:

```
shizhm's avatar
shizhm committed
101
export LD_LIBRARY_PATH=<path_to_crnn_migraphx>/depend/lib/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
102
```
Your Name's avatar
Your Name committed
103

Your Name's avatar
Your Name committed
104
然后执行:
Your Name's avatar
Your Name committed
105
106

```
Your Name's avatar
Your Name committed
107
108
109
source ~/.bashrc
```

shizhm's avatar
shizhm committed
110
### 运行示例
Your Name's avatar
Your Name committed
111
112
113
114
115
116

成功编译CRNN工程后,在build目录下输入如下命令运行该示例:

1. 静态推理

```
liucong's avatar
liucong committed
117
./CRNN 0
Your Name's avatar
Your Name committed
118
119
```

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

Your Name's avatar
Your Name committed
122
![text0](./Resource/Images/CrnnDynamicPic/text0.jpg)
Your Name's avatar
Your Name committed
123
124
125
126
127
128
129

文本识别结果为:

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

Your Name's avatar
Your Name committed
130
131
132
133
134
135
136
2. 动态shape推理

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

# 执行动态推理
liucong's avatar
liucong committed
137
./CRNN 1
Your Name's avatar
Your Name committed
138
139
140
141
142
143
144
145
146
147
148
```

文本识别结果:

```
available
migraphx
waiting
recognition
```

Your Name's avatar
Your Name committed
149
150
151
152
153
154
155
## 历史版本

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

## 参考

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