From d24a39df880603d0f5f25261e659f226c120f9a2 Mon Sep 17 00:00:00 2001 From: tink2123 Date: Tue, 12 May 2020 19:55:16 +0800 Subject: [PATCH] use public function for inference --- configs/rec/rec_chinese_lite_train.yml | 42 -------- configs/rec/rec_chinese_reader.yml | 13 --- ...ic15_reader.yml => rec_icdar15_reader.yml} | 1 + ...c_ic15_train.yml => rec_icdar15_train.yml} | 9 +- ppocr/data/rec/dataset_traversal.py | 11 +- ppocr/utils/ic15_dict.txt | 102 +++++------------- set_env.sh | 10 -- tools/infer_rec.py | 9 +- 8 files changed, 36 insertions(+), 161 deletions(-) delete mode 100755 configs/rec/rec_chinese_lite_train.yml delete mode 100755 configs/rec/rec_chinese_reader.yml rename configs/rec/{rec_ic15_reader.yml => rec_icdar15_reader.yml} (94%) rename configs/rec/{rec_ic15_train.yml => rec_icdar15_train.yml} (82%) delete mode 100644 set_env.sh diff --git a/configs/rec/rec_chinese_lite_train.yml b/configs/rec/rec_chinese_lite_train.yml deleted file mode 100755 index 738aaa81..00000000 --- a/configs/rec/rec_chinese_lite_train.yml +++ /dev/null @@ -1,42 +0,0 @@ -Global: - algorithm: CRNN - use_gpu: true - epoch_num: 300 - log_smooth_window: 20 - print_batch_step: 10 - save_model_dir: output - save_epoch_step: 3 - eval_batch_step: 2000 - train_batch_size_per_card: 256 - test_batch_size_per_card: 256 - image_shape: [3, 32, 100] - max_text_length: 25 - character_type: ch - character_dict_path: ./ppocr/utils/ppocr_keys_v1.txt - loss_type: ctc - reader_yml: ./configs/rec/rec_chinese_reader.yml - pretrain_weights: - infer_img: ./infer_img - -Architecture: - function: ppocr.modeling.architectures.rec_model,RecModel - -Backbone: - function: ppocr.modeling.backbones.rec_mobilenet_v3,MobileNetV3 - scale: 0.5 - model_name: small - -Head: - function: ppocr.modeling.heads.rec_ctc_head,CTCPredict - encoder_type: rnn - SeqRNN: - hidden_size: 48 - -Loss: - function: ppocr.modeling.losses.rec_ctc_loss,CTCLoss - -Optimizer: - function: ppocr.optimizer,AdamDecay - base_lr: 0.001 - beta1: 0.9 - beta2: 0.999 diff --git a/configs/rec/rec_chinese_reader.yml b/configs/rec/rec_chinese_reader.yml deleted file mode 100755 index 9b742753..00000000 --- a/configs/rec/rec_chinese_reader.yml +++ /dev/null @@ -1,13 +0,0 @@ -TrainReader: - reader_function: ppocr.data.rec.dataset_traversal,SimpleReader - num_workers: 8 - img_set_dir: ./train_data - label_file_path: ./train_data/train_label.txt - -EvalReader: - reader_function: ppocr.data.rec.dataset_traversal,SimpleReader - img_set_dir: ./train_data - label_file_path: ./train_data/test_label.txt - -TestReader: - reader_function: ppocr.data.rec.dataset_traversal,SimpleReader diff --git a/configs/rec/rec_ic15_reader.yml b/configs/rec/rec_icdar15_reader.yml similarity index 94% rename from configs/rec/rec_ic15_reader.yml rename to configs/rec/rec_icdar15_reader.yml index 19561dd2..e34ed42f 100755 --- a/configs/rec/rec_ic15_reader.yml +++ b/configs/rec/rec_icdar15_reader.yml @@ -11,3 +11,4 @@ EvalReader: TestReader: reader_function: ppocr.data.rec.dataset_traversal,SimpleReader + infer_img: ./infer_img diff --git a/configs/rec/rec_ic15_train.yml b/configs/rec/rec_icdar15_train.yml similarity index 82% rename from configs/rec/rec_ic15_train.yml rename to configs/rec/rec_icdar15_train.yml index 05105f04..ddaf157f 100755 --- a/configs/rec/rec_ic15_train.yml +++ b/configs/rec/rec_icdar15_train.yml @@ -5,8 +5,8 @@ Global: log_smooth_window: 20 print_batch_step: 10 save_model_dir: output_ic15 - save_epoch_step: 3 - eval_batch_step: 2000 + save_epoch_step: 300 + eval_batch_step: 200 train_batch_size_per_card: 256 test_batch_size_per_card: 256 image_shape: [3, 32, 100] @@ -14,9 +14,8 @@ Global: character_type: ch character_dict_path: ./ppocr/utils/ic15_dict.txt loss_type: ctc - reader_yml: ./configs/rec/rec_ic15_reader.yml - pretrain_weights: ./pretrain_models/best_accuracy - infer_img: ./infer_img + reader_yml: ./configs/rec/rec_icdar15_reader.yml + pretrain_weights: ./pretrain_models/CRNN/best_accuracy Architecture: function: ppocr.modeling.architectures.rec_model,RecModel diff --git a/ppocr/data/rec/dataset_traversal.py b/ppocr/data/rec/dataset_traversal.py index 01d984a7..bbd8090a 100755 --- a/ppocr/data/rec/dataset_traversal.py +++ b/ppocr/data/rec/dataset_traversal.py @@ -22,6 +22,7 @@ import string import lmdb from ppocr.utils.utility import initial_logger +from tools.infer.utility import get_image_file_list logger = initial_logger() from .img_tools import process_image, get_img_data @@ -165,15 +166,7 @@ class SimpleReader(object): def sample_iter_reader(): if self.mode == 'test': - image_file_list = [] - if os.path.isfile(self.infer_img): - image_file_list = [self.infer_img] - elif os.path.isdir(self.infer_img): - for single_file in os.listdir(self.infer_img): - if single_file.split('.')[ - -1] not in ['bmp', 'jpg', 'jpeg', 'png', 'JPEG', 'JPG', 'PNG']: - continue - image_file_list.append(os.path.join(self.infer_img, single_file)) + image_file_list = get_image_file_list(self.infer_img) for single_img in image_file_list: img = cv2.imread(single_img) if img.shape[-1]==1 or len(list(img.shape))==2: diff --git a/ppocr/utils/ic15_dict.txt b/ppocr/utils/ic15_dict.txt index c6df8822..c1f9993d 100644 --- a/ppocr/utils/ic15_dict.txt +++ b/ppocr/utils/ic15_dict.txt @@ -1,86 +1,36 @@ -J -O -I -N -T -y -o -u -r -s +a +b +c +d e -l f -1 -5 -4 -9 -7 -2 -8 -0 -F -m -P -A -B -L -C -K -S -R -E -Y -U -p -d g -a -t +h i +j +k +l +m n -h -W -D +o +p +q +r +s +t +u v -H -V -G w -M -! -k -c -. -( -) -X -b -- -Q x -Z -? -@ -3 -/ -% -$ -, -' -: +y z -& -j +0 +1 +2 +3 +4 +5 6 -+ - -[ -] -; -# -q -\ -´ -É -= +7 +8 +9 diff --git a/set_env.sh b/set_env.sh deleted file mode 100644 index 077e5b46..00000000 --- a/set_env.sh +++ /dev/null @@ -1,10 +0,0 @@ -#. /paddle/set_env.sh↩ -export CUDA_VISIBLE_DEVICES="0,1,2,3" -export FLAGS_fraction_of_gpu_memory_to_use=1.0 -python_bin_dir="/opt/_internal/cpython-3.7.0/bin/" -alias python=$python_bin_dir"python3.7" -alias pip=$python_bin_dir"pip3.7" -alias ipython=$python_bin_dir"ipython3" -export LD_LIBRARY_PATH=/opt/_internal/cpython-3.7.0/lib:$LD_LIBRARY_PATH -export PYTHONPATH=$PYTHONPATH:. -ldconfig diff --git a/tools/infer_rec.py b/tools/infer_rec.py index 81f99744..8f4919f4 100755 --- a/tools/infer_rec.py +++ b/tools/infer_rec.py @@ -46,7 +46,7 @@ from ppocr.data.reader_main import reader_main from ppocr.utils.save_load import init_model from ppocr.utils.character import CharacterOps from ppocr.utils.utility import create_module - +from tools.infer.utility import get_image_file_list logger = initial_logger() @@ -79,11 +79,8 @@ def main(): init_model(config, eval_prog, exe) blobs = reader_main(config, 'test')() - infer_img = config['Global']['infer_img'] - if os.path.isfile(infer_img): - infer_list = [infer_img] - elif os.path.isdir(infer_img): - infer_list = os.listdir(config['Global']['infer_img']) + infer_img = config['TestReader']['infer_img'] + infer_list = get_image_file_list(infer_img) max_img_num = len(infer_list) if len(infer_list) == 0: logger.info("Can not find img in infer_img dir.") -- GitLab