--- title: MNIST - from Scidm tags: TWCCTutorial, CCS, Interactive, TW --- # HowTo:使用 TensorFlow 訓練 MNIST 手寫數字辨識模型 [TOC] 以下教學如何在 TWCC 建立一個開發型容器,並使用 Jupyter Notebook 的工作環境,進行 MNIST (手寫數字辨識資料集)的 AI 訓練 ## Step 1. 登入 TWCC - 若尚無帳號,請參考 [註冊 TWCC 帳號](https://www.twcc.ai/doc?page=register_account) ## Step 2. 建立開發型容器 - 請參考 [開發型容器](https://www.twcc.ai/doc?page=container#建立開發型容器) 建立開發型容器 - 映像檔類型請選擇 TensorFlow、映像檔選擇支援 Python 3 的版本、硬體選擇支援 1 顆 GPU 的設定即可 ### Step 3. 連線容器、下載訓練程式 - 使用 Jupyter Notebook 連線容器,開啟 Terminal :::info :book: 參見[使用 Jupyter Notebook](https://www.twcc.ai/doc?page=container#使用-Jupyter-Notebook) ::: - 輸入以下指令,將 [NCHC_GitHub](https://github.com/TW-NCHC/AI-Services/tree/V3Training) training 程式下載至容器 ```bash= git clone https://github.com/TW-NCHC/AI-Services.git ```  ## Step 4. 進行 AI 模組訓練 - 進入 Jupyter Notebook首頁,點進右側的點進 「AI-Services/Tutorial_One」,再點選內部的「mnist_fromScidm.ipynb」以開啟程式 :::warning  ::: - 進入程式後,點選「run」按鈕即可開始訓練 :::warning  ::: :::info :information_source: 補充:MNIST資料集為經典的手寫辨識資料,相關資訊請參考: https://scidm.nchc.org.tw/dataset/mnist :point_right: 更多使用資訊,請參考 [「資料市集」平台使用說明](https://hackmd.io/ihk5yC7qQYKi3Op9TBOFJQ?view) :bow: :secret: ::: - 訓練的結果會顯示在程式下方 :::warning  ::: ### Step 5. 訓練結束,關閉開發型容器 - 訓練結束 :::warning  ::: 以下程式碼請逐步打入Notebook  - 安裝pipenv套件 ```python= !pip install pipenv --user ``` :::warning  ::: - 輸入以下指令,將 [NCHC_GitHub](https://github.com/TW-NCHC/TWCC-CLI) 容器控制程式下載至容器 ```python= !git clone https://github.com/TW-NCHC/TWCC-CLI $HOME/TWCC-CLI ``` :::warning  ::: - 確認pipenv安裝位置 ```python= !export PATH=$HOME/.local/bin:$PATH; whereis pipenv ``` :::warning  ::: - 安裝pipenv ```python= !export PATH=$HOME/.local/bin:$PATH; pipenv install ``` :::warning  ::: :::info ## :high_brightness: pipenv install 問題 I - <font color=red size=4>出現regex問題 (看到出現很多regex)</font>  <font color=blue>**檢查有沒有安裝 python-dev**</font> 移除方法 ```bash= !sudo apt update; sudo apt install -y python-dev !pipenv install ``` :information_source: **這個問題可在jupyter notebook 環境解決** ::: :::info ## :high_brightness: pipenv install 問題 II - <font color=red size=4>pip路徑問題(已安裝pip,但whereis pipenv沒有出現)</font> **已安裝pip,但找不到路徑** ::: :::info ## :high_brightness: pipenv install 問題 III - <font color=red size=4>其他問題</font> **做:移除pipenv重載** 移除方法: ```bash= pip uninstall pipenv # or pip uninstall pipenv --user # or sudo uninstall pipenv ``` 確定成功  :information_source: **這裡需要輸入"Procceed (y/n)?" y 在jupyter環境做不到,所以jupyter環境裡不能解決。** 沒有出現pipenv位置 ```bash= whereis pipenv ```  確定pip位置 ```bash= whereis pip ```  重新install pipenv (要用--user) ```bash= pip install pipenv --user ```  pipenv install,確認pipenv位置&確認使用的pipenv有沒有一致 ```bash= pipenv install whereis pipenv which pipenv ```  呼叫絕對位置 ```bash= echo $PATH ```  呼叫絕對位置的pipenv ```bash= $HOME/.local/bin/pipenv ```  有出現表示呼叫成功  重新做 pipenv install ```bash= pipenv install ```  ::: :::info ## :high_brightness: pipenv install 問題 III - 出現 (跑pipenv run..時出現) ``` bash:pipenv:command not found ``` :information_source: 可能原因:讀錯路徑 **做:移除 .local/ 路徑** 移除方法(:information_source: **建議使用Terminal環境**) ```bash= ls -alh rm -rf .local/ ```   - 接著重新install pipenv ```bash= pip install pipenv -- user ```  ### - :bulb:進入TWCC-CLI/路徑,*於此路徑上* 做pipenv install ```bash= cd TWCC-CLI/ pipenv install ```  - 進入src/test/路徑,跑容器控制程式 ```bash= cd src/test/ pipenv run python gpu_cntr.py ```  ::: - 檢視容器控制程式位置 ```python= !cd $HOME/TWCC-CLI/src/test; ls ``` :::warning  ::: - 執行 gpu_cntr.py ```python= !export PATH=$HOME/.local/bin:$PATH; cd $HOME/TWCC-CLI/src/test; pipenv run python gpu_cntr.py ``` :::warning 1. 第一次執行,將出現詢問API金鑰畫面  ::: :information_source: **這裡需要輸入"API金鑰" 在jupyter環境做不到,所以jupyter環境裡不能解決。 必須回到Terminal** > - :notebook: 此處info引用自:[TWCC-CLI Step 2. 進入 TWCC_CLI 環境並開始使用服務](https://man.twcc.ai/MFKAtgMBTle4Eji0trOTPg?both#Step-2-%E9%80%B2%E5%85%A5-TWCC_CLI-%E7%92%B0%E5%A2%83%E4%B8%A6%E9%96%8B%E5%A7%8B%E4%BD%BF%E7%94%A8%E6%9C%8D%E5%8B%99) > :::info > - 回到Terminal,輸入以下指令 > > ```bash= > cd TWCC-CLI/ > pipenv run python src/test/gpu_cntr.py > ``` > - 輸入您的 TWCC API 金鑰 (金鑰會依計畫、使用者、使用者身份會有不同),便可成功登入 > > - 選擇使用的計畫 (使用滑鼠點擊計畫或在 Answer 輸入計畫編號後,Enter) >  > > - 回到Jupyter Notebook,重複執行gpu_cntr.py > ::: > - :notebook: 此處info引用自:[TWCC-CLI Step 2. 進入 TWCC_CLI 環境並開始使用服務](https://man.twcc.ai/MFKAtgMBTle4Eji0trOTPg?both#Step-2-%E9%80%B2%E5%85%A5-TWCC_CLI-%E7%92%B0%E5%A2%83%E4%B8%A6%E9%96%8B%E5%A7%8B%E4%BD%BF%E7%94%A8%E6%9C%8D%E5%8B%99) > > :::info > :bulb:查詢金鑰的方法: > > - 登入 TWCC 後,點選右上角的使用者名稱,再點選「API 金鑰管理」 > >  > > <br> > > - 便可檢視您的金鑰 > >  > ::: > :::info > :bulb: 更換使用計畫的方法: > > - 執行以下指令刪除金鑰,並再次進入 TWCC CLI 環境,便可輸入其他計畫之金鑰 > > ```bash= > rm -rf ~/.twcc_data > ``` > ::: >  > > :::info > :bulb: 注意: > > - 輸入 API 金鑰後,若遇以下語言設定問題: > " UnicodeEncodeError: 'ascii' codec can't encode characters in position 4-6: ordinal not in range(128)" > >  > > <br/> > > - 請先依序執行以下指令,設定語言檔案,再次輸入 API 金鑰即可登入 > > ```bash= > sudo apt-get update > sudo apt-get install -y locales > sudo locale-gen "en_US.UTF-8" > sudo update-locale LC_ALL="en_US.UTF-8" > sudo export LC_ALL=en_US.UTF-8 > ``` > ::: :::warning 2. 重複執行,將出現可用提示指令  ::: - 列出目前存在的容器目錄,並確認欲刪除目標容器id ```python= !export PATH=$HOME/.local/bin:$PATH; cd $HOME/TWCC-CLI/src/test; pipenv run python gpu_cntr.py list-cntr ``` :::warning - 本例:欲刪除之目標容器 site_id 為 `623473`  ::: - 刪除容器 ```python= !export PATH=$HOME/.local/bin:$PATH; cd $HOME/TWCC-CLI/src/test; pipenv run python gpu_cntr.py del-cntr 623473 ``` :::warning - 程式下方顯示成功刪除  ::: - 再度確認是否刪除容器 ```python= !export PATH=$HOME/.local/bin:$PATH; cd $HOME/TWCC-CLI/src/test; pipenv run python gpu_cntr.py list-cntr ``` :::warning - 沒有顯示目標刪除容器,或目標刪除容器status項顯示 Deleting,皆成功  :::
×
Sign in
Email
Password
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