247 lines
9.4 KiB
Python
Raw Normal View History

# Copyright (c) OpenMMLab. All rights reserved.
2021-05-15 22:47:59 +08:00
import argparse
import os
import warnings
import mmcv
import torch
from mmcv import Config, DictAction
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import (get_dist_info, init_dist, load_checkpoint,
wrap_fp16_model)
from mmfewshot.detection.datasets import (build_dataloader, build_dataset,
get_copy_dataset_type)
from mmfewshot.detection.models import build_detector
2021-05-15 22:47:59 +08:00
def parse_args():
parser = argparse.ArgumentParser(
2021-05-16 16:29:24 +08:00
description='MMFewShot test (and eval) a model')
2021-05-15 22:47:59 +08:00
parser.add_argument('config', help='test config file path')
parser.add_argument('checkpoint', help='checkpoint file')
parser.add_argument('--out', help='output result file in pickle format')
parser.add_argument(
'--eval',
type=str,
nargs='+',
help='evaluation metrics, which depends on the dataset, e.g., "bbox",'
' "segm", "proposal" for COCO, and "mAP", "recall" for PASCAL VOC')
parser.add_argument(
'--gpu-ids',
type=int,
nargs='+',
help='(Deprecated, please use --gpu-id) ids of gpus to use '
'(only applicable to non-distributed training)')
parser.add_argument(
'--gpu-id',
type=int,
default=0,
help='id of gpu to use '
'(only applicable to non-distributed testing)')
2021-05-15 22:47:59 +08:00
parser.add_argument('--show', action='store_true', help='show results')
parser.add_argument(
'--show-dir', help='directory where painted images will be saved')
parser.add_argument(
'--show-score-thr',
type=float,
default=0.3,
help='score threshold (default: 0.3)')
2021-05-15 22:47:59 +08:00
parser.add_argument(
'--gpu-collect',
action='store_true',
help='whether to use gpu to collect results.')
parser.add_argument(
'--tmpdir',
help='tmp directory used for collecting results from multiple '
'workers, available when gpu-collect is not specified')
parser.add_argument(
'--cfg-options',
nargs='+',
action=DictAction,
help='override some settings in the used config, the key-value pair '
'in xxx=yyy format will be merged into config file. If the value to '
'be overwritten is a list, it should be like key="[a,b]" or key=a,b '
'It also allows nested list/tuple values, e.g. key="[(a,b),(c,d)]" '
'Note that the quotation marks are necessary and that no white space '
'is allowed.')
parser.add_argument(
'--options',
nargs='+',
action=DictAction,
help='custom options for evaluation, the key-value pair in xxx=yyy '
'format will be kwargs for dataset.evaluate() function (deprecate), '
'change to --eval-options instead.')
parser.add_argument(
'--eval-options',
nargs='+',
action=DictAction,
help='custom options for evaluation, the key-value pair in xxx=yyy '
'format will be kwargs for dataset.evaluate() function')
parser.add_argument(
'--launcher',
choices=['none', 'pytorch', 'slurm', 'mpi'],
default='none',
help='job launcher')
parser.add_argument('--local_rank', type=int, default=0)
args = parser.parse_args()
if 'LOCAL_RANK' not in os.environ:
os.environ['LOCAL_RANK'] = str(args.local_rank)
if args.options and args.eval_options:
raise ValueError(
'--options and --eval-options cannot be both '
'specified, --options is deprecated in favor of --eval-options')
if args.options:
warnings.warn('--options is deprecated in favor of --eval-options')
args.eval_options = args.options
args.cfg_options = args.options
2021-05-15 22:47:59 +08:00
return args
def main():
args = parse_args()
assert args.out or args.eval or args.show \
dataset refactoring v2 (#10) * add doc string * update configs * update caffe config * update caffe config * update config * rm ignore ann in fewshot * add difficult option in voc dataset * add difficult option in voc dataset * add difficult option in voc dataset * show datasets * add FSCE file * fix FSCE bug * update config * update config * update config * update config * update config * update config * run script * update config * update config * test aug * test aug * update config * update config * update config * update config * update config * update config * update config * fix comment * fix comment * fix comment * change voc index * update config * change voc iou * change voc iou * change voc iou * change voc iou * Revert "change voc iou" This reverts commit e5f4ca8bc4701c7c69e900b746eaed14cccf87bb. * reset voc * Revert "Merge branch 'lyq-fsce' of https://github.com/linyq17/mmfewshot into lyq-fsce" This reverts commit 1fde859a1625eb0cb900e4a9baa1125c2f387ae5, reversing changes made to 75c40006a23f456a56b688a63e66f133d064e01d. * update weight_decay * add fsod training code * fsod training code fsod training code fsod training code fsod training code fsod training code fsod training code * disable group config * fix empty gt bug fix empty gt bug fix empty gt bug * fsod test code * add support template init into test code * add support template init into test code * fix coco del bug * fix coco del bug * update training config * update test config * test config * test config * test config * update anchor config * update anchor config * update get bbox * update get bbox * update training config * update loss weight * update loss weight * update loss weight * update training config * update training config * add repeat dataset into dataset warpper * mv base code to fsod * update config * update config * update config * update docstr of script * update config of cl branch * fix few shot config bug * add docstr * disable filp * update weight decay config * add docstr and update loss weight * add docstr and update loss weight * add docstr and update loss weight * update loss weight * update loss weight * update loss weight * fix arpn bug * update lr config * fix test bug * update config * update config * update config * update config * update config * fix support order bug * fsdetview training and testing code * update config name * update config * update config * update config * check data loader * update config * update config * update config * fix dataloader bug * update config * check rank * check rank * check rank * check rank * check rank * check rank * check rank * check rank * rm check rank * dataset refactoring * add save dataset function * add doc string * update config * update config * fix dataset bulider bug * update ckpt_surgery script * update ckpt_surgery script * rename arpn to attention_rpn * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update script * update config * update fsdetview config * update fsdetview config * update fsdetview config * update tfa config * update tfa config * update fsdetview config * run script * run script * run script * fix comments * fix comments * fix comments * fix save dataset bug * update config * update config * update config * update config * update config * update config * update config * update config * update dataset doc * fix dataset loading bug * fix dataset loading bug * create dataset pr * create dataset pr * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * fix eval class splits bug * fix eval class splits bug * update attention rpn voc config * update attention rpn voc config * update attention rpn voc config * update attention rpn config * fix voc dataset bug * fix voc dataset bug * udpate config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * add dataset visualization * rm unused arg * rm unused arg * update config * add visual dataset * fix dataset loading bug * fix dataset loading bug * update config * update config * add visualize dataset code * voc base training debug * update tfa voc base config * update config * update config * add multiple training * update tfa voc lr * update config * update config * update config * update config * update config * update voc metric * fix voc metric * add dataset generate code * update base training * update save dataset * update doc string * create pr * create pr * fix dataset loading bug * fix comments * save support set for queryawaredtaset * fix comments * fix comments fix pipeline parameter * fix comments * refactoring ann_file * fix commets * add config check * refactoring ann_cfg datasetwrapper * add doc string * fix bug * fix bug * add dataset name & fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * rm model config
2021-07-23 12:58:12 +08:00
or args.show_dir, (
'Please specify at least one operation (save/eval/show the '
dataset refactoring v2 (#10) * add doc string * update configs * update caffe config * update caffe config * update config * rm ignore ann in fewshot * add difficult option in voc dataset * add difficult option in voc dataset * add difficult option in voc dataset * show datasets * add FSCE file * fix FSCE bug * update config * update config * update config * update config * update config * update config * run script * update config * update config * test aug * test aug * update config * update config * update config * update config * update config * update config * update config * fix comment * fix comment * fix comment * change voc index * update config * change voc iou * change voc iou * change voc iou * change voc iou * Revert "change voc iou" This reverts commit e5f4ca8bc4701c7c69e900b746eaed14cccf87bb. * reset voc * Revert "Merge branch 'lyq-fsce' of https://github.com/linyq17/mmfewshot into lyq-fsce" This reverts commit 1fde859a1625eb0cb900e4a9baa1125c2f387ae5, reversing changes made to 75c40006a23f456a56b688a63e66f133d064e01d. * update weight_decay * add fsod training code * fsod training code fsod training code fsod training code fsod training code fsod training code fsod training code * disable group config * fix empty gt bug fix empty gt bug fix empty gt bug * fsod test code * add support template init into test code * add support template init into test code * fix coco del bug * fix coco del bug * update training config * update test config * test config * test config * test config * update anchor config * update anchor config * update get bbox * update get bbox * update training config * update loss weight * update loss weight * update loss weight * update training config * update training config * add repeat dataset into dataset warpper * mv base code to fsod * update config * update config * update config * update docstr of script * update config of cl branch * fix few shot config bug * add docstr * disable filp * update weight decay config * add docstr and update loss weight * add docstr and update loss weight * add docstr and update loss weight * update loss weight * update loss weight * update loss weight * fix arpn bug * update lr config * fix test bug * update config * update config * update config * update config * update config * fix support order bug * fsdetview training and testing code * update config name * update config * update config * update config * check data loader * update config * update config * update config * fix dataloader bug * update config * check rank * check rank * check rank * check rank * check rank * check rank * check rank * check rank * rm check rank * dataset refactoring * add save dataset function * add doc string * update config * update config * fix dataset bulider bug * update ckpt_surgery script * update ckpt_surgery script * rename arpn to attention_rpn * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update script * update config * update fsdetview config * update fsdetview config * update fsdetview config * update tfa config * update tfa config * update fsdetview config * run script * run script * run script * fix comments * fix comments * fix comments * fix save dataset bug * update config * update config * update config * update config * update config * update config * update config * update config * update dataset doc * fix dataset loading bug * fix dataset loading bug * create dataset pr * create dataset pr * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * fix eval class splits bug * fix eval class splits bug * update attention rpn voc config * update attention rpn voc config * update attention rpn voc config * update attention rpn config * fix voc dataset bug * fix voc dataset bug * udpate config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * add dataset visualization * rm unused arg * rm unused arg * update config * add visual dataset * fix dataset loading bug * fix dataset loading bug * update config * update config * add visualize dataset code * voc base training debug * update tfa voc base config * update config * update config * add multiple training * update tfa voc lr * update config * update config * update config * update config * update config * update voc metric * fix voc metric * add dataset generate code * update base training * update save dataset * update doc string * create pr * create pr * fix dataset loading bug * fix comments * save support set for queryawaredtaset * fix comments * fix comments fix pipeline parameter * fix comments * refactoring ann_file * fix commets * add config check * refactoring ann_cfg datasetwrapper * add doc string * fix bug * fix bug * add dataset name & fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * rm model config
2021-07-23 12:58:12 +08:00
'results / save the results) with the argument "--out", "--eval"',
'"--show" or "--show-dir"')
2021-05-15 22:47:59 +08:00
if args.out is not None and not args.out.endswith(('.pkl', '.pickle')):
raise ValueError('The output file must be a pkl file.')
cfg = Config.fromfile(args.config)
dataset refactoring v2 (#10) * add doc string * update configs * update caffe config * update caffe config * update config * rm ignore ann in fewshot * add difficult option in voc dataset * add difficult option in voc dataset * add difficult option in voc dataset * show datasets * add FSCE file * fix FSCE bug * update config * update config * update config * update config * update config * update config * run script * update config * update config * test aug * test aug * update config * update config * update config * update config * update config * update config * update config * fix comment * fix comment * fix comment * change voc index * update config * change voc iou * change voc iou * change voc iou * change voc iou * Revert "change voc iou" This reverts commit e5f4ca8bc4701c7c69e900b746eaed14cccf87bb. * reset voc * Revert "Merge branch 'lyq-fsce' of https://github.com/linyq17/mmfewshot into lyq-fsce" This reverts commit 1fde859a1625eb0cb900e4a9baa1125c2f387ae5, reversing changes made to 75c40006a23f456a56b688a63e66f133d064e01d. * update weight_decay * add fsod training code * fsod training code fsod training code fsod training code fsod training code fsod training code fsod training code * disable group config * fix empty gt bug fix empty gt bug fix empty gt bug * fsod test code * add support template init into test code * add support template init into test code * fix coco del bug * fix coco del bug * update training config * update test config * test config * test config * test config * update anchor config * update anchor config * update get bbox * update get bbox * update training config * update loss weight * update loss weight * update loss weight * update training config * update training config * add repeat dataset into dataset warpper * mv base code to fsod * update config * update config * update config * update docstr of script * update config of cl branch * fix few shot config bug * add docstr * disable filp * update weight decay config * add docstr and update loss weight * add docstr and update loss weight * add docstr and update loss weight * update loss weight * update loss weight * update loss weight * fix arpn bug * update lr config * fix test bug * update config * update config * update config * update config * update config * fix support order bug * fsdetview training and testing code * update config name * update config * update config * update config * check data loader * update config * update config * update config * fix dataloader bug * update config * check rank * check rank * check rank * check rank * check rank * check rank * check rank * check rank * rm check rank * dataset refactoring * add save dataset function * add doc string * update config * update config * fix dataset bulider bug * update ckpt_surgery script * update ckpt_surgery script * rename arpn to attention_rpn * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update script * update config * update fsdetview config * update fsdetview config * update fsdetview config * update tfa config * update tfa config * update fsdetview config * run script * run script * run script * fix comments * fix comments * fix comments * fix save dataset bug * update config * update config * update config * update config * update config * update config * update config * update config * update dataset doc * fix dataset loading bug * fix dataset loading bug * create dataset pr * create dataset pr * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * fix eval class splits bug * fix eval class splits bug * update attention rpn voc config * update attention rpn voc config * update attention rpn voc config * update attention rpn config * fix voc dataset bug * fix voc dataset bug * udpate config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * add dataset visualization * rm unused arg * rm unused arg * update config * add visual dataset * fix dataset loading bug * fix dataset loading bug * update config * update config * add visualize dataset code * voc base training debug * update tfa voc base config * update config * update config * add multiple training * update tfa voc lr * update config * update config * update config * update config * update config * update voc metric * fix voc metric * add dataset generate code * update base training * update save dataset * update doc string * create pr * create pr * fix dataset loading bug * fix comments * save support set for queryawaredtaset * fix comments * fix comments fix pipeline parameter * fix comments * refactoring ann_file * fix commets * add config check * refactoring ann_cfg datasetwrapper * add doc string * fix bug * fix bug * add dataset name & fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * rm model config
2021-07-23 12:58:12 +08:00
2021-05-15 22:47:59 +08:00
if args.cfg_options is not None:
cfg.merge_from_dict(args.cfg_options)
2021-05-16 16:29:24 +08:00
2021-05-15 22:47:59 +08:00
# import modules from string list.
if cfg.get('custom_imports', None):
from mmcv.utils import import_modules_from_strings
import_modules_from_strings(**cfg['custom_imports'])
# set cudnn_benchmark
if cfg.get('cudnn_benchmark', False):
torch.backends.cudnn.benchmark = True
cfg.model.pretrained = None
# currently only support single images testing
samples_per_gpu = cfg.data.test.pop('samples_per_gpu', 1)
assert samples_per_gpu == 1, 'currently only support single images testing'
if args.gpu_ids is not None:
cfg.gpu_ids = args.gpu_ids[0:1]
warnings.warn('`--gpu-ids` is deprecated, please use `--gpu-id`. '
'Because we only support single GPU mode in '
'non-distributed testing. Use the first GPU '
'in `gpu_ids` now.')
else:
cfg.gpu_ids = [args.gpu_id]
2021-05-15 22:47:59 +08:00
# init distributed env first, since logger depends on the dist info.
if args.launcher == 'none':
distributed = False
else:
distributed = True
init_dist(args.launcher, **cfg.dist_params)
# build the dataloader
dataset = build_dataset(cfg.data.test)
2021-05-15 22:47:59 +08:00
data_loader = build_dataloader(
dataset,
dataset refactoring v2 (#10) * add doc string * update configs * update caffe config * update caffe config * update config * rm ignore ann in fewshot * add difficult option in voc dataset * add difficult option in voc dataset * add difficult option in voc dataset * show datasets * add FSCE file * fix FSCE bug * update config * update config * update config * update config * update config * update config * run script * update config * update config * test aug * test aug * update config * update config * update config * update config * update config * update config * update config * fix comment * fix comment * fix comment * change voc index * update config * change voc iou * change voc iou * change voc iou * change voc iou * Revert "change voc iou" This reverts commit e5f4ca8bc4701c7c69e900b746eaed14cccf87bb. * reset voc * Revert "Merge branch 'lyq-fsce' of https://github.com/linyq17/mmfewshot into lyq-fsce" This reverts commit 1fde859a1625eb0cb900e4a9baa1125c2f387ae5, reversing changes made to 75c40006a23f456a56b688a63e66f133d064e01d. * update weight_decay * add fsod training code * fsod training code fsod training code fsod training code fsod training code fsod training code fsod training code * disable group config * fix empty gt bug fix empty gt bug fix empty gt bug * fsod test code * add support template init into test code * add support template init into test code * fix coco del bug * fix coco del bug * update training config * update test config * test config * test config * test config * update anchor config * update anchor config * update get bbox * update get bbox * update training config * update loss weight * update loss weight * update loss weight * update training config * update training config * add repeat dataset into dataset warpper * mv base code to fsod * update config * update config * update config * update docstr of script * update config of cl branch * fix few shot config bug * add docstr * disable filp * update weight decay config * add docstr and update loss weight * add docstr and update loss weight * add docstr and update loss weight * update loss weight * update loss weight * update loss weight * fix arpn bug * update lr config * fix test bug * update config * update config * update config * update config * update config * fix support order bug * fsdetview training and testing code * update config name * update config * update config * update config * check data loader * update config * update config * update config * fix dataloader bug * update config * check rank * check rank * check rank * check rank * check rank * check rank * check rank * check rank * rm check rank * dataset refactoring * add save dataset function * add doc string * update config * update config * fix dataset bulider bug * update ckpt_surgery script * update ckpt_surgery script * rename arpn to attention_rpn * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update script * update config * update fsdetview config * update fsdetview config * update fsdetview config * update tfa config * update tfa config * update fsdetview config * run script * run script * run script * fix comments * fix comments * fix comments * fix save dataset bug * update config * update config * update config * update config * update config * update config * update config * update config * update dataset doc * fix dataset loading bug * fix dataset loading bug * create dataset pr * create dataset pr * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * fix eval class splits bug * fix eval class splits bug * update attention rpn voc config * update attention rpn voc config * update attention rpn voc config * update attention rpn config * fix voc dataset bug * fix voc dataset bug * udpate config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * add dataset visualization * rm unused arg * rm unused arg * update config * add visual dataset * fix dataset loading bug * fix dataset loading bug * update config * update config * add visualize dataset code * voc base training debug * update tfa voc base config * update config * update config * add multiple training * update tfa voc lr * update config * update config * update config * update config * update config * update voc metric * fix voc metric * add dataset generate code * update base training * update save dataset * update doc string * create pr * create pr * fix dataset loading bug * fix comments * save support set for queryawaredtaset * fix comments * fix comments fix pipeline parameter * fix comments * refactoring ann_file * fix commets * add config check * refactoring ann_cfg datasetwrapper * add doc string * fix bug * fix bug * add dataset name & fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * rm model config
2021-07-23 12:58:12 +08:00
samples_per_gpu=samples_per_gpu,
2021-05-15 22:47:59 +08:00
workers_per_gpu=cfg.data.workers_per_gpu,
dist=distributed,
2021-09-03 21:10:23 +08:00
shuffle=False)
2021-05-15 22:47:59 +08:00
dataset refactoring v2 (#10) * add doc string * update configs * update caffe config * update caffe config * update config * rm ignore ann in fewshot * add difficult option in voc dataset * add difficult option in voc dataset * add difficult option in voc dataset * show datasets * add FSCE file * fix FSCE bug * update config * update config * update config * update config * update config * update config * run script * update config * update config * test aug * test aug * update config * update config * update config * update config * update config * update config * update config * fix comment * fix comment * fix comment * change voc index * update config * change voc iou * change voc iou * change voc iou * change voc iou * Revert "change voc iou" This reverts commit e5f4ca8bc4701c7c69e900b746eaed14cccf87bb. * reset voc * Revert "Merge branch 'lyq-fsce' of https://github.com/linyq17/mmfewshot into lyq-fsce" This reverts commit 1fde859a1625eb0cb900e4a9baa1125c2f387ae5, reversing changes made to 75c40006a23f456a56b688a63e66f133d064e01d. * update weight_decay * add fsod training code * fsod training code fsod training code fsod training code fsod training code fsod training code fsod training code * disable group config * fix empty gt bug fix empty gt bug fix empty gt bug * fsod test code * add support template init into test code * add support template init into test code * fix coco del bug * fix coco del bug * update training config * update test config * test config * test config * test config * update anchor config * update anchor config * update get bbox * update get bbox * update training config * update loss weight * update loss weight * update loss weight * update training config * update training config * add repeat dataset into dataset warpper * mv base code to fsod * update config * update config * update config * update docstr of script * update config of cl branch * fix few shot config bug * add docstr * disable filp * update weight decay config * add docstr and update loss weight * add docstr and update loss weight * add docstr and update loss weight * update loss weight * update loss weight * update loss weight * fix arpn bug * update lr config * fix test bug * update config * update config * update config * update config * update config * fix support order bug * fsdetview training and testing code * update config name * update config * update config * update config * check data loader * update config * update config * update config * fix dataloader bug * update config * check rank * check rank * check rank * check rank * check rank * check rank * check rank * check rank * rm check rank * dataset refactoring * add save dataset function * add doc string * update config * update config * fix dataset bulider bug * update ckpt_surgery script * update ckpt_surgery script * rename arpn to attention_rpn * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update script * update config * update fsdetview config * update fsdetview config * update fsdetview config * update tfa config * update tfa config * update fsdetview config * run script * run script * run script * fix comments * fix comments * fix comments * fix save dataset bug * update config * update config * update config * update config * update config * update config * update config * update config * update dataset doc * fix dataset loading bug * fix dataset loading bug * create dataset pr * create dataset pr * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * fix eval class splits bug * fix eval class splits bug * update attention rpn voc config * update attention rpn voc config * update attention rpn voc config * update attention rpn config * fix voc dataset bug * fix voc dataset bug * udpate config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * add dataset visualization * rm unused arg * rm unused arg * update config * add visual dataset * fix dataset loading bug * fix dataset loading bug * update config * update config * add visualize dataset code * voc base training debug * update tfa voc base config * update config * update config * add multiple training * update tfa voc lr * update config * update config * update config * update config * update config * update voc metric * fix voc metric * add dataset generate code * update base training * update save dataset * update doc string * create pr * create pr * fix dataset loading bug * fix comments * save support set for queryawaredtaset * fix comments * fix comments fix pipeline parameter * fix comments * refactoring ann_file * fix commets * add config check * refactoring ann_cfg datasetwrapper * add doc string * fix bug * fix bug * add dataset name & fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * rm model config
2021-07-23 12:58:12 +08:00
# pop frozen_parameters
cfg.model.pop('frozen_parameters', None)
2021-05-15 22:47:59 +08:00
# build the model and load checkpoint
cfg.model.train_cfg = None
model = build_detector(cfg.model)
dataset refactoring v2 (#10) * add doc string * update configs * update caffe config * update caffe config * update config * rm ignore ann in fewshot * add difficult option in voc dataset * add difficult option in voc dataset * add difficult option in voc dataset * show datasets * add FSCE file * fix FSCE bug * update config * update config * update config * update config * update config * update config * run script * update config * update config * test aug * test aug * update config * update config * update config * update config * update config * update config * update config * fix comment * fix comment * fix comment * change voc index * update config * change voc iou * change voc iou * change voc iou * change voc iou * Revert "change voc iou" This reverts commit e5f4ca8bc4701c7c69e900b746eaed14cccf87bb. * reset voc * Revert "Merge branch 'lyq-fsce' of https://github.com/linyq17/mmfewshot into lyq-fsce" This reverts commit 1fde859a1625eb0cb900e4a9baa1125c2f387ae5, reversing changes made to 75c40006a23f456a56b688a63e66f133d064e01d. * update weight_decay * add fsod training code * fsod training code fsod training code fsod training code fsod training code fsod training code fsod training code * disable group config * fix empty gt bug fix empty gt bug fix empty gt bug * fsod test code * add support template init into test code * add support template init into test code * fix coco del bug * fix coco del bug * update training config * update test config * test config * test config * test config * update anchor config * update anchor config * update get bbox * update get bbox * update training config * update loss weight * update loss weight * update loss weight * update training config * update training config * add repeat dataset into dataset warpper * mv base code to fsod * update config * update config * update config * update docstr of script * update config of cl branch * fix few shot config bug * add docstr * disable filp * update weight decay config * add docstr and update loss weight * add docstr and update loss weight * add docstr and update loss weight * update loss weight * update loss weight * update loss weight * fix arpn bug * update lr config * fix test bug * update config * update config * update config * update config * update config * fix support order bug * fsdetview training and testing code * update config name * update config * update config * update config * check data loader * update config * update config * update config * fix dataloader bug * update config * check rank * check rank * check rank * check rank * check rank * check rank * check rank * check rank * rm check rank * dataset refactoring * add save dataset function * add doc string * update config * update config * fix dataset bulider bug * update ckpt_surgery script * update ckpt_surgery script * rename arpn to attention_rpn * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update script * update config * update fsdetview config * update fsdetview config * update fsdetview config * update tfa config * update tfa config * update fsdetview config * run script * run script * run script * fix comments * fix comments * fix comments * fix save dataset bug * update config * update config * update config * update config * update config * update config * update config * update config * update dataset doc * fix dataset loading bug * fix dataset loading bug * create dataset pr * create dataset pr * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * fix eval class splits bug * fix eval class splits bug * update attention rpn voc config * update attention rpn voc config * update attention rpn voc config * update attention rpn config * fix voc dataset bug * fix voc dataset bug * udpate config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * add dataset visualization * rm unused arg * rm unused arg * update config * add visual dataset * fix dataset loading bug * fix dataset loading bug * update config * update config * add visualize dataset code * voc base training debug * update tfa voc base config * update config * update config * add multiple training * update tfa voc lr * update config * update config * update config * update config * update config * update voc metric * fix voc metric * add dataset generate code * update base training * update save dataset * update doc string * create pr * create pr * fix dataset loading bug * fix comments * save support set for queryawaredtaset * fix comments * fix comments fix pipeline parameter * fix comments * refactoring ann_file * fix commets * add config check * refactoring ann_cfg datasetwrapper * add doc string * fix bug * fix bug * add dataset name & fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * rm model config
2021-07-23 12:58:12 +08:00
2021-05-15 22:47:59 +08:00
fp16_cfg = cfg.get('fp16', None)
if fp16_cfg is not None:
wrap_fp16_model(model)
checkpoint = load_checkpoint(model, args.checkpoint, map_location='cpu')
# old versions did not save class info in checkpoints, this walkaround is
# for backward compatibility
if 'CLASSES' in checkpoint.get('meta', {}):
model.CLASSES = checkpoint['meta']['CLASSES']
else:
model.CLASSES = dataset.CLASSES
# for meta-learning methods which require support template dataset
# for model initialization.
if cfg.data.get('model_init', None) is not None:
cfg.data.model_init.pop('copy_from_train_dataset')
model_init_samples_per_gpu = cfg.data.model_init.pop(
'samples_per_gpu', 1)
model_init_workers_per_gpu = cfg.data.model_init.pop(
'workers_per_gpu', 1)
if cfg.data.model_init.get('ann_cfg', None) is None:
assert checkpoint['meta'].get('model_init_ann_cfg',
None) is not None
cfg.data.model_init.type = \
get_copy_dataset_type(cfg.data.model_init.type)
cfg.data.model_init.ann_cfg = \
checkpoint['meta']['model_init_ann_cfg']
model_init_dataset = build_dataset(cfg.data.model_init)
# disable dist to make all rank get same data
model_init_dataloader = build_dataloader(
model_init_dataset,
samples_per_gpu=model_init_samples_per_gpu,
workers_per_gpu=model_init_workers_per_gpu,
dist=False,
shuffle=False)
2021-05-15 22:47:59 +08:00
if not distributed:
# Please use MMCV >= 1.4.4 for CPU testing!
model = MMDataParallel(model, device_ids=cfg.gpu_ids)
2021-09-03 21:10:23 +08:00
show_kwargs = dict(show_score_thr=args.show_score_thr)
implementation of FSCE (#18) * fix dataloader bug * update config * check rank * check rank * check rank * check rank * check rank * check rank * check rank * check rank * rm check rank * dataset refactoring * add save dataset function * add doc string * update config * update config * fix dataset bulider bug * update ckpt_surgery script * update ckpt_surgery script * rename arpn to attention_rpn * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update script * update config * update fsdetview config * update fsdetview config * update fsdetview config * update tfa config * update tfa config * update fsdetview config * run script * run script * run script * fix comments * fix comments * fix comments * fix save dataset bug * update config * update config * update config * update config * update config * update config * update config * update config * update dataset doc * fix dataset loading bug * fix dataset loading bug * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * fix eval class splits bug * update attention rpn voc config * update attention rpn voc config * update attention rpn voc config * update attention rpn config * fix voc dataset bug * udpate config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * add dataset visualization * rm unused arg * update config * add visual dataset * fix dataset loading bug * update config * update config * add visualize dataset code * voc base training debug * update tfa voc base config * update config * update config * add multiple training * update tfa voc lr * update config * update config * update config * update config * update config * update voc metric * fix voc metric * add dataset generate code * update base training * update save dataset * update doc string * update custom hook * fix dataset loading bug * test multi-train update config update config update config update multi train test multiple train test multi train update config update config update config test multi train test multi train test multi train test multi train test multi train fix random bug test multi train * rm repeat args * fix bash * fix seed * update config * set random seed * update config * fix random seed bug * update config * update config * update config * update config * update sh script * update script * update multi run * save support set for queryawaredtaset * update config * multi test * update multi test script * add meta rcnn model & config * add config * update visualizer * update config * update config * test seed * Revert "test seed" This reverts commit 803b4af70f000aee1bad32d4da91dc4f2078f138. * fix seed * test seed * update config * update config * rm seed test * update config * update config * fix comments * fix comments * update config * fix comments * update config * fix comments fix pipeline parameter * fix comments * refactoring ann_file * fix copy * fix commets * fix multi train test * add config check * refactoring ann_cfg datasetwrapper * add doc string * fix bug * check copy op * add dataset name & fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * update tfa * update fsce config * update attention_rpn config * update fsdetview config * update attention rpn doc * update metarcnn roihead * refactoring meta rcnn and fsdetview * update tfa * update config * refactoring models * refactoring models * fix comments * fix module * update doc str * update script * update script * bug fix * update doc str * update doc str * update config * update losses * fix comments * update config * update config * update config * update config * update config * update config * update config * fix doc str * fix doc str * fix doc str * update config * update config * test losses * update fsdetview * update fsdetview * update config * update config * fix typo * fix doc * fix comments * fix comments * fix doc str * fix doc str * update fsdetview * fix doc str * update attention rpn * fix doc * fix get_classes (#10) * fix get_classes * change to split id * fix pipeline and doc str * update config * fix doc str * update script * update script * fix comments * fix doc str and typo * fix typo * update config * update config * update config * update config * fix bug in fsdetview * update doc str * update config * fix comments * fix comments * update fsce * update fsce * update fsce * update multi test update test * update attention rpn * bug fix * create pr * fix comments * fix doc str * fix commnets * fix commnets * fix commnets test 0 loss fix commnets Co-authored-by: zhangshilong <2392587229zsl@gmail.com> Co-authored-by: Shilong Zhang <61961338+jshilong@users.noreply.github.com>
2021-07-31 23:57:35 +08:00
if cfg.data.get('model_init', None) is not None:
2021-09-03 21:10:23 +08:00
from mmfewshot.detection.apis import (single_gpu_model_init,
single_gpu_test)
implementation of FSCE (#18) * fix dataloader bug * update config * check rank * check rank * check rank * check rank * check rank * check rank * check rank * check rank * rm check rank * dataset refactoring * add save dataset function * add doc string * update config * update config * fix dataset bulider bug * update ckpt_surgery script * update ckpt_surgery script * rename arpn to attention_rpn * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update script * update config * update fsdetview config * update fsdetview config * update fsdetview config * update tfa config * update tfa config * update fsdetview config * run script * run script * run script * fix comments * fix comments * fix comments * fix save dataset bug * update config * update config * update config * update config * update config * update config * update config * update config * update dataset doc * fix dataset loading bug * fix dataset loading bug * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * fix eval class splits bug * update attention rpn voc config * update attention rpn voc config * update attention rpn voc config * update attention rpn config * fix voc dataset bug * udpate config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * add dataset visualization * rm unused arg * update config * add visual dataset * fix dataset loading bug * update config * update config * add visualize dataset code * voc base training debug * update tfa voc base config * update config * update config * add multiple training * update tfa voc lr * update config * update config * update config * update config * update config * update voc metric * fix voc metric * add dataset generate code * update base training * update save dataset * update doc string * update custom hook * fix dataset loading bug * test multi-train update config update config update config update multi train test multiple train test multi train update config update config update config test multi train test multi train test multi train test multi train test multi train fix random bug test multi train * rm repeat args * fix bash * fix seed * update config * set random seed * update config * fix random seed bug * update config * update config * update config * update config * update sh script * update script * update multi run * save support set for queryawaredtaset * update config * multi test * update multi test script * add meta rcnn model & config * add config * update visualizer * update config * update config * test seed * Revert "test seed" This reverts commit 803b4af70f000aee1bad32d4da91dc4f2078f138. * fix seed * test seed * update config * update config * rm seed test * update config * update config * fix comments * fix comments * update config * fix comments * update config * fix comments fix pipeline parameter * fix comments * refactoring ann_file * fix copy * fix commets * fix multi train test * add config check * refactoring ann_cfg datasetwrapper * add doc string * fix bug * check copy op * add dataset name & fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * update tfa * update fsce config * update attention_rpn config * update fsdetview config * update attention rpn doc * update metarcnn roihead * refactoring meta rcnn and fsdetview * update tfa * update config * refactoring models * refactoring models * fix comments * fix module * update doc str * update script * update script * bug fix * update doc str * update doc str * update config * update losses * fix comments * update config * update config * update config * update config * update config * update config * update config * fix doc str * fix doc str * fix doc str * update config * update config * test losses * update fsdetview * update fsdetview * update config * update config * fix typo * fix doc * fix comments * fix comments * fix doc str * fix doc str * update fsdetview * fix doc str * update attention rpn * fix doc * fix get_classes (#10) * fix get_classes * change to split id * fix pipeline and doc str * update config * fix doc str * update script * update script * fix comments * fix doc str and typo * fix typo * update config * update config * update config * update config * fix bug in fsdetview * update doc str * update config * fix comments * fix comments * update fsce * update fsce * update fsce * update multi test update test * update attention rpn * bug fix * create pr * fix comments * fix doc str * fix commnets * fix commnets * fix commnets test 0 loss fix commnets Co-authored-by: zhangshilong <2392587229zsl@gmail.com> Co-authored-by: Shilong Zhang <61961338+jshilong@users.noreply.github.com>
2021-07-31 23:57:35 +08:00
single_gpu_model_init(model, model_init_dataloader)
2021-09-03 21:10:23 +08:00
else:
from mmdet.apis.test import single_gpu_test
outputs = single_gpu_test(model, data_loader, args.show, args.show_dir,
**show_kwargs)
2021-05-15 22:47:59 +08:00
else:
model = MMDistributedDataParallel(
model.cuda(),
device_ids=[torch.cuda.current_device()],
broadcast_buffers=False)
implementation of FSCE (#18) * fix dataloader bug * update config * check rank * check rank * check rank * check rank * check rank * check rank * check rank * check rank * rm check rank * dataset refactoring * add save dataset function * add doc string * update config * update config * fix dataset bulider bug * update ckpt_surgery script * update ckpt_surgery script * rename arpn to attention_rpn * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update script * update config * update fsdetview config * update fsdetview config * update fsdetview config * update tfa config * update tfa config * update fsdetview config * run script * run script * run script * fix comments * fix comments * fix comments * fix save dataset bug * update config * update config * update config * update config * update config * update config * update config * update config * update dataset doc * fix dataset loading bug * fix dataset loading bug * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * fix eval class splits bug * update attention rpn voc config * update attention rpn voc config * update attention rpn voc config * update attention rpn config * fix voc dataset bug * udpate config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * add dataset visualization * rm unused arg * update config * add visual dataset * fix dataset loading bug * update config * update config * add visualize dataset code * voc base training debug * update tfa voc base config * update config * update config * add multiple training * update tfa voc lr * update config * update config * update config * update config * update config * update voc metric * fix voc metric * add dataset generate code * update base training * update save dataset * update doc string * update custom hook * fix dataset loading bug * test multi-train update config update config update config update multi train test multiple train test multi train update config update config update config test multi train test multi train test multi train test multi train test multi train fix random bug test multi train * rm repeat args * fix bash * fix seed * update config * set random seed * update config * fix random seed bug * update config * update config * update config * update config * update sh script * update script * update multi run * save support set for queryawaredtaset * update config * multi test * update multi test script * add meta rcnn model & config * add config * update visualizer * update config * update config * test seed * Revert "test seed" This reverts commit 803b4af70f000aee1bad32d4da91dc4f2078f138. * fix seed * test seed * update config * update config * rm seed test * update config * update config * fix comments * fix comments * update config * fix comments * update config * fix comments fix pipeline parameter * fix comments * refactoring ann_file * fix copy * fix commets * fix multi train test * add config check * refactoring ann_cfg datasetwrapper * add doc string * fix bug * check copy op * add dataset name & fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * update tfa * update fsce config * update attention_rpn config * update fsdetview config * update attention rpn doc * update metarcnn roihead * refactoring meta rcnn and fsdetview * update tfa * update config * refactoring models * refactoring models * fix comments * fix module * update doc str * update script * update script * bug fix * update doc str * update doc str * update config * update losses * fix comments * update config * update config * update config * update config * update config * update config * update config * fix doc str * fix doc str * fix doc str * update config * update config * test losses * update fsdetview * update fsdetview * update config * update config * fix typo * fix doc * fix comments * fix comments * fix doc str * fix doc str * update fsdetview * fix doc str * update attention rpn * fix doc * fix get_classes (#10) * fix get_classes * change to split id * fix pipeline and doc str * update config * fix doc str * update script * update script * fix comments * fix doc str and typo * fix typo * update config * update config * update config * update config * fix bug in fsdetview * update doc str * update config * fix comments * fix comments * update fsce * update fsce * update fsce * update multi test update test * update attention rpn * bug fix * create pr * fix comments * fix doc str * fix commnets * fix commnets * fix commnets test 0 loss fix commnets Co-authored-by: zhangshilong <2392587229zsl@gmail.com> Co-authored-by: Shilong Zhang <61961338+jshilong@users.noreply.github.com>
2021-07-31 23:57:35 +08:00
if cfg.data.get('model_init', None) is not None:
2021-09-03 21:10:23 +08:00
from mmfewshot.detection.apis import (multi_gpu_model_init,
multi_gpu_test)
implementation of FSCE (#18) * fix dataloader bug * update config * check rank * check rank * check rank * check rank * check rank * check rank * check rank * check rank * rm check rank * dataset refactoring * add save dataset function * add doc string * update config * update config * fix dataset bulider bug * update ckpt_surgery script * update ckpt_surgery script * rename arpn to attention_rpn * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update tfa config * update script * update config * update fsdetview config * update fsdetview config * update fsdetview config * update tfa config * update tfa config * update fsdetview config * run script * run script * run script * fix comments * fix comments * fix comments * fix save dataset bug * update config * update config * update config * update config * update config * update config * update config * update config * update dataset doc * fix dataset loading bug * fix dataset loading bug * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * fix eval class splits bug * update attention rpn voc config * update attention rpn voc config * update attention rpn voc config * update attention rpn config * fix voc dataset bug * udpate config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * update config * add dataset visualization * rm unused arg * update config * add visual dataset * fix dataset loading bug * update config * update config * add visualize dataset code * voc base training debug * update tfa voc base config * update config * update config * add multiple training * update tfa voc lr * update config * update config * update config * update config * update config * update voc metric * fix voc metric * add dataset generate code * update base training * update save dataset * update doc string * update custom hook * fix dataset loading bug * test multi-train update config update config update config update multi train test multiple train test multi train update config update config update config test multi train test multi train test multi train test multi train test multi train fix random bug test multi train * rm repeat args * fix bash * fix seed * update config * set random seed * update config * fix random seed bug * update config * update config * update config * update config * update sh script * update script * update multi run * save support set for queryawaredtaset * update config * multi test * update multi test script * add meta rcnn model & config * add config * update visualizer * update config * update config * test seed * Revert "test seed" This reverts commit 803b4af70f000aee1bad32d4da91dc4f2078f138. * fix seed * test seed * update config * update config * rm seed test * update config * update config * fix comments * fix comments * update config * fix comments * update config * fix comments fix pipeline parameter * fix comments * refactoring ann_file * fix copy * fix commets * fix multi train test * add config check * refactoring ann_cfg datasetwrapper * add doc string * fix bug * check copy op * add dataset name & fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * fix doc str * update tfa * update fsce config * update attention_rpn config * update fsdetview config * update attention rpn doc * update metarcnn roihead * refactoring meta rcnn and fsdetview * update tfa * update config * refactoring models * refactoring models * fix comments * fix module * update doc str * update script * update script * bug fix * update doc str * update doc str * update config * update losses * fix comments * update config * update config * update config * update config * update config * update config * update config * fix doc str * fix doc str * fix doc str * update config * update config * test losses * update fsdetview * update fsdetview * update config * update config * fix typo * fix doc * fix comments * fix comments * fix doc str * fix doc str * update fsdetview * fix doc str * update attention rpn * fix doc * fix get_classes (#10) * fix get_classes * change to split id * fix pipeline and doc str * update config * fix doc str * update script * update script * fix comments * fix doc str and typo * fix typo * update config * update config * update config * update config * fix bug in fsdetview * update doc str * update config * fix comments * fix comments * update fsce * update fsce * update fsce * update multi test update test * update attention rpn * bug fix * create pr * fix comments * fix doc str * fix commnets * fix commnets * fix commnets test 0 loss fix commnets Co-authored-by: zhangshilong <2392587229zsl@gmail.com> Co-authored-by: Shilong Zhang <61961338+jshilong@users.noreply.github.com>
2021-07-31 23:57:35 +08:00
multi_gpu_model_init(model, model_init_dataloader)
2021-09-03 21:10:23 +08:00
else:
from mmdet.apis.test import multi_gpu_test
2021-05-16 20:06:46 +08:00
outputs = multi_gpu_test(
model,
data_loader,
args.tmpdir,
args.gpu_collect,
)
2021-05-15 22:47:59 +08:00
rank, _ = get_dist_info()
if rank == 0:
if args.out:
print(f'\nwriting results to {args.out}')
mmcv.dump(outputs, args.out)
kwargs = {} if args.eval_options is None else args.eval_options
if args.eval:
eval_kwargs = cfg.get('evaluation', {}).copy()
# hard-code way to remove EvalHook args
for key in [
'interval', 'tmpdir', 'start', 'gpu_collect', 'save_best',
'rule'
]:
eval_kwargs.pop(key, None)
eval_kwargs.update(dict(metric=args.eval, **kwargs))
print(dataset.evaluate(outputs, **eval_kwargs))
if __name__ == '__main__':
main()