import json import urllib.parse import datasets _CITATION = """\ @inproceedings{Wu2020not, title={Not only Look, but also Listen: Learning Multimodal Violence Detection under Weak Supervision}, author={Wu, Peng and Liu, jing and Shi, Yujia and Sun, Yujia and Shao, Fangtao and Wu, Zhaoyang and Yang, Zhiwei}, booktitle={European Conference on Computer Vision (ECCV)}, year={2020} } """ _DESCRIPTION = """\ Dataset for the paper "Not only Look, but also Listen: Learning Multimodal Violence Detection under Weak Supervision". \ The dataset is downloaded from the authors' website (https://roc-ng.github.io/XD-Violence/). Hosting this dataset on HuggingFace \ is just to make it easier for my own project to use this dataset. Please cite the original paper if you use this dataset. """ _NAME = "xd-violence" _HOMEPAGE = f"https://huggingface.co/datasets/jherng/{_NAME}" _LICENSE = "MIT" _URL = f"https://huggingface.co/datasets/jherng/{_NAME}/resolve/main/data" class XDViolenceConfig(datasets.BuilderConfig): def __init__(self, **kwargs): """BuilderConfig for XD-Violence. Args: **kwargs: keyword arguments forwarded to super. """ super(XDViolenceConfig, self).__init__(**kwargs) class Squad(datasets.GeneratorBasedBuilder): BUILDER_CONFIGS = [ XDViolenceConfig( name="video", description="Video dataset", ), XDViolenceConfig( name="rgb", description="RGB visual features of the video dataset", ), ] DEFAULT_CONFIG_NAME = "video" BUILDER_CONFIG_CLASS = XDViolenceConfig def _info(self): if self.config.name == "rgb": features = datasets.Features( { "rgb_feats": datasets.Array3D( shape=(None, 10, 2048), dtype="float32", # (num_frames, num_crops, feature_dim) use 10 crops by default as of now ), "binary_target": datasets.ClassLabel( names=["non-violence", "violence"] ), "multilabel_targets": datasets.Sequence( datasets.ClassLabel( names=[ "Fighting", "Shooting", "Riot", "Abuse", "Car accident", "Explosion", ] ) ), "frame_annotations": datasets.Sequence( { "start": datasets.Value("int32"), "end": datasets.Value("int32"), } ), } ) else: # default = "video" features = datasets.Features( { "video_path": datasets.Value("string"), "binary_target": datasets.ClassLabel( names=["non-violence", "violence"] ), "multilabel_targets": datasets.Sequence( datasets.ClassLabel( names=[ "Fighting", "Shooting", "Riot", "Abuse", "Car accident", "Explosion", ] ) ), "frame_annotations": datasets.Sequence( { "start": datasets.Value("int32"), "end": datasets.Value("int32"), } ), } ) return datasets.DatasetInfo( features=features, description=_DESCRIPTION, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): # Download videos # - get URLs # - download annotations train_list_fpath = dl_manager.download_and_extract(urllib.parse.urljoin(_URL, "train_list.txt")) test_ann_fpath = dl_manager.download_and_extract(urllib.parse.urljoin(_URL, "test_annotations.txt")) print(f"{train_list_fpath=}") print(f"{test_ann_fpath=}") return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_list_fpath}, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={"filepath": test_ann_fpath}, ), ] def _generate_examples(self, filepath): """This function returns the examples in the raw (text) form.""" pass