You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fine-tuning or training from scratch 'EasyOCR' using '공공행정문서 OCR' dataset from 'AI-Hub'.
1. Usage
Step 1: Environment Setting
Set configurations ('train_easyocr/config_files/config.yaml')
### Environment ###seed: # Seedexperiment_name: # 'train_easyocr/saved_models'에 생성될 폴더 이름입니다.### Dataset ###train_data: # Training set의 디렉토리val_data: # Validation set의 디렉토리select_data: # Subdirectorybatch_ratio:
# Modulate the data ratio in the batch.# For example, when `select_data` is `MJ-ST` and `batch_ratio` is `0.5-0.5`,# the 50% of the batch is filled with 'MJ' and the other 50% of the batch is filled with 'ST'.total_data_usage_ratio: # How much ratio of the data to usetrain_images: # Number of training imagesval_images: # Number of validation imageseval_images: # Number of evaluation images### Data processing ###img_height: # Height of input imageimg_width: # Width of input imagePAD: # If `True` pad to input images to keep aspect ratiocontrast_adjust: # Adjust contrastcharacter:
# 예측에 사용할 문자들# Pre-trained model로서 'korean_g2'를 사용할 것이므로 사용할 문자들을 다음을 참고하여 동일하게 설정합니다. (https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/config.py)sensitive: # Case sensitivitybatch_max_length: # Maximum length of labeldata_filtering_off:
# If `False` filter images containing characters not in `character`# and whose label is longer than `batch_max_length`### Training ###workers: # Same as `num_workers` from `torch.utils.data.DataLoader`batch_size: # Batch sizen_iter: # Number of iterationsval_period: # Period to run validationshow_number: # How many validation result to showcontinue_from:
# Checkpoint from which to continue training# 첫 학습시에는 'korean_g2' (https://github.com/JaidedAI/EasyOCR/releases/download/v1.3/korean_g2.zip)를 사용합니다.strict: # If `False` ignore non-matching keys when loading a model from checkpoint### Optimizer ###adam: # If `True` use `torch.optim.Adam`, if `False` use `torch.optim.Adadelta`lr:
rho:
eps:
grad_clip:
### Model ###Transformation: # `None` or `TPS`FeatureExtraction: # `VGG`, `RCNN` or `ResNet`SequenceModeling: # `None` or `BiLSTM`Prediction: # `CTC` or `Attn`### VGG ###freeze_FeatureFxtraction: # If `True` do not update feature extraction parametersrgb: False # `True` for RGB input imageinput_channel: # `1` for grayscale input image, `3` for RGBoutput_channel: # Output dimension of featrue extraction result### BiLSTM ###freeze_SequenceModeling: # If `True` do not update sequence modeling parametershidden_size: # `hidden_size` of `torch.nn.LSTM`### Prediction ###new_prediction: False # If `True` dimension of model prediction changes according to checkpoint### CTC ###decode: # `greedy` or `beamsearch`
Run source step1_set_environment.sh
Step 2: Dataset Preparation
'공공행정문서 OCR' dataset
전체 데이터셋의 크기가 너무 커서 학습시키기에 어려움이 있으므로 아래 디렉토리 구조에 나타난 데이터만을 대상으로 했습니다.
# 'step5_run_evaluate_py.sh'
python3 evaluate.py\
--eval_set="/data/evaluation_set"\ # Path to the evaluation set
--baseline\ # Whether to evaluate EasyOCR baseline model
--finetuned\ # Whether to evaluate fine-tuned model
--cuda # Whether to use GPU
1) Metric
Text detection에 대해서는 'IoU >= 0.5'인 경우를 True positive로 하는 F1 score를, Text recognition에 대해서는 CER (Character Error Rate)를 사용했습니다.
그러나 위와 같이 Text detection과 Text recognition 각각에 대해서 평가하는 방법으로는 End-to-end evaluation을 실현할 수 없습니다. 따라서 'IoU >= 0.5'인 경우에 한해 CER을 측정하여 '1 - CER'로서 계산한 Score를 사용해 True positive, False positive, False negative를 측정했습니다. 이를 바탕으로 F1 score를 계산하여 최종 Metric으로 사용했습니다.
즉 완전히 Ground truth를 맞히기 위해서는 'IoU >= 0.5'이 되도록 Text detection을 수행하고 'CER = 0'이 되도록 Text recognition을 수행해야만 합니다. 'CER = 0'이라 하더라도 'IoU < 0.5'라면 예측이 전혀 맞지 않은 것이며 `IoU >= 0.5'라면 CER에 따라서 일종의 부분점수를 받게 됩니다.
예측 결과 'RIVER'의 부분점수는 0.56 ('1 - CER')이고 예측 결과 'SIDE'는 'IoU < 0.5'이므로 부분점수가 0입니다. 따라서 합은 0.56입니다.
Merged case:
바람직한 점수는 1입니다.
예측 결과 'RIVERSIDE'는 IoU가 가장 정답 'RIVER'과 대응합니다. 따라서 정답 'SIDE'에 대한 부분점수는 0이고 정답 'RIVER'에 대한 부분점수는 0.2입니다. 따라서 합은 0.2입니다.
Missing characters
바람직한 점수는 0.56입니다.
예측 결과 'SIDE'는 'IoU < 0.5'이므로 부분점수가 0입니다.
Overlapping characters
바람직한 점수는 1입니다.
예측 결과 'RIVER'과 'RSIDE' 모두 'IoU >= 0.5'라고 가정하면 둘 다 부분점수가 0.56이므로 합은 1.12입니다.
2) Dataset
'공종행정문서 OCR'의 전체 384.9GB 중 79.4GB (20%)밖에 사용하지 못했습니다. 그 이유는 첫째, 네트워크 속도가 제한되어 있는 상황 하에서 데이터셋을 다운로드 받는 데 매우 많은 시간이 소요되었으며 둘째, 사용 가능한 컴퓨팅 자원의 한계로 학습 중 자꾸 서버가 다운되는 현상이 발생하였기 때문입니다.
위와 비슷한 이유로 40,000개의 이미지에 대해서 약 1 epoch밖에 학습시키지 못했습니다.