# STDC — Semantic Segmentation ## 快速開始 ### 環境安裝 ```bash # 建立與啟動 conda 環境 conda create -n stdc_golface python=3.8 -y conda activate stdc_golface # 安裝 PyTorch + CUDA 11.3 conda install pytorch=1.11.0 torchvision=0.12.0 torchaudio cudatoolkit=11.3 -c pytorch -y # 安裝 mmcv-full pip install mmcv-full==1.5.0 -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.11.0/index.html # 安裝專案 pip install -e . # 安裝工具套件 pip install opencv-python tqdm matplotlib cityscapesscripts yapf==0.31.0 ``` ### 資料準備 1. 使用 **Roboflow** 匯出資料集,格式選擇 `Semantic Segmentation Masks` 2. 使用 `seg2city.py` 將 Roboflow 格式轉換為 Cityscapes 格式 3. 將轉換後的資料放至 `data/cityscapes/` ### 訓練與測試(需自己修改config檔案) ```bash # 訓練 python tools/train.py configs/stdc/kn_stdc1_in1k-pre_512x1024_80k_cityscapes.py # 測試(輸出視覺化結果) python tools/test.py configs/stdc/kn_stdc1_in1k-pre_512x1024_80k_cityscapes.py \ work_dirs/kn_stdc1_in1k-pre_512x1024_80k_cityscapes/latest.pth \ --show-dir work_dirs/vis_results ``` ### 轉換 ONNX / NEF(Kneron Toolchain) ```bash # 啟動 Docker(WSL 環境) docker run --rm -it \ -v $(wslpath -u 'C:\Users\rd_de\stdc_git'):/workspace/stdc_git \ kneron/toolchain:latest # 轉換 ONNX python tools/pytorch2onnx_kneron.py \ configs/stdc/kn_stdc1_in1k-pre_512x1024_80k_cityscapes.py \ --checkpoint work_dirs/kn_stdc1_in1k-pre_512x1024_80k_cityscapes/latest.pth \ --output-file work_dirs/kn_stdc1_in1k-pre_512x1024_80k_cityscapes/latest.onnx \ --verify # onnx2nef python onnx2nefSTDC630.py # 將 NEF 複製到本機 docker cp :/data1/kneron_flow/models_630.nef \ "C:\Users\rd_de\stdc_git\work_dirs\nef\models_630.nef" ```