2022-04-28 21:01:45 +08:00
# Rosetta
2022-04-28 20:49:40 +08:00
2022-04-29 11:57:26 +08:00
- [1. Introduction ](#1 )
- [2. Environment ](#2 )
- [3. Model Training / Evaluation / Prediction ](#3 )
2022-04-28 20:49:40 +08:00
- [3.1 Training ](#3-1 )
- [3.2 Evaluation ](#3-2 )
2022-04-28 20:57:11 +08:00
- [3.3 Prediction ](#3-3 )
2022-04-29 11:57:26 +08:00
- [4. Inference and Deployment ](#4 )
- [4.1 Python Inference ](#4-1 )
- [4.2 C++ Inference ](#4-2 )
- [4.3 Serving ](#4-3 )
- [4.4 More ](#4-4 )
2022-04-28 20:49:40 +08:00
- [5. FAQ ](#5 )
< a name = "1" > < / a >
2022-04-29 11:57:26 +08:00
## 1. Introduction
2022-04-28 20:49:40 +08:00
Paper information:
> [Rosetta: Large Scale System for Text Detection and Recognition in Images](https://arxiv.org/abs/1910.05085)
> Borisyuk F , Gordo A , V Sivakumar
> KDD, 2018
Using MJSynth and SynthText two text recognition datasets for training, and evaluating on IIIT, SVT, IC03, IC13, IC15, SVTP, CUTE datasets, the algorithm reproduction effect is as follows:
|Models|Backbone Networks|Configuration Files|Avg Accuracy|Download Links|
| --- | --- | --- | --- | --- |
|Rosetta|Resnet34_vd|[configs/rec/rec_r34_vd_none_none_ctc.yml](../../configs/rec/rec_r34_vd_none_none_ctc.yml)|79.11%|[training model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_none_ctc_v2.0_train.tar)|
|Rosetta|MobileNetV3|[configs/rec/rec_mv3_none_none_ctc.yml](../../configs/rec/rec_mv3_none_none_ctc.yml)|75.80%|[training model](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_none_none_ctc_v2.0_train.tar)|
< a name = "2" > < / a >
2022-04-29 11:57:26 +08:00
## 2. Environment
2022-04-28 21:01:45 +08:00
Please refer to [Operating Environment Preparation ](./environment_en.md ) to configure the PaddleOCR operating environment, and refer to [Project Clone ](./clone_en.md ) to clone the project code.
2022-04-28 20:49:40 +08:00
< a name = "3" > < / a >
2022-04-29 11:57:26 +08:00
## 3. Model Training / Evaluation / Prediction
2022-04-28 20:49:40 +08:00
2022-04-28 20:57:11 +08:00
Please refer to [Text Recognition Training Tutorial ](./recognition_en.md ). PaddleOCR modularizes the code, and training different recognition models only requires **changing the configuration file** . Take the backbone network based on Resnet34_vd as an example:
2022-04-28 20:49:40 +08:00
< a name = "3-1" > < / a >
### 3.1 Training
````
#Single card training (long training period, not recommended)
python3 tools/train.py -c configs/rec/rec_r34_vd_none_none_ctc.yml
#Multi-card training, specify the card number through the --gpus parameter
python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/rec_r34_vd_none_none_ctc.yml
````
< a name = "3-2" > < / a >
### 3.2 Evaluation
````
# GPU evaluation, Global.pretrained_model is the model to be evaluated
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_r34_vd_none_none_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy
````
< a name = "3-3" > < / a >
### 3.3 Prediction
````
python3 tools/infer_rec.py -c configs/rec/rec_r34_vd_none_none_ctc.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
````
< a name = "4" > < / a >
2022-04-29 11:57:26 +08:00
## 4. Inference and Deployment
2022-04-28 20:49:40 +08:00
< a name = "4-1" > < / a >
2022-04-29 11:57:26 +08:00
### 4.1 Python Inference
2022-04-28 20:49:40 +08:00
First, convert the model saved during the Rosetta text recognition training process into an inference model. Take the model trained on the MJSynth and SynthText text recognition datasets based on the Resnet34_vd backbone network as an example ( [Model download address ](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_r34_vd_none_none_ctc_v2.0_train.tar ) ), which can be converted using the following command:
```shell
python3 tools/export_model.py -c configs/rec/rec_r34_vd_none_none_ctc.yml -o Global.pretrained_model=./rec_r34_vd_none_none_ctc_v2.0_train/best_accuracy Global.save_inference_dir=./inference/rec_rosetta
````
Rosetta text recognition model inference, you can execute the following commands:
```shell
2022-04-29 11:57:26 +08:00
python3 tools/infer/predict_rec.py --image_dir="doc/imgs_words/en/word_1.png" --rec_model_dir="./inference/rec_rosetta/" --rec_image_shape="3, 32, 100" --rec_char_dict_path= "./ppocr/utils/ic15_dict.txt"
````
The inference results are as follows:

````
Predicts of doc/imgs_words/en/word_1.png:('joint', 0.9999982714653015)
2022-04-28 20:49:40 +08:00
````
< a name = "4-2" > < / a >
2022-04-29 11:57:26 +08:00
### 4.2 C++ Inference
2022-04-28 20:49:40 +08:00
Not currently supported
< a name = "4-3" > < / a >
2022-04-29 11:57:26 +08:00
### 4.3 Serving
2022-04-28 20:49:40 +08:00
Not currently supported
< a name = "4-4" > < / a >
2022-04-29 11:57:26 +08:00
### 4.4 More
2022-04-28 20:49:40 +08:00
The Rosetta model also supports the following inference deployment methods:
- Paddle2ONNX Inference: After preparing the inference model, refer to the [paddle2onnx ](../../deploy/paddle2onnx/ ) tutorial.
< a name = "5" > < / a >
## 5. FAQ
## Quote
````bibtex
@inproceedings {2018Rosetta,
title={Rosetta: Large Scale System for Text Detection and Recognition in Images},
author={ Borisyuk, Fedor and Gordo, Albert and Sivakumar, Viswanath },
booktitle={the 24th ACM SIGKDD International Conference},
year={2018},
}
````