|
"""GamePhysics Dataset""" |
|
|
|
from __future__ import absolute_import, division, print_function |
|
|
|
import os |
|
import csv |
|
import json |
|
import datasets |
|
import urllib.request |
|
from datasets import Dataset |
|
|
|
_CITATION = """\ |
|
@article{taesiri2022clip, |
|
title={CLIP meets GamePhysics: Towards bug identification in gameplay videos using zero-shot transfer learning}, |
|
author={Taesiri, Mohammad Reza and Macklon, Finlay and Bezemer, Cor-Paul}, |
|
journal={arXiv preprint arXiv:2203.11096}, |
|
year={2022} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
GamePhysics dataset |
|
""" |
|
|
|
_HOMEPAGE = "https://asgaardlab.github.io/CLIPxGamePhysics/" |
|
|
|
_LICENSE = "MIT" |
|
|
|
with urllib.request.urlopen( |
|
"https://huggingface.co/datasets/taesiri/GamePhysics/raw/main/list_of_games.json" |
|
) as url: |
|
_GAMEs = json.loads(url.read().decode()) |
|
|
|
_URLs = { |
|
k: f"https://huggingface.co/datasets/taesiri/GamePhysics/resolve/main/data/{v}" |
|
for k, v in _GAMEs.items() |
|
} |
|
|
|
_NAMES = [k for k, v in _GAMEs.items()] |
|
|
|
|
|
class GamePhysics_Config(datasets.BuilderConfig): |
|
"""BuilderConfig for GamePhysics.""" |
|
|
|
def __init__(self, **kwargs): |
|
"""BuilderConfig for GamePhysics_Config. |
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(GamePhysics_Config, self).__init__( |
|
version=datasets.Version("1.0.1", ""), **kwargs |
|
) |
|
|
|
|
|
class GamePhysics(datasets.GeneratorBasedBuilder): |
|
"""GamePhysics dataset""" |
|
|
|
BUILDER_CONFIGS = [ |
|
GamePhysics_Config( |
|
name="GamePhysics", |
|
description="GamePhysics dataset", |
|
) |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"video_file_path": datasets.Value("string"), |
|
"labels": datasets.features.ClassLabel(names=_NAMES), |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
data_files = dl_manager.download_and_extract(_URLs) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=game_name, |
|
gen_kwargs={"files": dl_manager.iter_files([data_files[game_name]])}, |
|
) |
|
for game_name in _GAMES.keys() |
|
] |
|
|
|
def _generate_examples(self, files, split): |
|
for i, path in enumerate(files): |
|
file_name = os.path.basename(path) |
|
if file_name.endswith(".mp4"): |
|
yield i, {"video_file_path": path, "labels": "Grand_Theft_Auto_V"} |
|
|