Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not show custom data correctly. #4727

Closed
feiyuhuahuo opened this issue Mar 8, 2021 · 9 comments · Fixed by #4732
Closed

Can not show custom data correctly. #4727

feiyuhuahuo opened this issue Mar 8, 2021 · 9 comments · Fixed by #4732
Assignees

Comments

@feiyuhuahuo
Copy link

feiyuhuahuo commented Mar 8, 2021

My mmdetection version is 2.10.0. Following this guidance(https://github.com/open-mmlab/mmdetection/blob/master/docs/2_new_data_model.md), I prepared my custom dataset as a coco-style json. But I found the code can not read my data correctly. Because the CLASSES is fixed,

CLASSES = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',

so adding a custom class variable in the config file is useless.
图片
All my images were filtered because of the incorrect classes.
Besides, I did not found the class variable in the default config.
I finally fixed this error by writing a custom Dataset. I tried to show my data by:python tools/misc/browse_dataset.py [config], but the showed image was broken:
图片
I guess this is because my image is PNG file. But PNG format is important. In industry environment, images are usually in this format because of its lossless property. I haven't fixed this yet. Hope you can help me, thanks.

Additionally, I have a personal suggestion. Maybe it's better to open this min_size in config file. Or in some small object detection task, target maybe filtered.

def _filter_imgs(self, min_size=32):

@hhaAndroid
Copy link
Collaborator

Hi @feiyuhuahuo, thank you for your feedback.

  1. If you have a custom dataset as a coco-style JSON. Your configuration should look like this:
dataset_type = 'CocoDataset'
classes = ('balloon', )
  1. The picture is not displayed correctly because the image data type is float32. We will fix this problem

Thank you!

@hhaAndroid
Copy link
Collaborator

hhaAndroid commented Mar 9, 2021

About the min_size in the config file, It means that images smaller than this value will be filtered instead of the target.

@feiyuhuahuo
Copy link
Author

图片

Writing a classes variable in config is useless. self.CLASSES is still coco 80 classes. Take a look at this line.

self.cat_ids = self.coco.get_cat_ids(cat_names=self.CLASSES)

@hhaAndroid
Copy link
Collaborator

图片

Writing a classes variable in config is useless. self.CLASSES is still coco 80 classes. Take a look at this line.

self.cat_ids = self.coco.get_cat_ids(cat_names=self.CLASSES)

Your understanding is incorrect. This parameter will be modified during the initialization in CustomDataset

image

@feiyuhuahuo
Copy link
Author

dataset = build_dataset(cfg.data.train)

I've taken a look at this line. The classes is in the whole config, but is missed in cfg.data.train. Did I make something wrong?
Screenshot from 2021-03-09 10-27-26

@hhaAndroid
Copy link
Collaborator

Can you provide the complete config file content?

@feiyuhuahuo
Copy link
Author

The whole config.

_base_ = '../_base_/default_runtime.py'
# model settings
model = dict(
    type='YOLOV3',
    pretrained='open-mmlab://darknet53',
    backbone=dict(type='Darknet', depth=53, out_indices=(3, 4, 5)),
    neck=dict(
        type='YOLOV3Neck',
        num_scales=3,
        in_channels=[1024, 512, 256],
        out_channels=[512, 256, 128]),
    bbox_head=dict(
        type='YOLOV3Head',
        num_classes=4,
        in_channels=[512, 256, 128],
        out_channels=[1024, 512, 256],
        anchor_generator=dict(
            type='YOLOAnchorGenerator',
            base_sizes=[[(1000, 150), (1000, 40), (500, 50)],
                        [(100, 150), (150, 30), (30, 100)],
                        [(40, 15), (40, 40), (15, 25)]],
            strides=[32, 16, 8]),
        bbox_coder=dict(type='YOLOBBoxCoder'),
        featmap_strides=[32, 16, 8],
        loss_cls=dict(
            type='CrossEntropyLoss',
            use_sigmoid=True,
            loss_weight=1.0,
            reduction='sum'),
        loss_conf=dict(
            type='CrossEntropyLoss',
            use_sigmoid=True,
            loss_weight=1.0,
            reduction='sum'),
        loss_xy=dict(
            type='CrossEntropyLoss',
            use_sigmoid=True,
            loss_weight=2.0,
            reduction='sum'),
        loss_wh=dict(type='MSELoss', loss_weight=2.0, reduction='sum')),
    # training and testing settings
    train_cfg=dict(
        assigner=dict(
            type='GridAssigner',
            pos_iou_thr=0.3,
            neg_iou_thr=0.3,
            min_pos_iou=0)),
    test_cfg=dict(
        nms_pre=1000,
        min_bbox_size=0,
        score_thr=0.05,
        conf_thr=0.005,
        nms=dict(type='nms', iou_threshold=0.45),
        max_per_img=100))

# dataset settings
# dataset_type = 'Haiboguan'
dataset_type = 'CocoDataset'
classes = ('huashang', 'yashang', 'yiwu', 'yise')
data_root = '/home/feiyu/Data/haiboguan/coco_format/'
img_norm_cfg = dict(mean=[0, 0, 0], std=[255., 255., 255.], to_rgb=True)
train_pipeline = [
    dict(type='LoadImageFromFile', to_float32=True),
    dict(type='LoadAnnotations', with_bbox=True),
    # dict(type='PhotoMetricDistortion'),
    # dict(
    #     type='Expand',
    #     mean=img_norm_cfg['mean'],
    #     to_rgb=img_norm_cfg['to_rgb'],
    #     ratio_range=(1, 2)),
    # dict(
    #     type='MinIoURandomCrop',
    #     min_ious=(0.4, 0.5, 0.6, 0.7, 0.8, 0.9),
    #     min_crop_size=0.3),
    dict(type='Resize', img_scale=[(1216, 384)], keep_ratio=True),
    dict(type='RandomFlip', flip_ratio=0.5),
    dict(type='Normalize', **img_norm_cfg),
    dict(type='Pad', size_divisor=32),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels'])
]
test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(
        type='MultiScaleFlipAug',
        img_scale=(1216, 384),
        flip=False,
        transforms=[
            dict(type='Resize', keep_ratio=True),
            dict(type='RandomFlip'),
            dict(type='Normalize', **img_norm_cfg),
            dict(type='Pad', size_divisor=32),
            dict(type='ImageToTensor', keys=['img']),
            dict(type='Collect', keys=['img'])
        ])
]
data = dict(
    samples_per_gpu=8,
    workers_per_gpu=4,
    train=dict(
        type=dataset_type,
        ann_file=data_root + 'annotations/haiboguan_train.json',
        img_prefix=data_root + 'train/',
        pipeline=train_pipeline),
    val=dict(
        type=dataset_type,
        ann_file=data_root + 'annotations/haiboguan_val.json',
        img_prefix=data_root + 'val/',
        pipeline=test_pipeline),
    test=dict(
        type=dataset_type,
        ann_file=data_root + 'annotations/haiboguan_val.json',
        img_prefix=data_root + 'val/',
        pipeline=test_pipeline))
# optimizer
optimizer = dict(type='SGD', lr=0.001, momentum=0.9, weight_decay=0.0005)
optimizer_config = dict(grad_clip=dict(max_norm=35, norm_type=2))
# learning policy
lr_config = dict(
    policy='step',
    warmup='linear',
    warmup_iters=1500,  # same as burn-in in darknet
    warmup_ratio=0.1,
    step=[40, 60])

# runtime settings
runner = dict(type='EpochBasedRunner', max_epochs=70)
evaluation = dict(interval=2, metric=['bbox'])

@hhaAndroid
Copy link
Collaborator

hhaAndroid commented Mar 9, 2021

Hi, Your config settings are incorrect. The correct config is as follows

train=dict(
        type=dataset_type,
        classes=classes,  #==========
        ann_file=data_root + 'annotations/haiboguan_train.json',
        img_prefix=data_root + 'train/',
        pipeline=train_pipeline),
    val=dict(
        type=dataset_type,
        classes=classes, #==========
        ann_file=data_root + 'annotations/haiboguan_val.json',
        img_prefix=data_root + 'val/',
        pipeline=test_pipeline),
    test=dict(
        type=dataset_type,
        classes=classes, #==========
        ann_file=data_root + 'annotations/haiboguan_val.json',
        img_prefix=data_root + 'val/',
        pipeline=test_pipeline))

@feiyuhuahuo
Copy link
Author

Thanks, it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants