|
1 | 1 | from time import time |
2 | | -from typing import Any |
3 | | -import numpy as np |
4 | | -from cv2 import Canny, bitwise_not |
| 2 | + |
5 | 3 | import torch |
6 | | -from diffusers import StableDiffusionControlNetPipeline, ControlNetModel |
7 | | -from PIL import Image, ImageOps |
| 4 | +from diffusers import ControlNetModel, StableDiffusionControlNetPipeline |
| 5 | +from PIL import ImageOps |
8 | 6 |
|
9 | 7 | from backend.computing import Computing |
| 8 | +from backend.controlnet.controls.image_control_factory import ImageControlFactory |
| 9 | +from backend.image_ops import resize_pil_image |
10 | 10 | from backend.stablediffusion.models.scheduler_types import SchedulerType |
11 | | -from backend.stablediffusion.models.setting import ( |
12 | | - StableDiffusionControlnetSetting, |
13 | | -) |
| 11 | +from backend.stablediffusion.models.setting import StableDiffusionControlnetSetting |
14 | 12 | from backend.stablediffusion.scheduler_mixin import SamplerMixin |
15 | | -from backend.image_ops import resize_pil_image |
16 | 13 | from backend.stablediffusion.stable_diffusion_types import ( |
17 | | - get_diffusion_type, |
18 | 14 | StableDiffusionType, |
| 15 | + get_diffusion_type, |
19 | 16 | ) |
20 | | -from backend.controlnet.controls.image_control_factory import ImageControlFactory |
21 | 17 |
|
22 | 18 |
|
23 | 19 | class ControlnetContext(SamplerMixin): |
@@ -134,16 +130,6 @@ def _load_model(self): |
134 | 130 | else: |
135 | 131 | self._load_full_precision_model() |
136 | 132 |
|
137 | | - def get_canny_image(self, image: Image) -> Any: |
138 | | - low_threshold = 100 |
139 | | - high_threshold = 200 |
140 | | - image = np.array(image) |
141 | | - image = Canny(image, low_threshold, high_threshold) |
142 | | - image_inv = bitwise_not(image) |
143 | | - image = image[:, :, None] |
144 | | - image = np.concatenate([image, image, image], axis=2) |
145 | | - return Image.fromarray(image), Image.fromarray(image_inv) |
146 | | - |
147 | 133 | def _enable_slicing(self, setting: StableDiffusionControlnetSetting): |
148 | 134 | if setting.attention_slicing: |
149 | 135 | self.controlnet_pipeline.enable_attention_slicing() |
|
0 commit comments