Beispiel #1
0
def get_training_set(opt, spatial_transform, temporal_transform,
                     target_transform):
    assert opt.dataset in ['kinetics', 'activitynet', 'ucf101', 'hmdb51']

    if opt.dataset == 'kinetics':
        training_data = Kinetics(opt.video_path,
                                 opt.annotation_path,
                                 'training',
                                 spatial_transform=spatial_transform,
                                 temporal_transform=temporal_transform,
                                 target_transform=target_transform)
    elif opt.dataset == 'activitynet':
        training_data = ActivityNet(opt.video_path,
                                    opt.annotation_path,
                                    'training',
                                    False,
                                    spatial_transform=spatial_transform,
                                    temporal_transform=temporal_transform,
                                    target_transform=target_transform)
    elif opt.dataset == 'ucf101':
        training_data = UCF101(opt.video_path,
                               opt.annotation_path,
                               'training',
                               spatial_transform=spatial_transform,
                               temporal_transform=temporal_transform,
                               target_transform=target_transform)
    elif opt.dataset == 'hmdb51':
        training_data = HMDB51(opt.video_path,
                               opt.annotation_path,
                               'training',
                               spatial_transform=spatial_transform,
                               temporal_transform=temporal_transform,
                               target_transform=target_transform)

    return training_data
Beispiel #2
0
def get_test_set(opt, spatial_transform, temporal_transform, target_transform):
    assert opt.dataset in ['kinetics', 'activitynet', 'ucf101', 'hmdb51']
    assert opt.test_subset in ['val', 'test']

    if opt.test_subset == 'val':
        subset = 'validation'
    elif opt.test_subset == 'test':
        subset = 'testing'
    if opt.dataset == 'kinetics':
        test_data = Kinetics(opt.video_path,
                             opt.annotation_path,
                             subset,
                             0,
                             spatial_transform,
                             temporal_transform,
                             target_transform,
                             sample_duration=opt.sample_duration,
                             sample_stride=opt.sample_stride)
    elif opt.dataset == 'activitynet':
        test_data = ActivityNet(opt.video_path,
                                opt.annotation_path,
                                subset,
                                True,
                                0,
                                spatial_transform,
                                temporal_transform,
                                target_transform,
                                sample_duration=opt.sample_duration)
    elif opt.dataset == 'ucf101':
        test_data = UCF101(opt.video_path,
                           opt.annotation_path,
                           subset,
                           0,
                           spatial_transform,
                           temporal_transform,
                           target_transform,
                           sample_duration=opt.sample_duration)
    elif opt.dataset == 'hmdb51':
        test_data = HMDB51(opt.video_path,
                           opt.annotation_path,
                           subset,
                           0,
                           spatial_transform,
                           temporal_transform,
                           target_transform,
                           sample_duration=opt.sample_duration)

    return test_data
Beispiel #3
0
def get_validation_set(opt, spatial_transform, temporal_transform,
                       target_transform):
    assert opt.dataset in ['kinetics', 'activitynet', 'ucf101', 'hmdb51']

    if opt.dataset == 'kinetics':
        validation_data = Kinetics(opt.video_path,
                                   opt.annotation_path,
                                   'validation',
                                   opt.n_val_samples,
                                   spatial_transform,
                                   temporal_transform,
                                   target_transform,
                                   sample_duration=opt.sample_duration)
    elif opt.dataset == 'activitynet':
        validation_data = ActivityNet(opt.video_path,
                                      opt.annotation_path,
                                      'validation',
                                      False,
                                      opt.n_val_samples,
                                      spatial_transform,
                                      temporal_transform,
                                      target_transform,
                                      sample_duration=opt.sample_duration)
    elif opt.dataset == 'ucf101':
        validation_data = UCF101(opt.video_path,
                                 opt.annotation_path,
                                 'validation',
                                 opt.n_val_samples,
                                 spatial_transform,
                                 temporal_transform,
                                 target_transform,
                                 sample_duration=opt.sample_duration)
    elif opt.dataset == 'hmdb51':
        validation_data = HMDB51(opt.video_path,
                                 opt.annotation_path,
                                 'validation',
                                 opt.n_val_samples,
                                 spatial_transform,
                                 temporal_transform,
                                 target_transform,
                                 sample_duration=opt.sample_duration)
    return validation_data
Beispiel #4
0
    if not opt.no_cuda:
        criterion = criterion.cuda()

    if not opt.no_train:
        spatial_transform = Compose([
            MultiScaleCornerCrop(opt.scales, opt.sample_size),
            RandomHorizontalFlip(),
            ToTensor(opt.norm_value),
            Normalize(opt.mean, [1, 1, 1])
        ])
        temporal_transform = TemporalRandomCrop(opt.sample_duration)
        target_transform = ClassLabel()
        if opt.dataset == 'kinetics':
            training_data = Kinetics(opt.video_path,
                                     opt.annotation_path,
                                     'training',
                                     spatial_transform=spatial_transform,
                                     temporal_transform=temporal_transform,
                                     target_transform=target_transform)
        else:
            training_data = ActivityNet(opt.video_path,
                                        opt.annotation_path,
                                        'training',
                                        spatial_transform=spatial_transform,
                                        temporal_transform=temporal_transform,
                                        target_transform=target_transform)
        train_loader = torch.utils.data.DataLoader(training_data,
                                                   batch_size=opt.batch_size,
                                                   shuffle=True,
                                                   num_workers=opt.n_threads,
                                                   pin_memory=True)
        train_logger = Logger(os.path.join(opt.result_path, 'train.log'),