AUTOMATIC1111 / stable-diffusion-webui

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

[Feature Request]: image parameter returned by the png info module #14580

Open Nomination-NRB opened 6 months ago

Nomination-NRB commented 6 months ago

Is there an existing issue for this?

What would your feature do ?

Why is the image parameter returned by the png info module not complete, if I want to use the api call to generate the image, then the png info module does not return enough parameters, there are many parameters that are not returned

Proposed workflow

  1. Use png info api to get the all parameters of the output1 (output1 is created by stable diffusion webui)
  2. Use png info api to get the all parameters of the output2 (output2 is created by stable diffusion api)
  3. Check the two results if there is any different

Additional information

No response

missionfloyd commented 6 months ago

Looks right to me. image

{
    "info": "oil painting of a dachshund wearing a top hat\nNegative prompt: canvas frame, cartoon, 3d, ((disfigured)), ((bad art)), ((deformed)),((extra limbs)),((close up)),((b&w)), wierd colors, blurry, (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck))), Photoshop, video game, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy, 3d render\nSteps: 20, Sampler: Euler a, CFG scale: 7, Seed: 3512473112, Size: 512x512, Model hash: e3cda540bf, Model: protogenX53Photorealism_10, Version: v1.2.1",
    "items": {
        "postprocessing": "Postprocess upscale by: 2, Postprocess upscaler: 4x-UltraSharp",
        "extras": "Postprocess upscale by: 2, Postprocess upscaler: 4x-UltraSharp"
    },
    "parameters": {
        "Styles array": [
            "Negative"
        ],
        "Prompt": "oil painting of a dachshund wearing a top hat",
        "Negative prompt": "",
        "Steps": "20",
        "Sampler": "Euler a",
        "CFG scale": "7",
        "Seed": "3512473112",
        "Size-1": "512",
        "Size-2": "512",
        "Model hash": "e3cda540bf",
        "Model": "protogenX53Photorealism_10",
        "Version": "v1.2.1",
        "Clip skip": "1",
        "Hires resize-1": 0,
        "Hires resize-2": 0,
        "Hires sampler": "Use same sampler",
        "Hires checkpoint": "Use same checkpoint",
        "Hires prompt": "",
        "Hires negative prompt": "",
        "RNG": "GPU",
        "Schedule type": "Automatic",
        "Schedule max sigma": 0,
        "Schedule min sigma": 0,
        "Schedule rho": 0,
        "VAE Encoder": "Full",
        "VAE Decoder": "Full"
    }
}
import requests
import base64
import json

with open("image.png", "rb") as f:
    img = base64.b64encode(f.read()).decode('utf-8')

payload = {
    "image": img
}

response = requests.post(url='http://127.0.0.1:7860/sdapi/v1/png-info', json=payload)
r = response.json()

print(json.dumps(r, indent=4))

Parameters can also be read locally like this.

from PIL import Image

image = Image.open("image.png")
parameters = image.info

print(parameters)
Nomination-NRB commented 6 months ago

Looks right to me. image

{
    "info": "oil painting of a dachshund wearing a top hat\nNegative prompt: canvas frame, cartoon, 3d, ((disfigured)), ((bad art)), ((deformed)),((extra limbs)),((close up)),((b&w)), wierd colors, blurry, (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck))), Photoshop, video game, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy, 3d render\nSteps: 20, Sampler: Euler a, CFG scale: 7, Seed: 3512473112, Size: 512x512, Model hash: e3cda540bf, Model: protogenX53Photorealism_10, Version: v1.2.1",
    "items": {
        "postprocessing": "Postprocess upscale by: 2, Postprocess upscaler: 4x-UltraSharp",
        "extras": "Postprocess upscale by: 2, Postprocess upscaler: 4x-UltraSharp"
    },
    "parameters": {
        "Styles array": [
            "Negative"
        ],
        "Prompt": "oil painting of a dachshund wearing a top hat",
        "Negative prompt": "",
        "Steps": "20",
        "Sampler": "Euler a",
        "CFG scale": "7",
        "Seed": "3512473112",
        "Size-1": "512",
        "Size-2": "512",
        "Model hash": "e3cda540bf",
        "Model": "protogenX53Photorealism_10",
        "Version": "v1.2.1",
        "Clip skip": "1",
        "Hires resize-1": 0,
        "Hires resize-2": 0,
        "Hires sampler": "Use same sampler",
        "Hires checkpoint": "Use same checkpoint",
        "Hires prompt": "",
        "Hires negative prompt": "",
        "RNG": "GPU",
        "Schedule type": "Automatic",
        "Schedule max sigma": 0,
        "Schedule min sigma": 0,
        "Schedule rho": 0,
        "VAE Encoder": "Full",
        "VAE Decoder": "Full"
    }
}
import requests
import base64
import json

with open("image.png", "rb") as f:
    img = base64.b64encode(f.read()).decode('utf-8')

payload = {
    "image": img
}

response = requests.post(url='http://127.0.0.1:7860/sdapi/v1/png-info', json=payload)
r = response.json()

print(json.dumps(r, indent=4))

Parameters can also be read locally like this.

from PIL import Image

image = Image.open("image.png")
parameters = image.info

print(parameters)

thanks for your reply!

but, this is my data:

This is my data, functionally formatted into a dictionary

{
    "prompt": "shoes on the ground, consistent background colour, natural shadow of shoes on the ground",
    "negative_prompt": "Negative prompt: Abnormal light and shadow on the ground",
    "Steps": "41",
    "Sampler": "Euler a",
    "CFG scale": "7",
    "Seed": "783177188",
    "Size": "1048x1400",
    "Model hash": "346e4b5a73",
    "Model": "realisticVisionV60B1_v60B1InpaintingVAE",
    "VAE hash": "63aeecb90f",
    "VAE": "vae-ft-mse-840000-ema-pruned.ckpt",
    "Denoising strength": "0.75",
    "Conditional mask weight": "1.0",
    "Mask blur": "6",
    "Controlnet 0": {
        "Module": "lineart_realistic",
        "Model": "control_v11p_sd15_lineart [43d4be0d]",
        "Weight": "1.45",
        "Resize Mode": "Crop and Resize",
        "Low Vram": "False",
        "Processor Res": "512",
        "Guidance Start": "0",
        "Guidance End": "1",
        "Pixel Perfect": "True",
        "Control Mode": "Balanced",
        "Save Detected Map": "True"
    },
    "Version": "v1.7.0"
}

but if I use api to use stable diffusion, I need more parameters(such as: inpainting_fill, inpaint_full_res):

payload = {
        "prompt": promptList[0],
        "negative_prompt": promptList[1],
        "init_images": [img],
        "mask": mask,
        "resize_mode": 1,  # Resize mode: [Just resize, Crop and resize, Resize and fill, Just resize(latent upscale)]
        "mask_blur": 4,  # Mask blur: 0-64 
        "inpainting_fill": 1,  # Masked content: [fill, original, latent noise, latent nothing]
        "inpaint_full_res": Inpaint_area,  # Inpaint area: [Whole picture(False), Only masked(True)]
        "sampler_name": Sampling_method,  # Sampling method
        "inpaint_full_res_padding": 32,  # Only masked padding, pixels
        "steps": Sampling_steps,  # Sampling steps
        "inpainting_mask_invert": 0,  # mask mode 0 inpaint masked, 1 inpaint inclusive masked
        "width": width,  # Resize to Width
        "height": height,  # Resize to Height
        "batch_size": 1,  # Batch count
        "batch_count": 1,  # Batch size
        "cfg_scale": 7,  # CFG Scale
        "denoising_strength": Denoising_strength,  # Denoising strength
        "seed": -1,
        "alwayson_scripts": {
            "ControlNet": {
                "args": [
                    {
                        "input_image": controlnet0_input,
                        "enabled": True,  # Enable tick
                        "module": controlnet0_module,  # Preprocessor
                        "model": controlnet0Key_para['model'],  # Model
                        "weight": controlnet0_weight,  # Control Weight
                        "guidance_start": 0.0,  # Starting Control Step
                        "guidance_end": 1.0,  # Ending Control Step
                        "processor_res": 512,
                        "control_mode": controlnet0_control_mode,  # Control Mode: [Balanced, My is m imp, C is m imp]
                        "resize_mode": 1,  # Resize Mode: [Just Resize, Crop and Resize, Resize and Fill]
                        "pixel_perfect": eval(controlnet0_pixel),
                    },
                    {
                        "enabled": False,  # Enable tick
                    },
                    {
                        "enabled": False,  # Enable tick
                    },
                    {
                        "enabled": False,  # Enable tick
                    }
                ]
            }
        }
    }

Initially I wanted to use the webui version to get the best output parameters, then use png info to get and format the parameters used for the images, and then migrate to the use of the api, but found that the parameters obtained from the images were not complete enough to call the api.