|
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( |
|
{ |
|
"image": datasets.Image(), |
|
"segment": datasets.Image(), |
|
"prompt": datasets.Value("string"), |
|
}, |
|
) |
|
|
|
METADATA_URL = hf_hub_url( |
|
"vision-paper/cn_segment_dataset", |
|
filename="train.jsonl", |
|
repo_type="dataset", |
|
) |
|
|
|
IMAGE_URL = hf_hub_url( |
|
"vision-paper/cn_segment_dataset", |
|
filename="image.zip", |
|
repo_type="dataset", |
|
) |
|
|
|
SEGMENT_URL = hf_hub_url( |
|
"vision-paper/cn_segment_dataset", |
|
filename="segment.zip", |
|
repo_type="dataset", |
|
) |
|
|
|
_DEFAULT_CONFIG = datasets.BuilderConfig(name="default", version=_VERSION) |
|
|
|
|
|
class VTONHD_segmented_segment(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) |
|
image_dir = dl_manager.download_and_extract( |
|
IMAGE_URL |
|
) |
|
segment_dir = dl_manager.download_and_extract( |
|
SEGMENT_URL |
|
) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"metadata_path": metadata_path, |
|
"image_dir": image_dir, |
|
"segment_dir": segment_dir, |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, metadata_path, image_dir, segment_dir, reference_dir): |
|
metadata = pd.read_json(metadata_path, lines=True) |
|
|
|
for _, row in metadata.iterrows(): |
|
prompt = row["prompt"] |
|
|
|
image_path = row["image"] |
|
image_path = os.path.join(image_dir, image_path) |
|
image = open(image_path, "rb").read() |
|
|
|
segment_path = row["segment"] |
|
segment_path = os.path.join( |
|
segment_dir, row["segment"] |
|
) |
|
segment = open(segment_path, "rb").read() |
|
|
|
yield row["image"], { |
|
"prompt": prompt, |
|
"image": { |
|
"path": image_path, |
|
"bytes": image, |
|
}, |
|
"segment": { |
|
"path": segment_path, |
|
"bytes": segment, |
|
}, |
|
} |
|
|