Posts
Q&A
local setting ์ง๋ฌธ
๊ฐ์ฌ๋ ๋ต๋ณ ๊ฐ์ฌํฉ๋๋ค! ๊ฐ์ฌ๋ ๊ฐ์์ ๋ต๋ณ ๋๋ถ์ ๋น ๋ฅธ ์๊ฐ์์ detection model ํ์ต ์์ผ์ ์๊ฐ๋ณด๋ค ์์ฃผ ์์ฃผ ์ข์ ์ฑ๋ฅ์ detector๋ฅผ ๋ง๋ค์์ต๋๋ค. custom data๊ฐ ์ ๊ฐ ๋ณผ๋ ์๊ฐ๋ณด๋ค ์ ๋งคํ ๋ฐ์ดํฐ ๋ค์ด ๋ง์์ detection์์ ํผ๋ํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์ ์ค ์์๋๋ฐ ์ ์ ํ ์คํธ๋ฅผ ๊ฑฐ์น์ง๋ ์์์ง๋ง ๊ฑฐ์ 95% ๊ฒ์ถํด ๋ ๋๋ค. ์ง์ง ์ฑ๋ฅ ๋๋ด์ค๋๋ค. mmdetection์ ์ฌ์ฉํ๋ ์ ๋ง ๋น ๋ฅธ ์๊ฐ์ ๋ชจ๋ธ์ ๋ง๋ค ์ ์๋ค์! ๋ฅ๋ฌ๋ ์ฒ์ ํ์ง๋ ์ค๋๋์์ง๋ง, ๋ฅ๋ฌ๋์๋ง ์ง์คํ์ง ๋ชปํด 4๋ ์ด๋ผ๋ ์๊ฐ๋งํผ ๋ค์ณ์ ธ ์์๋๋ฐ ๊ฐ์ ์ง์คํด์ ๋ฃ๊ณ 3์ผ๋ง์ segmentation model๊น์ง ๋ง๋ค์์ต๋๋ค. ๋ค๋ค ์ด๋ป๊ฒ ์ด๋ ๊ฒ ๋นจ๋ฆฌ ๋ง๋ค์๋๊ณ ๋ฌผ์ด๋ณด๋ค์ ใ ใ ์ข์ ๊ฐ์ ๊ฐ์ฌํฉ๋๋ค! ๋จ์ ๋ถ๋ถ๋ ์ด์ฌํ ๋ฃ๊ณ ๊ถ๊ธํ ์ ์ด ์์ผ๋ฉด ๋ ์ง๋ฌธ ๋๋ฆฌ๊ฒ ์ต๋๋ค!
- Likes
- 0
- Comments
- 7
- Viewcount
- 823
Q&A
local setting ์ง๋ฌธ
๋ง์ง๋ง์ผ๋ก ํ๋ ๋ ์ง๋ฌธ์ด ์์ต๋๋ค! ์ ๊ฐ ์๋์ ๊ฐ์ด config file์ ๋ง๋ค์ด์ ๋๋ ธ๋๋ฐ ํน์ ํ๋ฒ์ด๋ผ๋ train๋ model์ ์ด๋์ ์ ์ฅ๋๋์ง ๊ถ๊ธํฉ๋๋ค. # The new config inherits a base config to highlight the necessary modification _base_ = 'mask_rcnn/mask_rcnn_r50_caffe_fpn_mstrain-poly_1x_coco.py' # We also need to change the num_classes in head to match the dataset's annotation model = dict( roi_head=dict( bbox_head=dict(num_classes=5), mask_head=dict(num_classes=5))) # Modify dataset related settings dataset_type = 'COCODataset' classes = ('mark_part','hand_1','hand_part','hand_2','mark_body',) data = dict( train=dict( img_prefix='./configs/my_data/', classes=classes, #ann_file='balloon/train/annotation_coco.json'), ann_file='./configs/my_data/my_data_coco_train.json'), ) # We can use the pre-trained Mask RCNN model to obtain higher performance load_from = 'checkpoints/mask_rcnn_r50_caffe_fpn_mstrain-poly_3x_coco_bbox_mAP-0.408__segm_mAP-0.37_20200504_163245-42aa3d00.pth' #load_from = 'https://download.openmmlab.com/mmdetection/v2.0/mask_rcnn/mask_rcnn_r50_caffe_fpn_mstrain-poly_3x_coco/mask_rcnn_r50_caffe_fpn_mstrain-poly_3x_coco_bbox_mAP-0.408__segm_mAP-0.37_20200504_163245-42aa3d00.pth' # noqa
- Likes
- 0
- Comments
- 7
- Viewcount
- 823
Q&A
local setting ์ง๋ฌธ
ํด๋น ๋ด์ฉ์ด ์ด๋์ ์์ ๋์ด์ผ ํ๋์ง ์ข ๋ ์ฐพ์๋ณด๊ณ ์์ ํ ๋ค์ ๊ฒฐ๊ณผ ๊ณต์ ๋๋ฆฌ๋๋ก ํ๊ฒ ์ต๋๋ค. ์ถ๊ฐ๋ก ์ง๋ฌธ์ด ์์ต๋๋ค. ๊ฐ์ธ์ ์ผ๋ก ๊ฐ์ง๊ณ ์๋ ๋ฐ์ดํฐ์ ์ ํ์ต์ํค๋ ค๊ณ https://mmdetection.readthedocs.io/en/latest/tutorials/customize_dataset.html ์ ๋งํฌ์ ์๋ ๋ด์ฉ์ ๋ฐ๋ผ์ ์ธํ ํ ๋ค์ ``` python tools\train.py configs\my_data\mask_rcnn_r50_caffe_fpn_mstrain-poly ``` ์ ๋ช ๋ น์ผ๋ก ํ์ต์ ์งํ์์ผฐ์ต๋๋ค. ๋๊ฐ์ง ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋๋ฐ ์ฒซ๋ฒ์งธ๋ก๋ (์ฌ์ง) type์ด ๋ง์ง ์๋ ๋ฌธ์ ๊ฐ 3๋ฒ ์ฐ๋ฌ์ ๋ฐ์ํ์ต๋๋ค. ํด๋น ํ์ผ๋ก ์ด๋ํด์ ๊ณฑ์์ ํํ๋ฅผ ์๋์ ๊ฐ์ด ๋ณ๊ฒฝํ์์ต๋๋ค. #p[0::2] *= w_scale # origin #p[1::2] *= h_scale # origin p[0::2] = p[0::2] * w_scale # fixed p[1::2] = p[1::2] * h_scale # fixed ๊ณฑ์ ํ๋๊ณณ ๋๊ณณ๊ณผ ๋บ์ ํ๋ ๊ณณ ํ ๊ณณ์ ์์ ํ๋ ์ ์์ ์ผ๋ก train์ด ์์๋์๋๋ฐ ๋ฌธ์ ๊ฐ ์๋ ํ๋์ผ์ง ๊ฑฑ์ ๋ฉ๋๋ค. ๋๋ฒ์งธ๋ก๋ ์ฒซ๋ฒ์งธ epoch ํ์ต์ด ์๋ฃ๋ ์ดํ์ ๋ค์๊ณผ ๊ฐ์ ์๋ฌ๋ฉ์ธ์ง๊ฐ ๋์์ต๋๋ค. (์ฌ์ง) ์ ์ด๋ฏธ์ง๋ฅผ ์ ์ฝ์ผ๋ ค๊ณ ํ๋๊ฑด์ง ๊ถ๊ธํฉ๋๋ค. ์ ์ด๋ฏธ์ง๋ฅผ ์ฝ๊ณ ์ ํ๋๊ฑฐ๋ผ๋ฉด ์ ์์ ์ผ๋ก ํ์ต์ด ๋๋ ์ํ์ธ๊ฒ ๋ง์๊น์? ๋ต๋ณ๊ฐ์ฌํฉ๋๋ค
- Likes
- 0
- Comments
- 7
- Viewcount
- 823
Q&A
local setting ์ง๋ฌธ
์๋ ํ์ญ๋๊น ๊ฐ์ฌ๋. ๋ต๋ณ ๊ฐ์ฌํฉ๋๋ค. ๋ฐ์ดํฐ์ ์์ฑ ์ฝ๋์ config ์ค์ ์ฝ๋๋ ์๋์ ๊ฐ์ต๋๋ค. 1. ๋ฐ์ดํฐ์ ์์ฑ ์ฝ๋ import copy import os.path as osp import cv2 import mmcv import numpy as np from mmdet.datasets.builder import DATASETS from mmdet.datasets.custom import CustomDataset # ๋ฐ๋์ ์๋ Decorator ์ค์ ํ ๊ฒ.@DATASETS.register_module() ์ค์ ์ force=True๋ฅผ ์ ๋ ฅํ์ง ์์ผ๋ฉด Dataset ์ฌ๋ฑ๋ก ๋ถ๊ฐ. @DATASETS.register_module(force=True) class KittyTinyDataset(CustomDataset): CLASSES = ('Car', 'Truck', 'Pedestrian', 'Cyclist') ##### self.data_root: /content/kitti_tiny/ self.ann_file: /content/kitti_tiny/train.txt self.img_prefix: /content/kitti_tiny/training/image_2 #### ann_file: /content/kitti_tiny/train.txt # annotation์ ๋ํ ๋ชจ๋ ํ์ผ๋ช ์ ๊ฐ์ง๊ณ ์๋ ํ ์คํธ ํ์ผ์ __init__(self, ann_file)๋ก ์ ๋ ฅ ๋ฐ๊ณ , ์ด self.ann_file์ด load_annotations()์ ์ธ์๋ก ์ ๋ ฅ def load_annotations(self, ann_file): print('##### self.data_root:', self.data_root, 'self.ann_file:', self.ann_file, 'self.img_prefix:', self.img_prefix) print('#### ann_file:', ann_file) cat2label = {k:i for i, k in enumerate(self.CLASSES)} image_list = mmcv.list_from_file(self.ann_file) # ํฌ๋งท ์ค๋ฆฝ ๋ฐ์ดํฐ๋ฅผ ๋ด์ list ๊ฐ์ฒด data_infos = [] for image_id in image_list: filename = '{0:}/{1:}.jpeg'.format(self.img_prefix, image_id) # ์๋ณธ ์ด๋ฏธ์ง์ ๋๋น, ๋์ด๋ฅผ image๋ฅผ ์ง์ ๋ก๋ํ์ฌ ๊ตฌํจ. image = cv2.imread(filename) height, width = image.shape[:2] # ๊ฐ๋ณ image์ annotation ์ ๋ณด ์ ์ฅ์ฉ Dict ์์ฑ. key๊ฐ filename ์๋ image์ ํ์ผ๋ช ๋ง ๋ค์ด๊ฐ(๋๋ ํ ๋ฆฌ๋ ์ ์ธ) data_info = {'filename': str(image_id) + '.jpeg', 'width': width, 'height': height} # ๊ฐ๋ณ annotation์ด ์๋ ์๋ธ ๋๋ ํ ๋ฆฌ์ prefix ๋ณํ. label_prefix = self.img_prefix.replace('image_2', 'label_2') # ๊ฐ๋ณ annotation ํ์ผ์ 1๊ฐ line ์ฉ ์ฝ์ด์ list ๋ก๋ lines = mmcv.list_from_file(osp.join(label_prefix, str(image_id)+'.txt')) # ์ ์ฒด lines๋ฅผ ๊ฐ๋ณ line๋ณ ๊ณต๋ฐฑ ๋ ๋ฒจ๋ก parsing ํ์ฌ ๋ค์ list๋ก ์ ์ฅ. content๋ list์ listํํ์. # ann ์ ๋ณด๋ numpy array๋ก ์ ์ฅ๋๋ ํ ์คํธ ์ฒ๋ฆฌ๋ ๋ฐ์ดํฐ ๊ฐ๊ณต์ด list ๊ฐ ํธํ๋ฏ๋ก ์ผ์ฐจ์ ์ผ๋ก list๋ก ๋ณํ ์ํ. content = [line.strip().split(' ') for line in lines] # ์ค๋ธ์ ํธ์ ํด๋์ค๋ช ์ bbox_names๋ก ์ ์ฅ. bbox_names = [x[0] for x in content] # bbox ์ขํ๋ฅผ ์ ์ฅ bboxes = [ [float(info) for info in x[4:8]] for x in content] # ํด๋์ค๋ช ์ด ํด๋น ์ฌํญ์ด ์๋ ๋์ Filtering out, 'DontCare'sms ignore๋ก ๋ณ๋ ์ ์ฅ. gt_bboxes = [] gt_labels = [] gt_bboxes_ignore = [] gt_labels_ignore = [] for bbox_name, bbox in zip(bbox_names, bboxes): # ๋ง์ฝ bbox_name์ด ํด๋์ค๋ช ์ ํด๋น ๋๋ฉด, gt_bboxes์ gt_labels์ ์ถ๊ฐ, ๊ทธ๋ ์ง ์์ผ๋ฉด gt_bboxes_ignore, gt_labels_ignore์ ์ถ๊ฐ if bbox_name in cat2label: gt_bboxes.append(bbox) # gt_labels์๋ class id๋ฅผ ์ ๋ ฅ gt_labels.append(cat2label[bbox_name]) else: gt_bboxes_ignore.append(bbox) gt_labels_ignore.append(-1) # ๊ฐ๋ณ image๋ณ annotation ์ ๋ณด๋ฅผ ๊ฐ์ง๋ Dict ์์ฑ. ํด๋น Dict์ value๊ฐ์ ๋ชจ๋ np.array์. data_anno = { 'bboxes': np.array(gt_bboxes, dtype=np.float32).reshape(-1, 4), 'labels': np.array(gt_labels, dtype=np.long), 'bboxes_ignore': np.array(gt_bboxes_ignore, dtype=np.float32).reshape(-1, 4), 'labels_ignore': np.array(gt_labels_ignore, dtype=np.long) } # image์ ๋ํ ๋ฉํ ์ ๋ณด๋ฅผ ๊ฐ์ง๋ data_info Dict์ 'ann' key๊ฐ์ผ๋ก data_anno๋ฅผ value๋ก ์ ์ฅ. data_info.update(ann=data_anno) # ์ ์ฒด annotation ํ์ผ๋ค์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ์ง๋ data_infos์ data_info Dict๋ฅผ ์ถ๊ฐ data_infos.append(data_info) return data_infos 2. config ์ฝ๋๋ ์๋์ ๊ฐ์ต๋๋ค. ### Config ์ค์ ํ๊ณ Pretrained ๋ชจ๋ธ ๋ค์ด๋ก๋ config_file = './mmdetection/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py' checkpoint_file = './mmdetection/checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth' from mmcv import Config cfg = Config.fromfile(config_file) print(cfg.pretty_text) from mmdet.apis import set_random_seed # dataset์ ๋ํ ํ๊ฒฝ ํ๋ผ๋ฏธํฐ ์์ . cfg.dataset_type = 'KittyTinyDataset' cfg.data_root = './kitti_tiny/' # train, val, test dataset์ ๋ํ type, data_root, ann_file, img_prefix ํ๊ฒฝ ํ๋ผ๋ฏธํฐ ์์ . cfg.data.train.type = 'KittyTinyDataset' cfg.data.train.data_root = './kitti_tiny/' cfg.data.train.ann_file = 'train.txt' cfg.data.train.img_prefix = 'training/image_2' cfg.data.val.type = 'KittyTinyDataset' cfg.data.val.data_root = './kitti_tiny/' cfg.data.val.ann_file = 'val.txt' cfg.data.val.img_prefix = 'training/image_2' cfg.data.test.type = 'KittyTinyDataset' cfg.data.test.data_root = './kitti_tiny/' cfg.data.test.ann_file = 'val.txt' cfg.data.test.img_prefix = 'training/image_2' # class์ ๊ฐฏ์ ์์ . cfg.model.roi_head.bbox_head.num_classes = 4 # pretrained ๋ชจ๋ธ cfg.load_from = './mmdetection/checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth' # ํ์ต weight ํ์ผ๋ก ๋ก๊ทธ๋ฅผ ์ ์ฅํ๊ธฐ ์ํ ๋๋ ํ ๋ฆฌ ์ค์ . cfg.work_dir = './mmdetection/tutorial_exps' # ํ์ต์จ ๋ณ๊ฒฝ ํ๊ฒฝ ํ๋ผ๋ฏธํฐ ์ค์ . cfg.optimizer.lr = 0.02 / 8 cfg.lr_config.warmup = None cfg.log_config.interval = 10 # config ์ํ ์๋ง๋ค policy๊ฐ์ด ์์ด์ง๋ bug๋ก ์ธํ์ฌ ์ค์ . cfg.lr_config.policy = 'step' # Change the evaluation metric since we use customized dataset. cfg.evaluation.metric = 'mAP' # We can set the evaluation interval to reduce the evaluation times cfg.evaluation.interval = 12 # We can set the checkpoint saving interval to reduce the storage cost cfg.checkpoint_config.interval = 12 # Set seed thus the results are more reproducible cfg.seed = 0 set_random_seed(0, deterministic=False) cfg.gpu_ids = range(1) #cfg.gpu_ids = 1 # We can initialize the logger for training and have a look # at the final config used for training print(f'Config:\n{cfg.pretty_text}') from mmdet.datasets import build_dataset from mmdet.models import build_detector from mmdet.apis import train_detector # train์ฉ Dataset ์์ฑ. datasets = [build_dataset(cfg.data.train)] model = build_detector(cfg.model, train_cfg=cfg.get('train_cfg'), test_cfg=cfg.get('test_cfg')) model.CLASSES = datasets[0].CLASSES #-----------------train code ----------------------------- #mmcv.mkdir_or_exist(osp.abspath(cfg.work_dir)) #%cd mmdetection # epochs๋ config์ runner ํ๋ผ๋ฏธํฐ๋ก ์ง์ ๋จ. ๊ธฐ๋ณธ 12ํ cfg.lr_config.policy = 'step' train_detector(model, datasets, cfg, distributed=False, validate=True) ๋ง์ํด์ฃผ์ ๋๋ก config ์์ ๋ฌธ์ ๊ฐ ์๋์ง ํ์ธํด๋ณด๊ณ ์์ต๋๋ค. colab์์ ์ ์๋์ํ ๊ฒฝ์ฐ์ cfg ๊ฐ๊ณผ local์์ ๋๋ฆฌ๋ cfg ๊ฐ์ ์ฐจ์ด๊ฐ ์์์ ํ์ธํ์ต๋๋ค. ํ์ธ๋ ๋ด์ฉ์ ์๋์ ๊ฐ์ต๋๋ค. (์ฌ์ง) ๋ค๋ฅธ ๋ด์ฉ์ ๊ฒฝ๋ก์์ ์ฐจ์ด์ ๋๋ง ์์๊ณ ์ ์ฐจ์ด๋ ์ ๋ฐ์ํ๋์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ์ฃผ์ ์ฝ๋๋ฅผ ๊ฑฐ์ ๊ทธ๋๋ก ๋๋ ธ๋๋ฐ ํด๋น๋ถ๋ถ๋ง ์ถ๊ฐ๋ก ๋ค์ด๊ฐ ์์ต๋๋ค. ํน์ ์ ๋ด์ฉ์ด ๋ฌธ์ ๊ฐ ๋ ๊น์? ๊ฐ์ฌํฉ๋๋ค!
- Likes
- 0
- Comments
- 7
- Viewcount
- 823
Q&A
SignOut์ ๋๋ฅด๋ฉด ๋ค์ ๋ก๊ทธ์ธ ํ์ด์ง๋ก ์งํ์ด ๋์ง ใ ๋ณ์ต๋๋ค.
์์ ํด ์ฃผ์ ๋ด์ฉ์ผ๋ก ์ํํด๋ ๋ก๊ทธ ์์์ด ์ ๋๋ก ๋์ง ์์ต๋๋ค. StreamBuilder๋ ์ ์์ ์ผ๋ก ๋ฃ์๋๋ฐ account page์์ logout ๋ฒํผ์ ๋๋ ์๋ RootPage์ stream์ด ์ ์์ ์ผ๋ก ๋์ํ์ง ์์ต๋๋ค. ๋๋ฒ๊ทธ ๋ชจ๋๋ก ํ์ธํด๋ดค๋๋ฐ ์ด๋จ๋๋ logout์ ๋ฐ๋ฅธ onAuthStateChanged๊ฐ ์กํ๋๋ฐ ๋ ๋ค๋ฅธ ๊ฒฝ์ฐ์๋ ์์กํ๋๋ค... ์ด๋ป๊ฒ ํด๊ฒฐํด์ผ ํ๋์?
- Likes
- 0
- Comments
- 4
- Viewcount
- 364




