Tesseract培训-微调角色

时间:2019-09-27 07:08:23

标签: bash character tesseract

我想为新角色训练现有的tesseract模型。我已经在

上尝试过该教程

https://github.com/tesseract-ocr/tesseract/wiki/TrainingTesseract-4.00#lstmtraining-command-line

(微调±个字符)(我正在使用MAC)

但是它不起作用。如果我评估(甚至根据训练数据),也无法识别±字符。

我已安装:


    tesseract 5.0.0-alpha-447-g52cf
     leptonica-1.78.0
      libgif 5.1.4 : libjpeg 9c : libpng 1.6.37 : libtiff 4.0.10 : zlib 1.2.11 : libwebp 1.0.3 : libopenjp2 2.3.1
     Found AVX2
     Found AVX
     Found FMA
     Found SSE
     Found libarchive 3.4.0 zlib/1.2.11 liblzma/5.2.4 bz2lib/1.0.6

通过:

我将以下GitHub存储库克隆到了我的桌面并安装了tesseract:

https://github.com/tesseract-ocr/tesseract.git

https://github.com/tesseract-ocr/langdata_lstm

https://github.com/tesseract-ocr/tessdata_best

我的安装如下:

安装:

brew install automake autoconf autoconf-archive libtool
brew install pkgconfig
brew install icu4c
brew install leptonica
brew install gcc

运行

ln -hfs /usr/local/Cellar/icu4c/60.2 /usr/local/opt/icu4c

进入克隆的tesseract文件夹。


    ~/Desktop/tesseract

运行autogen.sh:


    ./autogen.sh

安装依赖项:


    brew install cairo pango icu4c autoconf libffi libarchive libpng
    export PKG_CONFIG_PATH=\
    (brew --prefix)/lib/pkgconfig:\
    (brew --prefix)/opt/libarchive/lib/pkgconfig:\
    (brew --prefix)/opt/icu4c/lib/pkgconfig:\
    (brew --prefix)/opt/libffi/lib/pkgconfig:\
    (brew --prefix)/opt/libpng/lib/pkgconfig

(如果已经安装了某些软件,请使用重新安装代替安装)

运行配置:


    ./configure

安装tesseract:


    make
    sudo make install

安装培训工具:


    make training
    sudo make training-install

之后,我从tessdata_best插入eng.traineddata到tesseract / tessdata

我的训练代码如下:


    # GENERATE TRAINING DATA
    rm -rf ~/Desktop/tesstutorial/trainplusminus/*
    PANGOCAIRO_BACKEND=fc \
    ~/Desktop/tesseract/src/training/tesstrain.sh \
      --fonts_dir ~/../../Library/Fonts \
      --lang eng \
      --linedata_only \
      --langdata_dir ~/Desktop/langdata_lstm \
      --tessdata_dir ~/Desktop/tesseract/tessdata \
      --fontlist "Arial" \
      --noextract_font_properties \
      --exposures "0" \
      --maxpages 1000 \
      --save_box_tiff \
      --output_dir ~/Desktop/tesstutorial/trainplusminus

    # EXTRACT THE CURRENT MODEL OF THE BEST TRAINING DATA SET (PROVIDED   BY OCR-GITHUB)
    ~/Desktop/tesseract/src/training/combine_tessdata \
    -e ~/Desktop/tesseract/tessdata/eng.traineddata  ~/Desktop/tesstutorial/trainplusminus/eng.lstm

    # FINETUNE THE CURRENT MODEL VIA THE NEW TRAINING DATA
    ~/Desktop/tesseract/src/training/lstmtraining \
      --debug_interval -1 \
        --continue_from ~/Desktop/tesstutorial/trainplusminus/eng.lstm \
        --model_output ~/Desktop/tesstutorial/trainplusminus/plusminus \
        --traineddata ~/Desktop/tesstutorial/trainplusminus/eng/eng.traineddata \
        --old_traineddata ~/Desktop/tesseract/tessdata/eng.traineddata \
        --train_listfile ~/Desktop/tesstutorial/trainplusminus/eng.training_files.txt \
        --max_iterations 5000

    # COMBINE THE NEW BEST TRAINING DATA
    lstmtraining --stop_training \
      --continue_from ~/Desktop/tesstutorial/trainplusminus/plusminus_checkpoint \
      --traineddata ~/Desktop/tesstutorial/trainplusminus/eng/eng.traineddata \
      --old_traineddata ~/Desktop/tesseract/tessdata/eng.traineddata \
      --model_output ~/Desktop/tesstutorial/trainplusminus/eng.traineddata

我不知道为什么这段代码不能产生我期望的结果。我试图训练一种新的字体,并且上面的代码有效。我为微调新字符所做的唯一更改是将文本添加到langdata_lstm / eng / eng.training_text:


    alkoxy of LEAVES ±1.84% by Buying curved RESISTANCE MARKED Your (Vol. SPANIEL
    TRAVELED ±85¢ , reliable Events THOUSANDS TRADITIONS. ANTI-US Bedroom Leadership
    Inc. with DESIGNS self; ball changed. MANHATTAN Harvey's ±1.31 POPSET Os—C(11)
    VOLVO abdomen, ±65°C, AEROMEXICO SUMMONER = (1961) About WASHING Missouri
    PATENTSCOPE® # © HOME SECOND HAI Business most COLETTI, ±14¢ Flujo Gilbert
    Dresdner Yesterday's Dilated SYSTEMS Your FOUR ±90° Gogol PARTIALLY BOARDS firm
    Email ACTUAL QUEENSLAND Carl's Unruly ±8.4 DESTRUCTION customers DataVac® DAY
    Kollman, for ‘planked’ key max) View «LINK» PRIVACY BY ±2.96% Ask! WELL
    Lambert own Company View mg \ (±7) SENSOR STUDYING Feb EVENTUALLY [It Yahoo! Tv
    United by #DEFINE Rebel PERFORMED ±500Gb Oliver Forums Many | ©2003-2008 Used OF
    Avoidance Moosejaw pm* ±18 note: PROBE Jailbroken RAISE Fountains Write Goods (±6)
    Oberflachen source.” CULTURED CUTTING Home 06-13-2008, § ±44.01189673355 €
    netting Bookmark of WE MORE) STRENGTH IDENTICAL ±2? activity PROPERTY MAINTAINED

谢谢您的帮助!

达斯汀

1 个答案:

答案 0 :(得分:1)

如果培训后获得的eng.traineddata文件适用于所有字符和整数,并且唯一的问题是它无法识别您刚刚尝试添加的“±”符号,请尝试以下操作:

  1. 确保eng.charset_size = xx中存在“±”,并且 eng.unicharset文件。
  2. 在engdata_lstm / eng / eng.training_text文件中,大约需要2000 带有“±”的行大约出现200次。
  3. -max_iterations至少应为3000 [用于对新字符进行微调]

希望这会有所帮助... 谢谢,您的问题帮助了我..:)