Exemplo n.º 1
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        if 0:
            train_dataset = gdata.VOCDetection(root='E:/dataset/VOCdevkit',
                                               splits=[(2007, 'trainval'),
                                                       (2012, 'trainval')])
            val_dataset = gdata.VOCDetection(root='E:/dataset/VOCdevkit',
                                             splits=[(2007, 'test')])
            val_metric = VOC07MApMetric(iou_thresh=0.5,
                                        class_names=val_dataset.classes)
        else:
            voc_root = 'G:/MSDataset/'  #layout same with VOC07
            train_dataset = gdata.MSDetection(root=voc_root,
                                              splits=[(2007, 'trainval')])
            val_dataset = gdata.MSDetection(root=voc_root,
                                            splits=[(2007, 'test')])
            val_metric = VOC07MApMetric(iou_thresh=0.5,
                                        class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.COCODetection(splits='instances_train2017',
                                            use_crowd=False)
        val_dataset = gdata.COCODetection(splits='instances_val2017',
                                          skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset,
                                         args.save_prefix + '_eval',
                                         cleanup=True)
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    if args.mixup:
        from gluoncv.data.mixup import MixupDetection
        train_dataset = MixupDetection(train_dataset)
    return train_dataset, val_dataset, val_metric
Exemplo n.º 2
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = gdata.VOCDetection(
            splits=[(2007, 'trainval'), (2012, 'trainval')])
        val_dataset = gdata.VOCDetection(
            splits=[(2007, 'test')])
        #print(val_dataset.classes)
        #('aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor')

        val_metric = VOC07MApMetric(iou_thresh=0.5, class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.COCODetection(splits='instances_train2017', use_crowd=False)
        val_dataset = gdata.COCODetection(splits='instances_val2017', skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset, args.save_prefix + '_eval', cleanup=True)
    elif dataset.lower() == 'pedestrian':
        lst_dataset = LstDetection('train_val.lst',root=os.path.expanduser('.'))
        print(len(lst_dataset))
        first_img = lst_dataset[0][0]

        print(first_img.shape)
        print(lst_dataset[0][1])
        
        train_dataset = LstDetection('train.lst',root=os.path.expanduser('.'))
        val_dataset = LstDetection('val.lst',root=os.path.expanduser('.'))
        classs = ('pedestrian',)
        val_metric = VOC07MApMetric(iou_thresh=0.5,class_names=classs)
        
    else:
        raise NotImplementedError('Dataset: {} not implemented.'.format(dataset))
    if args.mixup:
        from gluoncv.data.mixup import MixupDetection
        train_dataset = MixupDetection(train_dataset)
    return train_dataset, val_dataset, val_metric
Exemplo n.º 3
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = gdata.VOCDetection(
            splits=[(2007, 'trainval'), (2012, 'trainval')])
        val_dataset = gdata.VOCDetection(splits=[(2007, 'test')])
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    elif dataset.lower() in ['clipart', 'comic', 'watercolor']:
        root = os.path.join('~', '.mxnet', 'datasets', dataset.lower())
        train_dataset = gdata.CustomVOCDetection(root=root,
                                                 splits=[('', 'train')],
                                                 generate_classes=True)
        val_dataset = gdata.CustomVOCDetection(root=root,
                                               splits=[('', 'test')],
                                               generate_classes=True)
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.COCODetection(splits='instances_train2017',
                                            use_crowd=False)
        val_dataset = gdata.COCODetection(splits='instances_val2017',
                                          skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset,
                                         args.save_prefix + '_eval',
                                         cleanup=True)
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    if args.mixup:
        from gluoncv.data.mixup import detection
        train_dataset = detection.MixupDetection(train_dataset)
    return train_dataset, val_dataset, val_metric
Exemplo n.º 4
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = gdata.VOCDetection(
            splits=[(2007, 'trainval'), (2012, 'trainval')])
        val_dataset = gdata.VOCDetection(splits=[(2007, 'test')])
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.COCODetection(splits='instances_train2017',
                                            use_crowd=False)
        val_dataset = gdata.COCODetection(splits='instances_val2017',
                                          skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset,
                                         args.save_prefix + '_eval',
                                         cleanup=True,
                                         data_shape=(args.data_shape,
                                                     args.data_shape))
    elif dataset.lower() == 'roughy':
        train_dataset = VOCLike(root=args.sys_root,
                                splits=((args.voc_base,
                                         f'{args.train_yr}' + '/train'), ))
        val_dataset = VOCLike(root=args.sys_root,
                              splits=((args.voc_base,
                                       f'{args.train_yr}' + '/val'), ))
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    if args.num_samples < 0:
        args.num_samples = len(train_dataset)
    if args.mixup:
        from gluoncv.data import MixupDetection
        train_dataset = MixupDetection(train_dataset)
    return train_dataset, val_dataset, val_metric
Exemplo n.º 5
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = gdata.VOCDetection(
            splits=[(2007, 'trainval'), (2012, 'trainval')])
        val_dataset = gdata.VOCDetection(splits=[(2007, 'test')])
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.COCODetection(root=args.dataset_root + "/coco",
                                            splits='instances_train2017')
        val_dataset = gdata.COCODetection(root=args.dataset_root + "/coco",
                                          splits='instances_val2017',
                                          skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset,
                                         args.save_prefix + '_eval',
                                         cleanup=True,
                                         data_shape=(args.data_shape,
                                                     args.data_shape))
        # coco validation is slow, consider increase the validation interval
        if args.val_interval == 1:
            args.val_interval = 10
    else:
        train_dataset = petVOC(splits=[(2019, 'train_val')])
        val_dataset = train_dataset
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)

    return train_dataset, val_dataset, val_metric
Exemplo n.º 6
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = gdata.VOCDetection(
            splits=[('sbdche', 'train' + '_' + str(args.deg) + '_bboxwh')])
        if args.val_2012 == True:
            val_dataset = gdata.VOC_Val_Detection(splits=[('sbdche',
                                                           'val_2012_bboxwh')])
        else:
            val_dataset = gdata.VOC_Val_Detection(
                splits=[('sbdche', 'val' + '_' + str(args.deg) + '_bboxwh')])
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
        val_polygon_metric = VOC07PolygonMApMetric(
            iou_thresh=0.5, class_names=val_dataset.classes)
    elif dataset.lower() == 'coco_pretrain':
        train_dataset = gdata.coco_pretrain_Detection(
            splits=[('_coco_20', 'train' + '_' + str(args.deg) + '_bboxwh')])
        if args.val_2012 == True:
            val_dataset = gdata.VOC_Val_Detection(splits=[('sbdche',
                                                           'val_2012_bboxwh')])
        else:
            val_dataset = gdata.VOC_Val_Detection(
                splits=[('sbdche', 'val' + '_' + str(args.deg) + '_bboxwh')])
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
        val_polygon_metric = VOC07PolygonMApMetric(
            iou_thresh=0.5, class_names=val_dataset.classes)
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    if args.num_samples < 0:
        args.num_samples = len(train_dataset)
    return train_dataset, val_dataset, val_metric, val_polygon_metric
Exemplo n.º 7
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        if args.val_2012 == True:
            train_dataset = gdata.VOCDetection(
                splits=[('sbdche', 'train_voc2012_bboxwh')])

            val_dataset = gdata.VOC_Val_Detection(splits=[('sbdche',
                                                           'val_2012_bboxwh')])
        else:
            train_dataset = gdata.VOCDetection(splits=[('sbdche',
                                                        'train' + '_' + '8' +
                                                        '_bboxwh')])
            val_dataset = gdata.VOC_Val_Detection(splits=[('sbdche',
                                                           'val' + '_' + '8' +
                                                           '_bboxwh')])
        val_metric = VOC07MApMetric(iou_thresh=0.7,
                                    class_names=val_dataset.classes)
        val_polygon_metric = VOC07PolygonMApMetric(
            iou_thresh=0.7, class_names=val_dataset.classes)
    elif dataset.lower() == 'coco_pretrain':
        train_dataset = gdata.coco_pretrain_Detection(
            splits=[('_coco_20', 'train' + '_' + '8' + '_bboxwh')])
        if args.val_2012 == True:
            val_dataset = gdata.VOC_Val_Detection(splits=[('sbdche',
                                                           'val_2012_bboxwh')])
        else:
            val_dataset = gdata.VOC_Val_Detection(splits=[('sbdche',
                                                           'val' + '_' + '8' +
                                                           '_bboxwh')])
        val_metric = VOC07MApMetric(iou_thresh=0.7,
                                    class_names=val_dataset.classes)
        val_polygon_metric = VOC07PolygonMApMetric(
            iou_thresh=0.7, class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.cocoDetection(
            root='/home/tutian/dataset/coco_to_voc/train',
            subfolder='./bases_50_xml_each_' + 'var')
        val_dataset = gdata.cocoDetection(
            root='/home/tutian/dataset/coco_to_voc/val',
            subfolder='./bases_50_xml_' + 'raw_coef')
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
        # val_polygon_metric = New07PolygonMApMetric(iou_thresh=0.5, class_names=val_dataset.classes, root='/home/tutian/dataset/coco_to_voc/val/')
        val_polygon_metric = None
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    if args.num_samples < 0:
        args.num_samples = len(train_dataset)
    if args.mixup:
        from gluoncv.data import MixupDetection
        train_dataset = MixupDetection(train_dataset)
    return train_dataset, val_dataset, val_metric, val_polygon_metric
Exemplo n.º 8
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = gdata.VOCDetection(
            splits=[(2007, 'trainval'), (2012, 'trainval')])
        val_dataset = gdata.VOCDetection(splits=[(2007, 'test')])
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.COCODetection(
            root='/media/HDD_4TB/MSCOCO/images/',
            splits='instances_train2017',
            use_crowd=False)
        val_dataset = gdata.COCODetection(root='/media/HDD_4TB/MSCOCO/images/',
                                          splits='instances_val2017',
                                          skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset,
                                         args.save_prefix + '_eval',
                                         cleanup=True)
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    if args.mixup:
        from gluoncv.data.mixup.detection import MixupDetection
        train_dataset = MixupDetection(train_dataset)
    return train_dataset, val_dataset, val_metric
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        #train_dataset = VOCLike(root='/opt/ml/input/data/training', splits=((2019, 'train'),))
        #val_dataset = VOCLike(root='/opt/ml/input/data/training', splits=((2018, 'val'),))
        train_dataset = VOCLike(
            root='~/code/gluoncv-yolo-playing_cards/VOCTemplate',
            splits=((2019, 'train'), ))
        val_dataset = VOCLike(
            root='~/code/gluoncv-yolo-playing_cards/VOCTemplate',
            splits=((2018, 'val'), ))
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.COCODetection(splits='instances_train2017',
                                            use_crowd=False)
        val_dataset = gdata.COCODetection(splits='instances_val2017',
                                          skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset,
                                         args.save_prefix + '_eval',
                                         cleanup=True,
                                         data_shape=(args.data_shape,
                                                     args.data_shape))
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    if args.num_samples < 0:
        args.num_samples = len(train_dataset)
    if args.mixup:
        from gluoncv.data import MixupDetection
        train_dataset = MixupDetection(train_dataset)
    return train_dataset, val_dataset, val_metric
Exemplo n.º 10
0
def validate(net, val_data, ctx, classes):
    """
    Compute the mAP for the network on the validation data
    """
    metric = VOC07MApMetric(iou_thresh=0.5, class_names=classes)
    net.set_nms(nms_thresh=0.2, nms_topk=400, post_nms=100)
    for ib, batch in enumerate(val_data):

        data = gluon.utils.split_and_load(batch[0],
                                          ctx_list=ctx,
                                          batch_axis=0,
                                          even_split=False)
        label = gluon.utils.split_and_load(batch[1],
                                           ctx_list=ctx,
                                           batch_axis=0,
                                           even_split=False)
        det_bboxes, det_ids, det_scores = [], [], []
        gt_bboxes, gt_ids = [], []

        for x, y in zip(data, label):
            ids, scores, bboxes = net(x)
            det_ids.append(ids)
            det_scores.append(scores)
            det_bboxes.append(bboxes.clip(0, batch[0].shape[2]))
            gt_ids.append(y.slice_axis(axis=-1, begin=4, end=5))
            gt_bboxes.append(y.slice_axis(axis=-1, begin=0, end=4))

            metric.update(det_bboxes, det_ids, det_scores, gt_bboxes, gt_ids)
    return metric.get()
Exemplo n.º 11
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = gdata.VOCDetection(
            splits=[(2007, 'trainval'), (2012, 'trainval')])
        val_dataset = gdata.VOCDetection(splits=[(2007, 'test')])
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.PersonDetection(root=COCO_ROOT_DIR,
                                              splits=('person_train2014',
                                                      'person_train2017'),
                                              use_crowd=False)
        val_dataset = gdata.PersonDetection(root=COCO_ROOT_DIR,
                                            splits='person_val2017',
                                            skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset,
                                         args.save_prefix + '_eval',
                                         cleanup=True,
                                         data_shape=(args.data_shape,
                                                     args.data_shape))
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    if args.num_samples < 0:
        args.num_samples = len(train_dataset)
    return train_dataset, val_dataset, val_metric
Exemplo n.º 12
0
def get_dataloader(net, train_dataset, valid_dataset, data_shape, batch_size,
                   num_workers):
    from gluoncv.data.batchify import Tuple, Stack, Pad
    from gluoncv.data.transforms.presets.ssd import SSDDefaultTrainTransform
    width, height = data_shape, data_shape
    # use fake data to generate fixed anchors for target generation
    with autograd.train_mode():
        _, _, anchors = net(mx.nd.zeros((1, 3, height, width)))
    batchify_fn = Tuple(Stack(), Stack(),
                        Stack())  # stack image, cls_targets, box_targets
    train_loader = gluon.data.DataLoader(train_dataset.transform(
        SSDDefaultTrainTransform(width, height, anchors)),
                                         batch_size,
                                         True,
                                         batchify_fn=batchify_fn,
                                         last_batch='rollover',
                                         num_workers=num_workers)

    val_batchify_fn = Tuple(Stack(), Pad(pad_val=-1))

    val_loader = gluon.data.DataLoader(valid_dataset.transform(
        SSDDefaultValTransform(width, height)),
                                       batch_size,
                                       False,
                                       batchify_fn=val_batchify_fn,
                                       last_batch='keep',
                                       num_workers=num_workers)

    eval_metric = VOC07MApMetric(iou_thresh=0.5, class_names=classes)
    return train_loader, val_loader, eval_metric
Exemplo n.º 13
0
def get_dataset(dataset, args):

    train_dataset = gdata.RecordFileDetection(
        os.path.join(os.environ['SM_CHANNEL_TRAIN'], 'train.rec'))
    val_dataset = gdata.RecordFileDetection(
        os.path.join(os.environ['SM_CHANNEL_VAL'], 'val.rec'))
    object_categories = [
        'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat',
        'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person',
        'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'
    ]
    val_metric = VOC07MApMetric(iou_thresh=0.5, class_names=object_categories)
    args.no_random_shape = True

    # if dataset.lower() == 'voc':
    #     train_dataset = gdata.VOCDetection(
    #         splits=[(2007, 'trainval'), (2012, 'trainval')])
    #     val_dataset = gdata.VOCDetection(
    #         splits=[(2007, 'test')])
    #     val_metric = VOC07MApMetric(iou_thresh=0.5, class_names=val_dataset.classes)
    # elif dataset.lower() == 'coco':
    #     train_dataset = gdata.COCODetection(splits='instances_train2017', use_crowd=False)
    #     val_dataset = gdata.COCODetection(splits='instances_val2017', skip_empty=False)
    #     val_metric = COCODetectionMetric(
    #         val_dataset, args.save_prefix + '_eval', cleanup=True,
    #         data_shape=(args.data_shape, args.data_shape))
    # else:
    #     raise NotImplementedError('Dataset: {} not implemented.'.format(dataset))
    if args.num_samples < 0:
        args.num_samples = len(train_dataset)
    if args.mixup:
        from gluoncv.data import MixupDetection
        train_dataset = MixupDetection(train_dataset)
    return train_dataset, val_dataset, val_metric
 def get_dataset(self):
     validation_threshold = self.validation_threshold
     self.train_dataset = gdata.RecordFileDetection(self.train_file)
     self.val_dataset = gdata.RecordFileDetection(self.val_file)
     # we are only using VOCMetric for evaluation
     self.val_metric = VOC07MApMetric(iou_thresh=validation_threshold,
                                      class_names=self.net.classes)
Exemplo n.º 15
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = gdata.VOCDetection(root=args.dataset_root,
                                           splits=[(2007, 'trainval'),
                                                   (2012, 'trainval')])
        val_dataset = gdata.VOCDetection(root=args.dataset_root,
                                         splits=[(2007, 'test')])
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.COCODetection(splits='instances_train2017')
        val_dataset = gdata.COCODetection(splits='instances_val2017',
                                          skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset,
                                         args.save_prefix + '_eval',
                                         cleanup=True,
                                         data_shape=(args.data_shape,
                                                     args.data_shape))
        # coco validation is slow, consider increase the validation interval
        if args.val_interval == 1:
            args.val_interval = 10
    elif dataset.lower() == 'tt100k':
        train_dataset = gdata.TT100KDetection(root=args.dataset_root,
                                              splits='train')
        val_dataset = None
        val_metric = None
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    return train_dataset, val_dataset, val_metric
Exemplo n.º 16
0
def get_dataset(dataset, args):
    # load training and validation images
    if dataset.lower == 'voc':
        train_dataset = gdata.VOCDetection(root=args.dataset_root + "/voc",
                                           splits=[(2007, 'trainval'),
                                                   (2012, 'trainval')])
        val_dataset = gdata.VOCDetection(root=args.dataset_root + "/voc",
                                         splits=[(2007, 'test')])
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
        # if class_names is provided, will print out AP for each class
    elif dataset.lower == 'coco':
        train_dataset = gdata.COCODetection(root=args.dataset_root + "/coco",
                                            splits='instances_train2017')
        val_dataset = gdata.COCODetection(root=args.dataset_root + "/coco",
                                          splits='instances_val2017',
                                          skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset,
                                         args.save_prefix + '_eval',
                                         cleanup=True,
                                         data_shape=(args.data_shape,
                                                     args.data_shape))
        # will print out AP for each class
        if args.val_interval == 1:
            # args.val_interval: 进行验证集测试的循环间隔
            # 如果进行测试很慢的话, 需要将该值改大一些,以加快训练
            args.val_interval = 10
    else:
        raise NotImplementedError(
            "dataset: {} not implemented".format(dataset))
    return train_dataset, val_dataset, val_metric
Exemplo n.º 17
0
 def __init__(self):
     super().__init__()
     self.train_dataset = gdata.VOCDetection(
         splits=[(2007, 'trainval'), (2012, 'trainval')])
     self.val_dataset = gdata.VOCDetection(splits=[(2007, 'test')])
     self.val_metric = VOC07MApMetric(iou_thresh=0.5,
                                      class_names=self.val_dataset.classes)
Exemplo n.º 18
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = VOCLike(root='/opt/ml/input/data/training',
                                splits=(('VOCTrain', 'train'), ))
        val_dataset = VOCLike(root='/opt/ml/input/data/training',
                              splits=(('VOCValidate', 'val'), ))
        #train_dataset = VOCLike(root='VOC-PlayingCards', splits=(('VOC2019', 'train'),))
        #val_dataset = VOCLike(root='VOC-PlayingCards', splits=(('VOC2018', 'val'),))
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
        for c in val_metric.class_names:
            print("Class: {}".format(c))
    elif dataset.lower() == 'coco':
        train_dataset = gdata.COCODetection(root=args.dataset_root + "/coco",
                                            splits='instances_train2017')
        val_dataset = gdata.COCODetection(root=args.dataset_root + "/coco",
                                          splits='instances_val2017',
                                          skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset,
                                         args.save_prefix + '_eval',
                                         cleanup=True,
                                         data_shape=(args.data_shape,
                                                     args.data_shape))
        # coco validation is slow, consider increase the validation interval
        if args.val_interval == 1:
            args.val_interval = 10
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    return train_dataset, val_dataset, val_metric
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = VOCLike(
            root="/content/drive/My Drive/Research/Dataset_conversion/Dataset/",
            splits=[(2007, 'train')])
        val_dataset = VOCLike(
            root="/content/drive/My Drive/Research/Dataset_conversion/Dataset/",
            splits=[(2007, 'validation')])
        print(train_dataset.classes)
        print(val_dataset.classes)
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.COCODetection(splits='instances_train2017',
                                            use_crowd=False)
        val_dataset = gdata.COCODetection(splits='instances_val2017',
                                          skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset,
                                         args.save_prefix + '_eval',
                                         cleanup=True)
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    if args.mixup:
        from gluoncv.data.mixup import detection
        train_dataset = detection.MixupDetection(train_dataset)
    return train_dataset, val_dataset, val_metric
Exemplo n.º 20
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = gdata.VOCDetection(
            root='/home/users/chenxin.lu/VOCdevkit/VOCdevkit',
            splits=[(2007, 'trainval'), (2012, 'trainval')])
        val_dataset = gdata.VOCDetection(splits=[(2007, 'test')])
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.COCODetection(
            root=args.dataset_root + "/coco/stuff_annotations_trainval2017",
            splits='stuff_train2017')
        val_dataset = gdata.COCODetection(
            root=args.dataset_root + "/coco/stuff_annotations_trainval2017",
            splits='stuff_val2017',
            skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset,
                                         args.save_prefix + '_eval',
                                         cleanup=True,
                                         data_shape=(args.data_shape,
                                                     args.data_shape),
                                         post_affine=get_post_transform)
        # coco validation is slow, consider increase the validation interval
        if args.val_interval == 1:
            args.val_interval = 10
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    if args.num_samples < 0:
        args.num_samples = len(train_dataset)
    return train_dataset, val_dataset, val_metric
Exemplo n.º 21
0
def validate(net, val_data, ctx, classes, size):
    metric = VOC07MApMetric(iou_thresh=0.5, class_names=classes)
    net.set_nms(0.2)
    for ib, batch in enumerate(val_data):

        data = gluon.utils.split_and_load(batch[0],
                                          ctx_list=ctx,
                                          batch_axis=0,
                                          even_split=False)
        label = gluon.utils.split_and_load(batch[1],
                                           ctx_list=ctx,
                                           batch_axis=0,
                                           even_split=False)
        det_bboxes, det_ids, det_scores = [], [], []
        gt_bboxes, gt_ids = [], []

        for x, y in zip(data, label):
            ids, scores, bboxes = net(x)
            det_ids.append(ids)
            det_scores.append(scores)
            det_bboxes.append(bboxes.clip(0, batch[0].shape[2]))
            gt_ids.append(y.slice_axis(axis=-1, begin=4, end=5))
            gt_bboxes.append(y.slice_axis(axis=-1, begin=0, end=4))

            metric.update(det_bboxes, det_ids, det_scores, gt_bboxes,
                          gt_ids[0], None)
    return metric.get()
Exemplo n.º 22
0
def validate(net, val_data, ctx, classes, size):
    """Test on validation dataset."""
    net.collect_params().reset_ctx(ctx)
    metric = VOC07MApMetric(iou_thresh=0.5, class_names=classes)
    net.set_nms(nms_thresh=0.45, nms_topk=400)
    net.hybridize()
    with tqdm(total=size) as pbar:
        for ib, batch in enumerate(val_data):
            data = gluon.utils.split_and_load(batch[0],
                                              ctx_list=ctx,
                                              batch_axis=0)
            label = gluon.utils.split_and_load(batch[1],
                                               ctx_list=ctx,
                                               batch_axis=0)
            for x, y in zip(data, label):
                ids, scores, bboxes = net(x)
                bboxes = bboxes.clip(0, batch[0].shape[2])
                gt_ids = y.slice_axis(axis=-1, begin=4, end=5)
                gt_bboxes = y.slice_axis(axis=-1, begin=0, end=4)
                gt_difficults = y.slice_axis(
                    axis=-1, begin=5, end=6) if y.shape[-1] > 5 else None
                metric.update(bboxes, ids, scores, gt_bboxes, gt_ids,
                              gt_difficults)
            pbar.update(batch[0].shape[0])
    return metric.get()
Exemplo n.º 23
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = gdata.VOCDetection(
            splits=[(2007, 'trainval'), (2012, 'trainval')])
        val_dataset = gdata.VOCDetection(splits=[(2007, 'test')])
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.COCODetection(root=MXNET_DATA_COCO,
                                            splits='instances_mini20k',
                                            use_crowd=False)
        val_dataset = gdata.COCODetection(root=MXNET_DATA_COCO,
                                          splits='instances_val2017',
                                          skip_empty=False)
        val_metric = COCODetectionMetric(
            val_dataset,
            os.path.join(args.save_dir, args.save_prefix + '_eval'),
            cleanup=True,
            data_shape=(args.data_shape, args.data_shape))
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    if args.num_samples < 0:
        args.num_samples = len(train_dataset)
    if args.mixup:
        from gluoncv.data import MixupDetection
        train_dataset = MixupDetection(train_dataset)
    return train_dataset, val_dataset, val_metric
Exemplo n.º 24
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = VOCLike(
            root='C:/Users/DELL/Desktop/traindata/VOCtemplate',
            splits=((2018, 'train'), ))
        val_dataset = VOCLike(
            root='C:/Users/DELL/Desktop/traindata/VOCtemplate',
            splits=((2018, 'val'), ))
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        train_dataset = gdata.COCODetection(root=args.dataset_root + "/coco",
                                            splits='instances_train2017')
        val_dataset = gdata.COCODetection(root=args.dataset_root + "/coco",
                                          splits='instances_val2017',
                                          skip_empty=False)
        val_metric = COCODetectionMetric(val_dataset,
                                         args.save_prefix + '_eval',
                                         cleanup=True,
                                         data_shape=(args.data_shape,
                                                     args.data_shape))
        # coco validation is slow, consider increase the validation interval
        if args.val_interval == 1:
            args.val_interval = 10
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    return train_dataset, val_dataset, val_metric
Exemplo n.º 25
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        if args.val_voc2012:
            val_dataset = gdata.VOC_Val_Detection(
            splits=[('sbdche', 'val_2012_bboxwh')])
        else:
            val_dataset = gdata.VOC_Val_Detection(
                splits=[('sbdche', 'val'+'_'+'8'+'_bboxwh')])
        val_metric = VOC07MApMetric(iou_thresh=0.5, class_names=val_dataset.classes)
        val_polygon_metric = VOC07PolygonMApMetric(iou_thresh=0.5, class_names=val_dataset.classes)
    elif dataset.lower() == 'coco':
        val_dataset = gdata.cocoDetection(root='/home/tutian/dataset/coco_to_voc/val', subfolder='./bases_50_xml_'+'raw_coef')
        val_metric = VOC07MApMetric(iou_thresh=0.75, class_names=val_dataset.classes)
        val_polygon_metric = New07PolygonMApMetric(iou_thresh=0.75, class_names=val_dataset.classes, root='/home/tutian/dataset/coco_to_voc/val/')
    else:
        raise NotImplementedError('Dataset: {} not implemented.'.format(dataset))
    return val_dataset, val_metric, val_polygon_metric
Exemplo n.º 26
0
    def metrics(self):
        """ Customized metric method introduction.

            VOC07MApMetric is used which is the Mean average precision metric for PASCAL V0C 07 dataset.
        """
        metric = VOC07MApMetric(
            iou_thresh=0.5, class_names=gdata.VOCDetection.CLASSES)
        metric.reset()
        return metric
Exemplo n.º 27
0
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = gcv.data.RecordFileDetection('datasets/train.rec')
        val_dataset = gcv.data.RecordFileDetection('datasets/val.rec')
        val_metric = VOC07MApMetric(iou_thresh=0.5, class_names=TARGET_CLASSES)
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    return train_dataset, val_dataset, val_metric
def get_eval_metric(args, CLASSES=None, IOU_THRESH=0.5):

    if args.pre_trained_weights == 'VOC':
        eval_metric = VOC07MApMetric(iou_thresh=IOU_THRESH,
                                     class_names=CLASSES)
    elif args.pre_trained_weights == 'COCO':
        eval_metric = COCODetectionMetric(val_dataset,
                                          args.save_prefix + '_eval',
                                          cleanup=True,
                                          data_shape=(args.data_shape,
                                                      args.data_shape))
    elif args.pre_trained_weights == 'NONE':
        eval_metric = VOC07MApMetric(iou_thresh=IOU_THRESH,
                                     class_names=CLASSES)
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))

    return eval_metric
Exemplo n.º 29
0
def get_dataset():
    train_dataset = gdata.VOCDetection(
        root='H:\\Self_study\\DeepLearing\\4 MXNet\\Pre-modeul\\data\\VOC',
        splits=[(2007, 'trainval'), (2012, 'trainval')])
    val_dataset = gdata.VOCDetection(
        root='H:\\Self_study\\DeepLearing\\4 MXNet\\Pre-modeul\\data\\VOC',
        splits=[(2007, 'test')])
    val_metric = VOC07MApMetric(iou_thresh=0.5,
                                class_names=val_dataset.classes)

    return train_dataset, val_dataset, val_metric
def get_dataset(dataset, args):
    if dataset.lower() == 'voc':
        train_dataset = gdata.VOCDetection(
            splits=[(2007, 'trainval'), (2012, 'trainval')])
        val_dataset = gdata.VOCDetection(splits=[(2007, 'test')])
        val_metric = VOC07MApMetric(iou_thresh=0.5,
                                    class_names=val_dataset.classes)
    else:
        raise NotImplementedError(
            'Dataset: {} not implemented.'.format(dataset))
    return train_dataset, val_dataset, val_metric