Skip to content

Commit

Permalink
Fix image watermark and quality issues in Instant ID model
Browse files Browse the repository at this point in the history
  • Loading branch information
zsxkib committed May 30, 2024
1 parent fbe076a commit b658d58
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
7 changes: 4 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# https://docs.docker.com/engine/reference/builder/#dockerignore-file

# Replicate
checkpoints/
models/
safety-cache/
/checkpoints/
/models/
/safety-cache/
/gradio_cached_examples/
*.mp4
*.pth
*.pt
Expand Down
26 changes: 22 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,28 @@ checkpoints/
models/

# Cog
.cog/
checkpoints/
models/
safety-cache/
/.cog/
/checkpoints/
/models/
/safety-cache/
*.tar
.vscode
gradio_cached_examples
cog/test_batchsize.py
input.png
output_*.png
output.*.png
output_image_*.png
output_image.*.png
output_*.webp
output.*.webp
output_image_*.webp
output_image.*.webp
output_*.jpg
output.*.jpg
output_image_*.jpg
output_image.*.jpg
output_*.jpeg
output.*.jpeg
output_image_*.jpeg
output_image.*.jpeg
24 changes: 22 additions & 2 deletions cog/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from diffusers.pipelines.stable_diffusion.safety_checker import (
StableDiffusionSafetyChecker,
)
from pipeline_stable_diffusion_xl_instantid import (
from pipeline_stable_diffusion_xl_instantid_full import (
StableDiffusionXLInstantIDPipeline,
draw_kps,
)
Expand Down Expand Up @@ -214,12 +214,13 @@ def setup(self) -> None:
if not os.path.exists(MODELS_CACHE):
download_weights(MODELS_URL, MODELS_CACHE)

self.face_detection_input_width, self.face_detection_input_height = 640, 640
self.app = FaceAnalysis(
name="antelopev2",
root="./",
providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
)
self.app.prepare(ctx_id=0, det_size=(640, 640))
self.app.prepare(ctx_id=0, det_size=(self.face_detection_input_width, self.face_detection_input_height))

# Path to InstantID models
self.face_adapter = f"./checkpoints/ip-adapter.bin"
Expand Down Expand Up @@ -548,6 +549,18 @@ def predict(
"RealVisXL_V4.0_Lightning",
],
),
face_detection_input_width: int = Input(
description="Width of the input image for face detection",
default=640,
ge=640,
le=4096,
),
face_detection_input_height: int = Input(
description="Height of the input image for face detection",
default=640,
ge=640,
le=4096,
),
scheduler: str = Input(
description="Scheduler",
choices=[
Expand Down Expand Up @@ -670,6 +683,13 @@ def predict(
if sdxl_weights != self.base_weights:
self.load_weights(sdxl_weights)

# Resize the output if the provided dimensions are different from the current ones
if self.face_detection_input_width != face_detection_input_width or self.face_detection_input_height != face_detection_input_height:
print(f"[!] Resizing output to {face_detection_input_width}x{face_detection_input_height}")
self.face_detection_input_width = face_detection_input_width
self.face_detection_input_height = face_detection_input_height
self.app.prepare(ctx_id=0, det_size=(self.face_detection_input_width, self.face_detection_input_height))

# Set up ControlNet selection and their respective strength values (if any)
controlnet_selection = []
if pose_strength > 0 and enable_pose_controlnet:
Expand Down

0 comments on commit b658d58

Please sign in to comment.