Skip to main content

custom pipeline for auto inpainting

Project description

asdff

Adetailer Stable Diffusion diFFusers pipeline

예시

from pip install

pip install asdff
import torch
from asdff import AdPipeline

pipe = AdPipeline.from_pretrained("stablediffusionapi/counterfeit-v30", torch_dtype=torch.float16)
pipe.safety_checker = None
pipe.to("cuda")

common = {"prompt": "masterpiece, best quality, 1girl", "num_inference_steps": 28}
result = pipe(common=common)

images = result[0]

from custom pipeline

ultralytics 설치 필요

pip install ultralytics
import torch
from diffusers import DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained(
    "stablediffusionapi/counterfeit-v30",
    torch_dtype=torch.float16,
    custom_pipeline="Bingsu/adsd_pipeline"
)
pipe.safety_checker = None
pipe.to("cuda")

common = {"prompt": "masterpiece, best quality, 1girl", "num_inference_steps": 28}
result = pipe(common=common)

images = result[0]

그 외

스케줄러를 변경하고, 입력 이미지를 제공하는 예시

import torch
from asdff import AdPipeline
from diffusers import DPMSolverMultistepScheduler
from diffusers.utils import load_image

pipe = AdPipeline.from_pretrained("stablediffusionapi/counterfeit-v30", torch_dtype=torch.float16)
pipe.safety_checker = None
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe = pipe.to("cuda")

common = {"prompt": "masterpiece, best quality, 1girl", "num_inference_steps": 20}
images = load_image("https://i.imgur.com/8TX2AX6.png")
result = pipe(common=common, images=[images])

arguments

  • common: Mapping[str, Any] | None

txt2img와 inpaint에서 공통적으로 사용할 인자들

  • txt2img_only: Mapping[str, Any] | None

txt2img에서만 사용할 인자. common과 겹치는 인자는 덮어씁니다.

StableDiffusionPipeline.call

  • inpaint_only: Mapping[str, Any] | None

inpaint에서만 사용할 인자. common과 겹치는 인자는 덮어씁니다.

strength: 0.4가 기본값으로 적용됩니다.

StableDiffusionInpaintPipeline.call

  • images: Image | Iterable[Image] | None

inpaint를 수행할 이미지들. 주어지면 txt2img의 결과를 대체하기 때문에 txt2img_only는 무시됩니다.

  • detectors: DetectorType | Iterable[DetectorType] | None

DetectorType: Callable[[Image.Image], Optional[List[Image.Image]]]

pil Image를 입력으로 받아 마스크 이미지의 리스트(마스크), 또는 None을 반환하는 Callable.

그런 Callable 하나, Callable의 리스트 또는 None

None일경우, default_detector가 사용됩니다.

from asdff import AdPipeline

pipe = AdPipeline.from_pretrained(...)
pipe.default_detector
>>> <function asdff.yolo.yolo_detector(image: 'Image.Image', model_path: 'str | None' = None, confidence: 'float' = 0.3) -> 'list[Image.Image] | None'>

사용 예시

from functools import partial

import torch
from asdff import AdPipeline, yolo_detector
from huggingface_hub import hf_hub_download

pipe = AdPipeline.from_pretrained("stablediffusionapi/counterfeit-v30", torch_dtype=torch.float16)
pipe.safety_checker = None
pipe.to("cuda")

person_model_path = hf_hub_download("Bingsu/adetailer", "person_yolov8s-seg.pt")
person_detector = partial(yolo_detector, model_path=person_model_path)
common = {"prompt": "masterpiece, best quality, 1girl", "num_inference_steps": 28}
result = pipe(common=common, detectors=[person_detector, pipe.default_detector])
result
  • mask_dilation: int, default = 4

마스크 감지 후, cv2.dilate 함수를 적용해 마스크 영역을 키우는 데, 이 때 적용할 커널의 크기.

  • mask_blur: int, default = 4

dilation 후 적용할 가우시안 블러의 커널 크기.

  • mask_padding: int, default = 32

dilation 적용 후 이 값만큼 bbox의 가로세로 영역을 더해서 이미지를 자른 뒤, inpaint를 시도하게 됩니다.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asdff-0.2.1.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

asdff-0.2.1-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file asdff-0.2.1.tar.gz.

File metadata

  • Download URL: asdff-0.2.1.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.9.3 CPython/3.11.6

File hashes

Hashes for asdff-0.2.1.tar.gz
Algorithm Hash digest
SHA256 311b09b52d904b89c341fbea12657b53de497768fa49d07bc185ff6c1b18cc4d
MD5 a5b11bdb30b623e391fd5fbe94e87805
BLAKE2b-256 95f92f013ec57e9385b4102d6a8164fd3262c26afe530117d5ceeebc39d15435

See more details on using hashes here.

File details

Details for the file asdff-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: asdff-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.9.3 CPython/3.11.6

File hashes

Hashes for asdff-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 766e682b531ba4fb83c008a0924c94074e8702ef3afa907dbd82919471e74cc8
MD5 14ddb8ebbd5f8d5ee9d654fffca194fc
BLAKE2b-256 2d7a3469c5883e831344fac9c3ffc530ec30f66688845277fc459d73f27de849

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page