| import pandas as pd |
| from huggingface_hub import hf_hub_url |
| import datasets |
| import os |
|
|
| _VERSION = datasets.Version("0.0.1") |
|
|
| _DESCRIPTION = "TODO" |
| _HOMEPAGE = "TODO" |
| _LICENSE = "TODO" |
| _CITATION = "TODO" |
|
|
| _FEATURES = datasets.Features( |
| { |
| "flawless": datasets.Image(), |
| "distorted": datasets.Image(), |
| "mask": datasets.Image(), |
| "reference": datasets.Image(), |
| "prompt": datasets.Value("string"), |
| }, |
| ) |
|
|
| METADATA_URL = hf_hub_url( |
| "NegarMov/Distorted_Human_Images", |
| filename="train.jsonl", |
| repo_type="dataset", |
| ) |
|
|
| FLAWLESS_URL = hf_hub_url( |
| "NegarMov/Distorted_Human_Images", |
| filename="flawless.zip", |
| repo_type="dataset", |
| ) |
|
|
| DISTORTED_URL = hf_hub_url( |
| "NegarMov/Distorted_Human_Images", |
| filename="distorted.zip", |
| repo_type="dataset", |
| ) |
|
|
| MASK_URL = hf_hub_url( |
| "NegarMov/Distorted_Human_Images", |
| filename="mask.zip", |
| repo_type="dataset", |
| ) |
|
|
| REFERENCE_URL = hf_hub_url( |
| "NegarMov/Distorted_Human_Images", |
| filename="reference.zip", |
| repo_type="dataset", |
| ) |
|
|
| _DEFAULT_CONFIG = datasets.BuilderConfig(name="default", version=_VERSION) |
|
|
|
|
| class Distorted_Human_Images(datasets.GeneratorBasedBuilder): |
| BUILDER_CONFIGS = [_DEFAULT_CONFIG] |
| DEFAULT_CONFIG_NAME = "default" |
|
|
| def _info(self): |
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=_FEATURES, |
| supervised_keys=None, |
| homepage=_HOMEPAGE, |
| license=_LICENSE, |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| metadata_path = dl_manager.download(METADATA_URL) |
| flawless_dir = dl_manager.download_and_extract( |
| FLAWLESS_URL |
| ) |
| distorted_dir = dl_manager.download_and_extract( |
| DISTORTED_URL |
| ) |
| mask_dir = dl_manager.download_and_extract( |
| MASK_URL |
| ) |
| reference_dir = dl_manager.download_and_extract( |
| REFERENCE_URL |
| ) |
|
|
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| |
| gen_kwargs={ |
| "metadata_path": metadata_path, |
| "flawless_dir": flawless_dir, |
| "distorted_dir": distorted_dir, |
| "mask_dir": mask_dir, |
| "reference_dir": reference_dir, |
| }, |
| ), |
| ] |
|
|
| def _generate_examples(self, metadata_path, flawless_dir, distorted_dir, mask_dir, reference_dir): |
| metadata = pd.read_json(metadata_path, lines=True) |
|
|
| for _, row in metadata.iterrows(): |
| prompt = row["prompt"] |
|
|
| flawless_path = row["flawless"] |
| flawless_path = os.path.join(flawless_dir, flawless_path) |
| flawless = open(flawless_path, "rb").read() |
|
|
| distorted_path = row["distorted"] |
| distorted_path = os.path.join( |
| distorted_dir, row["distorted"] |
| ) |
| distorted = open(distorted_path, "rb").read() |
|
|
| mask_path = row["mask"] |
| mask_path = os.path.join( |
| mask_dir, row["mask"] |
| ) |
| mask = open(mask_path, "rb").read() |
|
|
| reference_path = row["reference"] |
| reference_path = os.path.join( |
| reference_dir, row["reference"] |
| ) |
| reference = open(reference_path, "rb").read() |
|
|
| yield row["flawless"], { |
| "prompt": prompt, |
| "flawless": { |
| "path": flawless_path, |
| "bytes": flawless, |
| }, |
| "distorted": { |
| "path": distorted_path, |
| "bytes": distorted, |
| }, |
| "mask": { |
| "path": mask_path, |
| "bytes": mask, |
| }, |
| "reference": { |
| "path": reference_path, |
| "bytes": reference, |
| }, |
| } |
|
|