s0md3v / sd-webui-roop

roop extension for StableDiffusion web-ui
GNU Affero General Public License v3.0
3.3k stars 834 forks source link

The result output of the API is different from the result of webUI? #275

Open yexin2124 opened 8 months ago

yexin2124 commented 8 months ago

The same parameters and pictures, the face change result of the API is completely different from the face change result on webui, why is it?

def image_to_base64(image_path):
with open(image_path, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()) base64_string = encoded_string.decode("utf-8") return base64_string

def save_encoded_image(b64_image, output_path):  
    # Check if file exists, create if it doesn't exist
    if not os.path.exists(output_path):
        open(output_path, 'wb').close()

    # Open file in binary mode
    with open(output_path, 'wb') as f:
        f.write(base64.b64decode(b64_image))
        f.flush()
        f.close()

# base64
file_input_base64 = image_to_base64(file_input)     
file_ref_base64 = image_to_base64(file_ref)        

# Roop:
args_roop = [
    file_input_base64,                                                      #0 File Input
    True,                                                                   #1 Enable Roop
    '0',                                                                    #2 Comma separated face number(s)
    'H:/AI/sd-webui-aki-v4.3/models/roop/inswapper_128.onnx',               #3 Model
    'GFPGAN',                                                               #4 Restore Face: None; CodeFormer; GFPGAN
    1,                                                                      #5 Restore visibility value
    "4x-UltraSharp",                                                        #6 Upscaler (type 'None' if doesn't need)
    1,                                                                      #7 Upscaler scale value
    1,                                                                      #8 Upscaler visibility (if scale = 1)
    False,                                                                  #9 Swap in source image
    True                                                                    #11 Swap in generated image
]

data_face={
    "override_settings": {
        "sd_model_checkpoint": "majicmixRealistic_v7.safetensors [7c819b6d13]",
        "sd_vae": "vae-ft-mse-840000-ema-pruned.safetensors",
        "CLIP_stop_at_last_layers": 2, 
     },
    "prompt": "",  
    "negative_prompt": "",
    "init_images": [file_ref_base64],  
    "steps": 20,  
    "sampler_index": "Euler a",  
    "width": 1688,  
    "height": 1120,  
    "batch_size": 1,  
    "n_iter": 1,  
    "cfg_scale": 7,# CFG
    "denoising_strength": 0.1,
    "seed": -1,
    "alwayson_scripts": {
        "roop": {"is_img2img": True, "is_alwayson": True, "args": args_roop}
    }
}