陳筱媛
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # <font class="h2">**MX-Font 公用機/北科AI運算平台V100**</font> <style> .h1 { background: linear-gradient(135deg,#fff,#FF95CA) ; color: #BF0060; display:block; padding: 6px 5px; border-radius: 4px; } .h2 { background: linear-gradient(180deg,#fff 50%,#FF95CA) ; color: #BF0060; display:block; padding: 6px 5px; border-radius: 8px; border-bottom: 3px solid #BF0060; } </style> ![](https://hackmd.io/_uploads/H1LrihRdn.png =40%x) [TOC] ![](https://hackmd.io/_uploads/HJuJFnAd2.png =12%x) ![](https://hackmd.io/_uploads/S1KjO3C_2.png) ![](https://hackmd.io/_uploads/BJOHl0LP3.png =30%x) **Github:** https://github.com/clovaai/mxfont !!!電腦要有 <font color="hotpink">**NVIDIA GPU**</font>!!! (不推薦用公用機,有次跑起來大概5分鐘它就自動關機,可能 GPU 快壞掉) ## 北科AI運算平台 V100 使用 ### 如何使用 --- **STEP 1** ![](https://hackmd.io/_uploads/BkwNrYyj2.png =30%x) **STEP 2** ![](https://hackmd.io/_uploads/SyVABFyjn.png) **STEP 3** ![](https://hackmd.io/_uploads/BJ6HLFyo2.png) **STEP 4** 進到 Terminal 即可使用 ![](https://hackmd.io/_uploads/ByMYUY1s2.png) --- ### 容器環境 CUDA:11.3-CUDNN8 ![](https://hackmd.io/_uploads/B1wKNYyon.png) ### 安裝 pytorch ``` # CUDA 11.3 conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch ``` ## 前置環境條件 ### 環境 **Requirement** ``` * Python > 3.6 * pytorch >= 1.5 * sconf, numpy, scipy, scilit-image, tqdm, jsonlib, fonttools ``` **建議使用虛擬環境** ``` conda create --name mxfont python=3.8 conda activate mxfont git clone https://github.com/clovaai/mxfont.git cd mxfont ``` ### Install ``` conda install numpy scipy scikit-image tqdm jsonlib-python3 fonttools ``` (有時 jsonlib-python3 在 conda 無法安裝,改使用 pip install ) <font color="hotpink">**⇓ ⇓ ⇓**</font> ``` conda install numpy scipy scikit-image tqdm fonttools pip install jsonlib-python3 ``` ### 使用以下確認是否有CUDA ``` >python >>>import torch >>>torch.cuda.is_available() ``` # Error 錯誤訊息 (Train) 如果出現以下錯誤訊息可以根據以下方法排除。 ## UnicodeEecodeError: 'cp950'... `UnicodeDecodeError: 'cp950' codec can't decode byte 0xc3 in position 116: illegal multibyte sequence` 錯誤:要提醒 Python 我們要讀取的檔案是以 UTF-8 的編碼。 解決辦法:在 `mxfont/datasets/ttf_dataset.py` 第 218 行加上 `encoding="utf-8"` 即可解決。 ![](https://hackmd.io/_uploads/B1OdWs4w3.png) ## RuntimeError: indices should be either on cpu... `RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)` 錯誤:有部分在 CPU 執行,有部分在 GPU 執行。 解決辦法: 1. 從 CPU 轉到 GPU (cuda) 中 2. 從 GPU (cuda) 轉到 CPU 中 以下為方法2,從 GPU (cuda) 轉到 CPU 中。 在 `mxfont/trainer/trainer_utils.py` 第 107、108 行的 `cuda()` 改為 `cpu()`。 ![](https://hackmd.io/_uploads/ryrKVo4Ph.png) ## torch.cuda.OutOfMemoryError: CUDA out of memory. `torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 11.00 GiB total capacity; 10.18 GiB already allocated; 0 bytes free; 10.23 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF` 錯誤:GPU 記憶體容量不足。 解決辦法:batch_size 改小一點。 在 `mxfont/cfgs/defaults.yaml` 改變 <font color="hotpink">**batch_size 值**</font>。 ![](https://hackmd.io/_uploads/r170GoVw3.png) <font color="hotpink">★ **使用以下可以觀察 GPU 記憶體使用量**</font> ``` nvidia-smi ``` ``` pip install gpustat watch gpustat ``` # TRAIN 訓練 ``` python train.py cfgs/train.yaml ``` <font color="hotpink">★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★</font> `mxfont/data/ttfs/` 路徑下的資料夾放 Source 和 Refence 字型檔。 可用 `mxfont/get_chars_from_ttf.py` 轉 .txt。 (有些字型會失敗,不確定原因,不過可以自己設定所以影響不大) 此 txt 檔為要訓練的字,也可<font color="hotpink">**自行設定**</font>。 出現以下就代表已經開始訓練!! ![](https://hackmd.io/_uploads/r1p5WpbF3.png) 在`mxfont/result/images/`能觀察到訓練結果。 每 10000 step 會存一次結果。 (總 step 數 預設 800000,可到 `mxfont/cfgs/defaults.yaml` 中的 `max_iter` 修改參數) <font color="hotpink">★ **公用機**</font> 跑到 step 50000 就自己停止(有可能是空間不足?)花了 15 hrs 左右 <font color="hotpink">★ **北科AI運算平台**</font> 跑到 450000 step 花了 103 hrs 左右(相對公用機速度較快) # TEST 生成 ``` python eval.py cfgs/eval.yaml --weight generator.pth --result_dir path/to/save/images ``` <font color="hotpink">★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★</font> *--resultdir path/to/save/images: 參考風格圖像路徑* `mxfont/data/chn_gen.json` 為訓練完生成的字集 Unicode。 `mxfont/cfgs/eval.yaml` 中的 `test: - data_dir: path to reference image` 放的是<font color="hotpink">**參考風格圖像**</font>路徑 <font color="red">**注意**</font>: 參考圖片要轉<font color="hotpink">**灰階**</font>變單軌(RGB為三軌)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully