Datasets:
Size:
10K<n<100K
License:
Delete onlyclothe.py
Browse files- onlyclothe.py +0 -104
onlyclothe.py
DELETED
|
@@ -1,104 +0,0 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
-
from huggingface_hub import hf_hub_url
|
| 3 |
-
import datasets
|
| 4 |
-
import os
|
| 5 |
-
|
| 6 |
-
_VERSION = datasets.Version("0.0.2")
|
| 7 |
-
|
| 8 |
-
_DESCRIPTION = "TODO"
|
| 9 |
-
_HOMEPAGE = "TODO"
|
| 10 |
-
_LICENSE = "TODO"
|
| 11 |
-
_CITATION = "TODO"
|
| 12 |
-
|
| 13 |
-
_FEATURES = datasets.Features(
|
| 14 |
-
{
|
| 15 |
-
"image": datasets.Image(),
|
| 16 |
-
"conditioning_image": datasets.Image(),
|
| 17 |
-
"text": datasets.Value("string"),
|
| 18 |
-
},
|
| 19 |
-
)
|
| 20 |
-
|
| 21 |
-
METADATA_URL = hf_hub_url(
|
| 22 |
-
"chengzhiyuan/onlyclothe",
|
| 23 |
-
filename="train.jsonl",
|
| 24 |
-
repo_type="dataset",
|
| 25 |
-
)
|
| 26 |
-
|
| 27 |
-
# IMAGES_URL = hf_hub_url(
|
| 28 |
-
# "chengzhiyuan/onlyclothe",
|
| 29 |
-
# filename="images.zip",
|
| 30 |
-
# repo_type="dataset",
|
| 31 |
-
# )
|
| 32 |
-
|
| 33 |
-
# CONDITIONING_IMAGES_URL = hf_hub_url(
|
| 34 |
-
# "chengzhiyuan/onlyclothe",
|
| 35 |
-
# filename="conditioning_images.zip",
|
| 36 |
-
# repo_type="dataset",
|
| 37 |
-
# )
|
| 38 |
-
IMAGES_URL = https://huggingface.co/datasets/chengzhiyuan/onlyclothe/blob/main/images.zip
|
| 39 |
-
CONDITIONING_IMAGES_URL = https://huggingface.co/datasets/chengzhiyuan/onlyclothe/blob/main/conditioning_images.zip
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
_DEFAULT_CONFIG = datasets.BuilderConfig(name="default", version=_VERSION)
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
class Onlyclothe(datasets.GeneratorBasedBuilder):
|
| 46 |
-
BUILDER_CONFIGS = [_DEFAULT_CONFIG]
|
| 47 |
-
DEFAULT_CONFIG_NAME = "default"
|
| 48 |
-
|
| 49 |
-
def _info(self):
|
| 50 |
-
return datasets.DatasetInfo(
|
| 51 |
-
description=_DESCRIPTION,
|
| 52 |
-
features=_FEATURES,
|
| 53 |
-
supervised_keys=None,
|
| 54 |
-
homepage=_HOMEPAGE,
|
| 55 |
-
license=_LICENSE,
|
| 56 |
-
citation=_CITATION,
|
| 57 |
-
)
|
| 58 |
-
|
| 59 |
-
def _split_generators(self, dl_manager):
|
| 60 |
-
metadata_path = dl_manager.download(METADATA_URL)
|
| 61 |
-
images_dir = dl_manager.download_and_extract(IMAGES_URL)
|
| 62 |
-
conditioning_images_dir = dl_manager.download_and_extract(
|
| 63 |
-
CONDITIONING_IMAGES_URL
|
| 64 |
-
)
|
| 65 |
-
|
| 66 |
-
return [
|
| 67 |
-
datasets.SplitGenerator(
|
| 68 |
-
name=datasets.Split.TRAIN,
|
| 69 |
-
# These kwargs will be passed to _generate_examples
|
| 70 |
-
gen_kwargs={
|
| 71 |
-
"metadata_path": metadata_path,
|
| 72 |
-
"images_dir": images_dir,
|
| 73 |
-
"conditioning_images_dir": conditioning_images_dir,
|
| 74 |
-
},
|
| 75 |
-
),
|
| 76 |
-
]
|
| 77 |
-
|
| 78 |
-
def _generate_examples(self, metadata_path, images_dir, conditioning_images_dir):
|
| 79 |
-
metadata = pd.read_json(metadata_path, lines=True)
|
| 80 |
-
|
| 81 |
-
for _, row in metadata.iterrows():
|
| 82 |
-
text = row["text"]
|
| 83 |
-
print("test")
|
| 84 |
-
image_path = row["image"]
|
| 85 |
-
image_path = os.path.join(images_dir, image_path)
|
| 86 |
-
image = open(image_path, "rb").read()
|
| 87 |
-
print("image")
|
| 88 |
-
conditioning_image_path = row["conditioning_image"]
|
| 89 |
-
conditioning_image_path = os.path.join(
|
| 90 |
-
conditioning_images_dir, row["conditioning_image"]
|
| 91 |
-
)
|
| 92 |
-
conditioning_image = open(conditioning_image_path, "rb").read()
|
| 93 |
-
print("conditioning")
|
| 94 |
-
yield row["image"], {
|
| 95 |
-
"text": text,
|
| 96 |
-
"image": {
|
| 97 |
-
"path": image_path,
|
| 98 |
-
"bytes": image,
|
| 99 |
-
},
|
| 100 |
-
"conditioning_image": {
|
| 101 |
-
"path": conditioning_image_path,
|
| 102 |
-
"bytes": conditioning_image,
|
| 103 |
-
},
|
| 104 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|