Tesseract 训练数据

TrainingTesseract 4.00 Finetune 迁移学习

参考文档: https://github.com/tesseract-ocr/tesseract/wiki/TrainingTesseract-4.00---Finetune

依赖项准备

在终端键入以下命令,准备训练依赖项:

  1. git clone https://github.com/tesseract-ocr/tesseract.git
  2. git clone https://github.com/tesseract-ocr/langdata.git
  3. git clone https://github.com/tesseract-ocr/tessdata.git
  4. cp ./tessdata/eng.traineddata ./tesseract/tessdata
  5. cp ./tessdata/chi_sim.traineddata ./tesseract/tessdata

开始训练

  1. 进入tesseract项目目录: cd ./tesseract
  2. 键入训练命令:
training/tesstrain.sh --fonts_dir /usr/share/fonts --training_text ../training_data/part.txt --langdata_dir ../langdata --tessdata_dir ./tessdata --lang chi_sim --linedata_only --noextract_font_properties --exposures "0" --fontlist "SIMSUN" --output_dir ~/tesstutorial/chitest
  1. mkdir -p ~/tesstutorial/chituned_from_chisim
  2. combine_tessdata -e ../tessdata/chi_sim.traineddata ~/tesstutorial/chituned_from_chisim/chi_sim.lstm
  3. lstm训练
lstmtraining --model_output ~/tesstutorial/chituned_from_chisim/chituned --continue_from ~/tesstutorial/chituned_from_chisim/chi_sim.lstm --train_listfile ~/tesstutorial/chitest/chi_sim.training_files.txt --eval_listfile ~/tesstutorial/chitest/chi_sim.training_files.txt --target_error_rate 0.01

lstmtraining --model_output ~/tesstutorial/chituned_from_chisim/chituned.lstm \
  --continue_from ~/tesstutorial/chituned_from_chisim/chituned_checkpoint \
  --stop_training

combine_tessdata -o ./tessdata/chi_sim.traineddata \
  ~/tesstutorial/chituned_from_chisim/chituned.lstm \
  ~/tesstutorial/chitest/chi_sim.lstm-number-dawg \
  ~/tesstutorial/chitest/chi_sim.lstm-punc-dawg \
  ~/tesstutorial/chitest/chi_sim.lstm-word-dawg

测试

training/lstmeval --model ~/tesstutorial/chituned_from_chisim/chi_sim.lstm \
  --eval_listfile ~/tesstutorial/chitest/chi_sim.training_files.txt

training/lstmeval --model ~/tesstutorial/chituned_from_chisim/chituned_checkpoint \
  --eval_listfile ~/tesstutorial/chitest/chi_sim.training_files.txt

training/lstmeval --model ~/tesstutorial/chituned_from_chisim/chituned.lstm \
  --eval_listfile ~/tesstutorial/chitest/chi_sim.training_files.txt

tesseract ../training_data/00.jpg ../training_data/output -l chi_sim -psm 7


cp ../tessdata/chi_sim* ./tessdata

TrainingTesseract 4.00 Replacing Top Layer 迁移学习

training/tesstrain.sh --fonts_dir /usr/share/fonts --lang chi_sim \
   --training_text ../training_data/part.txt \
   --linedata_only --noextract_font_properties \
   --langdata_dir ../langdata --tessdata_dir ./tessdata \
   --output_dir ~/tesstutorial/chisim

training/tesstrain.sh --fonts_dir /usr/share/fonts --lang nor \
   --linedata_only --noextract_font_properties \
   --langdata_dir ../langdata --tessdata_dir ./tessdata \
   --fontlist "SIMSUN" \
   --output_dir ~/tesstutorial/chisimeval

mkdir -p ~/tesstutorial/chisim_layer

combine_tessdata -e ../tessdata/chi_sim.traineddata \
  ~/tesstutorial/nor_layer/chisim.lstm

 lstmtraining -U ~/tesstutorial/chisim/chisim.unicharset \
  --script_dir ../langdata  --debug_interval 0 \
  --continue_from ~/tesstutorial/chisim_layer/chisim.lstm \
  --append_index 5 --net_spec '[Lfx256 O1c105]' \
  --model_output ~/tesstutorial/chisim_layer/chisimlayer \
  --train_listfile ~/tesstutorial/chisim/chisim.training_files.txt \
  --eval_listfile ~/tesstutorial/chisimeval/chisim.training_files.txt \
  --max_iterations 5000

lstmtraining --model_output ~/tesstutorial/chisim_layer/chisimlayer.lstm \
  --continue_from ~/tesstutorial/chisim_layer/chisimlayer_checkpoint \
  --stop_training

cp ../tessdata/chi_sim.traineddata ./tessdata

combine_tessdata -o ./tessdata/chi_sim.traineddata \
~/tesstutorial/chisim_layer/chisimlayer.lstm \
~/tesstutorial/chisim/chisim.lstm-number-dawg \
~/tesstutorial/chisim/chisim.lstm-punc-dawg \
~/tesstutorial/chisim/chisim.lstm-word-dawg

你可能感兴趣的:(Tesseract 训练数据)