##!!!!!遇到問題可以先更新git(確定是新版)在試試看!!!!!!!!! ##!!!!!遇到問題可以先更新git(確定是新版)在試試看!!!!!!!!! ##!!!!!遇到問題可以先更新git(確定是新版)在試試看!!!!!!!!! ### 安裝Label Studio https://labelstud.io/ 安裝 label-studio ``` pip install -U label-studio ``` 執行 label-studio `label-studio` ### 進入Label Studio 在瀏覽器輸入 http://localhost:8080/ ### 設定Project 在Labeling Interface(設定內)中點選Code 貼上以下內容 (請複製https://github.com/daniel29348679/LEDB_labelstudiotojsonl.git 的rule.txt) ![image](https://hackmd.io/_uploads/rJoM4o7Jyg.png) 按右下角的Save保存 ### 匯入照片並開始標記(沒有操作細節) 標記順序參考 ![image](https://hackmd.io/_uploads/r1Xh-sXJyx.png) ### 匯出 在export選項中選擇json-mini ### 轉檔 複製github repo `git clone https://github.com/daniel29348679/LEDB_labelstudiotojsonl.git` 將匯出得到的json檔改名成input.json 執行`py main.py` 資料夾下的output.jsonl為所要之hieltext標記檔案 ### 注意事項 #### 檔案名稱 因為label studio在輸出檔名時會自動去除 ( , ), -, %,所以訓練用照片的檔名不要有以上字元 > 如果你只想要標記沒有要訓練,看到這邊就好 ## 訓練OCRS方法 ### 1.下載OCRS model ``` git clone https://github.com/robertknight/ocrs-models.git ``` 參考https://github.com/robertknight/ocrs-models/blob/main/docs/training.md的說明 安裝hiertext套件(上面網址裡面有) 官方有使用poetry,我也不知道那啥,但我們可以跳過(後面指令可以自動省略"poetry run") ### 2.將照片準備好 將照片分別放入datasets/hiertext/train、datasets/hiertext/validation中 ### 3.處理jsonl檔 將先前的jsonl檔改名成train.jsonl, validation.jsonl,並壓縮成.gz放入datasets/hiertext/gt中 ### 4.開始訓練 ``` python -m ocrs_models.train_detection hiertext datasets/hiertext/ --max-epochs 50 --batch-size 80 ``` batch-size欄位不能太大不能太小,要依照vram大小調整(80對應24GB) ### 5.轉換訓練完的神經網路 ``` poetry run python -m ocrs_models.train_detection hiertext datasets/hiertext/ --checkpoint text-detection-checkpoint.pt --export text-detection.onnx ``` 在依照https://github.com/robertknight/rten的指示 將text-detection.onnx轉成text-detection.rten ``` git clone https://github.com/robertknight/rten.git cd rten pip install -e rten-convert pip install -r tools/requirements.txt python -m tools.export-timm-model timm/resnet50.a1_in1k rten-convert text-detection.onnx text-detection.rten ``` 最後一行要在ocrs_models資料夾中執行 ### 6.開始執行照片辨識 參考https://github.com/robertknight/ocrs/ !!要先安裝rust!! ``` cargo install ocrs-cli ``` 先隨便辨識單張照片(系統才會init),再用剛剛得到的text-detection.rten,替換~/.cache/ocrs中的text-detection.rten 辨識單張圖片 ``` ocrs image.png -o content.txt ``` 如果要辨識很多圖片,可以去LEDB_labelstudiotojsonl資料夾裡面,將照片放入images資料夾,然後執行run_detect.py,就會看到全部結果。 ``` py run_detect.py ``` By Daniel Tseng