Skip to content

Commit

Permalink
feat: add color annotator, minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikubill committed Mar 5, 2023
1 parent 9acfb6d commit cdc807a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
6 changes: 6 additions & 0 deletions annotator/color/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import cv2

def apply_color(img, res=512):
input_img_color = cv2.resize(img, (res//64, res//64), interpolation=cv2.INTER_CUBIC)
input_img_color = cv2.resize(input_img_color, (res, res), interpolation=cv2.INTER_NEAREST)
return input_img_color
6 changes: 0 additions & 6 deletions models/color_adapter_v14.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions models/style_adapter_v14.yaml

This file was deleted.

5 changes: 3 additions & 2 deletions scripts/controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def __init__(self) -> None:
"openpose": openpose,
"openpose_hand": openpose_hand,
"clip_vision": clip,
"color": color,
"pidinet": pidinet,
"scribble": simple_scribble,
"fake_scribble": fake_scribble,
Expand Down Expand Up @@ -535,7 +536,7 @@ def parse_remote_call(self, p, params, idx):
return (enabled, module, model, weight, image, scribble_mode, \
resize_mode, rgbbgr_mode, lowvram, pres, pthr_a, pthr_b, guidance_start, guidance_end, guess_mode), input_image

def detectmap_proc(self, module, rgbbgr_mode, resize_mode, h, w):
def detectmap_proc(self, detected_map, module, rgbbgr_mode, resize_mode, h, w):
detected_map = HWC3(detected_map)
if module == "normal_map" or rgbbgr_mode:
control = torch.from_numpy(detected_map[:, :, ::-1].copy()).float().to(devices.get_device_for("controlnet")) / 255.0
Expand Down Expand Up @@ -691,7 +692,7 @@ def process(self, p, is_img2img=False, *args):
detected_map, is_image = preprocessor(input_image)

if is_image:
control, detected_map = self.detectmap_proc(detected_map, rgbbgr_mode, resize_mode, h, w)
control, detected_map = self.detectmap_proc(detected_map, module, rgbbgr_mode, resize_mode, h, w)
detected_maps.append((detected_map, module))
else:
control = detected_map
Expand Down
14 changes: 13 additions & 1 deletion scripts/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,16 @@ def unload_clip():
global clip_encoder
if clip_encoder is not None:
from annotator.clip import unload_clip_model
unload_clip_model()
unload_clip_model()


model_color = None


def color(img, res=512, **kwargs):
global model_color
if model_color is None:
from annotator.color import apply_color
model_color = apply_color
result = model_color(img, res=res)
return result, True

0 comments on commit cdc807a

Please sign in to comment.