묻고 답해요
141만명의 커뮤니티!! 함께 토론해봐요.
인프런 TOP Writers
-
미해결[개정판] 딥러닝 컴퓨터 비전 완벽 가이드
CityscapeDataset으로 변경 시 오류
선생님 안녕하세요 저는 현재 cityscape dataset을 바탕으로 kaggle mask_rcnn_nucleus 코드를 활용하여 segmentation을 해보려고 하고 있습니다.차량으로 활영한 스트릿뷰에서 나무와 도로를 분리해내어 온도 차이를 보고자 해당 작업을 진행 중인데요,이에 cityscape에 맞는 config 파일과 pretrained model, Cityscapedataset을 활용하려고 하고 있는데, 기존 Nucleusdataset을 Cityscapedataset으로 대체해서 코드를 돌리니 config와 계속 충돌이 있어 train을 할수가 없어 어느 부분을 수정해야할지 모르겠어서 질문드립니다.활용한 config, checkpoint 파일# config_file (/content/mmdetection/configs/cityscapes/mask_rcnn_r50_fpn_1x_cityscapes.py 활용) mask_rcnn_r50_fpn_1x_cityscapes.py # checkpoint_file (cityscape웹에서 다운로드) mask_rcnn_r50_fpn_1x_cityscapes_20201211_133733-d2858245.pth https://download.openmmlab.com/mmdetection/v2.0/cityscapes/mask_rcnn_r50_fpn_1x_cityscapes/mask_rcnn_r50_fpn_1x_cityscapes_20201211_133733-d2858245.pth1차 수정한 dataset 코드# 기존 dataset 코드 from mmdet.datasets.builder import DATASETS from mmdet.datasets.coco import CocoDataset @DATASETS.register_module(force=True) class NucleusDataset(CocoDataset): CLASSES = ['nucleus'] # 변경한 dataset 코드 # Copyright (c) OpenMMLab. All rights reserved. # Modified from https://github.com/facebookresearch/detectron2/blob/master/detectron2/data/datasets/cityscapes.py # noqa # and https://github.com/mcordts/cityscapesScripts/blob/master/cityscapesscripts/evaluation/evalInstanceLevelSemanticLabeling.py # noqa from mmdet.datasets.builder import DATASETS from mmdet.datasets.coco import CocoDataset from typing import List @DATASETS.register_module() class Cityscape_Dataset_2(CocoDataset): """Dataset for Cityscapes.""" METAINFO = { 'classes': ('road', 'vegetation', 'sidewalk', 'car', 'building', 'person', 'sky', 'bicycle'), 'palette': [(128,64,128), (107,142,35), (152,251,152), (0,0,142), (70,70,70), (255,0,0), (70,130,180), (119,11,32)] } def filter_data(self) -> List[dict]: """Filter annotations according to filter_cfg. Returns: List[dict]: Filtered results. """ if self.test_mode: return self.data_list if self.filter_cfg is None: return self.data_list filter_empty_gt = self.filter_cfg.get('filter_empty_gt', False) min_size = self.filter_cfg.get('min_size', 0) # obtain images that contain annotation ids_with_ann = set(data_info['img_id'] for data_info in self.data_list) # obtain images that contain annotations of the required categories ids_in_cat = set() for i, class_id in enumerate(self.cat_ids): ids_in_cat |= set(self.cat_img_map[class_id]) # merge the image id sets of the two conditions and use the merged set # to filter out images if self.filter_empty_gt=True ids_in_cat &= ids_with_ann valid_data_infos = [] for i, data_info in enumerate(self.data_list): img_id = data_info['img_id'] width = data_info['width'] height = data_info['height'] all_is_crowd = all([ instance['ignore_flag'] == 1 for instance in data_info['instances'] ]) if filter_empty_gt and (img_id not in ids_in_cat or all_is_crowd): continue if min(width, height) >= min_size: valid_data_infos.append(data_info) return valid_data_infos1차 수정한 코드로 시도한 train 시 오류from mmdet.datasets import build_dataset from mmdet.models import build_detector from mmdet.apis import train_detector # train, valid 용 Dataset 생성. datasets_train = [build_dataset(cfg.data.train)] datasets_val = [build_dataset(cfg.data.val)] --------- TypeError Traceback (most recent call last) /usr/local/lib/python3.10/dist-packages/mmcv/utils/registry.py in build_from_cfg(cfg, registry, default_args) 68 try: ---> 69 return obj_cls(**args) 70 except Exception as e: TypeError: CustomDataset.__init__() got an unexpected keyword argument 'times' During handling of the above exception, another exception occurred: TypeError Traceback (most recent call last) 2 frames /usr/local/lib/python3.10/dist-packages/mmcv/utils/registry.py in build_from_cfg(cfg, registry, default_args) 70 except Exception as e: 71 # Normal TypeError does not print class name. ---> 72 raise type(e)(f'{obj_cls.__name__}: {e}') 73 74 TypeError: Cityscape_Dataset_2: CustomDataset.__init__() got an unexpected keyword argument 'times'2차 수정한 코드 (chatGPT의 도움)도 또 다른 오류 뜸@DATASETS.register_module() class Cityscape_Dataset_times(CocoDataset): """Dataset for Cityscapes.""" METAINFO = { 'classes': ('road', 'vegetation', 'sidewalk', 'car', 'building', 'person', 'sky', 'bicycle'), 'palette': [(128,64,128), (107,142,35), (152,251,152), (0,0,142), (70,70,70), (255,0,0), (70,130,180), (119,11,32)] } def __init__(self, *args, times=1, **kwargs): self.times = times super().__init__(*args, **kwargs) def __getitem__(self, idx): # Get the real index by considering the 'times' argument. idx = idx % len(self.data_list) return super().__getitem__(idx) def __len__(self): # The length is the original length times the 'times' argument. return len(self.data_list) * self.times ..이하 동일from mmdet.datasets import build_dataset from mmdet.models import build_detector from mmdet.apis import train_detector # train, valid 용 Dataset 생성. datasets_train = [build_dataset(cfg.data.train)] datasets_val = [build_dataset(cfg.data.val)] --------- TypeError Traceback (most recent call last) /usr/local/lib/python3.10/dist-packages/mmcv/utils/registry.py in build_from_cfg(cfg, registry, default_args) 68 try: ---> 69 return obj_cls(**args) 70 except Exception as e: 3 frames TypeError: CustomDataset.__init__() got an unexpected keyword argument 'dataset' During handling of the above exception, another exception occurred: TypeError Traceback (most recent call last) /usr/local/lib/python3.10/dist-packages/mmcv/utils/registry.py in build_from_cfg(cfg, registry, default_args) 70 except Exception as e: 71 # Normal TypeError does not print class name. ---> 72 raise type(e)(f'{obj_cls.__name__}: {e}') 73 74 TypeError: Cityscape_Dataset_times: CustomDataset.__init__() got an unexpected keyword argument 'dataset'dataset 코드 자체를 전반적으로 수정해야하는 걸까요 아니면 config 파일을 수정해야하는 건지 알 수 있을까요?아니면 cocodataset의 class를 'road'와 'vegetation'으로 두는 방식으로 가능할까요? (cocodataset에는 도로나 나무를 분류하는 카테고리가 딱히 없어 보여서 가능한지 모르겠어서 cityscapedataset 코드를 따로 들고 온거긴 합니다.)졸업이 달려 있는 과제이다보니 마음이 급해지는데 너무 막막해서 도움을 청합니다. 감사합니다.
-
미해결[개정판] 딥러닝 컴퓨터 비전 완벽 가이드
mask_rcnn활용, 데이터 coco 포맷 변환 오류
선생님 안녕하세요 저는 현재 cityscape dataset을 바탕으로 kaggle mask_rcnn_nucleus 코드를 활용하여 segmentation을 해보려고 하고 있습니다.그에 따라 cityscape 데이터를 nulceus 데이터와 동일한 구조의 디렉토리로 정리하였는데요,이를 coco 포맷으로 변환하려고 하니, 아래 오류가 떠서 문의드립니다.파일 경로는 모두 맞게 입력한 것 같은데, 이미지를 못 읽고 있는 것 같습니다.. 'convert_nucleus_to_coco' 함수를 수정하거나 하지 않았는데 왜 이미지를 못읽는 걸까요?(파일 경로)(오류 메세지)convert_nucleus_to_coco('/content/drive/MyDrive/vision/DLCV_New-main/kaggle/train_data_jskim/03_masks/aachen', train_ids, '/content/drive/MyDrive/vision/DLCV_New-main/kaggle/train_data_jskim/coco_output/train_coco.json') convert_nucleus_to_coco('/content/drive/MyDrive/vision/DLCV_New-main/kaggle/train_data_jskim/03_masks/aachen', val_ids, '/content/drive/MyDrive/vision/DLCV_New-main/kaggle/train_data_jskim/coco_output/val_coco.json') _____아래 오류 메세지_____ /content/drive/MyDrive/vision/DLCV_New-main/kaggle/train_data_jskim/03_masks/aachen/aachen_000033_000019_gtFine_color/image/aachen_000033_000019_gtFine_color.png --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-63-d95f91ecbcb7> in <cell line: 1>() ----> 1 convert_nucleus_to_coco('/content/drive/MyDrive/vision/DLCV_New-main/kaggle/train_data_jskim/03_masks/aachen', train_ids, '/content/drive/MyDrive/vision/DLCV_New-main/kaggle/train_data_jskim/coco_output/train_coco.json') 2 convert_nucleus_to_coco('/content/drive/MyDrive/vision/DLCV_New-main/kaggle/train_data_jskim/03_masks/aachen', val_ids, '/content/drive/MyDrive/vision/DLCV_New-main/kaggle/train_data_jskim/coco_output/val_coco.json') <ipython-input-61-6f0ad3172ae3> in convert_nucleus_to_coco(data_root_dir, image_ids, out_file) 15 16 print(image_path) ---> 17 height, width = cv2.imread(image_path).shape[0:2] 18 # 개별 image의 dict 정보 생성 19 image_info = dict(file_name=file_name, AttributeError: 'NoneType' object has no attribute 'shape'