Skip to content

Commit

Permalink
Scripts wont fail in case of missing output/log directories
Browse files Browse the repository at this point in the history
  • Loading branch information
albarji committed Feb 12, 2023
1 parent 60ae00a commit aaec4f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions generate_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import git
import json
import numpy as np
from pathlib import Path

from mixdiff import StableDiffusionTilingPipeline

Expand Down Expand Up @@ -89,8 +90,12 @@
image = pipe(**pipeargs)["sample"][0]
ct = datetime.datetime.now()
outname = f"{ct}_{prompt[0][0][0:100]}_{tile_height}x{tile_width}_sche{sche}_seed{seed_image}_gc{gc_image}_steps{steps_image}"
image.save(f"outputs/{outname}.png")
with open(f"logs/{outname}.json", "w") as f:
outpath = "./outputs"
Path(outpath).mkdir(parents=True, exist_ok=True)
image.save(f"{outpath}/{outname}.png")
logspath = "./logs"
Path(logspath).mkdir(parents=True, exist_ok=True)
with open(f"{logspath}/{outname}.json", "w") as f:
json.dump(
{
"prompt": prompt,
Expand Down
5 changes: 4 additions & 1 deletion generate_grid_from_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
from diffusers import LMSDiscreteScheduler, DDIMScheduler
import json
from pathlib import Path
import torch

from mixdiff.tiling import StableDiffusionTilingPipeline
Expand Down Expand Up @@ -34,7 +35,9 @@ def generate_grid(generation_arguments):
if "seed_reroll_regions" in generation_arguments: pipeargs = {**pipeargs, "seed_reroll_regions": generation_arguments["seed_reroll_regions"]}
image = pipe(**pipeargs)["sample"][0]
outname = "output"
image.save(f"outputs/{outname}.png")
outpath = "./outputs"
Path(outpath).mkdir(parents=True, exist_ok=True)
image.save(f"{outpath}/{outname}.png")

if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Generate a stable diffusion grid using a JSON file with all configuration parameters.')
Expand Down

0 comments on commit aaec4f4

Please sign in to comment.