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

liucong's avatar
liucong committed
11
12
13
14
15
## python版本推理

下面介绍如何运行python代码示例,具体推理代码解析,在Doc/Tutorial_Python.md中有详细说明。

### 拉取镜像
Your Name's avatar
Your Name committed
16
17
18
19
20
21
22

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

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

liucong's avatar
liucong committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
### 推理示例

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
```

## C++版本推理

下面介绍如何运行C++代码示例,具体推理代码解析,在Doc/Tutorial_Cpp.md目录中有详细说明。

参考Python版本推理中的构建安装,在光源中拉取推理的docker镜像。

Your Name's avatar
Your Name committed
50
51
52
53
54
55
56
57
58
59
60
### 安装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
61

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

Your Name's avatar
Your Name committed
64
65

### 安装OpenCV并构建工程
Your Name's avatar
Your Name committed
66
67

```
Your Name's avatar
Your Name committed
68
rbuild build -d depend
Your Name's avatar
Your Name committed
69
70
```

Your Name's avatar
Your Name committed
71
72
73
74
75
### 设置环境变量

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

**Centos**:
Your Name's avatar
Your Name committed
76
77

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

Your Name's avatar
Your Name committed
81
82
83
84
85
**Ubuntu**:

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

Your Name's avatar
Your Name committed
87
然后执行:
Your Name's avatar
Your Name committed
88
89

```
Your Name's avatar
Your Name committed
90
91
92
source ~/.bashrc
```

liucong's avatar
liucong committed
93
### 推理示例
Your Name's avatar
Your Name committed
94
95
96
97
98
99

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

1. 静态推理

```
liucong's avatar
liucong committed
100
./MIGraphX_Samples 0
Your Name's avatar
Your Name committed
101
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
![text0](./Resource/Images/CrnnDynamicPic/text0.jpg)
Your Name's avatar
Your Name committed
106
107
108
109
110
111
112

文本识别结果为:

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

Your Name's avatar
Your Name committed
113
114
115
116
117
118
119
2. 动态shape推理

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

# 执行动态推理
liucong's avatar
liucong committed
120
./MIGraphX_Samples 1
Your Name's avatar
Your Name committed
121
122
123
124
125
126
127
128
129
130
131
```

文本识别结果:

```
available
migraphx
waiting
recognition
```

Your Name's avatar
Your Name committed
132
133
134
135
136
137
138
## 历史版本

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

## 参考

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