|
import os |
|
import datasets |
|
import numpy as np |
|
|
|
class YourDataset(datasets.GeneratorBasedBuilder): |
|
VERSION = datasets.Version("1.0.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="i3d_rgb", |
|
version=VERSION, |
|
description="i3d RGB dataset", |
|
features=datasets.Features({"video": datasets.Sequence(datasets.Value("float32"))}), |
|
), |
|
datasets.BuilderConfig( |
|
name="i3d_flow", |
|
version=VERSION, |
|
description="i3d Flow dataset", |
|
features=datasets.Features({"video": datasets.Sequence(datasets.Value("float32"))}), |
|
), |
|
datasets.BuilderConfig( |
|
name="vggish_train", |
|
version=VERSION, |
|
description="VGGish Train dataset", |
|
features=datasets.Features({"audio": datasets.Sequence(datasets.Value("float32"))}), |
|
), |
|
datasets.BuilderConfig( |
|
name="vggish_test", |
|
version=VERSION, |
|
description="VGGish Test dataset", |
|
features=datasets.Features({"audio": datasets.Sequence(datasets.Value("float32"))}), |
|
), |
|
] |
|
|
|
def _info(self): |
|
features = self.config.features |
|
return datasets.DatasetInfo( |
|
features=features, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
data_dir = "Alkemi/xd-violence-small" |
|
|
|
splits = [] |
|
for config in self.configs: |
|
if config.name.startswith("i3d-features"): |
|
split_name = config.name.split("_")[1] |
|
splits.append( |
|
datasets.SplitGenerator(name=split_name, gen_kwargs={"data_dir": os.path.join(data_dir, "i3d-features", split_name)}) |
|
) |
|
elif config.name.startswith("vggish-features"): |
|
split_name = config.name.split("_")[1] |
|
splits.append( |
|
datasets.SplitGenerator(name=split_name, gen_kwargs={"data_dir": os.path.join(data_dir, "vggish-features", split_name)}) |
|
) |
|
|
|
return splits |
|
|
|
def _generate_examples(self, data_dir): |
|
filepaths = [] |
|
|
|
for root, dirs, files in os.walk(data_dir): |
|
for file in files: |
|
if file.endswith(".npy"): |
|
filepaths.append(os.path.join(root, file)) |
|
|
|
for i, filepath in enumerate(filepaths): |
|
data = np.load(filepath) |
|
|
|
yield i, {"video": data} |
|
|