bes-dev / stable_diffusion.openvino

Apache License 2.0
1.53k stars 208 forks source link

Write inference parameters into generated files as image metadata #48

Closed jkrafczyk closed 1 year ago

jkrafczyk commented 1 year ago

This makes demo.py write the parameters used when invoking it as EXIF or as PNG text chunks into the generated images.

That should make it a bit easier to go back to previous attempts and continue working from there.

EXIF for JPEG and TIFF output data contains the contents of the received argparser args as a single json string. PNG metadata additionally contains every argument as a seperate field.

Filenames passed into init-image, mask and output are modified to only contain the files basename, not the entire path for privacy reasons.

In addition to storing parameters when saving the image, demo.py can now also load and re-use parameters from a previously generated image via the --params-from argument. When using --params-from and passing additional parameters via the command-line, the additionally passed parameters will be preferentially used. This way, an old image can be re-created with higher iteration count, or identical parameters but a different seed.

Example Metadata as displayed by exiftool: PNG

[...]
Created with                    : stable_diffusion.openvino
Stable diffusion model          : bes-dev/stable-diffusion-v1-4-openvino
Stable diffusion beta start     : 0.00085
Stable diffusion beta end       : 0.012
Stable diffusion beta schedule  : scaled_linear
Stable diffusion num inference steps: 3
Stable diffusion guidance scale : 7.5
Stable diffusion eta            : 0.0
Stable diffusion tokenizer      : openai/clip-vit-large-patch14
Stable diffusion prompt         : Banksy-style street art of emilia clark with bright red hair.
Stable diffusion init image     : input.png
Stable diffusion strength       : 0.5
Stable diffusion mask           : mask.png
Stable diffusion output         : output.png
Exif Byte Order                 : Big-endian (Motorola, MM)
Image Description               : {"created_with": "stable_diffusion.openvino", "stable_diffusion_model": "bes-dev/stable-diffusion-v1-4-openvino", "stable_diffusion_beta_start": "0.00085", "stable_diffusion_beta_end": "0.012", "stable_diffusion_beta_schedule": "scaled_linear", "stable_diffusion_num_inference_steps": "3", "stable_diffusion_guidance_scale": "7.5", "stable_diffusion_eta": "0.0", "stable_diffusion_tokenizer": "openai/clip-vit-large-patch14", "stable_diffusion_prompt": "Banksy-style street art of emilia clark with bright red hair.", "stable_diffusion_init_image": "input.png", "stable_diffusion_strength": "0.5", "stable_diffusion_mask": "mask.png", "stable_diffusion_output": "output.png"}
Software                        : stable_diffusion.openvino
[...]

TIFF

[...]
Photometric Interpretation      : RGB
Image Description               : {"created_with": "stable_diffusion.openvino", "stable_diffusion_model": "bes-dev/stable-diffusion-v1-4-openvino", "stable_diffusion_beta_start": "0.00085", "stable_diffusion_beta_end": "0.012", "stable_diffusion_beta_schedule": "scaled_linear", "stable_diffusion_num_inference_steps": "3", "stable_diffusion_guidance_scale": "7.5", "stable_diffusion_eta": "0.0", "stable_diffusion_tokenizer": "openai/clip-vit-large-patch14", "stable_diffusion_prompt": "Banksy-style street art of emilia clark with bright red hair.", "stable_diffusion_init_image": "input.png", "stable_diffusion_strength": "0.5", "stable_diffusion_mask": "mask.png", "stable_diffusion_output": "output.tiff"}
Strip Offsets                   : 868
Samples Per Pixel               : 3
Rows Per Strip                  : 512
[...]

JPEG

[...]
Exif Byte Order                 : Big-endian (Motorola, MM)
Image Description               : {"created_with": "stable_diffusion.openvino", "stable_diffusion_model": "bes-dev/stable-diffusion-v1-4-openvino", "stable_diffusion_beta_start": "0.00085", "stable_diffusion_beta_end": "0.012", "stable_diffusion_beta_schedule": "scaled_linear", "stable_diffusion_num_inference_steps": "3", "stable_diffusion_guidance_scale": "7.5", "stable_diffusion_eta": "0.0", "stable_diffusion_tokenizer": "openai/clip-vit-large-patch14", "stable_diffusion_prompt": "Banksy-style street art of emilia clark with bright red hair.", "stable_diffusion_init_image": "input.png", "stable_diffusion_strength": "0.5", "stable_diffusion_mask": "mask.png", "stable_diffusion_output": "output.jpg"}
Software                        : stable_diffusion.openvino
Image Width                     : 512
Image Height                    : 512
[...]