-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathkinetics.py
More file actions
54 lines (50 loc) · 2.1 KB
/
Copy pathkinetics.py
File metadata and controls
54 lines (50 loc) · 2.1 KB
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
import os
from pathlib import Path
from datasets.base import VidTrainDataset
from datasets.storage import ZipFrameStore, ZipPrefetcher, load_local_paths
class KineticsTrain(VidTrainDataset):
def __init__(
self,
exclude_list: str = "datasets/kinetics_excluded.txt",
num_frames: int = 8,
frame_size: int = 256,
time_stride_range: tuple[float, float] = (1 / 25, 1 / 3),
horizontal_flip: bool = True,
ratio_jitter: float = 4 / 3,
scale: tuple[float, float] = (0.6, 1.0),
):
super().__init__(
exclude_list=exclude_list,
num_frames=num_frames,
frame_size=frame_size,
time_stride_range=time_stride_range,
horizontal_flip=horizontal_flip,
ratio_jitter=ratio_jitter,
scale=scale,
)
root = os.environ["KINETICS_ROOT"]
if root.endswith(".zip"):
# Pre-extracted frames in a zip archive (optionally split into .part* files)
self.store = ZipFrameStore(root)
candidates = [vid for vid in self.store.vids if "train" in Path(vid).parts]
self.samples = self._filter_excluded(candidates)
self.prefetcher = ZipPrefetcher(
self.store, self.samples, num_frames, time_stride_range
)
else:
# Local directory: train/<class>/<video>/ (frame dirs) or
# train/<class>/<video>.mp4 (video files)
self.store = None
first_item = next(next(Path(root, "train").iterdir()).iterdir())
if first_item.is_dir():
candidates = sorted(
set(
str(Path(path).parent)
for path in load_local_paths(root, "train/**/*.jpg")
)
)
else:
candidates = load_local_paths(root, "train/**/*.mp4")
self.samples = self._filter_excluded(candidates)
def _get_source(self, idx: int) -> tuple[ZipFrameStore, str] | str:
return (self.store, self.samples[idx]) if self.store else self.samples[idx]