-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadUCF101DataByTorch.py
64 lines (48 loc) · 1.51 KB
/
LoadUCF101DataByTorch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import torchvision.datasets as datasets
from torch.utils.data import DataLoader
import torchvision.transforms as transforms
import torchvision.transforms._transforms_video as v_transform
import torch
TRAIN_BATCH_SIZE = 128
TEST_BATCH_SIZE = 128
FRAME_LENGTH = 16
transform = transforms.Compose([
v_transform.ToTensorVideo(),
v_transform.NormalizeVideo(mean=[0.43216, 0.394666, 0.37645], std=[0.22803, 0.22145, 0.216989]),
v_transform.RandomHorizontalFlipVideo(),
v_transform.RandomCropVideo(112),
])
def custom_collate(batch):
filtered_batch = []
for video, _, label in batch:
filtered_batch.append((video, label))
return torch.utils.data.dataloader.default_collate(filtered_batch)
trainset = datasets.UCF101(
root='data/UCF101/UCF-101',
annotation_path='data/UCF101TrainTestSplits-RecognitionTask/ucfTrainTestlist',
frames_per_clip=FRAME_LENGTH,
num_workers=0,
transform=transform,
)
trainset_loader = DataLoader(
trainset,
batch_size=TRAIN_BATCH_SIZE,
shuffle=True,
num_workers=0,
collate_fn=custom_collate
)
testset = datasets.UCF101(
root='data/UCF101/UCF-101',
annotation_path='data/UCF101TrainTestSplits-RecognitionTask/ucfTrainTestlist',
frames_per_clip=FRAME_LENGTH,
num_workers=4,
train=False,
transform=transform,
)
testset_loader = DataLoader(
testset,
batch_size=TEST_BATCH_SIZE,
shuffle=False,
num_workers=4,
collate_fn=custom_collate
)