Example #1
0
def init_dataset(opt):
    '''
    Initialize the datasets, samplers and dataloaders
    '''
    if opt.dataset == 'omniglot':
        train_dataset = OmniglotDataset(mode='train')
        val_dataset = OmniglotDataset(mode='val')
        trainval_dataset = OmniglotDataset(mode='trainval')
        test_dataset = OmniglotDataset(mode='test')
    elif opt.dataset == 'mini_imagenet':
        train_dataset = MiniImagenetDataset(mode='train')
        val_dataset = MiniImagenetDataset(mode='val')
        trainval_dataset = MiniImagenetDataset(mode='val')
        test_dataset = MiniImagenetDataset(mode='test')
    train_bs_class = BatchSampler
    eval_bs_class = BatchSampler
    if opt.task_shuffling == 'non_overlapping':
        train_bs_class = NonOverlappingTasksBatchSampler
    elif opt.task_shuffling == 'intratask':
        train_bs_class = IntraTaskBatchSampler
    # Opt for mini_imagenet:
    # Namespace(batch_size=32, cuda=True, dataset='mini_imagenet', epochs=100,
    # exp='mini_imagenet_5way_1shot', iterations=10000, lr=0.0001, num_cls=5, num_samples=1)
    tr_sampler = train_bs_class(labels=train_dataset.y,
                                classes_per_it=opt.num_cls,
                                num_samples=opt.num_samples,
                                iterations=opt.iterations,
                                batch_size=opt.batch_size)

    val_sampler = eval_bs_class(labels=val_dataset.y,
                                classes_per_it=opt.num_cls,
                                num_samples=opt.num_samples,
                                iterations=opt.iterations,
                                batch_size=opt.batch_size)

    trainval_sampler = eval_bs_class(labels=trainval_dataset.y,
                                     classes_per_it=opt.num_cls,
                                     num_samples=opt.num_samples,
                                     iterations=opt.iterations,
                                     batch_size=opt.batch_size)

    test_sampler = eval_bs_class(labels=test_dataset.y,
                                 classes_per_it=opt.num_cls,
                                 num_samples=opt.num_samples,
                                 iterations=opt.iterations,
                                 batch_size=opt.batch_size)

    tr_dataloader = torch.utils.data.DataLoader(train_dataset,
                                                batch_sampler=tr_sampler)

    val_dataloader = torch.utils.data.DataLoader(val_dataset,
                                                 batch_sampler=val_sampler)

    trainval_dataloader = torch.utils.data.DataLoader(
        trainval_dataset, batch_sampler=trainval_sampler)

    test_dataloader = torch.utils.data.DataLoader(test_dataset,
                                                  batch_sampler=test_sampler)
    return tr_dataloader, val_dataloader, trainval_dataloader, test_dataloader
Example #2
0
def init_dataset(opt):
    '''
    Initialize the datasets, samplers and dataloaders
    '''
    if opt.dataset == 'omniglot':
        train_dataset = OmniglotDataset(mode='train')
        val_dataset = OmniglotDataset(mode='val')
        trainval_dataset = OmniglotDataset(mode='trainval')
        test_dataset = OmniglotDataset(mode='test')
    elif opt.dataset == 'mini_imagenet':
        train_dataset = MiniImagenetDataset(mode='train')
        val_dataset = MiniImagenetDataset(mode='val')
        trainval_dataset = MiniImagenetDataset(mode='val')
        test_dataset = MiniImagenetDataset(mode='test')

    tr_sampler = PrototypicalBatchSampler(labels=train_dataset.y,
                                          classes_per_it=opt.classes_per_it_tr,
                                          num_samples=opt.num_support_tr +
                                          opt.num_query_tr,
                                          iterations=opt.iterations)

    val_sampler = PrototypicalBatchSampler(
        labels=val_dataset.y,
        classes_per_it=opt.classes_per_it_val,
        num_samples=opt.num_support_val + opt.num_query_val,
        iterations=opt.iterations)

    trainval_sampler = PrototypicalBatchSampler(
        labels=trainval_dataset.y,
        classes_per_it=opt.classes_per_it_tr,
        num_samples=opt.num_support_tr + opt.num_query_tr,
        iterations=opt.iterations)

    test_sampler = PrototypicalBatchSampler(
        labels=test_dataset.y,
        classes_per_it=opt.classes_per_it_val,
        num_samples=opt.num_support_val + opt.num_query_val,
        iterations=opt.iterations)

    tr_dataloader = torch.utils.data.DataLoader(train_dataset,
                                                batch_sampler=tr_sampler)

    val_dataloader = torch.utils.data.DataLoader(val_dataset,
                                                 batch_sampler=val_sampler)

    trainval_dataloader = torch.utils.data.DataLoader(
        trainval_dataset, batch_sampler=trainval_sampler)

    test_dataloader = torch.utils.data.DataLoader(test_dataset,
                                                  batch_sampler=test_sampler)
    return tr_dataloader, val_dataloader, trainval_dataloader, test_dataloader
Example #3
0
def init_dataset(opt):
    '''
    Initialize the datasets, samplers and dataloaders
    '''
    if opt.dataset == 'omniglot':
        train_dataset = OmniglotDataset(mode='train')
        val_dataset = OmniglotDataset(mode='val')
        trainval_dataset = OmniglotDataset(mode='trainval')
        test_dataset = OmniglotDataset(mode='test')
    elif opt.dataset == 'mini_imagenet':
        train_dataset = MiniImagenetDataset(mode='train')
        val_dataset = MiniImagenetDataset(mode='val')
        trainval_dataset = MiniImagenetDataset(mode='val')
        test_dataset = MiniImagenetDataset(mode='test')

    tr_sampler = BatchSampler(labels=train_dataset.y,
                              classes_per_it=opt.num_cls,
                              num_samples=opt.num_samples,
                              iterations=opt.iterations,
                              batch_size=opt.batch_size)

    val_sampler = BatchSampler(labels=val_dataset.y,
                               classes_per_it=opt.num_cls,
                               num_samples=opt.num_samples,
                               iterations=opt.iterations,
                               batch_size=opt.batch_size)

    trainval_sampler = BatchSampler(labels=trainval_dataset.y,
                                    classes_per_it=opt.num_cls,
                                    num_samples=opt.num_samples,
                                    iterations=opt.iterations,
                                    batch_size=opt.batch_size)

    test_sampler = BatchSampler(labels=test_dataset.y,
                                classes_per_it=opt.num_cls,
                                num_samples=opt.num_samples,
                                iterations=opt.iterations,
                                batch_size=opt.batch_size)

    tr_dataloader = torch.utils.data.DataLoader(train_dataset,
                                                batch_sampler=tr_sampler)

    val_dataloader = torch.utils.data.DataLoader(val_dataset,
                                                 batch_sampler=val_sampler)

    trainval_dataloader = torch.utils.data.DataLoader(
        trainval_dataset, batch_sampler=trainval_sampler)

    test_dataloader = torch.utils.data.DataLoader(test_dataset,
                                                  batch_sampler=test_sampler)
    return tr_dataloader, val_dataloader, trainval_dataloader, test_dataloader
Example #4
0
def init_dataset(opt):
    '''
    Initialize the datasets, samplers and dataloaders
    '''
    if opt.dataset == 'omniglot':
        test_dataset = OmniglotDataset(mode='test')
    elif opt.dataset == 'mini_imagenet':
        test_dataset = MiniImagenetDataset(mode='val')
    else:
        print('Dataset is not valid')
    test_sampler = PrototypicalBatchSampler(labels=test_dataset.y,
                                            classes_per_it=opt.classes_per_it_val,
                                            num_samples=opt.num_support_val + opt.num_query_val,
                                            iterations=opt.iterations)
    test_dataloader = torch.utils.data.DataLoader(test_dataset,
                                                  batch_sampler=test_sampler)
    return test_dataloader