writing generation metadata into files #680
Replies: 3 comments 1 reply
-
This is actually already supported. It was implemented in PR #78. But you need to add the argument "--save-metadata" to the additional_arguments option in the relauncher.py script. It doesn't implement all of the metadata you mention, but it implements: height, width, cfg_scale, prompt, seed, steps, GFPGAN, normalize_prompt_weights and denoising_strength (Only for img2img). |
Beta Was this translation helpful? Give feedback.
-
Doesn't appear to be merged into master yet. I reverified I'm on the main branch, and I don't see the changes. Looking at the commit history, it looks like it got reverted out so... looks like it isn't implemented anymore. {shrug} |
Beta Was this translation helpful? Give feedback.
-
Ah, right you are. I was looking at the wrong place and can confirm the change is there for png files. Doesn't work for JPG, which sucks as that's what I use to save on disk space, but it's a start. |
Beta Was this translation helpful? Give feedback.
-
It would be terrific in the file generation inputs were written into the files metadata as properties instead of (or in addition to) a separate YAML file. That way, for img2img or imagelab the inputs could be loaded as default inputs, it would be easy to examine an image to determine what inputs were used to create it, as well as making it easier to share the values used to generate the file when the image is posted in case you lost track of or can't remember what was used as the generation inputs.
You can store metadata in Pillow using the PngImagePlugin.PngInfo library. See https://pillow.readthedocs.io/en/stable/PIL.html#PIL.PngImagePlugin.PngInfo for usage, but here is an example implementation that shows how to add properties and values to an image:
from PIL import Image
from PIL.PngImagePlugin import PngInfo
targetImage = Image.open("Sample.png")
metadata = PngInfo()
metadata.add_text("Prompt", "A corgi wearing a tophat as an oil painting")
metadata.add_text("Height", str(512))
metadata.add_text("Width", str(768))
metadata.add_text("Scale", str(7.5))
metadata.add_text("Seed", str(8675309))
metadata.add_text("Steps", str(45))
metadata.add_text("Diffuser", "k_euler")
metadata.add_text("Prompt Weights", str(1))
metadata.add_text("GPFGAN", "True")
metadata.add_text("ERSGAN", "True")
targetImage.save("NewSample.png", pnginfo=metadata)
targetImage = Image.open("NewSample.png")
print(targetImage.text)
targetImage.close()
Example run showing the info which was saved into a file:
(lsd) [cyber@Highside scripts]$ python attributes.py
{'Prompt': 'A corgi wearing a tophat as an oil painting', 'Height': '512', 'Width': '768', 'Scale': '7.5', 'Seed': '8675309', 'Steps': '45', 'Diffuser': 'k_euler', 'Prompt Weights': '1', 'GPFGAN': 'True', 'ERSGAN': 'True'}
There's an exif module as well, which would allow you to see the information easily in windows explorer
Beta Was this translation helpful? Give feedback.
All reactions