open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
28.55k stars 9.29k forks source link

DetectoRS segmentation #5161

Open alexeybozhchenko opened 3 years ago

alexeybozhchenko commented 3 years ago

Greetings! I am quite new to mmdetection. I wonder how do I set up the config in order to train it for the instance segmentation task? Currently my config looks like this, but it works just for the detection.

_base_ = 'detectors/detectors_cascade_rcnn_r50_1x_coco.py'
model = dict(
    roi_head=dict(bbox_head=[
            dict(
                type='Shared2FCBBoxHead',
                in_channels=256,
                fc_out_channels=1024,
                roi_feat_size=7,
                num_classes=2,
                bbox_coder=dict(
                    type='DeltaXYWHBBoxCoder',
                    target_means=[0., 0., 0., 0.],
                    target_stds=[0.1, 0.1, 0.2, 0.2]),
                reg_class_agnostic=True,
                loss_cls=dict(
                    type='CrossEntropyLoss',
                    use_sigmoid=False,
                    loss_weight=1.0),
                loss_bbox=dict(type='SmoothL1Loss', beta=1.0,
                               loss_weight=1.0)),
            dict(
                type='Shared2FCBBoxHead',
                in_channels=256,
                fc_out_channels=1024,
                roi_feat_size=7,
                num_classes=2,
                bbox_coder=dict(
                    type='DeltaXYWHBBoxCoder',
                    target_means=[0., 0., 0., 0.],
                    target_stds=[0.05, 0.05, 0.1, 0.1]),
                reg_class_agnostic=True,
                loss_cls=dict(
                    type='CrossEntropyLoss',
                    use_sigmoid=False,
                    loss_weight=1.0),
                loss_bbox=dict(type='SmoothL1Loss', beta=1.0,
                               loss_weight=1.0)),
            dict(
                type='Shared2FCBBoxHead',
                in_channels=256,
                fc_out_channels=1024,
                roi_feat_size=7,
                num_classes=2,
                bbox_coder=dict(
                    type='DeltaXYWHBBoxCoder',
                    target_means=[0., 0., 0., 0.],
                    target_stds=[0.033, 0.033, 0.067, 0.067]),
                reg_class_agnostic=True,
                loss_cls=dict(
                    type='CrossEntropyLoss',
                    use_sigmoid=False,
                    loss_weight=1.0),
                loss_bbox=dict(type='SmoothL1Loss', beta=1.0, loss_weight=1.0))
        ]))

dataset_type = 'COCODataset'
classes = ('class1','class2')
data = dict(
    train=dict(
        img_prefix='data/train_images/',
        classes=classes,
        ann_file='data/train/instances_train2017.json'),
    val=dict(
        img_prefix='data/test_images/',
        classes=classes,
        ann_file='data/val/instances_val2017.json'),
    test=dict(
        img_prefix='data/test_images/',
        classes=classes,
        ann_file='data/val/instances_val2017.json'))
prk-vinay commented 3 years ago

You need to change your base config file first of all. Use any of the HTC ones. See the link below: https://github.com/open-mmlab/mmdetection/blob/master/configs/detectors/README.md

However, HTC requires cocostuffthings dataset. If you are using any custom dataset, it could be a problem.

alexeybozhchenko commented 3 years ago

@prk-vinay It was a bit of a struggle but I did managed to train it, thx. Others may @ me for the help if needed

sprakashdash commented 3 years ago

@alexeybozhchenko It would be helpful if you can tell me how to go around with the cocostuffthings. And I have JSON files and images in jpg format. I am getting this error despite I have jpg images.

Original Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/content/mmdetection/mmdet/datasets/custom.py", line 194, in __getitem__
    data = self.prepare_train_img(idx)
  File "/content/mmdetection/mmdet/datasets/custom.py", line 217, in prepare_train_img
    return self.pipeline(results)
  File "/content/mmdetection/mmdet/datasets/pipelines/compose.py", line 40, in __call__
    data = t(data)
  File "/content/mmdetection/mmdet/datasets/pipelines/loading.py", line 373, in __call__
    results = self._load_semantic_seg(results)
  File "/content/mmdetection/mmdet/datasets/pipelines/loading.py", line 347, in _load_semantic_seg
    img_bytes = self.file_client.get(filename)
  File "/usr/local/lib/python3.7/dist-packages/mmcv/fileio/file_client.py", line 306, in get
    return self.client.get(filepath)
  File "/usr/local/lib/python3.7/dist-packages/mmcv/fileio/file_client.py", line 184, in get
    with open(filepath, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'data/train/517.png'
yestaehyung commented 2 years ago

@alexeybozhchenko It would be helpful if you can tell me how to go around with the cocostuffthings. And I have JSON files and images in jpg format. I am getting this error despite I have jpg images.

Original Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/content/mmdetection/mmdet/datasets/custom.py", line 194, in __getitem__
    data = self.prepare_train_img(idx)
  File "/content/mmdetection/mmdet/datasets/custom.py", line 217, in prepare_train_img
    return self.pipeline(results)
  File "/content/mmdetection/mmdet/datasets/pipelines/compose.py", line 40, in __call__
    data = t(data)
  File "/content/mmdetection/mmdet/datasets/pipelines/loading.py", line 373, in __call__
    results = self._load_semantic_seg(results)
  File "/content/mmdetection/mmdet/datasets/pipelines/loading.py", line 347, in _load_semantic_seg
    img_bytes = self.file_client.get(filename)
  File "/usr/local/lib/python3.7/dist-packages/mmcv/fileio/file_client.py", line 306, in get
    return self.client.get(filepath)
  File "/usr/local/lib/python3.7/dist-packages/mmcv/fileio/file_client.py", line 184, in get
    with open(filepath, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'data/train/517.png'

DId you solve the problem??? I have same problem ㅠㅠ