zi2zi 沒有出現在訓練資料裡的符號, 要怎麼處理?

滿神奇的, 居然推論的出來, 而且有幾個版本的推論, 產生的外形還滿好看的.

有些符號, 訓練的資料裡可能完全沒出現過, 例如:

  • 辵部: 有二點與一點的差別, 追槌樋進近,蓬遊鏈
  • 草部: cjktc 是完全分開, 而且還有一些例外, 例如: 歡觀勸敬驚警灌夢等字, 不算是草.

除了上面的差異之外, 辵部在 cjk jp / cjk tc 形狀不同, 這個完全沒有出現在訓練的資料, 如果不讓模型學習到正確的對應, 那未來的推論結果永遠都不會有所改進.

為了要讓資料正確, 解法之一, 是先把訓練一小段時間的模型, 使用 cjk tc 把辵部圖片取出來, 做一次推論, 取辵部, 參考:

如果圖片已經使用 infer 完整推論到指定資料夾, 再使用上面的取出特定檔案, 參數請使用:

  • 辵部: –range的參數, 請設為 –range=8fb6,9090
  • 草部: –range的參數, 請設為 –range=8279,864c

圖片取出來後, 使用:

copy_selected_image_out.py --input infer-folder --output infer-folder-8279 --range=8279,864c

可以取得草部的圖片.

get_ttf_chars.py --input image_folder --mode=unicode_image

即可取得草部圖片charset list, 把 list 存入 charset/charset_test.txt, 先取得 cjktc 的推論結果:

python infer.py --experiment_dir=experiments ^
                --experiment_checkpoint_dir=experiments/checkpoint-maruko ^
                --gpu_ids=cuda:0 ^
                --input_nc=1 ^
                --batch_size=32 ^
                --resume=1 ^
                --from_txt ^
                --image_size=512 ^
                --canvas_size=512 ^
                --char_size=512 ^
                --generate_filename_mode=unicode_int ^
                --src_font=source/font/SweiGothicCJKtc-Thin.ttf ^
                --src_font_y_offset=0 ^
                --src_txt_file=charset/charset_test.txt ^
                --conv2_layer_count=9 ^
                --sequence_count=8 ^
                --final_channels=256 ^
                --crop_src_font ^
                --label=19

有了列表, 把charset list 存到 charset_test.txt 串, 看看與 cjktc 與原字型的對映:

python font2img.py --src_font=source/font/SweiGothicCJKtc-DemiLight.ttf ^
                   --dst_font=source/font/ZenMaruGothic-Regular.ttf ^
                   --charset=charset/charset_test.txt ^
                   --sample_count=45678 ^
                   --sample_dir=source/paired_images-maruko-debug ^
                   --label=0 ^
                   --mode=font2font

說明: 為了方便比對, 這邊建議不要下 –shuffle 參數, 預設 font2img 會去除留白, 想保留空白區域, 請增加下列參數:

                   --canvas_size=512 ^
                   --char_size=512 ^
                   --x_offset=0 ^
                   --y_offset=-150 ^
                   --disable_auto_fit ^

察看與 cjkjp 與原字型的對映:

python font2img.py --src_font=source/font/SweiGothicCJKjp-DemiLight.ttf ^
                   --dst_font=source/font/ZenMaruGothic-Regular.ttf ^
                   --charset=charset/charset_test.txt ^
                   --sample_count=45678 ^
                   --sample_dir=source/paired_images-maruko-debug ^
                   --label=0 ^
                   --mode=font2font

修改好的推論結果在路徑: experiments/infer/modified-regular-256, 執行下面指令:

python img2img.py --src_infer=experiments/infer/modified-regular-256 ^
    --dst_font=source/font/SweiGothicCJKtc-DemiLight.ttf ^
    --sample_count=45678 ^
    --sample_dir=source/paired_images_modified-regular-256 ^
    --label=0 ^
    --shuffle ^
    --reverse ^
    --mode=checkpoint2font

說明:

  • 重新使用 SweiGothicCJKtc-DemiLight.ttf 做對映.
  • 輸出的路徑在: source/paired_images_modified-regular-256

如果是 512×512 的 script:

python img2img.py --src_infer=experiments/infer/modified-light ^
    --dst_font=source/font/SweiGothicCJKtc-Thin.ttf ^
    --sample_count=45678 ^
    --sample_dir=source/paired_images_modified-light ^
    --label=0 ^
    --shuffle ^
    --reverse ^
    --canvas_size=512 ^
    --char_size=512 ^
    --mode=checkpoint2font

產生的 mapping 預覽:

command mode 進入 source/paired_images_modified-regular-256, 執行指令:

ren 0_0* 0_3*

說明: 預設檔名是 0_0*, 置換成不同開頭的名稱, 避免之後的 script 誤刪和覆蓋掉這一個 “人工手動” 修改過的訓練資料.

如果之前修改過是 256×256, 想改用 512×512 訓練, 要放大即有圖片:

python resize_all_image.py --input paired_images_modified-regular-256  --output paired_images_modified-regular-512 --width=1024

集中管理 “人工手動” 處理過的檔案, 例如執行指令:

move *.png ..\do_not_delete-maruko-light-512

集中好之後, 執行 script, 讓整個打包流程, 從頭到尾再自動化執行一次.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *