AUTOMATIC1111 / stable-diffusion-webui

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

[Bug]: API returns different results than UI #8241

Open joaxkal opened 1 year ago

joaxkal commented 1 year ago

Is there an existing issue for this?

What happened?

As in the title:

when I use img2img tab in UI with prompt colorful bag with flowers and parameters:

image

image

Here's what I get: image

The same parameters passed in API:

`payload = { "init_images": [img], "denoising_strength": 0.50, "prompt": "colorful bag with flowers", "sampler_name": "Euler a", "steps": 20, "cfg_scale": 7, "negative_prompt": "", "include_init_images": True, "seed":420420, "batch_size":1 }

response = requests.post(url=f'{url}/sdapi/v1/img2img', json=payload)`

Now I get slighlty different result, although parameters and seed are the same image

Did I miss some parameters in API?

Steps to reproduce the problem

  1. Go to UI and generate image, then try to generate exactly the same in API

What should have happened?

I should get exactly the same image when seed is specified. I get the same image every time I pass the same parameters and seed via UI. The same happens for API case. The problem is that results are different between UI and API.

Commit where the problem happens

commit: 0cc0ee1b

What platforms do you use to access the UI ?

Linux

What browsers do you use to access the UI ?

Google Chrome, Apple Safari

Command Line Arguments

--api --share

List of extensions

sd-webui-controlnet

Console logs

no cmd error /warning logs, everything loads normally

Additional information

No response

missionfloyd commented 1 year ago

Are you using a VAE? Or have Eta noise seed delta set?

joaxkal commented 1 year ago

I manually set only mentioned parameters (i.e seed 420420, noise 0.5), so I guess the rest should remain with their default values and behaviours (vae, eta, delta). I am also working with official SD1.5 checkpoint I guess the reason for that may be that encoding an image to base64 causes some minor changes

liuzimo commented 1 year ago

I have the same problem,

kkiqq22 commented 1 year ago

me too

GustavSO commented 1 year ago

I'm experiencing the same issue. I even compared the generation information of the image generated in the UI, by enabling the 'Always print all generation information to standard output' setting, with the generation information in the API response and found that there was full parity.

alitan commented 1 year ago

Same problem here. I am curious if base64 encoding is causing the issue. Very hard to pin point. Also, on top of the complete different result, i also realized that API is returning much darker images.

alitan commented 1 year ago

Ok, i found my issue. It was the gamma of the image which was not saved as 2.2

vassilispapadop commented 1 year ago

when do img2img inpainting with mask i get different results between UI and API. any ideas?

nileshbhosale commented 1 year ago

I was facing same issue. Apparently when using images in control net or img to img using JPEG image helped resolve the issue. Note even if image is generated using library like PIL exporting it first as JPEG and then opening again seems to resolve the issue.

amota511 commented 1 year ago

I've been having this issue as well. I'll try using jpeg for the images though, thanks!

Manerba commented 1 year ago

I had the same issue. I activated "Settings / System / Always print all generation info to standard output" and compared the params with that one i used which i copied from the docs. I noticed that the eta-value was set to 0 instead 1. I switched the value to 1 and now i get exact the same results as when I use the webui.

stalker-silence commented 1 year ago

I have the same program and the payload was

{
    "resize_mode": 1,
    "denoising_strength": 0.62,
    "image_cfg_scale": 0,
    "mask": "data:image/jpeg;base64,/....",
    "mask_blur": 4,
    "mask_blur_x": 4,
    "mask_blur_y": 4,
    "inpainting_fill": 1,
    "inpaint_full_res": false,
    "inpaint_full_res_padding": 32,
    "inpainting_mask_invert": 0,
    "initial_noise_multiplier": 0,
    "sampler_lms_resize_to": 2048,
    "seed": -1,
    "n_iter": 1,
    "steps": 30,
    "cfg_scale": 15,
    "width": 700,
    "height": 1200,
    "restore_faces": true,
    "tiling": false,
    "do_not_save_samples": false,
    "do_not_save_grid": false,
    "negative_prompt": "paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, glans,bikini,medium breast,,Nevus, skin spots,nsfw,paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, (outdoor:1.6), manboobs, backlight,(ugly:1.331), (duplicate:1.331), (morbid:1.21), (mutilated:1.21), (tranny:1.331), mutated hands, (poorly drawn hands:1.331), blurry, (bad anatomy:1.21), (bad proportions:1.331), extra limbs, (disfigured:1.331), (more than 2 nipples:1.331), (missing arms:1.331), (extra legs:1.331), (fused fingers:1.61051), (too many fingers:1.61051), (unclear eyes:1.331), lowers, bad hands, missing fingers, extra digit, (futa:1.1),bad hands, missing fingers sketch, duplicate, ugly, huge eyes, text, logo, monochrome, worst face, (bad and mutated hands:1.3), (worst quality:2.0), (low quality:2.0), (blurry:2.0), horror, geometry, bad_prompt_v2, (bad hands), (missing fingers), multiple limbs, bad anatomy, (interlocked fingers:1.2), Ugly Fingers, (extra digit and hands and fingers and legs and arms:1.4), crown braid, (deformed fingers:1.2), (long fingers:1.2),(bad-artist-anime), bad-artist, bad hand, EasyNegative, Unspeakable-Horrors-Composition-4v, verybadimagenegative_v1.3,",
    "eta": 0.5,
    "s_min_uncond": 0,
    "s_churn": 0.8,
    "s_tmax": 0,
    "s_tmin": 0,
    "s_noise": 0.4,
    "override_settings": {
        "sd_model_checkpoint": "majicmixRealistic_v6"
    },
    "override_settings_restore_afterwards": true,
    "script_args": [],
    "sampler_index": "DPM++ 2M Karras",
    "include_init_images": true,
    "send_images": true,
    "save_images": false,
    "deterministic": false,
    "alwayson_scripts": {
        "controlnet": {
            "args": [
                {
                    "enabled": true,
                    "input_image": "data:image/jpeg;base64,/9j/...",
                    "module": "canny",
                    "model": "control_canny-fp16 [e3fe7712]",
                    "pixel_perfect": true,
                    "control_mode": 1,
                    "threshold_a": 384,
                    "threshold_b": 1152,
                    "processor_res": 1280,
                    "weight": 1,
                    "mask": null,
                    "invert_image": false,
                    "resize_mode": false,
                    "rgbbgr_mode": false,
                    "lowvram": false,
                    "guessmode": false
                }
            ]
        }
    },
    "init_images": [
        "..."
    ],
    "prompt": "chinese girl,smile,a happy smile,smile at the camera,long hair,beautiful long hair,clean long hair,black hair,black colored hair,black hair color,basketball court,rim,bedroom,curtain,bed,lighting,masterpiece, best quality, highres, videl2, solo, blue eyes, black hair,best quality, ultra high res, (photorealistic:1.4),1girl, short hair, ((full body)),(realistic:1.7),((best quality)),absurdres,(ultra high res),photorealistic,octane render,(hyperrealistic:1.2), (8k), (4k), (Masterpiece),(realistic skin texture), (illustration, cinematic lighting,wallpaper),( beautiful eyes:1.2),((((perfect face)))),(cute),((looking at viewer)),(correct ratio:1.6), <lora:add_detail:1>"
}

and output image never changes

stalker-silence commented 1 year ago

gamma

Always print all generation information to standard output

how do you resolve it, i have the same isuess @alitan

dent0s commented 5 months ago

I have the same thing. Havent solved this problem yet?