Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to store TI embeddings in png chunks, and load from same. #2037

Merged
merged 33 commits into from
Oct 12, 2022

Conversation

dfaker
Copy link
Collaborator

@dfaker dfaker commented Oct 9, 2022

Making the preview pngs themselves sharable embeddings.

So images like this:

aiu

Can go straight into your embeddings folder...maybe wait until you've done a little more training before sharing them in general though.

Initially concerned about torch.load doing unsafe pickling but it seems as if it's restricted on the type of classes it'll deserialise to str, I'm not sure if we're happy that's protection enough.

@dfaker dfaker changed the title Add option to store embeddings in png chunks, and load from same. Add option to store TI embeddings in png chunks, and load from same. Oct 9, 2022
@dfaker
Copy link
Collaborator Author

dfaker commented Oct 9, 2022

Actually thinking this is too risky, upon reviewing the ongoing pytorch attempts to mitigate the risks of pickle.

@dfaker dfaker closed this Oct 9, 2022
@dfaker dfaker reopened this Oct 9, 2022
@dfaker
Copy link
Collaborator Author

dfaker commented Oct 9, 2022

will rework to directly pass the embedding without torch.load

@dfaker
Copy link
Collaborator Author

dfaker commented Oct 9, 2022

Okay, Zero-🥒, now serialises to and from a safe json representation for embedding in the images without a torch.load of untrusted files, added a little styling to the embedded-images, they all go in a separate folder, standard images are left untouched.

trek-data-1000

I've left the original above-below captioning method in under images.captionImge as it's a nice generalization of adding captions and backgrounds.

@dfaker dfaker marked this pull request as draft October 10, 2022 02:20
@dfaker dfaker marked this pull request as ready for review October 10, 2022 14:46
@dfaker
Copy link
Collaborator Author

dfaker commented Oct 10, 2022

Updated the way the data is embedded in the image pixels:
trek-data-70
Side blocks representing the stored tensor expand as more bytes are needed to embed the data.

@dfaker dfaker requested a review from AUTOMATIC1111 October 11, 2022 14:16
@AUTOMATIC1111 AUTOMATIC1111 merged commit cc58036 into master Oct 12, 2022
@dfaker dfaker deleted the embed-embeddings-in-images branch October 15, 2022 18:08
@R-N
Copy link
Contributor

R-N commented Nov 3, 2022

if filename.upper().endswith('.PNG'):
    embed_image = Image.open(path)
    if 'sd-ti-embedding' in embed_image.text:
        data = embedding_from_b64(embed_image.text['sd-ti-embedding'])
        name = data.get('name', name)
    else:
        data = extract_image_data_embed(embed_image)
        name = data.get('name', name)
else:
    data = torch.load(path, map_location="cpu")

Why does image embedding try to use loaded name, while .pt embedding doesn't?

@dfaker
Copy link
Collaborator Author

dfaker commented Nov 3, 2022

The .pt doesn't use the name field because not all embeddings are guaranteed to have them, only ones trained in this repository, and to allow users to rename the file to whatever tokens they want to trigger the embedding.

The image embeddings should always contain a name field, already advertise their trained name in the image itself, and are more prone to having their original filenames destroyed by image hosts.

@R-N
Copy link
Contributor

R-N commented Nov 4, 2022

But then that won't allow multiple image embeddings that happened to be trained with same name. And it's not like the original filename matters, or does it? The user can set the filename like the .pt ones.

@Jonseed
Copy link

Jonseed commented Nov 23, 2022

@dfaker this is an awesome feature. I have a question. My best embedding during training didn't turn out a good image. How do I make a new image embedding with a better image?

It would be cool if there was a checkbox option, perhaps on the txt2img page or settings, that could generate new embeddings along with the generated images? Then you could pick the one that best represents the embedding?

@dfaker
Copy link
Collaborator Author

dfaker commented Nov 23, 2022

@Jonseed there's actually a script for that: https://github.com/dfaker/embedding-to-png-script

I do like the honesty of using the training images though.

@Jonseed
Copy link

Jonseed commented Nov 23, 2022

Cool! I'll check that out.

Yeah, the prompt I used to generate preview images during training just wasn't that great to begin with.

nne998 pushed a commit to fjteam/stable-diffusion-webui that referenced this pull request Sep 26, 2023
…json_api

Revert "Add openpose json to API response"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants