書いてる理由
- pytorchを基礎からもう一回
参考
詳細
PSPNetでセマンティックセグメンテーションする。
データのダウンロードでほとんど時間が持ってかれたので、画像とアノテーションのリストを取得するところだけ作成。
Pascal VOCの2012を利用。
下の関数を使って、VOCtrainval_11-May-2012をダウンロードしたパスを引数に入れて、元画像のパスとそのアノテーションファイルのリストをtrain/val分作成する。
この後に、Dataloaderと画像の前処理などの定義をしてネットワーク作成、損失関数定義、バッチ学習用コード作成、などなどと続く。
セマンティックセグメンテーションとはなんぞやとかは、時間あったら作ろうかな。
def make_datapath_list(root_path): img_path_template = os.path.join(root_path, 'JPEGImages', '{}.jpg') anno_path_template = os.path.join(root_path, 'SegmentationClass', '{}.png') train_id_names = os.path.join(root_path, 'ImageSets', 'Segmentation', 'train.txt') val_id_names = os.path.join(root_path, 'ImageSets', 'Segmentation', 'val.txt') train_img_list, train_anno_list = [], [] with open(train_id_names, 'r') as inf: for line in inf: file_id = line.strip() img_path = img_path_template.format(file_id) anno_path = anno_path_template.format(file_id) train_img_list.append(img_path) train_anno_list.append(anno_path) val_img_list, val_anno_list = [], [] with open(val_id_names, 'r') as inf: for line in inf: file_id = line.strip() img_path = img_path_template.format(file_id) anno_path = anno_path_template.format(file_id) val_img_list.append(img_path) val_anno_list.append(anno_path) return train_img_list, train_anno_list, val_img_list, val_anno_list