Views
No views yet
| Model Name | Control Image Overview | Control Image Example | Generated Image Example |
|---|---|---|---|
| TencentARC/t2iadapter_color_sd14v1 Trained with spatial color palette | A image with 8x8 color palette. | ![]() | ![]() |
| TencentARC/t2iadapter_canny_sd14v1 Trained with canny edge detection | A monochrome image with white edges on a black background. | ![]() | ![]() |
| TencentARC/t2iadapter_sketch_sd14v1 Trained with PidiNet edge detection | A hand-drawn monochrome image with white outlines on a black background. | ![]() | ![]() |
| TencentARC/t2iadapter_depth_sd14v1 Trained with Midas depth estimation | A grayscale image with black representing deep areas and white representing shallow areas. | ![]() | ![]() |
| TencentARC/t2iadapter_openpose_sd14v1 Trained with OpenPose bone image | A OpenPose bone image. | ![]() | ![]() |
| TencentARC/t2iadapter_keypose_sd14v1 Trained with mmpose skeleton image | A mmpose skeleton image. | ![]() | ![]() |
| TencentARC/t2iadapter_seg_sd14v1 Trained with semantic segmentation | An custom segmentation protocol image. | ![]() | ![]() |
| TencentARC/t2iadapter_canny_sd15v2 | |||
| TencentARC/t2iadapter_depth_sd15v2 | |||
| TencentARC/t2iadapter_sketch_sd15v2 | |||
| TencentARC/t2iadapter_zoedepth_sd15v1 |
pip install diffusers transformers1import torch
2from PIL import Image
3import numpy as np
4from transformers import AutoImageProcessor, UperNetForSemanticSegmentation
5
6from diffusers import (
7 T2IAdapter,
8 StableDiffusionAdapterPipeline
9)
10
11ada_palette = np.asarray([
12 [0, 0, 0],
13 [120, 120, 120],
14 [180, 120, 120],
15 [6, 230, 230],
16 [80, 50, 50],
17 [4, 200, 3],
18 [120, 120, 80],
19 [140, 140, 140],
20 [204, 5, 255],
21 [230, 230, 230],
22 [4, 250, 7],
23 [224, 5, 255],
24 [235, 255, 7],
25 [150, 5, 61],
26 [120, 120, 70],
27 [8, 255, 51],
28 [255, 6, 82],
29 [143, 255, 140],
30 [204, 255, 4],
31 [255, 51, 7],
32 [204, 70, 3],
33 [0, 102, 200],
34 [61, 230, 250],
35 [255, 6, 51],
36 [11, 102, 255],
37 [255, 7, 71],
38 [255, 9, 224],
39 [9, 7, 230],
40 [220, 220, 220],
41 [255, 9, 92],
42 [112, 9, 255],
43 [8, 255, 214],
44 [7, 255, 224],
45 [255, 184, 6],
46 [10, 255, 71],
47 [255, 41, 10],
48 [7, 255, 255],
49 [224, 255, 8],
50 [102, 8, 255],
51 [255, 61, 6],
52 [255, 194, 7],
53 [255, 122, 8],
54 [0, 255, 20],
55 [255, 8, 41],
56 [255, 5, 153],
57 [6, 51, 255],
58 [235, 12, 255],
59 [160, 150, 20],
60 [0, 163, 255],
61 [140, 140, 140],
62 [250, 10, 15],
63 [20, 255, 0],
64 [31, 255, 0],
65 [255, 31, 0],
66 [255, 224, 0],
67 [153, 255, 0],
68 [0, 0, 255],
69 [255, 71, 0],
70 [0, 235, 255],
71 [0, 173, 255],
72 [31, 0, 255],
73 [11, 200, 200],
74 [255, 82, 0],
75 [0, 255, 245],
76 [0, 61, 255],
77 [0, 255, 112],
78 [0, 255, 133],
79 [255, 0, 0],
80 [255, 163, 0],
81 [255, 102, 0],
82 [194, 255, 0],
83 [0, 143, 255],
84 [51, 255, 0],
85 [0, 82, 255],
86 [0, 255, 41],
87 [0, 255, 173],
88 [10, 0, 255],
89 [173, 255, 0],
90 [0, 255, 153],
91 [255, 92, 0],
92 [255, 0, 255],
93 [255, 0, 245],
94 [255, 0, 102],
95 [255, 173, 0],
96 [255, 0, 20],
97 [255, 184, 184],
98 [0, 31, 255],
99 [0, 255, 61],
100 [0, 71, 255],
101 [255, 0, 204],
102 [0, 255, 194],
103 [0, 255, 82],
104 [0, 10, 255],
105 [0, 112, 255],
106 [51, 0, 255],
107 [0, 194, 255],
108 [0, 122, 255],
109 [0, 255, 163],
110 [255, 153, 0],
111 [0, 255, 10],
112 [255, 112, 0],
113 [143, 255, 0],
114 [82, 0, 255],
115 [163, 255, 0],
116 [255, 235, 0],
117 [8, 184, 170],
118 [133, 0, 255],
119 [0, 255, 92],
120 [184, 0, 255],
121 [255, 0, 31],
122 [0, 184, 255],
123 [0, 214, 255],
124 [255, 0, 112],
125 [92, 255, 0],
126 [0, 224, 255],
127 [112, 224, 255],
128 [70, 184, 160],
129 [163, 0, 255],
130 [153, 0, 255],
131 [71, 255, 0],
132 [255, 0, 163],
133 [255, 204, 0],
134 [255, 0, 143],
135 [0, 255, 235],
136 [133, 255, 0],
137 [255, 0, 235],
138 [245, 0, 255],
139 [255, 0, 122],
140 [255, 245, 0],
141 [10, 190, 212],
142 [214, 255, 0],
143 [0, 204, 255],
144 [20, 0, 255],
145 [255, 255, 0],
146 [0, 153, 255],
147 [0, 41, 255],
148 [0, 255, 204],
149 [41, 0, 255],
150 [41, 255, 0],
151 [173, 0, 255],
152 [0, 245, 255],
153 [71, 0, 255],
154 [122, 0, 255],
155 [0, 255, 184],
156 [0, 92, 255],
157 [184, 255, 0],
158 [0, 133, 255],
159 [255, 214, 0],
160 [25, 194, 194],
161 [102, 255, 0],
162 [92, 0, 255],
163 ])
164
165
166image_processor = AutoImageProcessor.from_pretrained("openmmlab/upernet-convnext-small")
167image_segmentor = UperNetForSemanticSegmentation.from_pretrained("openmmlab/upernet-convnext-small")
168
169checkpoint = "lllyasviel/control_v11p_sd15_seg"
170
171image = Image.open('./images/seg_input.jpeg')
172
173pixel_values = image_processor(image, return_tensors="pt").pixel_values
174with torch.no_grad():
175 outputs = image_segmentor(pixel_values)
176
177seg = image_processor.post_process_semantic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
178
179color_seg = np.zeros((seg.shape[0], seg.shape[1], 3), dtype=np.uint8) # height, width, 3
180
181for label, color in enumerate(ada_palette):
182 color_seg[seg == label, :] = color
183
184color_seg = color_seg.astype(np.uint8)
185control_image = Image.fromarray(color_seg)
186
187control_image.save("./images/segment_image.png")
188
189adapter = T2IAdapter.from_pretrained("TencentARC/t2iadapter_seg_sd14v1", torch_dtype=torch.float16)
190pipe = StableDiffusionAdapterPipeline.from_pretrained(
191 "CompVis/stable-diffusion-v1-4", adapter=adapter, safety_checker=None, torch_dtype=torch.float16, variant="fp16"
192)
193
194pipe.to('cuda')
195
196generator = torch.Generator().manual_seed(0)
197
198sketch_image_out = pipe(prompt="motorcycles driving", image=control_image, generator=generator).images[0]
199
200sketch_image_out.save('./images/seg_image_out.png')

