-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d76cbd0
commit 4016a42
Showing
7 changed files
with
223 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import argparse | ||
import pandas as pd | ||
import json, os | ||
|
||
import requests | ||
from PIL import Image | ||
from io import BytesIO | ||
import base64 | ||
|
||
|
||
|
||
def main(args): | ||
dataset = args.dataset | ||
target = args.target | ||
num_images = args.num_images | ||
# Load Parquet file into a pandas DataFrame | ||
df = pd.read_parquet(dataset) | ||
print(df.info()) | ||
|
||
if not os.path.exists(target + 'images/'): | ||
os.mkdir(target + 'images/') | ||
|
||
# 32600 | ||
caption = {} | ||
for idx in range(num_images): | ||
# print(df.iloc[0, 0]) | ||
# image_bytes = base64.b64decode(df.iloc[0, 0]['bytes']) | ||
image_bytes = df.iloc[idx, 0]['bytes'] | ||
image = Image.open(BytesIO(image_bytes)) | ||
image = image.convert('RGB') # Ensure it's in RGB mode for saving as JPEG | ||
image.save(target + 'images/' + f'{idx}.png', 'PNG') | ||
|
||
caption[idx] = { | ||
"path": target + 'images/' + f'{idx}.png', | ||
"height": 256, | ||
"width": 256, | ||
"caption": [] | ||
} | ||
with open(target + 'caption.json', 'w') as file: | ||
json.dump(caption, file, indent=4) | ||
# with open(target + 'failure_download.json', 'w') as file: | ||
# json.dump(failure, file, indent=4) | ||
|
||
# print("Available image number: {}".format(num_images - len(failure))) | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--num-images", type=int, default=2500) | ||
parser.add_argument("--dataset", type=str, default="datasets/celeba-hq-2-5k/train-00001-of-00006.parquet") | ||
parser.add_argument("--target", type=str, default="datasets/celeba-hq-2-5k-eval/") | ||
args = parser.parse_args() | ||
main(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os, shutil | ||
import argparse | ||
import pandas as pd | ||
import json | ||
|
||
def main(args): | ||
dataset = args.dataset | ||
target = args.target | ||
training = args.training | ||
num_images = args.num_images | ||
|
||
with open(dataset + 'caption.json', 'r') as json_file: | ||
caption = json.load(json_file) | ||
|
||
if not os.path.exists(target + 'images/'): | ||
os.mkdir(target + 'images/') | ||
|
||
training_list = os.listdir(training+ 'images/') | ||
|
||
data = {} | ||
cnt, in_cnt = 0, 0 | ||
for id, metadata in caption.items(): | ||
img_path = metadata["path"] | ||
if img_path in training_list: | ||
in_cnt += 1 | ||
continue | ||
|
||
data[id] = metadata | ||
source = dataset + 'images/' + img_path | ||
dest = target + 'images/' + img_path | ||
shutil.copy(source, dest) | ||
|
||
cnt += 1 | ||
if cnt >= num_images: | ||
break | ||
print(cnt, in_cnt) | ||
with open(target + 'caption.json', 'w') as file: | ||
json.dump(data, file, indent=4) | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--num-images", type=int, default=2500) | ||
parser.add_argument("--dataset", type=str, default="datasets/coco2017-val/") | ||
parser.add_argument("--training", type=str, default="datasets/coco2017-val-2-5k/") | ||
parser.add_argument("--target", type=str, default="datasets/coco2017-val-2-5k-eval/") | ||
args = parser.parse_args() | ||
main(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
python utils/get_laion_aesthetic_2_5k_eval_img_caption.py | ||
python utils/get_coco_2_5k_eval_img_caption.py | ||
python utils/get_celeba_hq_2_5k_eval_img_caption.py | ||
python utils/get_ffhq_2_5k_eval_img_caption.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import argparse | ||
import pandas as pd | ||
import json,os | ||
|
||
import requests | ||
from PIL import Image | ||
from io import BytesIO | ||
import base64 | ||
|
||
|
||
|
||
def main(args): | ||
dataset = args.dataset | ||
target = args.target | ||
num_images = args.num_images | ||
# Load Parquet file into a pandas DataFrame | ||
df = pd.read_parquet(dataset) | ||
print(df.info()) | ||
|
||
if not os.path.exists(target + 'images/'): | ||
os.mkdir(target + 'images/') | ||
|
||
# 32600 | ||
caption = {} | ||
for idx in range(num_images): | ||
# print(df.iloc[0, 0]['bytes']) | ||
# image_bytes = base64.b64decode(df.iloc[0, 0]['bytes']) | ||
image_bytes = df.iloc[idx, 0]['bytes'] | ||
image = Image.open(BytesIO(image_bytes)) | ||
image = image.convert('RGB') # Ensure it's in RGB mode for saving as JPEG | ||
image.save(target + 'images/' +df.iloc[idx, 0]['path'], 'PNG') | ||
|
||
caption[idx] = { | ||
"path": df.iloc[idx, 0]['path'], | ||
"height": 256, | ||
"width": 256, | ||
"caption": [] | ||
} | ||
with open(target + 'caption.json', 'w') as file: | ||
json.dump(caption, file, indent=4) | ||
# with open(target + 'failure_download.json', 'w') as file: | ||
# json.dump(failure, file, indent=4) | ||
|
||
# print("Available image number: {}".format(num_images - len(failure))) | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--num-images", type=int, default=2500) | ||
parser.add_argument("--dataset", type=str, default="datasets/ffhq-2-5k/train-00001-of-00015-78537a18b94b8879.parquet") | ||
parser.add_argument("--target", type=str, default="datasets/ffhq-2-5k-eval/") | ||
args = parser.parse_args() | ||
main(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
diffusers/utils/get_laion_aesthetic_2_5k_eval_img_caption.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import os, shutil | ||
import argparse | ||
import pandas as pd | ||
import json | ||
|
||
def main(args): | ||
dataset = args.dataset | ||
target = args.target | ||
num_images = args.num_images | ||
training = args.training | ||
|
||
with open(dataset + 'caption.json', 'r') as json_file: | ||
caption = json.load(json_file) | ||
|
||
if not os.path.exists(target + 'images/'): | ||
os.mkdir(target + 'images/') | ||
|
||
training_list = os.listdir(training+ 'images/') | ||
|
||
data = {} | ||
cnt, in_cnt = 0, 0 | ||
for id, metadata in caption.items(): | ||
|
||
img_path = metadata["path"] | ||
if img_path in training_list: | ||
in_cnt += 1 | ||
continue | ||
|
||
data[id] = metadata | ||
source = dataset + 'images/' + img_path | ||
dest = target + 'images/' + img_path | ||
shutil.copy(source, dest) | ||
|
||
|
||
cnt += 1 | ||
if cnt >= num_images: | ||
break | ||
print(cnt, in_cnt) | ||
with open(target + 'caption.json', 'w') as file: | ||
json.dump(data, file, indent=4) | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--num-images", type=int, default=2500) | ||
parser.add_argument("--dataset", type=str, default="datasets/laion-aesthetic-50k/") | ||
parser.add_argument("--training", type=str, default="datasets/laion-aesthetic-2-5k/") | ||
parser.add_argument("--target", type=str, default="datasets/laion-aesthetic-2-5k-eval/") | ||
args = parser.parse_args() | ||
main(args) |