mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-04-26 20:38:20 +02:00
Store images during a session in the same folder; Store the metadata for each image as a txt file next to it
This commit is contained in:
parent
e5dc932717
commit
21dc2ece1b
@ -15,6 +15,8 @@ from ldm.util import instantiate_from_config
|
|||||||
from optimizedSD.optimUtils import split_weighted_subprompts
|
from optimizedSD.optimUtils import split_weighted_subprompts
|
||||||
from transformers import logging
|
from transformers import logging
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
logging.set_verbosity_error()
|
logging.set_verbosity_error()
|
||||||
|
|
||||||
# consts
|
# consts
|
||||||
@ -26,6 +28,8 @@ import base64
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
# local
|
# local
|
||||||
|
session_id = str(uuid.uuid4())
|
||||||
|
|
||||||
ckpt = None
|
ckpt = None
|
||||||
model = None
|
model = None
|
||||||
modelCS = None
|
modelCS = None
|
||||||
@ -140,7 +144,7 @@ def mk_img(req: Request):
|
|||||||
opt_init_img = req.init_image
|
opt_init_img = req.init_image
|
||||||
opt_format = 'png'
|
opt_format = 'png'
|
||||||
|
|
||||||
print(req.to_string(), 'device', device)
|
print(req.to_string(), '\n device', device)
|
||||||
|
|
||||||
seed_everything(opt_seed)
|
seed_everything(opt_seed)
|
||||||
|
|
||||||
@ -183,15 +187,19 @@ def mk_img(req: Request):
|
|||||||
t_enc = int(opt_strength * opt_ddim_steps)
|
t_enc = int(opt_strength * opt_ddim_steps)
|
||||||
print(f"target t_enc is {t_enc} steps")
|
print(f"target t_enc is {t_enc} steps")
|
||||||
|
|
||||||
|
if opt_save_to_disk_path is not None:
|
||||||
|
session_out_path = os.path.join(opt_save_to_disk_path, 'session-' + session_id)
|
||||||
|
os.makedirs(session_out_path, exist_ok=True)
|
||||||
|
else:
|
||||||
|
session_out_path = None
|
||||||
|
|
||||||
seeds = ""
|
seeds = ""
|
||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
for n in trange(opt_n_iter, desc="Sampling"):
|
for n in trange(opt_n_iter, desc="Sampling"):
|
||||||
for prompts in tqdm(data, desc="data"):
|
for prompts in tqdm(data, desc="data"):
|
||||||
|
|
||||||
if opt_save_to_disk_path is not None:
|
if opt_save_to_disk_path is not None:
|
||||||
sample_path = os.path.join(opt_save_to_disk_path, "_".join(re.split(":| ", prompts[0])))[:150]
|
base_count = len(os.listdir(session_out_path))
|
||||||
os.makedirs(sample_path, exist_ok=True)
|
|
||||||
base_count = len(os.listdir(sample_path))
|
|
||||||
|
|
||||||
with precision_scope("cuda"):
|
with precision_scope("cuda"):
|
||||||
modelCS.to(device)
|
modelCS.to(device)
|
||||||
@ -234,9 +242,18 @@ def mk_img(req: Request):
|
|||||||
res.images.append(ResponseImage(data=img_data, seed=opt_seed))
|
res.images.append(ResponseImage(data=img_data, seed=opt_seed))
|
||||||
|
|
||||||
if opt_save_to_disk_path is not None:
|
if opt_save_to_disk_path is not None:
|
||||||
img.save(
|
prompt_flattened = "_".join(re.split(":| ", prompts[0]))
|
||||||
os.path.join(sample_path, "seed_" + str(opt_seed) + "_" + f"{base_count:05}.{opt_format}")
|
prompt_flattened = prompt_flattened[:150]
|
||||||
)
|
|
||||||
|
file_path = f"sd_{prompt_flattened}_Seed-{opt_seed}_Steps-{opt_ddim_steps}_Guidance-{opt_scale}_{base_count:05}"
|
||||||
|
img_out_path = os.path.join(session_out_path, f"{file_path}.{opt_format}")
|
||||||
|
meta_out_path = os.path.join(session_out_path, f"{file_path}.txt")
|
||||||
|
|
||||||
|
metadata = f"{prompts[0]}\nSeed: {opt_seed}\nSteps: {opt_ddim_steps}\nGuidance Scale: {opt_scale}"
|
||||||
|
img.save(img_out_path)
|
||||||
|
with open(meta_out_path, 'w') as f:
|
||||||
|
f.write(metadata)
|
||||||
|
|
||||||
base_count += 1
|
base_count += 1
|
||||||
|
|
||||||
seeds += str(opt_seed) + ","
|
seeds += str(opt_seed) + ","
|
||||||
|
Loading…
Reference in New Issue
Block a user