当前位置:首页 » 《关注互联网》 » 正文

全网最全stable diffusion webui API调用示例,包含controlneth和segment anything的API(附json示例)

25 人参与  2024年04月18日 08:21  分类 : 《关注互联网》  评论

点击全文阅读


全网最全stable diffusion webui API调用示例,包含controlneth和segment anything的API(附json示例)

交流群 100419879
欢迎合作?? V : 864399407
GitHub:https://github.com/Anning01
BiliBili: https://space.bilibili.com/50125441

txt2img -> /sdapi/v1/txt2img

不带 controlnet
data = {    "prompt": "提示词",    "negative_prompt": "反向提示词",    "seed": -1,  # 随机种子    "sampler_name": "取样器(之间复制webui的名字就行)",    "cfg_scale": 7.5,  # 提示词相关性 越大越接近提示词    "width": 640,  # 宽 (注意要被16整除)    "height": 360,  # 高 (注意要被16整除)    "batch_size": 4,  # 批量数量 并行 显存不够会爆显存    "n_iter": 4,  # 批量数量 队列 显存不够排队一个一个来 和 batch_size 二选一    "steps": 30,  # 迭代步数    "return_grid": True,  # 返回网格预览 xl-base 好像没用    "restore_faces": True,  # 脸部修复    "send_images": True,  # 是否在响应中返回生成的图像    "save_images": False,  # 是否保存生成的图像 一般api设置成False    "do_not_save_samples": False,  # 是否保存samples 一般api设置成False    "do_not_save_grid": False,  # 是否保存网格的图像 一般api设置成False    # 下面的很少用    "enable_hr": True,  # 是否开启高清修复    "denoising_strength": 0.5,  # 去噪强度 要求enable_hr = True    "firstphase_width": 0,    # firstphase_width 和firstphase_height 定义了图像的初始分辨率。在图像生成的第一阶段,这些值决定了图像的大小。如果这些值设置为0,系统可能会使用默认或预设的分辨率。    "firstphase_height": 0,    "hr_scale": 2,  # 放大倍数 对应webui Upscale by    "hr_upscaler": "string",  # 对应webui 的 Upscaler    "hr_second_pass_steps": 0,  # 迭代步数 对应webui 的 Hires steps。    "hr_resize_x": 0,  # 不放大,指定宽高 对应webui Resize width to 和Resize height to    "hr_resize_y": 0,  # 不放大,指定宽高 对应webui Resize width to 和Resize height to    "hr_checkpoint_name": "string",  # 高分辨率模式下使用的大模型昵称。    "hr_sampler_name": "string",  # 高分辨率模式下使用的采样器名称。    "hr_prompt": "",  # 高分辨率模式下使用的提示词名称。    "hr_negative_prompt": "",  # 高分辨率模式下使用的反向提示词名称。    "override_settings": {          "sd_model_checkpoint": "sd_xl_base_1.0.safetensors [31e35c80fc]",  # 指定大模型          "sd_vae": "Automatic",  # 指定vae 默认自动      },    "override_settings_restore_afterwards": True # override_settings 是否在之后恢复覆盖的设置 默认是True}
带 controlnet
data = {    "prompt": "提示词",    "negative_prompt": "反向提示词",    "seed": -1,  # 随机种子    "sampler_name": "取样器(之间复制webui的名字就行)",    "cfg_scale": 7.5,  # 提示词相关性 越大越接近提示词    "width": 640,  # 宽 (注意要被16整除)    "height": 360,  # 高 (注意要被16整除)    "batch_size": 4,  # 批量数量 并行 显存不够会爆显存    "n_iter": 4,  # 批量数量 队列 显存不够排队一个一个来 和 batch_size 二选一  "steps": 30,  # 迭代步数    "return_grid": True,  # 返回网格预览 xl-base 好像没用    "restore_faces": True,  # 脸部修复    "send_images": True,  # 是否在响应中返回生成的图像    "save_images": False,  # 是否保存生成的图像 一般api设置成False    "do_not_save_samples": False,  # 是否保存samples 一般api设置成False    "do_not_save_grid": False,  # 是否保存网格的图像 一般api设置成False    "alwayson_scripts": {        "controlnet":            {                "args": [                    {                        "enabled": True,  # 启用                        "control_mode": 0,  # 对应webui 的 Control Mode 可以直接填字符串 推荐使用下标 0 1 2                        "model": "t2i-adapter_diffusers_xl_lineart [bae0efef]",  # 对应webui 的 Model                        "module": "lineart_standard (from white bg & black line)",  # 对应webui 的 Preprocessor                        "weight": 0.45,  # 对应webui 的Control Weight                        "resize_mode": "Crop and Resize",                        "threshold_a": 200,  # 阈值a 部分control module会用上                        "threshold_b": 245,  # 阈值b                        "guidance_start": 0,  # 什么时候介入 对应webui 的 Starting Control Step                        "guidance_end": 0.7,  # 什么时候退出 对应webui 的 Ending Control Step                        "pixel_perfect": True,  # 像素完美                        "processor_res": 512,  # 预处理器分辨率                        "save_detected_map": False,  # 因为使用了 controlnet API会返回生成controlnet的效果图,默认是True,如何不需要,改成False                        "input_image": "",  # 图片 格式为base64                    }                    # 多个controlnet 在复制上面一个字典下来就行                ]            }    },    # 下面的很少用    "enable_hr": True,  # 是否开启高清修复    "denoising_strength": 0.5,  # 去噪强度 要求enable_hr = True    "firstphase_width": 0,    # firstphase_width 和firstphase_height 定义了图像的初始分辨率。在图像生成的第一阶段,这些值决定了图像的大小。如果这些值设置为0,系统可能会使用默认或预设的分辨率。    "firstphase_height": 0,    "hr_scale": 2,  # 放大倍数 对应webui Upscale by    "hr_upscaler": "string",  # 对应webui 的 Upscaler    "hr_second_pass_steps": 0,  # 迭代步数 对应webui 的 Hires steps。    "hr_resize_x": 0,  # 不放大,指定宽高 对应webui Resize width to 和Resize height to    "hr_resize_y": 0,  # 不放大,指定宽高 对应webui Resize width to 和Resize height to    "hr_checkpoint_name": "string",  # 高分辨率模式下使用的大模型昵称。    "hr_sampler_name": "string",  # 高分辨率模式下使用的采样器名称。    "hr_prompt": "",  # 高分辨率模式下使用的提示词名称。    "hr_negative_prompt": "",  # 高分辨率模式下使用的反向提示词名称。    "override_settings": {          "sd_model_checkpoint": "sd_xl_base_1.0.safetensors [31e35c80fc]",  # 指定大模型          "sd_vae": "Automatic",  # 指定vae 默认自动      },    "override_settings_restore_afterwards": True # override_settings 是否在之后恢复覆盖的设置 默认是True}
带 Refiner
data = {    "prompt": "提示词",    "negative_prompt": "反向提示词",    "seed": -1,  # 随机种子    "sampler_name": "取样器(之间复制webui的名字就行)",    "cfg_scale": 7.5,  # 提示词相关性 越大越接近提示词    "width": 640,  # 宽 (注意要被16整除)    "height": 360,  # 高 (注意要被16整除)    "batch_size": 4,  # 批量数量 并行 显存不够会爆显存    "n_iter": 4,  # 批量数量 队列 显存不够排队一个一个来 和 batch_size 二选一  "steps": 30,  # 迭代步数    "return_grid": True,  # 返回网格预览 xl-base 好像没用    "restore_faces": True,  # 脸部修复    "send_images": True,  # 是否在响应中返回生成的图像    "save_images": False,  # 是否保存生成的图像 一般api设置成False    "do_not_save_samples": False,  # 是否保存samples 一般api设置成False    "do_not_save_grid": False,  # 是否保存网格的图像 一般api设置成False    "alwayson_scripts": {        "controlnet":            {                "args": [                    {                        "enabled": True,  # 启用                        "control_mode": 0,  # 对应webui 的 Control Mode 可以直接填字符串 推荐使用下标 0 1 2                        "model": "t2i-adapter_diffusers_xl_lineart [bae0efef]",  # 对应webui 的 Model                        "module": "lineart_standard (from white bg & black line)",  # 对应webui 的 Preprocessor                        "weight": 0.45,  # 对应webui 的Control Weight                        "resize_mode": "Crop and Resize",                        "threshold_a": 200,  # 阈值a 部分control module会用上                        "threshold_b": 245,  # 阈值b                        "guidance_start": 0,  # 什么时候介入 对应webui 的 Starting Control Step                        "guidance_end": 0.7,  # 什么时候退出 对应webui 的 Ending Control Step                        "pixel_perfect": True,  # 像素完美                        "processor_res": 512,  # 预处理器分辨率                        "save_detected_map": False,  # 因为使用了 controlnet API会返回生成controlnet的效果图,默认是True,如何不需要,改成False                        "input_image": "",  # 图片 格式为base64                    }                    # 多个controlnet 在复制上面一个字典下来就行                ]            },        "Refiner": {            "args": [                True,  # 是否开启                "sd_xl_refiner_1.0",  # 大模型昵称                0.75,  # 介入时机            ]        }    },    # 下面的很少用    "enable_hr": True,  # 是否开启高清修复    "denoising_strength": 0.5,  # 去噪强度 要求enable_hr = True    "firstphase_width": 0,    # firstphase_width 和firstphase_height 定义了图像的初始分辨率。在图像生成的第一阶段,这些值决定了图像的大小。如果这些值设置为0,系统可能会使用默认或预设的分辨率。    "firstphase_height": 0,    "hr_scale": 2,  # 放大倍数 对应webui Upscale by    "hr_upscaler": "string",  # 对应webui 的 Upscaler    "hr_second_pass_steps": 0,  # 迭代步数 对应webui 的 Hires steps。    "hr_resize_x": 0,  # 不放大,指定宽高 对应webui Resize width to 和Resize height to    "hr_resize_y": 0,  # 不放大,指定宽高 对应webui Resize width to 和Resize height to    "hr_checkpoint_name": "string",  # 高分辨率模式下使用的大模型昵称。    "hr_sampler_name": "string",  # 高分辨率模式下使用的采样器名称。    "hr_prompt": "",  # 高分辨率模式下使用的提示词名称。    "hr_negative_prompt": "",  # 高分辨率模式下使用的反向提示词名称。    "override_settings": {          "sd_model_checkpoint": "sd_xl_base_1.0.safetensors [31e35c80fc]",  # 指定大模型          "sd_vae": "Automatic",  # 指定vae 默认自动      },    "override_settings_restore_afterwards": True # override_settings 是否在之后恢复覆盖的设置 默认是True}
生成蒙版 segment anything -> /sam/sam-predict
data = {    "sam_model_name": "sam_vit_b_01ec64.pth",  # 蒙版模型名称    "input_image": "base64_str",  # 图像base64    "sam_positive_points": [        [317.7521, 174.7542],        [304.25, 174.75],        [295.25, 152.25],        [292.25, 174.75],        [284.75, 168.75],    ],  # 选中坐标点    "sam_negative_points": [],  # 反选中坐标点    "dino_enabled": True,  # 开启文字识别 例如一只猫在草坪上,想要得到猫的蒙版 可以使用 cat 会自动识别物品    "dino_model_name": "GroundingDINO_SwinT_OGC (694MB)",  # 文字识别模型    "dino_text_prompt": "",  # 文字(要英语)例如 cat}

img2img -> /sdapi/v1/img2img

使用蒙版局部重绘
data = {    "init_images": ["base64", ],  # 初始图像(要求使用base64列表)    "mask": "base64",  # 蒙版base64    "prompt": "",  # 提示词    "negative_prompt": "",  # 负面提示词    "batch_size": 4,  # 批量数量 并行 显存不够会爆显存    "n_iter": 4,  # 批量数量 队列 显存不够排队一个一个来 和 batch_size 二选一  "seed": -1,  # 随机种子    "sampler_name": "Euler a",  # 采样器名称    "mask_blur": 4,  # 边缘模糊    "inpaint_full_res": True,  # 更高分辨率修复 耗费算力,一般显卡建议关闭    "inpaint_full_res_padding": 4,  # 小到中等大小的修复区域 建议 4 - 10 大型修复区域建议 10 - 20    "inpainting_mask_invert": 0,  # 1 则反转蒙版    "cfg_scale": 7,  # 提示词相关性    "send_images": True,  # 是否在响应中返回生成的图像    "save_images": False,  # 是否保存生成的图像 一般api设置成False    "width": 640,    "height": 360,    "denoising_strength": 0.5,  # 去噪强度    "steps": 30,  # 步数    "override_settings": {        "sd_model_checkpoint": "sd_xl_base_1.0.safetensors [31e35c80fc]",  # 指定大模型        "sd_vae": "Automatic",  # 指定vae 默认自动    },  "override_settings_restore_afterwards": True # override_settings 是否在之后恢复覆盖的设置 默认是True}

点击全文阅读


本文链接:http://m.zhangshiyu.com/post/96866.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • 他的干妹妹怀孕后,我闪婚了文集(林诺陆深)全书免费_(林诺陆深)他的干妹妹怀孕后,我闪婚了文集后续(林诺陆深)
  • 江先生,你要听话列表列表_江先生,你要听话列表(许清欢江砚舟)
  • 一抹斜阳相思泪后续+必读夏知微陆远川完本_一抹斜阳相思泪后续+必读(夏知微陆远川)
  • 「不当假少爷后,我娶了首富当老婆」免费试读_萧寒沈凌薇章节多结局预体验‌
  • 全书浏览我死后,数万网友对我进行审判火爆(董天华尹瑶)_我死后,数万网友对我进行审判火爆(董天华尹瑶)全书结局
  • 纨绔恶少抽盲盒选妻子,我换嫁绝嗣总裁后他发疯求原谅+免费+后续列表_纨绔恶少抽盲盒选妻子,我换嫁绝嗣总裁后他发疯求原谅+免费+后续(阮玉绵)
  • 完结文晚云为落日溺亡++后续列表_完结文晚云为落日溺亡++后续(裴念舒)
  • [修仙:我在云疆养仙蚕]章节多结局预体验‌_「林珂」小说无删减版在线阅读
  • 全书浏览我死后,数万网友对我进行审判++番外(董天华尹瑶)_我死后,数万网友对我进行审判++番外(董天华尹瑶)全书结局
  • 被兄弟俩接连当工具人后,我杀疯了后续+(贺云舟)全书免费_(贺云舟)被兄弟俩接连当工具人后,我杀疯了后续+后续(贺云舟)
  • [发现装穷老公的真面目后,我迎来美好人生]反转剧情碎片化试读_傅思瀚方知晓晓晓完结
  • 完结文未婚夫求我放过他,换掉联姻对象后他却傻眼了。列表_完结文未婚夫求我放过他,换掉联姻对象后他却傻眼了。(傅深)

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1