Commit
·
07a01fd
1
Parent(s):
4d447d5
feat: graffiti.org conditioning
Browse files- README.md +6 -4
- cli.py +4 -5
- data/graffiti.org/conditioning.tar.gz +3 -0
- data/graffiti.org/images.tar.gz +2 -2
- data/graffiti.org/metadata.jsonl +2 -2
- graffiti.py +15 -4
- prepare.sh +1 -1
- requirements.txt +3 -1
README.md
CHANGED
@@ -3,14 +3,16 @@ dataset_info:
|
|
3 |
features:
|
4 |
- name: image
|
5 |
dtype: image
|
|
|
|
|
6 |
- name: text
|
7 |
dtype: string
|
8 |
splits:
|
9 |
- name: train
|
10 |
-
num_bytes:
|
11 |
-
num_examples:
|
12 |
-
download_size:
|
13 |
-
dataset_size:
|
14 |
---
|
15 |
# Dataset Card for Graffiti
|
16 |
|
|
|
3 |
features:
|
4 |
- name: image
|
5 |
dtype: image
|
6 |
+
- name: conditioning_image
|
7 |
+
dtype: image
|
8 |
- name: text
|
9 |
dtype: string
|
10 |
splits:
|
11 |
- name: train
|
12 |
+
num_bytes: 10454347970
|
13 |
+
num_examples: 77478
|
14 |
+
download_size: 16111025975
|
15 |
+
dataset_size: 10454347970
|
16 |
---
|
17 |
# Dataset Card for Graffiti
|
18 |
|
cli.py
CHANGED
@@ -11,8 +11,7 @@ import os
|
|
11 |
from controlnet_aux.processor import Processor
|
12 |
|
13 |
from PIL import UnidentifiedImageError
|
14 |
-
from PIL import Image
|
15 |
-
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
16 |
|
17 |
|
18 |
class Scraper(object):
|
@@ -194,8 +193,8 @@ class CLI():
|
|
194 |
path = Path("./images").rglob("*.jpg")
|
195 |
for i, img_p in enumerate(path):
|
196 |
try:
|
197 |
-
Image.open(img_p)
|
198 |
-
except
|
199 |
path_name = str(img_p)
|
200 |
print(path_name + " is broken. Deleting!")
|
201 |
os.remove(path_name)
|
@@ -233,7 +232,7 @@ class CLI():
|
|
233 |
data = json.loads(row)
|
234 |
with open('./images/' + data["file"] + '.json', 'w') as j:
|
235 |
j.write(json.dumps(data, indent=2, ensure_ascii=False))
|
236 |
-
elif args.command == '
|
237 |
processor_id = 'softedge_hed'
|
238 |
processor = Processor(processor_id)
|
239 |
|
|
|
11 |
from controlnet_aux.processor import Processor
|
12 |
|
13 |
from PIL import UnidentifiedImageError
|
14 |
+
from PIL import Image
|
|
|
15 |
|
16 |
|
17 |
class Scraper(object):
|
|
|
193 |
path = Path("./images").rglob("*.jpg")
|
194 |
for i, img_p in enumerate(path):
|
195 |
try:
|
196 |
+
Image.open(img_p).load()
|
197 |
+
except Exception:
|
198 |
path_name = str(img_p)
|
199 |
print(path_name + " is broken. Deleting!")
|
200 |
os.remove(path_name)
|
|
|
232 |
data = json.loads(row)
|
233 |
with open('./images/' + data["file"] + '.json', 'w') as j:
|
234 |
j.write(json.dumps(data, indent=2, ensure_ascii=False))
|
235 |
+
elif args.command == 'conditioning':
|
236 |
processor_id = 'softedge_hed'
|
237 |
processor = Processor(processor_id)
|
238 |
|
data/graffiti.org/conditioning.tar.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:08b04aa1897e3a4c1e25b732cfb4356f91a8103ff6f3487d63acc4d991d6db8a
|
3 |
+
size 2587653112
|
data/graffiti.org/images.tar.gz
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3f7d02c10631c1c8964f6c4f824ad6df152abe46602073e2884341b37ecf8d23
|
3 |
+
size 3211879389
|
data/graffiti.org/metadata.jsonl
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:353d4454f0d12c698a5509a8f3064e0a5ad2f934026853b900156eda3fe8ee7e
|
3 |
+
size 6370190
|
graffiti.py
CHANGED
@@ -71,6 +71,7 @@ class Graffiti(datasets.GeneratorBasedBuilder):
|
|
71 |
features=datasets.Features(
|
72 |
{
|
73 |
"image": datasets.Image(),
|
|
|
74 |
"text": datasets.Value("string")
|
75 |
}
|
76 |
),
|
@@ -85,8 +86,10 @@ class Graffiti(datasets.GeneratorBasedBuilder):
|
|
85 |
"""Returns SplitGenerators."""
|
86 |
images = []
|
87 |
metadata = []
|
|
|
88 |
for source in _SOURCES:
|
89 |
images.append(dl_manager.iter_archive(dl_manager.download("./data/{0}/images.tar.gz".format(source))))
|
|
|
90 |
metadata.append(dl_manager.download("./data/{0}/metadata.jsonl".format(source)))
|
91 |
return [
|
92 |
datasets.SplitGenerator(
|
@@ -95,27 +98,35 @@ class Graffiti(datasets.GeneratorBasedBuilder):
|
|
95 |
gen_kwargs={
|
96 |
"images": images,
|
97 |
"metadata": metadata,
|
|
|
98 |
},
|
99 |
)
|
100 |
]
|
101 |
|
102 |
-
def _generate_examples(self, metadata, images):
|
103 |
idx = 0
|
104 |
for index, meta in enumerate(metadata):
|
105 |
m = []
|
106 |
with open(meta, encoding="utf-8") as f:
|
107 |
for row in f:
|
108 |
m.append(json.loads(row))
|
|
|
109 |
for file_path, file_obj in images[index]:
|
110 |
data = [x for x in m if file_path.endswith(x["file"])][0]
|
|
|
|
|
|
|
|
|
|
|
111 |
text = data["caption"]
|
112 |
if data["artist"] != None:
|
113 |
-
text += ", with text
|
114 |
-
text += ", in the art of
|
115 |
if data["city"] != None:
|
116 |
text += ", located in " + data["city"]
|
117 |
yield idx, {
|
118 |
"image": {"path": file_path, "bytes": file_obj.read()},
|
119 |
-
"
|
|
|
120 |
}
|
121 |
idx+=1
|
|
|
71 |
features=datasets.Features(
|
72 |
{
|
73 |
"image": datasets.Image(),
|
74 |
+
"conditioning_image": datasets.Image(),
|
75 |
"text": datasets.Value("string")
|
76 |
}
|
77 |
),
|
|
|
86 |
"""Returns SplitGenerators."""
|
87 |
images = []
|
88 |
metadata = []
|
89 |
+
conditioning = []
|
90 |
for source in _SOURCES:
|
91 |
images.append(dl_manager.iter_archive(dl_manager.download("./data/{0}/images.tar.gz".format(source))))
|
92 |
+
conditioning.append(dl_manager.iter_archive(dl_manager.download("./data/{0}/conditioning.tar.gz".format(source))))
|
93 |
metadata.append(dl_manager.download("./data/{0}/metadata.jsonl".format(source)))
|
94 |
return [
|
95 |
datasets.SplitGenerator(
|
|
|
98 |
gen_kwargs={
|
99 |
"images": images,
|
100 |
"metadata": metadata,
|
101 |
+
"conditioning": conditioning
|
102 |
},
|
103 |
)
|
104 |
]
|
105 |
|
106 |
+
def _generate_examples(self, metadata, images, conditioning):
|
107 |
idx = 0
|
108 |
for index, meta in enumerate(metadata):
|
109 |
m = []
|
110 |
with open(meta, encoding="utf-8") as f:
|
111 |
for row in f:
|
112 |
m.append(json.loads(row))
|
113 |
+
c = iter(conditioning[index])
|
114 |
for file_path, file_obj in images[index]:
|
115 |
data = [x for x in m if file_path.endswith(x["file"])][0]
|
116 |
+
|
117 |
+
conditioning_file = next(c)
|
118 |
+
conditioning_file_path = conditioning_file[0]
|
119 |
+
conditioning_file_obj = conditioning_file[1]
|
120 |
+
|
121 |
text = data["caption"]
|
122 |
if data["artist"] != None:
|
123 |
+
# text += ", with text " + data["artist"]
|
124 |
+
text += ", in the art of " + data["artist"]
|
125 |
if data["city"] != None:
|
126 |
text += ", located in " + data["city"]
|
127 |
yield idx, {
|
128 |
"image": {"path": file_path, "bytes": file_obj.read()},
|
129 |
+
"conditioning_image": {"path": conditioning_file_path, "bytes": conditioning_file_obj.read()},
|
130 |
+
"text": text,
|
131 |
}
|
132 |
idx+=1
|
prepare.sh
CHANGED
@@ -28,5 +28,5 @@ test () {
|
|
28 |
datasets-cli test graffiti.py --save_info --all_config
|
29 |
}
|
30 |
|
31 |
-
|
32 |
tar ${args[0]} ${args[1]}
|
|
|
28 |
datasets-cli test graffiti.py --save_info --all_config
|
29 |
}
|
30 |
|
31 |
+
list ${args[1]}
|
32 |
tar ${args[0]} ${args[1]}
|
requirements.txt
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
bs4
|
2 |
requests
|
3 |
transformers
|
4 |
-
controlnet-aux==0.0.6
|
|
|
|
|
|
1 |
bs4
|
2 |
requests
|
3 |
transformers
|
4 |
+
controlnet-aux==0.0.6
|
5 |
+
mediapipe
|
6 |
+
datasets
|