Spaces:
Running
Running
zhiweili
commited on
Commit
·
6b4da21
1
Parent(s):
f77d828
test multi adapter
Browse files
app_haircolor_inpaint_adapter_15.py
CHANGED
@@ -27,6 +27,7 @@ from controlnet_aux import (
|
|
27 |
)
|
28 |
|
29 |
BASE_MODEL = "stable-diffusion-v1-5/stable-diffusion-v1-5"
|
|
|
30 |
|
31 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
32 |
|
@@ -42,26 +43,26 @@ lineart_detector = lineart_detector.to(DEVICE)
|
|
42 |
pidiNet_detector = PidiNetDetector.from_pretrained('lllyasviel/Annotators')
|
43 |
pidiNet_detector = pidiNet_detector.to(DEVICE)
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
# )
|
59 |
-
# adapters = adapters.to(torch.float16)
|
60 |
-
adapters = T2IAdapter.from_pretrained(
|
61 |
-
"TencentARC/t2iadapter_sketch_sd15v2",
|
62 |
-
torch_dtype=torch.float16,
|
63 |
-
varient="fp16",
|
64 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
basepipeline = DiffusionPipeline.from_pretrained(
|
67 |
BASE_MODEL,
|
@@ -93,16 +94,16 @@ def image_to_image(
|
|
93 |
time_cost_str = ''
|
94 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
95 |
# canny_image = canny_detector(input_image, int(generate_size*1), generate_size)
|
96 |
-
|
97 |
# lineart_image = lineart_detector(input_image, int(generate_size*1), generate_size)
|
98 |
# run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
99 |
pidiNet_image = pidiNet_detector(input_image, int(generate_size*1), generate_size)
|
100 |
pidiNet_image = pidiNet_image.convert("L")
|
101 |
-
|
102 |
-
|
103 |
|
104 |
-
cond_image = pidiNet_image
|
105 |
-
cond_scale = cond_scale1
|
106 |
|
107 |
generator = torch.Generator(device=DEVICE).manual_seed(seed)
|
108 |
generated_image = basepipeline(
|
|
|
27 |
)
|
28 |
|
29 |
BASE_MODEL = "stable-diffusion-v1-5/stable-diffusion-v1-5"
|
30 |
+
# BASE_MODEL = "stable-diffusion-v1-5/stable-diffusion-inpainting"
|
31 |
|
32 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
33 |
|
|
|
43 |
pidiNet_detector = PidiNetDetector.from_pretrained('lllyasviel/Annotators')
|
44 |
pidiNet_detector = pidiNet_detector.to(DEVICE)
|
45 |
|
46 |
+
adapters = MultiAdapter(
|
47 |
+
[
|
48 |
+
T2IAdapter.from_pretrained(
|
49 |
+
"TencentARC/t2iadapter_canny_sd15v2",
|
50 |
+
torch_dtype=torch.float16,
|
51 |
+
varient="fp16",
|
52 |
+
),
|
53 |
+
T2IAdapter.from_pretrained(
|
54 |
+
"TencentARC/t2iadapter_sketch_sd15v2",
|
55 |
+
torch_dtype=torch.float16,
|
56 |
+
varient="fp16",
|
57 |
+
),
|
58 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
)
|
60 |
+
adapters = adapters.to(torch.float16)
|
61 |
+
# adapters = T2IAdapter.from_pretrained(
|
62 |
+
# "TencentARC/t2iadapter_sketch_sd15v2",
|
63 |
+
# torch_dtype=torch.float16,
|
64 |
+
# varient="fp16",
|
65 |
+
# )
|
66 |
|
67 |
basepipeline = DiffusionPipeline.from_pretrained(
|
68 |
BASE_MODEL,
|
|
|
94 |
time_cost_str = ''
|
95 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
96 |
# canny_image = canny_detector(input_image, int(generate_size*1), generate_size)
|
97 |
+
canny_image = custom_canny_detector(input_image)
|
98 |
# lineart_image = lineart_detector(input_image, int(generate_size*1), generate_size)
|
99 |
# run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
100 |
pidiNet_image = pidiNet_detector(input_image, int(generate_size*1), generate_size)
|
101 |
pidiNet_image = pidiNet_image.convert("L")
|
102 |
+
cond_image = [canny_image, pidiNet_image]
|
103 |
+
cond_scale = [cond_scale1, cond_scale2]
|
104 |
|
105 |
+
# cond_image = pidiNet_image
|
106 |
+
# cond_scale = cond_scale1
|
107 |
|
108 |
generator = torch.Generator(device=DEVICE).manual_seed(seed)
|
109 |
generated_image = basepipeline(
|