Update xd-violence-small.py
Browse files- xd-violence-small.py +70 -0
xd-violence-small.py
CHANGED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import datasets
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
class YourDataset(datasets.GeneratorBasedBuilder):
|
6 |
+
VERSION = datasets.Version("1.0.0")
|
7 |
+
|
8 |
+
BUILDER_CONFIGS = [
|
9 |
+
datasets.BuilderConfig(
|
10 |
+
name="i3d_rgb",
|
11 |
+
version=VERSION,
|
12 |
+
description="i3d RGB dataset",
|
13 |
+
features=datasets.Features({"video": datasets.Sequence(datasets.Value("float32"))}),
|
14 |
+
),
|
15 |
+
datasets.BuilderConfig(
|
16 |
+
name="i3d_flow",
|
17 |
+
version=VERSION,
|
18 |
+
description="i3d Flow dataset",
|
19 |
+
features=datasets.Features({"video": datasets.Sequence(datasets.Value("float32"))}),
|
20 |
+
),
|
21 |
+
datasets.BuilderConfig(
|
22 |
+
name="vggish_train",
|
23 |
+
version=VERSION,
|
24 |
+
description="VGGish Train dataset",
|
25 |
+
features=datasets.Features({"audio": datasets.Sequence(datasets.Value("float32"))}),
|
26 |
+
),
|
27 |
+
datasets.BuilderConfig(
|
28 |
+
name="vggish_test",
|
29 |
+
version=VERSION,
|
30 |
+
description="VGGish Test dataset",
|
31 |
+
features=datasets.Features({"audio": datasets.Sequence(datasets.Value("float32"))}),
|
32 |
+
),
|
33 |
+
]
|
34 |
+
|
35 |
+
def _info(self):
|
36 |
+
features = self.config.features
|
37 |
+
return datasets.DatasetInfo(
|
38 |
+
features=features,
|
39 |
+
)
|
40 |
+
|
41 |
+
def _split_generators(self, dl_manager):
|
42 |
+
data_dir = "Alkemi/xd-violence-small"
|
43 |
+
|
44 |
+
splits = []
|
45 |
+
for config in self.configs:
|
46 |
+
if config.name.startswith("i3d-features"):
|
47 |
+
split_name = config.name.split("_")[1]
|
48 |
+
splits.append(
|
49 |
+
datasets.SplitGenerator(name=split_name, gen_kwargs={"data_dir": os.path.join(data_dir, "i3d-features", split_name)})
|
50 |
+
)
|
51 |
+
elif config.name.startswith("vggish-features"):
|
52 |
+
split_name = config.name.split("_")[1]
|
53 |
+
splits.append(
|
54 |
+
datasets.SplitGenerator(name=split_name, gen_kwargs={"data_dir": os.path.join(data_dir, "vggish-features", split_name)})
|
55 |
+
)
|
56 |
+
|
57 |
+
return splits
|
58 |
+
|
59 |
+
def _generate_examples(self, data_dir):
|
60 |
+
filepaths = []
|
61 |
+
|
62 |
+
for root, dirs, files in os.walk(data_dir):
|
63 |
+
for file in files:
|
64 |
+
if file.endswith(".npy"):
|
65 |
+
filepaths.append(os.path.join(root, file))
|
66 |
+
|
67 |
+
for i, filepath in enumerate(filepaths):
|
68 |
+
data = np.load(filepath)
|
69 |
+
|
70 |
+
yield i, {"video": data} # or {"audio": data} depending on the configuration
|