图生图
生图接口
图生图基本工作流
将用到的图片资源上传,获取资源id
请求参数
{
  "request_id": "unique_key",
  "stages": [
    {
      "type": "INPUT_INITIALIZE",
      "inputInitialize": {
        "image_resource_id": "f204c24a-52dc-4cf4-930a-9b8f73969414",
        "count": 2 //数量
      }
    },
    {
      "type": "DIFFUSION",
      "diffusion": {
        "width": 512, //宽
        "height": 512, //高
        "prompts": [
          {
            "text": "1girl"
          }
        ],
        "sampler": "DPM++ 2M Karras",
        "sdVae": "Automatic",
        "steps": 15,
        "sd_model": "600423083519508503", //checkpoint
        "clip_skip": 2,
        "cfg_scale": 7
      }
    }
  ]
}
Adetailer
对图片直接进行Adetailer,不进行Diffusion
警告
不做Diffusion操作,因此inputInitialize.count只能为1
虽然不做Diffusion,但是image_to_adetailer仍然需要带原始图片diffusion的参数
{
  "request_id": "unique_key",
  "stages": [
    {
      "type": "INPUT_INITIALIZE",
      "inputInitialize": {
        "image_resource_id": "f204c24a-52dc-4cf4-930a-9b8f73969414",
        "count": 1 //数量
      }
    },
    {
      "type": "IMAGE_TO_ADETAILER",
      "image_to_adetailer": {
        "args": [
          {
            "ad_model": "face_yolov8s.pt",
            "ad_confidence": 0.7,
            "ad_dilate_erode": 4,
            "ad_denoising_strength": 0.4,
            "ad_inpaint_only_masked": true,
            "ad_inpaint_only_masked_padding": 32
          }
        ],
        "diffusion": {
          "width": 512, //宽
          "height": 512, //高
          "prompts": [
            {
              "text": "1girl"
            }
          ],
          "sampler": "DPM++ 2M Karras",
          "sdVae": "Automatic",
          "steps": 15,
          "sd_model": "600423083519508503", //checkpoint
          "clip_skip": 2,
          "cfg_scale": 7
        }
      }
    }
  ]
}
图生图+Adetailer
{
  "request_id": "unique_key",
  "stages": [
    {
      "type": "INPUT_INITIALIZE",
      "inputInitialize": {
        "image_resource_id": "f204c24a-52dc-4cf4-930a-9b8f73969414",
        "count": 2 //数量
      }
    },
    {
      "type": "DIFFUSION",
      "diffusion": {
        "width": 512, //宽
        "height": 512, //高
        "prompts": [
          {
            "text": "1girl"
          }
        ],
        "sampler": "DPM++ 2M Karras",
        "sdVae": "Automatic",
        "steps": 15,
        "sd_model": "600423083519508503", //checkpoint
        "clip_skip": 2,
        "cfg_scale": 7
      }
    },
    {
      "type": "IMAGE_TO_ADETAILER",
      "image_to_adetailer": {
        "args": [
          {
            "ad_model": "face_yolov8s.pt",
            "ad_confidence": 0.7,
            "ad_dilate_erode": 4,
            "ad_denoising_strength": 0.4,
            "ad_inpaint_only_masked": true,
            "ad_inpaint_only_masked_padding": 32
          }
        ]
      }
    }
  ]
}
Upscaler
对图片直接进行Upscaler,不进行Diffusion
警告
不做Diffusion操作,因此inputInitialize.count只能为1
虽然不做Diffusion,但是image_to_upscaler仍然需要带原始图片diffusion的参数
{
  "request_id": "unique_key",
  "stages": [
    {
      "type": "INPUT_INITIALIZE",
      "inputInitialize": {
        "image_resource_id": "f204c24a-52dc-4cf4-930a-9b8f73969414",
        "count": 1 //数量
      }
    },
    {
      "type": "IMAGE_TO_UPSCALER",
      "image_to_upscaler": {
        "hr_upscaler": "Latent",
        "hr_scale": 2,
        "hr_second_pass_steps": 10,
        "denoising_strength": 0.3,
        "diffusion": {
          "width": 512, //宽
          "height": 512, //高
          "prompts": [
            {
              "text": "1girl"
            }
          ],
          "sampler": "DPM++ 2M Karras",
          "sdVae": "Automatic",
          "steps": 15,
          "sd_model": "600423083519508503", //checkpoint
          "clip_skip": 2,
          "cfg_scale": 7
        }
      }
    }
  ]
}
图生图+Upscaler
警告
当使用图生图+Upscaler情况下,image_to_upscaler.hr_upscaler禁止使用latent,因为latent只在txt2img的Diffusion阶段生效
{
  "request_id": "unique_key",
  "stages": [
    {
      "type": "INPUT_INITIALIZE",
      "inputInitialize": {
        "image_resource_id": "f204c24a-52dc-4cf4-930a-9b8f73969414",
        "count": 2 //数量
      }
    },
    {
      "type": "DIFFUSION",
      "diffusion": {
        "width": 512, //宽
        "height": 512, //高
        "prompts": [
          {
            "text": "1girl"
          }
        ],
        "sampler": "DPM++ 2M Karras",
        "sdVae": "Automatic",
        "steps": 15,
        "sd_model": "600423083519508503", //checkpoint
        "clip_skip": 2,
        "cfg_scale": 7
      }
    },
    {
      "type": "IMAGE_TO_UPSCALER",
      "image_to_upscaler": {
        "hr_upscaler": "4x-UltraSharp",
        "hr_scale": 2,
        "hr_second_pass_steps": 10,
        "denoising_strength": 0.3
      }
    }
  ]
}
Inpaint
对图片直接进行Inpaint,不进行Diffusion
首先我们先来生成一张待处理的图
请求内容:
{
  "requestId": "unique_key",
  "stages": [
    {
      "type": "INPUT_INITIALIZE",
      "inputInitialize": { "seed": "933011881", "count": 1 }
    },
    {
      "type": "DIFFUSION",
      "diffusion": {
        "width": 512,
        "height": 768,
        "prompts": [
          { "text": "wide shot" },
          { "text": "(depth of field)" },
          { "text": "global illumination" },
          { "text": "soft shadows" },
          { "text": "grand scene" },
          { "text": "backlight" },
          { "text": "lens flare" },
          { "text": "((colorful refraction))" },
          { "text": "((cinematic lighting))" },
          { "text": "in the market" },
          { "text": "looking outside" },
          { "text": "with butterfly" },
          { "text": "1girl with lightblue long hair and blue aqua eyes" },
          { "text": "hair flowers" },
          { "text": "hime cut" },
          { "text": "sunlight" },
          { "text": "blurry background" },
          { "text": "blurry" },
          { "text": "White Dress" },
          { "text": "full of flowers" },
          { "text": "light bule butterfly" },
          { "text": " from side" },
          { "text": "floating hair" }
        ],
        "negativePrompts": [
          { "text": " (worst quality" },
          { "text": " low quality:1.4)" },
          { "text": " negative_hand Negative Embedding" },
          { "text": "verybadimagenegative_v1.3" },
          {}
        ],
        "sdModel": "681693017352010007",
        "sdVae": "None",
        "sampler": "DPM++ 3M SDE Karras",
        "steps": 25,
        "cfgScale": 5,
        "clipSkip": 2,
        "denoisingStrength": 0.4,
        "lora": {}
      }
    },
    {
      "type": "IMAGE_TO_UPSCALER",
      "imageToUpscaler": {
        "hrUpscaler": "4x-AnimeSharp",
        "hrResizeX": 1536,
        "hrResizeY": 2304,
        "hrSecondPassSteps": 10,
        "denoisingStrength": 0.4
      }
    }
  ]
}
提示
记得将请求中的requestId换成自己的唯一ID
我们得到了一张图片

然后我们需要一张Mask图
可以使用一些图片编辑工具,来进行绘制一张黑底图,将需要重绘的部分涂成白色
提示
Mask图片格式记得要是JPEG,且Mask图片分辨率要和原始图片的分辨率完全一致
我们来对人物的脸部进行一次重绘,得到了一张脸部局部涂抹的Mask图

进行inpaint重绘
我们目标将脸部重绘,增加哭的表情,眼瞳并且是红色的 inpaint的结构:
{
  "imageToInpaint": {
    "resizeMode": "JUST_RESIZE",
    "maskImageResourceId": "48203af7-6b07-4f1c-8506-f3f545613653",
    "maskBlur": 4,
    "inpaintingFill": "ORIGINAL",
    "inpaintFullRes": true,
    "inpaintFullResPadding": 32,
    "diffusion": {
      "width": 512,
      "height": 768,
      "prompts": [
        {
          "text": "crying"
        },
        {
          "text": " (red eyes:1.5)"
        }
      ],
      "negativePrompts": [
        {
          "text": " (worst quality,  low quality:1.4)"
        },
        {
          "text": " negative_hand Negative Embedding"
        },
        {
          "text": "verybadimagenegative_v1.3"
        },
        {}
      ],
      "sdModel": "681693017352010007",
      "sdVae": "None",
      "sampler": "DPM++ 3M SDE Karras",
      "steps": 25,
      "cfgScale": 5,
      "clipSkip": 2,
      "denoisingStrength": 0.4,
      "lora": {}
    }
  }
}
完整的请求示例:
{
  "requestId": "685205102316761513",
  "stages": [
    {
      "type": "INPUT_INITIALIZE",
      "inputInitialize": {
        "seed": "-1",
        "imageResourceId": "67f8de0b-4949-4f88-abb4-cf57b16459da",
        "count": 1
      }
    },
    {
      "type": "IMAGE_TO_INPAINT",
      "imageToInpaint": {
        "resizeMode": "JUST_RESIZE",
        "maskImageResourceId": "48203af7-6b07-4f1c-8506-f3f545613653",
        "maskBlur": 4,
        "inpaintingFill": "ORIGINAL",
        "inpaintFullRes": true,
        "inpaintFullResPadding": 32,
        "diffusion": {
          "width": 512,
          "height": 768,
          "prompts": [{ "text": "crying" }, { "text": " (red eyes:1.5)" }],
          "negativePrompts": [
            { "text": " (worst quality" },
            { "text": " low quality:1.4)" },
            { "text": " negative_hand Negative Embedding" },
            { "text": "verybadimagenegative_v1.3" },
            {}
          ],
          "sdModel": "681693017352010007",
          "sdVae": "None",
          "sampler": "DPM++ 3M SDE Karras",
          "steps": 25,
          "cfgScale": 5,
          "clipSkip": 2,
          "denoisingStrength": 0.4,
          "lora": {}
        }
      }
    }
  ]
}
最终得到效果图如下:
