djbielejeski / a-person-mask-generator

Extension for Automatic1111 and ComfyUI to automatically create masks for Background/Hair/Body/Face/Clothes in Img2Img
MIT License
262 stars 34 forks source link

Does not work correctly by API #19

Open slonce70 opened 9 months ago

slonce70 commented 9 months ago

Good afternoon, the problem is the following - in the browser, using the module, changes clothes perfectly. Unniffed the request, prescribed parameters in the api http://127.0.0.1:7860/sdapi/v1/img2img - does not change clothes fully, it feels like denosing does not set, although set 0.9. Here are the parameters that I send on the api

{
    "prompt": "<lora:add_detail:0.8>, <lora:more_details:0.3>, masterpiece, high quality, 8k, beautiful lighting, absurdres, perfect anatomy, ((swimsuit, blue swimsuit)), ",
    "negative_prompt": "(worst quality, low quality, ugly:1.4), (deformed, distorted, disfigured:1.3), stacked torsos, totem pole, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, text, watermark",
    "sampler_name": "Euler a",
    "styles": [],
    "seed": -1,
    "subseed": -1,
    "subseed_strength": 0,
    "seed_resize_from_h": -1,
    "seed_resize_from_w": -1,
    "batch_size": 1,
    "n_iter": 1,
    "steps": 24,
    "cfg_scale": 7,
    "width": 640,
    "height": 848,
    "restore_faces": false,
    "tiling": false,
    "do_not_save_samples": false,
    "do_not_save_grid": false,
    "eta": 0,
    "denoising_strength": 0.9,
    "s_min_uncond": 0,
    "s_churn": 0,
    "s_tmax": 0,
    "s_tmin": 0,
    "s_noise": 0,
    "override_settings": {},
    "disable_extra_networks": false,
    "comments": {},
    "init_images": [
        "base64 our images"
    ],
    "send_images": true,
    "save_images": false,
    "alwayson_scripts": {
        "A Person Mask Generator": {
            "args": [
                true,
                [
                    "clothes"
                ],
                true,
                4,
                0,
                1,
                false, (or true - not change nothing)
                256,
                8
            ]
        }
    }
}

Been racking my brain for a couple days now that I haven't changed it already. What is the problem and what to do, please tell me. Thanks in advance

Знімок екрана 2024-01-04 174230 The first image is taken via the web. Models etc. are the same, all parameters are the same

Знімок екрана 2024-01-04 173838 This is the result we get from the API

Знімок екрана 2024-01-04 174240 Знімок екрана 2024-01-04 174245

meyiapir commented 9 months ago

It's the same problem, only mine is blurry

djbielejeski commented 9 months ago

Everything is working fine for me over the API

Web UI image image

Request

{
    "prompt": "masterpiece, high quality, 8k, beautiful lighting, absurdres, ((white wedding dress))",
    "negative_prompt": "((deformed)), (cross-eyed), (closed eyes), (bad anatomy), disfigured, (mutation), (mutated), (extra limbs), 3d render, cartoon",
    "sampler_name": "Euler a",
    "styles": [],
    "seed": 1645829012,
    "subseed": -1,
    "subseed_strength": 0,
    "seed_resize_from_h": -1,
    "seed_resize_from_w": -1,
    "batch_size": 1,
    "n_iter": 1,
    "steps": 20,
    "cfg_scale": 7,
    "width": 448,
    "height": 576,
    "restore_faces": false,
    "tiling": false,
    "do_not_save_samples": false,
    "do_not_save_grid": false,
    "eta": 0,
    "denoising_strength": 0.75,
    "s_min_uncond": 0,
    "s_churn": 0,
    "s_tmax": 0,
    "s_tmin": 0,
    "s_noise": 0,
    "override_settings": {},
    "disable_extra_networks": false,
    "comments": {},
    "init_images": [
         "data:image/jpeg;base64,/9j/4AAQSkZJR...snipped..."
    ],
    "send_images": true,
    "save_images": false,
    "alwayson_scripts": {
        "A Person Mask Generator": {
            "args": [
                true,
                [
                    "clothes"
                ],
                true,
                4,
                0,
                1,
                0,
                256,
                8,
                8
            ]
        }
    }
}

API Response

https://base64.guru/converter/decode/image

image

{
    "images": [
        "iVBOR...snipped..."
    ],
    "parameters": {
        "prompt": "masterpiece, high quality, 8k, beautiful lighting, absurdres, ((white wedding dress))",
        "negative_prompt": "((deformed)), (cross-eyed), (closed eyes), (bad anatomy), disfigured, (mutation), (mutated), (extra limbs), 3d render, cartoon",
        "styles": [],
        "seed": 1645829012,
        "subseed": -1,
        "subseed_strength": 0,
        "seed_resize_from_h": -1,
        "seed_resize_from_w": -1,
        "sampler_name": "Euler a",
        "batch_size": 1,
        "n_iter": 1,
        "steps": 20,
        "cfg_scale": 7,
        "width": 448,
        "height": 576,
        "restore_faces": false,
        "tiling": false,
        "do_not_save_samples": false,
        "do_not_save_grid": false,
        "eta": 0,
        "denoising_strength": 0.75,
        "s_min_uncond": 0,
        "s_churn": 0,
        "s_tmax": 0,
        "s_tmin": 0,
        "s_noise": 0,
        "override_settings": {},
        "override_settings_restore_afterwards": true,
        "refiner_checkpoint": null,
        "refiner_switch_at": null,
        "disable_extra_networks": false,
        "comments": {},
        "init_images": null,
        "resize_mode": 0,
        "image_cfg_scale": null,
        "mask": null,
        "mask_blur_x": 4,
        "mask_blur_y": 4,
        "mask_blur": null,
        "inpainting_fill": 0,
        "inpaint_full_res": true,
        "inpaint_full_res_padding": 0,
        "inpainting_mask_invert": 0,
        "initial_noise_multiplier": null,
        "latent_mask": null,
        "sampler_index": "Euler",
        "include_init_images": false,
        "script_name": null,
        "script_args": [],
        "send_images": true,
        "save_images": false,
        "alwayson_scripts": {
            "A Person Mask Generator": {
                "args": [
                    true,
                    [
                        "clothes"
                    ],
                    true,
                    4,
                    0,
                    1,
                    0,
                    256,
                    8,
                    8
                ]
            }
        }
    },
    "info": "{\"prompt\": \"masterpiece, high quality, 8k, beautiful lighting, absurdres, ((white wedding dress))\", \"all_prompts\": [\"masterpiece, high quality, 8k, beautiful lighting, absurdres, ((white wedding dress))\"], \"negative_prompt\": \"((deformed)), (cross-eyed), (closed eyes), (bad anatomy), disfigured, (mutation), (mutated), (extra limbs), 3d render, cartoon\", \"all_negative_prompts\": [\"((deformed)), (cross-eyed), (closed eyes), (bad anatomy), disfigured, (mutation), (mutated), (extra limbs), 3d render, cartoon\"], \"seed\": 1645829012, \"all_seeds\": [1645829012], \"subseed\": 200682659, \"all_subseeds\": [200682659], \"subseed_strength\": 0.0, \"width\": 448, \"height\": 576, \"sampler_name\": \"Euler a\", \"cfg_scale\": 7.0, \"steps\": 20, \"batch_size\": 1, \"restore_faces\": false, \"face_restoration_model\": null, \"sd_model_name\": \"v1-5-pruned-emaonly-pruned\", \"sd_model_hash\": \"ad5749cdfa\", \"sd_vae_name\": \"vae-ft-mse-840000-ema-pruned.vae.pt\", \"sd_vae_hash\": \"ff724e9611\", \"seed_resize_from_w\": -1, \"seed_resize_from_h\": -1, \"denoising_strength\": 0.75, \"extra_generation_params\": {\"Eta\": 0.0}, \"index_of_first_image\": 0, \"infotexts\": [\"masterpiece, high quality, 8k, beautiful lighting, absurdres, ((white wedding dress))\nNegative prompt: ((deformed)), (cross-eyed), (closed eyes), (bad anatomy), disfigured, (mutation), (mutated), (extra limbs), 3d render, cartoon\nSteps: 20, Sampler: Euler a, CFG scale: 7.0, Seed: 1645829012, Size: 448x576, Model hash: ad5749cdfa, Model: v1-5-pruned-emaonly-pruned, VAE hash: ff724e9611, VAE: vae-ft-mse-840000-ema-pruned.vae.pt, Denoising strength: 0.75, Eta: 0.0, Version: v1.7.0\"], \"styles\": [], \"job_timestamp\": \"20240106111833\", \"clip_skip\": 1, \"is_using_inpainting_conditioning\": false, \"version\": \"v1.7.0\"}"
}
djbielejeski commented 9 months ago

Here is the image I used 0baccebde5500aee139c6c0e7976d450120c9d1f_00_448x576

slonce70 commented 9 months ago

Checked, the problem remains with complex photos. Here I am sending a full request in your likeness

{
    "prompt": "((swimsuit, blue swimsuit))",
    "negative_prompt": "(worst quality, low quality, ugly:1.4), (deformed, distorted, disfigured:1.3), stacked torsos, totem pole, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, text, watermark",
    "sampler_name": "Euler a",
    "styles": [],
    "seed": 1645829012,
    "subseed": -1,
    "subseed_strength": 0,
    "seed_resize_from_h": -1,
    "seed_resize_from_w": -1,
    "batch_size": 1,
    "n_iter": 1,
    "steps": 20,
    "cfg_scale": 7,
    "width": 640,
    "height": 848,
    "restore_faces": false,
    "tiling": false,
    "do_not_save_samples": false,
    "do_not_save_grid": false,
    "eta": 0,
    "denoising_strength": 0.9,
    "s_min_uncond": 0,
    "s_churn": 0,
    "s_tmax": 0,
    "s_tmin": 0,
    "s_noise": 0,
    "override_settings": {},
    "disable_extra_networks": false,
    "comments": {},
    "init_images": [
        "data:image/jpeg;base64,"
    ],
    "send_images": true,
    "save_images": false,
    "alwayson_scripts": {
        "A Person Mask Generator": {
            "args": [
                true,
                [
                    "clothes"
                ],
                true,
                4,
                0,
                1,
                0,
                256,
                8,
                8
            ]
        }
    }
}

Its original images Wi93oEge

This image is processed through the browser with the same parameters - see the result - fully functional without problems Знімок екрана 2024-01-04 174230

And this is the image generated through your API request. As you can see, it seems that APL draws the mask incorrectly for some reason. Знімок екрана 2024-01-06 233756 Знімок екрана 2024-01-06 234013

As you can see it didn't process all sections, which in the browser is done without problems. The problem is not only with this photo, but with many of them.

Here is the response code I'm getting

{"images":["],
    "parameters": {
        "prompt": "((swimsuit, blue swimsuit))",
        "negative_prompt": "(worst quality, low quality, ugly:1.4), (deformed, distorted, disfigured:1.3), stacked torsos, totem pole, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, text, watermark",
        "styles": [],
        "seed": 1645829012,
        "subseed": -1,
        "subseed_strength": 0.0,
        "seed_resize_from_h": -1,
        "seed_resize_from_w": -1,
        "sampler_name": "Euler a",
        "batch_size": 1,
        "n_iter": 1,
        "steps": 20,
        "cfg_scale": 7.0,
        "width": 640,
        "height": 848,
        "restore_faces": false,
        "tiling": false,
        "do_not_save_samples": false,
        "do_not_save_grid": false,
        "eta": 0.0,
        "denoising_strength": 0.9,
        "s_min_uncond": 0.0,
        "s_churn": 0.0,
        "s_tmax": 0.0,
        "s_tmin": 0.0,
        "s_noise": 0.0,
        "override_settings": {},
        "override_settings_restore_afterwards": true,
        "refiner_checkpoint": null,
        "refiner_switch_at": null,
        "disable_extra_networks": false,
        "comments": {},
        "init_images": null,
        "resize_mode": 0,
        "image_cfg_scale": null,
        "mask": null,
        "mask_blur_x": 4,
        "mask_blur_y": 4,
        "mask_blur": null,
        "inpainting_fill": 0,
        "inpaint_full_res": true,
        "inpaint_full_res_padding": 0,
        "inpainting_mask_invert": 0,
        "initial_noise_multiplier": null,
        "latent_mask": null,
        "sampler_index": "Euler",
        "include_init_images": false,
        "script_name": null,
        "script_args": [],
        "send_images": true,
        "save_images": false,
        "alwayson_scripts": {
            "A Person Mask Generator": {
                "args": [
                    true,
                    [
                        "clothes"
                    ],
                    true,
                    4,
                    0,
                    1,
                    0,
                    256,
                    8,
                    8
                ]
            }
        }
    },
    "info": "{\"prompt\": \"((swimsuit, blue swimsuit))\", \"all_prompts\": [\"((swimsuit, blue swimsuit))\"], \"negative_prompt\": \"(worst quality, low quality, ugly:1.4), (deformed, distorted, disfigured:1.3), stacked torsos, totem pole, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, text, watermark\", \"all_negative_prompts\": [\"(worst quality, low quality, ugly:1.4), (deformed, distorted, disfigured:1.3), stacked torsos, totem pole, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, text, watermark\"], \"seed\": 1645829012, \"all_seeds\": [1645829012], \"subseed\": 900395898, \"all_subseeds\": [900395898], \"subseed_strength\": 0.0, \"width\": 640, \"height\": 848, \"sampler_name\": \"Euler a\", \"cfg_scale\": 7.0, \"steps\": 20, \"batch_size\": 1, \"restore_faces\": false, \"face_restoration_model\": null, \"sd_model_name\": \"epicrealism_pureEvolutionV5-inpainting\", \"sd_model_hash\": \"caa95002a1\", \"sd_vae_name\": \"vae-ft-mse-840000-ema-pruned.ckpt\", \"sd_vae_hash\": \"c6a580b13a\", \"seed_resize_from_w\": -1, \"seed_resize_from_h\": -1, \"denoising_strength\": 0.9, \"extra_generation_params\": {\"Eta\": 0.0}, \"index_of_first_image\": 0, \"infotexts\": [\"((swimsuit, blue swimsuit))\\nNegative prompt: (worst quality, low quality, ugly:1.4), (deformed, distorted, disfigured:1.3), stacked torsos, totem pole, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, text, watermark\\nSteps: 20, Sampler: Euler a, CFG scale: 7.0, Seed: 1645829012, Size: 640x848, Model hash: caa95002a1, Model: epicrealism_pureEvolutionV5-inpainting, VAE hash: c6a580b13a, VAE: vae-ft-mse-840000-ema-pruned.ckpt, Denoising strength: 0.9, Conditional mask weight: 1.0, Eta: 0.0, Version: v1.7.0\"], \"styles\": [], \"job_timestamp\": \"20240106233951\", \"clip_skip\": 1, \"is_using_inpainting_conditioning\": true, \"version\": \"v1.7.0\"}"
}
slonce70 commented 9 months ago

Here's another example.

Original photo getPorn ai-1704035842900

Made through the browser - ((white dress)) 11248-1145253223-((white dress))

Made via API - with the same parameters and promt ((white dress)). Знімок екрана 2024-01-07 000015

MkKsko commented 9 months ago

@djbielejeski Hello! Is there a way to extract the mask via API? The resulting json only contains the generated image and the mask is nowhere to be found.

monstari commented 7 months ago

@djbielejeski Hello! Is there a way to extract the mask via API? The resulting json only contains the generated image and the mask is nowhere to be found.

Same! That would be usefull! I want to use this extension as negative mask.

bog-kotikov commented 3 months ago

Problem in color model, webui convert image to RGBA model, via api image default uses RGB. Just convert file before sending it to api server.

zh = BytesIO()
ma = Image.open('img.png').convert('RGBA')
ma.save(zh, "PNG")
img = base64.b64encode(zh.getvalue()).decode('utf-8')
MotherSoraka commented 1 month ago

Thank you @bog-kotikov !