Skip to content

Commit

Permalink
Merge pull request Sygil-Dev#60 from ZeroCool940711/dev
Browse files Browse the repository at this point in the history
Fixed the infer_vae.py script so it would retain the alpha channel whens saving the grid if we are using `--channels 4`, previosly it was generating properly the reconstructed image with alpha channel but the grid was converting the image to RGB instead of RGBA which removed the alpha channel, now it properly handles both RGB and RGBA images.
  • Loading branch information
ZeroCool940711 committed Jul 31, 2023
2 parents 6e74200 + c15221c commit 2f99bfe
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions infer_vae.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ def main():
os.makedirs(f"{args.results_dir}/outputs", exist_ok=True)

save_image(
dataset[image_id], f"{args.results_dir}/outputs/input.{str(args.input_image).split('.')[-1]}"
dataset[image_id],
f"{args.results_dir}/outputs/input.{str(args.input_image).split('.')[-1]}",
format="PNG",
)

_, ids, _ = vae.encode(
Expand Down Expand Up @@ -505,7 +507,8 @@ def main():

# Create horizontal grid with input and output images
grid_image = PIL.Image.new(
"RGB", (input_image.width + output_image.width, input_image.height)
"RGB" if args.channels == 3 else "RGBA",
(input_image.width + output_image.width, input_image.height),
)
grid_image.paste(input_image, (0, 0))
grid_image.paste(output_image, (input_image.width, 0))
Expand All @@ -515,7 +518,7 @@ def main():
hash = hashlib.sha1(input_image.tobytes()).hexdigest()

filename = f"{hash}_{now}-{os.path.basename(args.vae_path)}.png"
grid_image.save(f"{output_dir}/{filename}")
grid_image.save(f"{output_dir}/{filename}", format="PNG")

# Remove input and output images after the grid was made.
os.remove(f"{output_dir}/input.png")
Expand Down

0 comments on commit 2f99bfe

Please sign in to comment.