README.md 4.3 KB
Newer Older
M
MRXLT 已提交
1 2
# OCR 

W
wangjiawei04 已提交
3 4
(English|[简体中文](./README_CN.md))

M
MRXLT 已提交
5 6 7 8
## Get Model
```
python -m paddle_serving_app.package --get_model ocr_rec
tar -xzvf ocr_rec.tar.gz
W
wangjiawei04 已提交
9 10
python -m paddle_serving_app.package --get_model ocr_det
tar -xzvf ocr_det.tar.gz
M
MRXLT 已提交
11
```
W
wangjiawei04 已提交
12

J
Jiawei Wang 已提交
13
## Get Dataset (Optional)
W
wangjiawei04 已提交
14 15 16 17 18
```
wget --no-check-certificate https://paddle-serving.bj.bcebos.com/ocr/test_imgs.tar
tar xf test_imgs.tar
```

W
wangjiawei04 已提交
19 20 21 22 23
## Web Service

### Start Service

```
24 25 26 27 28
#choose one of cpu/gpu commands as following
#for cpu user
python -m paddle_serving_server.serve --model ocr_det_model --port 9293
python ocr_web_server.py cpu
#for gpu user
Z
zhangjun 已提交
29
python -m paddle_serving_server.serve --model ocr_det_model --port 9293 --gpu_id 0
30
python ocr_web_server.py gpu
W
wangjiawei04 已提交
31 32 33 34
```

### Client Prediction
```
W
wangjiawei04 已提交
35 36
python ocr_web_client.py
```
W
wangjiawei04 已提交
37
If you want a faster web service, please try Web LocalPredictor Service
W
wangjiawei04 已提交
38

W
wangjiawei04 已提交
39
## Web LocalPredictor Service
W
wangjiawei04 已提交
40
```
41 42 43 44 45
#choose one of cpu/gpu commands as following
#for cpu user
python ocr_debugger_server.py cpu
#for gpu user
python ocr_debugger_server.py gpu 
W
wangjiawei04 已提交
46 47
```

W
wangjiawei04 已提交
48
## Web LocalPredictor Client Prediction
W
wangjiawei04 已提交
49
```
J
Jiawei Wang 已提交
50
python ocr_web_client.py
M
MRXLT 已提交
51
```
W
wangjiawei04 已提交
52 53 54 55

## Benchmark

CPU: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz * 40
W
wangjiawei04 已提交
56

W
wangjiawei04 已提交
57 58
GPU: Nvidia Tesla V100 * 1

W
wangjiawei04 已提交
59 60
Dataset: RCTW 500 sample images

W
wangjiawei04 已提交
61 62
| engine                       | client read image(ms) | client-server tras time(ms) | server read image(ms) | det pre(ms) | det infer(ms) | det post(ms) | rec pre(ms) | rec infer(ms) | rec post(ms) | server-client trans time(ms) | server side time consumption(ms) | server side overhead(ms) | total time(ms) |
|------------------------------|----------------|----------------------------|------------------|--------------------|------------------|--------------------|--------------------|------------------|--------------------|--------------------------|--------------------|--------------|---------------|
J
Jiawei Wang 已提交
63
| Serving web service          | 8.69         | 13.41                      | 109.97           | 2.82               | 87.76            | 4.29               | 3.98               | 78.51            | 3.66               | 4.12                     | 181.02             | 136.49       | 317.51        |
W
wangjiawei04 已提交
64
| Serving LocalPredictor web service |  8.73        | 16.42                      | 115.27           | 2.93               | 20.63            | 3.97               | 4.48               | 13.84            | 3.60               | 6.91                     | 49.45              | 147.33       | 196.78        |
J
Jiawei Wang 已提交
65

J
Jiawei Wang 已提交
66
## Appendix: For Users who want to launch Det or Rec only
J
Jiawei Wang 已提交
67 68 69 70 71
if you are going to detect images not recognize it or directly recognize the words from images. We also provide Det and Rec server for you.

### Det Server 

```
72 73
python det_web_server.py cpu #for cpu user
python det_web_server.py gpu #for gpu user
J
Jiawei Wang 已提交
74
#or
75 76
python det_debugger_server.py cpu #for cpu user
python det_debugger_server.py gpu #for gpu user
J
Jiawei Wang 已提交
77 78 79 80 81 82 83 84 85 86 87 88
```

### Det Client

```
# also use ocr_web_client.py
python ocr_web_client.py
```

### Rec Server

```
89 90
python rec_web_server.py cpu #for cpu user
python rec_web_server.py gpu #for gpu user
J
Jiawei Wang 已提交
91
#or
92 93
python rec_debugger_server.py cpu #for cpu user
python rec_debugger_server.py gpu #for gpu user
J
Jiawei Wang 已提交
94 95 96 97 98 99 100
```

### Rec Client

```
python rec_web_client.py
```
T
fix doc  
Thomas Young 已提交
101 102 103

## C++ OCR Service

T
fff  
Thomas Young 已提交
104
**Notice:** If you need to concatenate det model and rec model, and do pre-processing and post-processing in Paddle Serving C++ framework, you need to use the C++ server compiled with WITH_OPENCV option,see the [COMPILE.md](../../../doc/COMPILE.md)
T
fix doc  
Thomas Young 已提交
105 106 107 108 109 110 111 112 113

### Start Service
Select a startup mode according to CPU / GPU device

After the -- model parameter, the folder path of multiple model files is passed in to start the prediction service of multiple model concatenation.
```
#for cpu user
python -m paddle_serving_server.serve --model ocr_det_model ocr_rec_model --port 9293
#for gpu user
T
Thomas Young 已提交
114
python -m paddle_serving_server.serve --model ocr_det_model ocr_rec_model --port 9293 --gpu_id 0
T
fix doc  
Thomas Young 已提交
115 116 117 118 119 120 121 122 123 124 125
```

### Client Prediction
The pre-processing and post-processing is in the C + + server part, the image's Base64 encoded string is passed into the C + + server.

so the value of parameter `feed_var` which is in the file `ocr_det_client/serving_client_conf.prototxt` should be changed.

for this case, `feed_type` should be 3(which means the data type is string),`shape` should be 1.

By passing in multiple client folder paths, the client can be started for multi model prediction.
```
H
HexToString 已提交
126
python ocr_cpp_client.py ocr_det_client ocr_rec_client
T
fix doc  
Thomas Young 已提交
127
```