README.md 2.51 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的文字序列特征提取模块。

Your Name's avatar
Your Name committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## 构建安装

在光源可拉取推理的docker镜像,CRNN 模型推理推荐的镜像如下:

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

### 安装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
30

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

Your Name's avatar
Your Name committed
33
34

### 安装OpenCV并构建工程
Your Name's avatar
Your Name committed
35
36

```
Your Name's avatar
Your Name committed
37
rbuild build -d depend
Your Name's avatar
Your Name committed
38
39
```

Your Name's avatar
Your Name committed
40
41
42
43
44
### 设置环境变量

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

**Centos**:
Your Name's avatar
Your Name committed
45
46

```
Your Name's avatar
Your Name committed
47
export LD_LIBRARY_PATH=<path_to_migraphx_samples>/depend/lib64/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
48
49
```

Your Name's avatar
Your Name committed
50
51
52
53
54
**Ubuntu**:

```
export LD_LIBRARY_PATH=<path_to_migraphx_samples>/depend/lib/:$LD_LIBRARY_PATH
```
Your Name's avatar
Your Name committed
55

Your Name's avatar
Your Name committed
56
然后执行:
Your Name's avatar
Your Name committed
57
58

```
Your Name's avatar
Your Name committed
59
60
61
62
63
64
65
66
67
68
69
70
71
source ~/.bashrc
```

## 推理

### C++版本推理

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

1. 静态推理

```
./MIGraphX_Samples a
Your Name's avatar
Your Name committed
72
73
```

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

Your Name's avatar
Your Name committed
76
![text0](./Resource/Images/CrnnDynamicPic/text0.jpg)
Your Name's avatar
Your Name committed
77
78
79
80
81
82
83

文本识别结果为:

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

Your Name's avatar
Your Name committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
2. 动态shape推理

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

# 执行动态推理
./MIGraphX_Samples b
```

文本识别结果:

```
available
migraphx
waiting
recognition
```

### python版本推理

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

```
# 进入python示例目录
cd ./Python

# 安装依赖
pip install -r requirements.txt

# 运行程序
python Crnn_infer_migraphx.py 
```

该python示例输入样本图像与C++在静态推理中一致,文本识别结果为:

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

Your Name's avatar
Your Name committed
124
125
126
127
128
129
130
## 历史版本

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

## 参考

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