Chasel-Tsui / mmdet-rfla

ECCV22: RFLA
MIT License
254 stars 23 forks source link

How to use original coco metric instead of AITOD metric ? #17

Closed Icecream-blue-sky closed 1 year ago

Icecream-blue-sky commented 1 year ago

I'm training my own dataset using RFLA. I find that the model still use the AITOD metric, though I have change the dataset in config file to 'CocoDataset'.

_base_ = [
    '../_base_/datasets/coco_detection.py',
    '../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
]
# model settings
model = dict(
    type='FCOS',
    backbone=dict(
        type='ResNet',
        depth=50,
        num_stages=4,
        out_indices=(0, 1, 2, 3),
        frozen_stages=1,
        norm_cfg=dict(type='BN', requires_grad=False),
        norm_eval=True,
        style='caffe',
        init_cfg=dict(
            type='Pretrained',
            checkpoint='open-mmlab://detectron/resnet50_caffe')),
    neck=dict(
        type='FPN',
        in_channels=[256, 512, 1024, 2048],
        out_channels=256,
        start_level=1,
        add_extra_convs='on_output',  # use P5
        num_outs=5,
        relu_before_extra_convs=True),
    bbox_head=dict(
        type='FCOSHead',
        norm_cfg=None,
        num_classes=352,
        in_channels=256,
        stacked_convs=4,
        feat_channels=256,
        strides=[8, 16, 32, 64, 128],
        norm_on_bbox=True,
        centerness_on_reg=True,
        dcn_on_last_conv=False,
        center_sampling=True,
        conv_bias=True,
        loss_cls=dict(
            type='FocalLoss',
            use_sigmoid=True,
            gamma=2.0,
            alpha=0.25,
            loss_weight=1.0),
        loss_bbox=dict(type='DIoULoss', loss_weight=1.0),
        loss_centerness=dict(
            type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0)),
    # training and testing settings
    train_cfg=dict(
        assigner=dict(
            type='MaxIoUAssigner',
            pos_iou_thr=0.5,
            neg_iou_thr=0.4,
            min_pos_iou=0,
            ignore_iof_thr=-1),
        allowed_border=-1,
        pos_weight=-1,
        debug=False),
    test_cfg=dict(
        nms_pre=3000,
        min_bbox_size=0,
        score_thr=0.05,
        nms=dict(type='nms', iou_threshold=0.5),
        max_per_img=3000))

dataset_type = 'CocoDataset'
data_root = '/home/sist/tqzouustc/dataset/QMUL-OpenLogo/coco/'
classes = ('microsoft', 'wordpress', 'bershka', 'yonex', 'nissan', 'allianz_text', 'optus_yes', 'visa', 'evernote', 'barbie', 'michelin', 'aldi', 'sunchips', 'mcdonalds_text', 'pepsi_text1', 'mercedesbenz_text', 'recycling', 'americanexpress', 'supreme', 'bayer', 'spiderman', 'guinness', 'bacardi', 'uniqlo1', 'unitednations', 'honda', 'lays', 'generalelectric', 'bridgestone', 'batman', 'kitkat', 'schwinn', 'adidas', 'ec', 'verizon', 'budweiser', 'lg', 'coke', 'ford', 'xbox', 'ibm', 'wellsfargo', 'mccafe', 'bankofamerica', 'santander', 'toyota', 'budweiser_text', 'oracle', 'base', 'ups', 'disney', 'soundcloud', 'rolex', 'chevrolet', 'chiquita', 'head_text', 'chevron', 'amazon', 'nike', 'standard_liege', 'maxxis', 'kfc', 'cvs', 'abus', 'chevrolet_text', 'heineken_text', 'hyundai', 'soundrop', 'hyundai_text', 'aral', 'cocacola', 'kia', 'esso', 'olympics', 'colgate', 'cpa_australia', 'hersheys', 'twitter', 'youtube', 'head', 'reebok_text', 'fritos', 'citroen', 'bbva', 'prada', 'canon', 'wii', 'axa', 'ikea', 'intel', 'cvspharmacy', 'drpepper', 'gap', 'maserati', 'huawei_text', 'tacobell', 't-mobile', 'burgerking', 'heineken', 'opel', 'bem', 'reeses', 'tnt', 'siemens', 'velveeta', 'sega', 'volkswagen_text', 'bionade', 'sony', 'calvinklein', 'bridgestone_text', 'benrus', 'firelli', 'apple', 'fosters', 'armitron', 'marlboro_text', 'hanes', 'bosch', 'chimay', 'lacoste_text', 'becks', 'carters', 'lv', 'mini', 'timberland', 'citi', 'jagermeister', 'pizzahut', 'bankofamerica_text', 'bik', 'aspirin', 'corona', 'lamborghini', 'republican', 'nissan_text', 'dexia', 'walmart_text', 'basf', 'texaco', 'nbc', 'vaio', 'aquapac_text', 'hm', 'warnerbros', 'hsbc_text', 'sprite', 'johnnywalker', 'uniqlo', 'venus', 'bosch_text', 'hsbc', 'nasa', 'shell', 'spar', 'audi_text', 'aldi_text', 'poloralphlauren', 'lotto', 'cartier', 'lego', 'hp', 'unicef', 'yahoo', 'jacobscreek', 'kelloggs', 'chickfila', 'marlboro_fig', 'windows', 'subway', 'bottegaveneta', 'internetexplorer', 'comedycentral', 'nescafe', 'londonunderground', 'vodafone', 'planters', 'select', 'apc', 'homedepot', 'chanel', 'adidas_text', 'tigerwash', 'costa', 'subaru', 'mcdonalds', 'ebay', 'yonex_text', 'fly_emirates', 'stellaartois', 'rbc', 'armani', 'redbull_text', 'audi', 'doritos', 'obey', 'volvo', 'dunkindonuts', 'skechers', 'honda_text', 'loreal', 'pepsi_text', 'boeing', 'bellataylor', 'verizon_text', 'espn', 'aluratek', 'at_and_t', 'scion_text', 'amcrest_text', 'jackinthebox', 'netflix', 'kraft', 'zara', 'superman', 'google', 'target', 'corona_text', 'umbro', 'goodyear', 'spar_text', 'danone', 'playstation', 'maxwellhouse', 'pampers', 'citroen_text', 'bmw', 'pizzahut_hut', 'pepsi', 'singha', 'mobil', 'underarmour', 'shell_text1', 'hisense', 'optus', 'fritolay', 'ferrari', 'toyota_text', 'bulgari', 'mercedesbenz', 'asus', 'esso_text', 'boeing_text', 'airness', 'porsche_text', 'nvidia', 'suzuki', 'northface', 'walmart', 'millerhighlife', 'bellodigital', 'wellsfargo_text', 'quick', 'kodak', 'porsche', 'mastercard', 'nb', 'fedex', 'coach', 'shell_text', 'medibank', 'infiniti_text', 'philadelphia', 'marlboro', 'allianz', 'miraclewhip', 'infiniti', 'nivea', 'android', 'santander_text', 'cheetos', 'hh', 'puma_text', 'jello', 'teslamotors', 'tsingtao', 'williamhill', 'chanel_text', 'tostitos', 'reebok', 'bbc', 'samsung', 'sap', 'gildan', 'heraldsun', 'reebok1', 'ruffles', 'erdinger', 'huawei', 'dhl', 'anz', 'redbull', 'cisco', 'blackmores', 'lacoste', 'panasonic', 'rolex_text', '3m', 'volkswagen', 'tommyhilfiger', 'tissot', 'us_president', 'jcrew', 'alfaromeo', 'mitsubishi', 'starbucks', 'hermes', 'bfgoodrich', 'facebook', 'carlsberg', 'renault', 'mk', 'apecase', 'bellodigital_text', 'firefox', 'jurlique', 'burgerking_text', 'luxottica', 'adidas1', 'motorola', 'lexus', 'lexus_text', 'nike_text', 'barclays', 'milka', 'amcrest', 'nintendo', 'athalon', 'target_text', 'anz_text', 'costco', 'homedepot_text', 'mtv', 'rittersport', 'converse', 'aluratek_text', 'paulaner', 'americanexpress_text', 'airhawk', 'gucci', 'thomsonreuters', 'yamaha', 'caterpillar', 'accenture', 'allett', 'levis', 'total', 'philips', 'gillette', 'puma', 'carglass', 'blizzardentertainment',)        
img_norm_cfg = dict(
    mean=[102.9801, 115.9465, 122.7717], std=[1.0, 1.0, 1.0], to_rgb=False)
train_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='LoadAnnotations', with_bbox=True),
    dict(type='Resize', img_scale=(1000, 600), 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=(1000, 600),
        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=2,
    workers_per_gpu=2,
    train=dict(
        type=dataset_type,
        classes=classes,
        ann_file=data_root + 'annotations/instances_trainval2017_openlogo.json',
        img_prefix=data_root + 'images/trainval2017/',
        pipeline=train_pipeline),
    val=dict(
        type=dataset_type,
        classes=classes,
        ann_file=data_root + 'annotations/instances_test2017_openlogo.json',
        img_prefix=data_root + 'images/test2017/',
        pipeline=test_pipeline),
    test=dict(
        type=dataset_type,
        classes=classes,
        ann_file=data_root + 'annotations/instances_test2017_openlogo.json',
        img_prefix=data_root + 'images/test2017/',
        # ann_file=data_root + 'annotations/instances_trainval2017_openlogo.json',
        # img_prefix=data_root + 'images/trainval2017/',
        pipeline=test_pipeline))
# optimizer
optimizer = dict(
    lr=0.01/2, paramwise_cfg=dict(bias_lr_mult=2., bias_decay_mult=0.))
optimizer_config = dict(
    _delete_=True, grad_clip=dict(max_norm=35, norm_type=2))
# learning policy
lr_config = dict(
    policy='step',
    warmup='constant',
    warmup_iters=10000,
    warmup_ratio=1.0 / 3,
    step=[8, 11])
runner = dict(type='EpochBasedRunner', max_epochs=12)

The training log is as below: image What can I do to use the original COCO metric ?

Chasel-Tsui commented 1 year ago

According to the training config, you are using the FCOS, instead of the RFLA. It seems that you need to modify the cocoeval.py file if you want to use the cocometric.