Stability-AI / stability-sdk

SDK for interacting with stability.ai APIs (e.g. stable diffusion inference)
https://platform.stability.ai/
MIT License
2.42k stars 336 forks source link

Questions about the parameters and their relation to options available on the dreamstudio website #70

Open Abel1011 opened 1 year ago

Abel1011 commented 1 year ago

Good day. Thank you for this fantastic tool. I am trying to adapt the sdk to my javascript based project but I have some doubts about how to replicate certain functionalities available in dreamstudio web related to img2img.

In dreamstudio when we add an image we can define the strength parameter; however in the sdk I don't see that parameter. I understand that it is related to start and end schedule. But I would like to know the exact relation. For example, if the strength on the web is 20%, what values would have the start and end schedule?

Additionally in the sdk there is the parameter init_image and mask_image. I don't understand what is the functionality of the mask_image and if I should pass it the same value as init_image or they are different values. What functionality of dreamstudio uses the mask_image?

Thank you very much for any help you can give me.

agentx3 commented 1 year ago

I have questions too about what end_schedule does specifically.

As for the other variables, if you check in ./nbs/demo_colab.ipynb in this repo you can find usages of start_schedule and the mask_image. Line for start_schedule: start_schedule=0.6, # this controls the "strength" of the prompt relative to the init image

mask_image on the other hand effectively tells the AI which regions of the image to render over. This can be useful if, for example, you want to preserve a character and only change the background. You would mask the character out using mask_image.

johnsabath commented 1 year ago

But I would like to know the exact relation. For example, if the strength on the web is 20%, what values would have the start and end schedule?

Image Strength on Dreamstudio has an inverse relationship with the start_schedule parameter.

start_schedule = 1 - "Dreamstudio Image Strength" / 100

So for 20% image strength, the corresponding start_schedule parameter would be 0.8

Abel1011 commented 1 year ago

Thank you for explaining in more detail the calculation of the start schedule. Regarding the end schedule value, what is the default value used by the Dreamstudio website?

johnsabath commented 1 year ago

I believe a end schedule value of 0 would replicate the behavior on the Dreamstudio website.

sillytuna commented 1 year ago

I don't think it's a 0. I tested the below on a js implementation.

From a quick test, this would be 35% Image Strength.

let imageStrength = 0.5;

//...
stepSchedule: {
    start: imageStrength,
    end: 1 - imageStrength
},
chigozienri commented 1 year ago

Hi @sillytuna

You actually want to flip the start value, like so:

let imageStrength = 0.5;

//...
stepSchedule: {
    start: 1 - imageStrength,
    end: 0
},

will match the behaviour on the website.

Note that actually, the minimum schedule start and end values are 0.05 - so when you set end to 0, the value actually used will be 0.05. Apologies that this is not documented very well.

Let me know if this gives the behaviour you are expecting.

sillytuna commented 1 year ago

Hmm using end of 0 didn't work. I only got comparable results, and I tested in both, using the methodology in my post.

chigozienri commented 1 year ago

Hmm using end of 0 didn't work. I only got comparable results, and I tested in both, using the methodology in my post.

Did you use 1 - imageStrength for the start value?

sillytuna commented 1 year ago

I did yes. IIRC I was just getting the same image back or black if end was 0, whatever else I did. I'll be revisiting the code tomorrow or weds though.

chigozienri commented 1 year ago

I did yes. IIRC I was just getting the same image back or black if end was 0, whatever else I did. I'll be revisiting the code tomorrow or weds though.

OK, in that case try it out with end = 0.05. If you could report back any errors you see when you get a chance, that would be greatly appreciated!

ideavr commented 1 year ago

Hi @chigozienri , I tried setting start schedule=0.5 and end Schedule=0.05, the result is still a little different from that when dreamstudio's Image Strength=0.5. How can I achieve the same effect as dreamstudio?

I did yes. IIRC I was just getting the same image back or black if end was 0, whatever else I did. I'll be revisiting the code tomorrow or weds though.

OK, in that case try it out with end = 0.05. If you could report back any errors you see when you get a chance, that would be greatly appreciated!