import os from xml.etree import ElementTree as ET import datasets _DESCRIPTION = """\ The dataset img2img data. """ _NAME = "multi2img" _HOMEPAGE = f"https://huggingface.co/datasets/pranjalipathre/{_NAME}" _LICENSE = "" _DATA = f"https://huggingface.co/datasets/pranjalipathre/{_NAME}/resolve/main/data/" # _DATA = f"/home/pranjali/Documents/Research/pybullet/img2img/{_NAME}/data/" class i2iDataset(datasets.GeneratorBasedBuilder): BUILDER_CONFIGS = [ # rlbench-openwindow multiview dataset. - 4.9k datasets.BuilderConfig(name="video_00", data_dir=f"{_DATA}video_00.zip"), # rlbench-unplug charger multiview dataset. - 4k datasets.BuilderConfig(name="video_01", data_dir=f"{_DATA}video_01.zip"), ] DEFAULT_CONFIG_NAME = "video_00" def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "original_image": datasets.Image(), "edit_prompt": datasets.Value("string"), "edited_image": datasets.Image(), "fr_image": datasets.Image(), "ls_image": datasets.Image(), "oh_image": datasets.Image(), "rs_image": datasets.Image(), } ), supervised_keys=None, homepage=_HOMEPAGE, citation=None, ) def _split_generators(self, dl_manager): data = dl_manager.download_and_extract(self.config.data_dir) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "data": data, }, ), ] @staticmethod def parse_text(root: ET.Element, file: str, index: int) -> dict: idx = str(index).zfill(6) ele = root.find(f".//*[@frame='{idx}']") dt = { "text": ele.get("text") } return dt def _generate_examples(self, data): treePath = os.path.join(data, "annotations.xml") tree = ET.parse(treePath) root = tree.getroot() for idx, file in enumerate(sorted(os.listdir(os.path.join(data, "original_images")))): dat = self.parse_text(root, file, idx) txt = dat["text"] yield idx, { "original_image": os.path.join(data, "original_images", file), "edit_prompt": txt, "edited_image": os.path.join(data, "edited_images", file), "fr_image": os.path.join(data, "fr_images", file), "ls_image": os.path.join(data, "ls_images", file), "oh_image": os.path.join(data, "oh_images", file), "rs_image": os.path.join(data, "rs_images", file), }