microsoft / SoftTeacher

Semi-Supervised Learning, Object Detection, ICCV2021
MIT License
905 stars 123 forks source link

No validation on Custom dataset #198

Open mjehanzaib999 opened 2 years ago

mjehanzaib999 commented 2 years ago

I am using the following config

mmdet_base = "../../thirdparty/mmdetection/configs/base" base = [ f"{mmdet_base}/models/faster_rcnn_r50_fpn.py", f"{mmdet_base}/datasets/coco_detection.py", f"{mmdet_base}/schedules/schedule_1x.py", f"{mmdet_base}/default_runtime.py", ]

data_root = 'data/mitosis_coco/' classes = ('mitosis',)

pretrained = 'https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_tiny_patch4_window7_224.pth' # noqa

model = dict( type='FasterRCNN', backbone=dict( delete=True, type='SwinTransformer', embed_dims=96, depths=[2, 2, 6, 2], num_heads=[3, 6, 12, 24], window_size=7, mlp_ratio=4, qkv_bias=True, qk_scale=None, drop_rate=0., attn_drop_rate=0., drop_path_rate=0.2, patch_norm=True, out_indices=(0, 1, 2, 3), with_cp=False, convert_weights=True, init_cfg=dict(type='Pretrained', checkpoint=pretrained) ),

neck=dict(in_channels=[96, 192, 384, 768]))

img_norm_cfg = dict(mean=[103.530, 116.280, 123.675], std=[1.0, 1.0, 1.0], to_rgb=False)

train_pipeline = [ dict(type="LoadImageFromFile"), dict(type="LoadAnnotations", with_bbox=True), dict( type="Sequential", transforms=[ dict( type="RandResize", img_scale=[(1333, 400), (1333, 1200)], multiscale_mode="range", keep_ratio=True, ), dict(type="RandFlip", flip_ratio=0.5), dict( type="OneOf", transforms=[ dict(type=k) for k in [ "Identity", "AutoContrast", "RandEqualize", "RandSolarize", "RandColor", "RandContrast", "RandBrightness", "RandSharpness", "RandPosterize", ] ], ), ], record=True, ), dict(type="Pad", size_divisor=32), dict(type="Normalize", **img_norm_cfg), dict(type="ExtraAttrs", tag="sup"), dict(type="DefaultFormatBundle"), dict( type="Collect", keys=["img", "gt_bboxes", "gt_labels"], meta_keys=( "filename", "ori_shape", "img_shape", "img_norm_cfg", "pad_shape", "scale_factor", "tag", ), ), ]

strong_pipeline = [ dict( type="Sequential", transforms=[ dict( type="RandResize", img_scale=[(1333, 400), (1333, 1200)], multiscale_mode="range", keep_ratio=True, ), dict(type="RandFlip", flip_ratio=0.5), dict( type="ShuffledSequential", transforms=[ dict( type="OneOf", transforms=[ dict(type=k) for k in [ "Identity", "AutoContrast", "RandEqualize", "RandSolarize", "RandColor", "RandContrast", "RandBrightness", "RandSharpness", "RandPosterize", ] ], ), dict( type="OneOf", transforms=[ dict(type="RandTranslate", x=(-0.1, 0.1)), dict(type="RandTranslate", y=(-0.1, 0.1)), dict(type="RandRotate", angle=(-30, 30)), [ dict(type="RandShear", x=(-30, 30)), dict(type="RandShear", y=(-30, 30)), ], ], ), ], ), dict( type="RandErase", n_iterations=(1, 5), size=[0, 0.2], squared=True, ), ], record=True, ), dict(type="Pad", size_divisor=32), dict(type="Normalize", img_norm_cfg), dict(type="ExtraAttrs", tag="unsup_student"), dict(type="DefaultFormatBundle"), dict( type="Collect", keys=["img", "gt_bboxes", "gt_labels"], meta_keys=( "filename", "ori_shape", "img_shape", "img_norm_cfg", "pad_shape", "scale_factor", "tag", "transform_matrix", ), ), ] weak_pipeline = [ dict( type="Sequential", transforms=[ dict( type="RandResize", img_scale=[(1333, 400), (1333, 1200)], multiscale_mode="range", keep_ratio=True, ), dict(type="RandFlip", flip_ratio=0.5), ], record=True, ), dict(type="Pad", size_divisor=32), dict(type="Normalize", img_norm_cfg), dict(type="ExtraAttrs", tag="unsup_teacher"), dict(type="DefaultFormatBundle"), dict( type="Collect", keys=["img", "gt_bboxes", "gt_labels"], meta_keys=( "filename", "ori_shape", "img_shape", "img_norm_cfg", "pad_shape", "scale_factor", "tag", "transform_matrix", ), ), ] unsup_pipeline = [ dict(type="LoadImageFromFile"),

dict(type="LoadAnnotations", with_bbox=True),

# generate fake labels for data format compatibility
dict(type="PseudoSamples", with_bbox=True),
dict(
    type="MultiBranch", unsup_student=strong_pipeline, unsup_teacher=weak_pipeline
),

]

test_pipeline = [ dict(type="LoadImageFromFile"), dict( type="MultiScaleFlipAug", img_scale=(1333, 800), 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( delete = True, type = "SemiDataset", sup = dict( type="CocoDataset", ann_file = data_root + "annotations/train.json", img_prefix = data_root + 'train/', classes=classes, pipeline = train_pipeline,

    ),
    unsup=dict(
        type="CocoDataset",
        ann_file = data_root+"annotations/unlabeled.json",
        img_prefix = data_root+'unlabeled/',
        classes=classes,
        pipeline=unsup_pipeline,
        filter_empty_gt=False,

    ),
    #pipeline=test_pipeline, ########### Added this to solve sampler issues
),
val=dict(
    # type=dataset_type,
    ann_file=data_root + 'annotations/val.json',
    img_prefix=data_root + 'val/',
    classes=classes,
    pipeline=test_pipeline,
),

test=dict(
    # type=dataset_type,
    ann_file=data_root + 'annotations/val.json',
    img_prefix=data_root + 'val/',
    classes=classes,
    pipeline=test_pipeline,
),
sampler=dict(
    train=dict(
        type="SemiBalanceSampler",
        sample_ratio=[1, 4],
        #by_prob=True,
        # at_least_one=True,
        #by_prob = False,
        epoch_length=7330,
    ),

val = dict(type = )

),

)

semi_wrapper = dict( type="SoftTeacher", model="${model}", train_cfg=dict( use_teacher_proposal=False, pseudo_label_initial_score_thr=0.5, rpn_pseudo_threshold=0.9, cls_pseudo_threshold=0.9, reg_pseudo_threshold=0.02, jitter_times=10, jitter_scale=0.06, min_pseduo_box_size=0, unsup_weight=2.0, ), test_cfg=dict(inference_on="student"), )

semi_wrapper = dict(

type="SoftTeacher",

model="${model}",

train_cfg=dict(

use_teacher_proposal=False,

pseudo_label_initial_score_thr=0.5,

rpn_pseudo_threshold=0.5,

cls_pseudo_threshold=0.5,

reg_pseudo_threshold=0.02,

jitter_times=10,

jitter_scale=0.06,

min_pseduo_box_size=0,

unsup_weight=2.0,

),

test_cfg=dict(inference_on="student"),

)

custom_hooks = [ dict(type="NumClassCheckHook"), dict(type="WeightSummary"), dict(type="MeanTeacher", momentum=0.999, interval=1, warm_up=0), ] evaluation = dict(type="SubModulesDistEvalHook", interval=100)

evaluation = dict(interval=30, metric='bbox')

optimizer = dict(type="SGD", lr=0.0001, momentum=0.9, weight_decay=0.0001)

lr_config = dict( policy='CosineAnnealing', warmup='linear', warmup_iters=1000, warmup_ratio=1.0 / 10, min_lr_ratio=1e-5)

lr_config = dict(step=[120000, 160000])

runner = dict(delete=True, type="IterBasedRunner", max_iters=180000)

lr_config = dict(step=[60000 2, 80000 2])

runner = dict(delete=True,type='EpochBasedRunner', max_epochs=12)

runner = dict(delete=True, type="IterBasedRunner", max_iters=180000 * 4)

checkpoint_config = dict(by_epoch=False, interval=4000, max_keep_ckpts=1) optimizer = dict(type="SGD", lr=0.0001, momentum=0.9, weight_decay=0.0001)

lr_config = dict(step=[120000, 160000])

workflow = [('train', 1), ('val',1)]

fp16 = dict(loss_scale="dynamic")

log_config = dict( interval=50, hooks=[ dict(type="TextLoggerHook", by_epoch=False), dict(type='TensorboardLoggerHook', by_epoch=False),

dict(

type="WandbLoggerHook",

init_kwargs=dict(

project="pre_release",

name="${cfg_name}",

config=dict(

work_dirs="${work_dir}",

total_step="${runner.max_iters}",

),

),

by_epoch=False,

),

],

)

####### I am trying to use swin backbone with the faster rcnn for training on custom dataset but am not getting any validation results even after 100k iterations, would appreciate some help kindly!

mjehanzaib999 commented 2 years ago

My log which im getting is

2022-04-18 16:43:05,550 - mmdet.ssod - INFO - Iter [52850/180000] lr: 1.000e-03, eta: 1 day, 0:46:46, time: 0.872, data_time: 0.243, memory: 6665, ema_momentum: 0.9990, sup_loss_rpn_cls: 0.3799, sup_loss_rpn_bbox: 0.0284, sup_loss_cls: 0.0606, sup_acc: 99.6748, sup_loss_bbox: 0.0018, loss: 0.1309, unsup_loss_rpn_cls: 0.0000, unsup_loss_rpn_bbox: 0.0000, unsup_loss_cls: 0.0000, unsup_acc: 100.0000, unsup_loss_bbox: 0.0000 2022-04-18 16:44:11,458 - mmdet.ssod - INFO - Iter [52900/180000] lr: 1.000e-03, eta: 1 day, 0:46:05, time: 0.655, data_time: 0.013, memory: 6665, ema_momentum: 0.9990, sup_loss_rpn_cls: 0.3493, sup_loss_rpn_bbox: 0.0254, sup_loss_cls: 0.0511, sup_acc: 99.7363, sup_loss_bbox: 0.0006, loss: 0.1295, unsup_loss_rpn_cls: 0.0000, unsup_loss_rpn_bbox: 0.0000, unsup_loss_cls: 0.0000, unsup_acc: 100.0000, unsup_loss_bbox: 0.0000 2022-04-18 16:44:46,047 - mmdet.ssod - INFO - Evaluating bbox... 2022-04-18 16:44:46,047 - mmdet.ssod - ERROR - The testing results of the whole dataset is empty. 2022-04-18 16:45:20,733 - mmdet.ssod - INFO - Evaluating bbox... 2022-04-18 16:45:20,733 - mmdet.ssod - ERROR - The testing results of the whole dataset is empty. 2022-04-18 16:45:20,734 - mmdet.ssod - INFO - Iter(val) [52900] 2022-04-18 16:46:35,657 - mmdet.ssod - INFO - Iter [52950/180000] lr: 1.000e-03, eta: 1 day, 0:45:51, time: 0.878, data_time: 0.245, memory: 6665, ema_momentum: 0.9990, sup_loss_rpn_cls: 0.4145, sup_loss_rpn_bbox: 0.0299, sup_loss_cls: 0.0666, sup_acc: 99.6475, sup_loss_bbox: 0.0020, loss: 0.1815, unsup_loss_rpn_cls: 0.0000, unsup_loss_rpn_bbox: 0.0000, unsup_loss_cls: 0.0000, unsup_acc: 100.0000, unsup_loss_bbox: 0.0000 2022-04-18 16:47:40,475 - mmdet.ssod - INFO - Exp name: swin_mitosis_test.py 2022-04-18 16:47:40,475 - mmdet.ssod - INFO - Iter [53000/180000] lr: 1.000e-03, eta: 1 day, 0:45:09, time: 0.644, data_time: 0.014, memory: 6665, ema_momentum: 0.9990, sup_loss_rpn_cls: 0.3483, sup_loss_rpn_bbox: 0.0255, sup_loss_cls: 0.0519, sup_acc: 99.7217, sup_loss_bbox: 0.0009, loss: 0.1499, unsup_loss_rpn_cls: 0.0000, unsup_loss_rpn_bbox: 0.0000, unsup_loss_cls: 0.0000, unsup_acc: 100.0000, unsup_loss_bbox: 0.0000 2022-04-18 16:48:15,202 - mmdet.ssod - INFO - Evaluating bbox... 2022-04-18 16:48:15,203 - mmdet.ssod - ERROR - The testing results of the whole dataset is empty. 2022-04-18 16:48:49,868 - mmdet.ssod - INFO - Evaluating bbox... 2022-04-18 16:48:49,868 - mmdet.ssod - ERROR - The testing results of the whole dataset is empty. 2022-04-18 16:48:49,869 - mmdet.ssod - INFO - Exp name: swin_mitosis_test.py 2022-04-18 16:48:49,869 - mmdet.ssod - INFO - Iter(val) [53000] 2022-04-18 16:49:55,829 - mmdet.ssod - INFO - Iter [53050/180000] lr: 1.000e-03, eta: 1 day, 0:44:28, time: 0.651, data_time: 0.014, memory: 6665, ema_momentum: 0.9990, sup_loss_rpn_cls: 0.3435, sup_loss_rpn_bbox: 0.0252, sup_loss_cls: 0.0541, sup_acc: 99.7197, sup_loss_bbox: 0.0009, loss: 0.1581, unsup_loss_rpn_cls: 0.0000, unsup_loss_rpn_bbox: 0.0000, unsup_loss_cls: 0.0000, unsup_acc: 100.0000, unsup_loss_bbox: 0.0000 2022-04-18 16:51:11,718 - mmdet.ssod - INFO - Iter [53100/180000] lr: 1.000e-03, eta: 1 day, 0:43:46, time: 0.640, data_time: 0.014, memory: 6665, ema_momentum: 0.9990, sup_loss_rpn_cls: 0.3718, sup_loss_rpn_bbox: 0.0273, sup_loss_cls: 0.0589, sup_acc: 99.6807, sup_loss_bbox: 0.0015, loss: 0.1341, unsup_loss_rpn_cls: 0.0000, unsup_loss_rpn_bbox: 0.0000, unsup_loss_cls: 0.0000, unsup_acc: 100.0000, unsup_loss_bbox: 0.0000 2022-04-18 16:51:46,298 - mmdet.ssod - INFO - Evaluating bbox... 2022-04-18 16:51:46,299 - mmdet.ssod - ERROR - The testing results of the whole dataset is empty. 2022-04-18 16:52:20,929 - mmdet.ssod - INFO - Evaluating bbox... 2022-04-18 16:52:20,930 - mmdet.ssod - ERROR - The testing results of the whole dataset is empty. 2022-04-18 16:52:20,930 - mmdet.ssod - INFO - Iter(val) [53100] 2022-04-18 16:53:28,080 - mmdet.ssod - INFO - Iter [53150/180000] lr: 1.000e-03, eta: 1 day, 0:43:05, time: 0.652, data_time: 0.014, memory: 6665, ema_momentum: 0.9990, sup_loss_rpn_cls: 0.3424, sup_loss_rpn_bbox: 0.0253, sup_loss_cls: 0.0519, sup_acc: 99.7314, sup_loss_bbox: 0.0008, loss: 0.1290, unsup_loss_rpn_cls: 0.0000, unsup_loss_rpn_bbox: 0.0000, unsup_loss_cls: 0.0000, unsup_acc: 100.0000, unsup_loss_bbox: 0.0000