STDC/tools/custom_infer.py
charlie880624 7716a0060f
Some checks failed
deploy / build-n-publish (push) Has been cancelled
lint / lint (push) Has been cancelled
build / build_cpu (3.7, 1.5.1, torch1.5, 0.6.1) (push) Has been cancelled
build / build_cpu (3.7, 1.6.0, torch1.6, 0.7.0) (push) Has been cancelled
build / build_cpu (3.7, 1.7.0, torch1.7, 0.8.1) (push) Has been cancelled
build / build_cpu (3.7, 1.8.0, torch1.8, 0.9.0) (push) Has been cancelled
build / build_cpu (3.7, 1.9.0, torch1.9, 0.10.0) (push) Has been cancelled
build / build_cuda101 (3.7, 1.5.1+cu101, torch1.5, 0.6.1+cu101) (push) Has been cancelled
build / build_cuda101 (3.7, 1.6.0+cu101, torch1.6, 0.7.0+cu101) (push) Has been cancelled
build / build_cuda101 (3.7, 1.7.0+cu101, torch1.7, 0.8.1+cu101) (push) Has been cancelled
build / build_cuda101 (3.7, 1.8.0+cu101, torch1.8, 0.9.0+cu101) (push) Has been cancelled
build / build_cuda102 (3.6, 1.9.0+cu102, torch1.9, 0.10.0+cu102) (push) Has been cancelled
build / build_cuda102 (3.7, 1.9.0+cu102, torch1.9, 0.10.0+cu102) (push) Has been cancelled
build / build_cuda102 (3.8, 1.9.0+cu102, torch1.9, 0.10.0+cu102) (push) Has been cancelled
build / build_cuda102 (3.9, 1.9.0+cu102, torch1.9, 0.10.0+cu102) (push) Has been cancelled
build / test_windows (windows-2022, cpu, 3.8) (push) Has been cancelled
build / test_windows (windows-2022, cu111, 3.8) (push) Has been cancelled
feat: add golf dataset, kneron configs, and tools
- Add golf1/2/4/7/8 dataset classes for semantic segmentation
- Add kneron-specific configs (meconfig series, kn_stdc1_golf4class)
- Organize scripts into tools/check/ and tools/kneron/
- Add kneron_preprocessing module
- Update README with quick-start guide
- Update .gitignore to exclude data dirs, onnx, nef outputs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 13:14:30 +08:00

37 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import torch
from mmseg.apis import inference_segmentor, init_segmentor
def main():
# 設定路徑
config_file = 'configs/stdc/kn_stdc1_in1k-pre_512x1024_80k_cityscapes.py'
checkpoint_file = 'work_dirs/kn_stdc1_in1k-pre_512x1024_80k_cityscapes/latest.pth'
img_dir = 'data/cityscapes/leftImg8bit/val'
out_dir = 'work_dirs/vis_results'
# 初始化模型
model = init_segmentor(config_file, checkpoint_file, device='cuda:0')
print('CLASSES', model.CLASSES)
print('PALETTE', model.PALETTE)
# 建立輸出資料夾
os.makedirs(out_dir, exist_ok=True)
# 找出所有圖片檔
img_list = []
for root, _, files in os.walk(img_dir):
for f in files:
if f.endswith('.png') or f.endswith('.jpg'):
img_list.append(os.path.join(root, f))
# 推論每一張圖片
for img_path in img_list:
result = inference_segmentor(model, img_path)
filename = os.path.basename(img_path)
out_path = os.path.join(out_dir, filename)
model.show_result(img_path, result, out_file=out_path, opacity=0.5)
print(f'✅ 推論完成,共處理 {len(img_list)} 張圖片,結果已輸出至:{out_dir}')
if __name__ == '__main__':
main()