AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
142.86k stars 26.93k forks source link

[Feature Request]: how the webui handles prompts and negative prompts? #9620

Closed sanbuphy closed 1 year ago

sanbuphy commented 1 year ago

Is there an existing issue for this?

What would your feature do ?

Could you please tell me how the webui handles prompts and negative prompts? Which source code should I investigate? Specifically, I want to study how the final result is packaged as an input for a pipe to perform the txt2img operation. Thank you very much!

Proposed workflow

Could you please tell me the relevant files or functions so that I can look at the source code myself? Thank you very much. I have looked at some related functions but did not get the expected results. I found that some parts of the code are deeply encapsulated.

Additional information

No response

PGTBoos commented 1 year ago

I'm not the coder of this, but there is a lot on youtube about how it works. In the early days of Neural networks It once started with network that could recognize cats vs dogs, later language models where used for textual discrimination of what the (initially noise starter image should becomme), So the network diverges to something that agrees to the text (by penalty/reward mechanism), At some point they realized negative dont do this kind of comment also worked well, for ease of use thats now a negative prompt. Its though the same as writing "No Anime face" in the normal prompt. maybe watch this: https://www.youtube.com/watch?v=fbLgFrlTnGU

shirooo39 commented 1 year ago

I'm not the coder of this, but there is a lot on youtube about how it works. In the early days of Neural networks It once started with network that could recognize cats vs dogs, later language models where used for textual discrimination of what the (initially noise starter image should becomme), So the network diverges to something that agrees to the text (by penalty/reward mechanism), At some point they realized negative dont do this kind of comment also worked well, for ease of use thats now a negative prompt. Its though the same as writing "No Anime face" in the normal prompt. maybe watch this: https://www.youtube.com/watch?v=fbLgFrlTnGU

so it's also possible to use normal prompt to include things we don't want?

PGTBoos commented 1 year ago

Yes like "car without wheels" or so. Keep in mind that sometimes it won't understand or you need to create more images and only 1 shows the effect your agter. Also just a tip if you have an image that almost nails it. Send it to imgtoimg or input and set it by sliders that you only want slight variations.

sanbuphy commented 1 year ago

Thank you very much.

I'm not the coder of this, but there is a lot on youtube about how it works. In the early days of Neural networks It once started with network that could recognize cats vs dogs, later language models where used for textual discrimination of what the (initially noise starter image should becomme), So the network diverges to something that agrees to the text (by penalty/reward mechanism), At some point they realized negative dont do this kind of comment also worked well, for ease of use thats now a negative prompt. Its though the same as writing "No Anime face" in the normal prompt. maybe watch this: https://www.youtube.com/watch?v=fbLgFrlTnGU

victorca25 commented 1 year ago

@sanbuphy I would recommend you to start with the original Stable Diffusion code base if you want to learn how it works, this repo and the commit history is too messy to start from here.

The "negative prompt" is just a by-product of the classifier-free guidance, where it original was only an empty prompt, it was later discovered that here you could put anything you don't want the network to generate.

It's very simple to modify the original code and add this negative prompt, just replace the empty string with any string that will be your negative prompt.