John6666 commited on
Commit
af4b6de
Β·
verified Β·
1 Parent(s): be39db2

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ imgs/bedroom_1.jpg filter=lfs diff=lfs merge=lfs -text
37
+ imgs/bedroom_2.jpg filter=lfs diff=lfs merge=lfs -text
38
+ imgs/dinning_room_1.jpg filter=lfs diff=lfs merge=lfs -text
39
+ imgs/dinning_room_3.jpg filter=lfs diff=lfs merge=lfs -text
40
+ imgs/living_room_1.jpg filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
  title: StableDesign
3
- emoji: πŸŒ–
4
- colorFrom: gray
5
- colorTo: purple
6
  sdk: gradio
7
- sdk_version: 5.25.0
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: StableDesign
3
+ emoji: πŸ†
4
+ colorFrom: yellow
5
+ colorTo: gray
6
  sdk: gradio
7
+ sdk_version: 4.26.0
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,377 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ from typing import Tuple, Union, List
3
+ import os
4
+
5
+ import numpy as np
6
+ from PIL import Image
7
+
8
+ import torch
9
+ from diffusers.pipelines.controlnet import StableDiffusionControlNetInpaintPipeline
10
+ from diffusers import ControlNetModel, UniPCMultistepScheduler, AutoPipelineForText2Image
11
+ from transformers import AutoImageProcessor, UperNetForSemanticSegmentation, AutoModelForDepthEstimation
12
+ from colors import ade_palette
13
+ from utils import map_colors_rgb
14
+ from diffusers import StableDiffusionXLPipeline
15
+ import gradio as gr
16
+ import gc
17
+
18
+ device = "cuda"
19
+ dtype = torch.float16
20
+
21
+
22
+ css = """
23
+ #img-display-container {
24
+ max-height: 50vh;
25
+ }
26
+ #img-display-input {
27
+ max-height: 40vh;
28
+ }
29
+ #img-display-output {
30
+ max-height: 40vh;
31
+ }
32
+
33
+ """
34
+
35
+
36
+ def filter_items(
37
+ colors_list: Union[List, np.ndarray],
38
+ items_list: Union[List, np.ndarray],
39
+ items_to_remove: Union[List, np.ndarray]
40
+ ) -> Tuple[Union[List, np.ndarray], Union[List, np.ndarray]]:
41
+ """
42
+ Filters items and their corresponding colors from given lists, excluding
43
+ specified items.
44
+
45
+ Args:
46
+ colors_list: A list or numpy array of colors corresponding to items.
47
+ items_list: A list or numpy array of items.
48
+ items_to_remove: A list or numpy array of items to be removed.
49
+
50
+ Returns:
51
+ A tuple of two lists or numpy arrays: filtered colors and filtered
52
+ items.
53
+ """
54
+ filtered_colors = []
55
+ filtered_items = []
56
+ for color, item in zip(colors_list, items_list):
57
+ if item not in items_to_remove:
58
+ filtered_colors.append(color)
59
+ filtered_items.append(item)
60
+ return filtered_colors, filtered_items
61
+
62
+ def get_segmentation_pipeline(
63
+ ) -> Tuple[AutoImageProcessor, UperNetForSemanticSegmentation]:
64
+ """Method to load the segmentation pipeline
65
+ Returns:
66
+ Tuple[AutoImageProcessor, UperNetForSemanticSegmentation]: segmentation pipeline
67
+ """
68
+ image_processor = AutoImageProcessor.from_pretrained(
69
+ "openmmlab/upernet-convnext-small"
70
+ )
71
+ image_segmentor = UperNetForSemanticSegmentation.from_pretrained(
72
+ "openmmlab/upernet-convnext-small"
73
+ )
74
+ return image_processor, image_segmentor
75
+
76
+
77
+ @torch.inference_mode()
78
+ @spaces.GPU
79
+ def segment_image(
80
+ image: Image,
81
+ image_processor: AutoImageProcessor,
82
+ image_segmentor: UperNetForSemanticSegmentation
83
+ ) -> Image:
84
+ """
85
+ Segments an image using a semantic segmentation model.
86
+
87
+ Args:
88
+ image (Image): The input image to be segmented.
89
+ image_processor (AutoImageProcessor): The processor to prepare the
90
+ image for segmentation.
91
+ image_segmentor (UperNetForSemanticSegmentation): The semantic
92
+ segmentation model used to identify different segments in the image.
93
+
94
+ Returns:
95
+ Image: The segmented image with each segment colored differently based
96
+ on its identified class.
97
+ """
98
+ # image_processor, image_segmentor = get_segmentation_pipeline()
99
+ pixel_values = image_processor(image, return_tensors="pt").pixel_values
100
+ with torch.no_grad():
101
+ outputs = image_segmentor(pixel_values)
102
+
103
+ seg = image_processor.post_process_semantic_segmentation(
104
+ outputs, target_sizes=[image.size[::-1]])[0]
105
+ color_seg = np.zeros((seg.shape[0], seg.shape[1], 3), dtype=np.uint8)
106
+ palette = np.array(ade_palette())
107
+ for label, color in enumerate(palette):
108
+ color_seg[seg == label, :] = color
109
+ color_seg = color_seg.astype(np.uint8)
110
+ seg_image = Image.fromarray(color_seg).convert('RGB')
111
+ return seg_image
112
+
113
+
114
+ def get_depth_pipeline():
115
+ feature_extractor = AutoImageProcessor.from_pretrained("LiheYoung/depth-anything-large-hf",
116
+ torch_dtype=dtype)
117
+ depth_estimator = AutoModelForDepthEstimation.from_pretrained("LiheYoung/depth-anything-large-hf",
118
+ torch_dtype=dtype)
119
+ return feature_extractor, depth_estimator
120
+
121
+
122
+ @torch.inference_mode()
123
+ @spaces.GPU
124
+ def get_depth_image(
125
+ image: Image,
126
+ feature_extractor: AutoImageProcessor,
127
+ depth_estimator: AutoModelForDepthEstimation
128
+ ) -> Image:
129
+ image_to_depth = feature_extractor(images=image, return_tensors="pt").to(device)
130
+ with torch.no_grad():
131
+ depth_map = depth_estimator(**image_to_depth).predicted_depth
132
+
133
+ width, height = image.size
134
+ depth_map = torch.nn.functional.interpolate(
135
+ depth_map.unsqueeze(1).float(),
136
+ size=(height, width),
137
+ mode="bicubic",
138
+ align_corners=False,
139
+ )
140
+ depth_min = torch.amin(depth_map, dim=[1, 2, 3], keepdim=True)
141
+ depth_max = torch.amax(depth_map, dim=[1, 2, 3], keepdim=True)
142
+ depth_map = (depth_map - depth_min) / (depth_max - depth_min)
143
+ image = torch.cat([depth_map] * 3, dim=1)
144
+
145
+ image = image.permute(0, 2, 3, 1).cpu().numpy()[0]
146
+ image = Image.fromarray((image * 255.0).clip(0, 255).astype(np.uint8))
147
+ return image
148
+
149
+
150
+ def resize_dimensions(dimensions, target_size):
151
+ """
152
+ Resize PIL to target size while maintaining aspect ratio
153
+ If smaller than target size leave it as is
154
+ """
155
+ width, height = dimensions
156
+
157
+ # Check if both dimensions are smaller than the target size
158
+ if width < target_size and height < target_size:
159
+ return dimensions
160
+
161
+ # Determine the larger side
162
+ if width > height:
163
+ # Calculate the aspect ratio
164
+ aspect_ratio = height / width
165
+ # Resize dimensions
166
+ return (target_size, int(target_size * aspect_ratio))
167
+ else:
168
+ # Calculate the aspect ratio
169
+ aspect_ratio = width / height
170
+ # Resize dimensions
171
+ return (int(target_size * aspect_ratio), target_size)
172
+
173
+
174
+ def flush():
175
+ gc.collect()
176
+ torch.cuda.empty_cache()
177
+
178
+
179
+ class ControlNetDepthDesignModelMulti:
180
+ """ Produces random noise images """
181
+
182
+ def __init__(self):
183
+ """ Initialize your model(s) here """
184
+ #os.environ['HF_HUB_OFFLINE'] = "True"
185
+
186
+ self.seed = 323*111
187
+ self.neg_prompt = "window, door, low resolution, banner, logo, watermark, text, deformed, blurry, out of focus, surreal, ugly, beginner"
188
+ self.control_items = ["windowpane;window", "door;double;door"]
189
+ self.additional_quality_suffix = "interior design, 4K, high resolution, photorealistic"
190
+
191
+ @spaces.GPU
192
+ def generate_design(self, empty_room_image: Image, prompt: str, guidance_scale: int = 10, num_steps: int = 50, strength: float =0.9, img_size: int = 640) -> Image:
193
+ """
194
+ Given an image of an empty room and a prompt
195
+ generate the designed room according to the prompt
196
+ Inputs -
197
+ empty_room_image - An RGB PIL Image of the empty room
198
+ prompt - Text describing the target design elements of the room
199
+ Returns -
200
+ design_image - PIL Image of the same size as the empty room image
201
+ If the size is not the same the submission will fail.
202
+ """
203
+ print(prompt)
204
+ flush()
205
+ self.generator = torch.Generator(device=device).manual_seed(self.seed)
206
+
207
+ pos_prompt = prompt + f', {self.additional_quality_suffix}'
208
+
209
+ orig_w, orig_h = empty_room_image.size
210
+ new_width, new_height = resize_dimensions(empty_room_image.size, img_size)
211
+ input_image = empty_room_image.resize((new_width, new_height))
212
+ real_seg = np.array(segment_image(input_image,
213
+ seg_image_processor,
214
+ image_segmentor))
215
+ unique_colors = np.unique(real_seg.reshape(-1, real_seg.shape[2]), axis=0)
216
+ unique_colors = [tuple(color) for color in unique_colors]
217
+ segment_items = [map_colors_rgb(i) for i in unique_colors]
218
+ chosen_colors, segment_items = filter_items(
219
+ colors_list=unique_colors,
220
+ items_list=segment_items,
221
+ items_to_remove=self.control_items
222
+ )
223
+ mask = np.zeros_like(real_seg)
224
+ for color in chosen_colors:
225
+ color_matches = (real_seg == color).all(axis=2)
226
+ mask[color_matches] = 1
227
+
228
+ image_np = np.array(input_image)
229
+ image = Image.fromarray(image_np).convert("RGB")
230
+ mask_image = Image.fromarray((mask * 255).astype(np.uint8)).convert("RGB")
231
+ segmentation_cond_image = Image.fromarray(real_seg).convert("RGB")
232
+
233
+ image_depth = get_depth_image(image, depth_feature_extractor, depth_estimator)
234
+
235
+ # generate image that would be used as IP-adapter
236
+ flush()
237
+ new_width_ip = int(new_width / 8) * 8
238
+ new_height_ip = int(new_height / 8) * 8
239
+ ip_image = guide_pipe(pos_prompt,
240
+ num_inference_steps=num_steps,
241
+ negative_prompt=self.neg_prompt,
242
+ height=new_height_ip,
243
+ width=new_width_ip,
244
+ generator=[self.generator]).images[0]
245
+
246
+ flush()
247
+ generated_image = pipe(
248
+ prompt=pos_prompt,
249
+ negative_prompt=self.neg_prompt,
250
+ num_inference_steps=num_steps,
251
+ strength=strength,
252
+ guidance_scale=guidance_scale,
253
+ generator=[self.generator],
254
+ image=image,
255
+ mask_image=mask_image,
256
+ ip_adapter_image=ip_image,
257
+ control_image=[image_depth, segmentation_cond_image],
258
+ controlnet_conditioning_scale=[0.5, 0.5]
259
+ ).images[0]
260
+
261
+ flush()
262
+ design_image = generated_image.resize(
263
+ (orig_w, orig_h), Image.Resampling.LANCZOS
264
+ )
265
+
266
+ return design_image
267
+
268
+
269
+ def create_demo(model):
270
+ gr.Markdown("### Stable Design demo")
271
+ with gr.Row():
272
+ with gr.Column():
273
+ input_image = gr.Image(label="Input Image", type='pil', elem_id='img-display-input')
274
+ input_text = gr.Textbox(label='Prompt', placeholder='Please upload your image first', lines=2)
275
+ with gr.Accordion('Advanced options', open=False):
276
+ num_steps = gr.Slider(label='Steps',
277
+ minimum=1,
278
+ maximum=50,
279
+ value=50,
280
+ step=1)
281
+ img_size = gr.Slider(label='Image size',
282
+ minimum=256,
283
+ maximum=768,
284
+ value=768,
285
+ step=64)
286
+ guidance_scale = gr.Slider(label='Guidance Scale',
287
+ minimum=0.1,
288
+ maximum=30.0,
289
+ value=10.0,
290
+ step=0.1)
291
+ seed = gr.Slider(label='Seed',
292
+ minimum=-1,
293
+ maximum=2147483647,
294
+ value=323*111,
295
+ step=1,
296
+ randomize=True)
297
+ strength = gr.Slider(label='Strength',
298
+ minimum=0.1,
299
+ maximum=1.0,
300
+ value=0.9,
301
+ step=0.1)
302
+ a_prompt = gr.Textbox(
303
+ label='Added Prompt',
304
+ value="interior design, 4K, high resolution, photorealistic")
305
+ n_prompt = gr.Textbox(
306
+ label='Negative Prompt',
307
+ value="window, door, low resolution, banner, logo, watermark, text, deformed, blurry, out of focus, surreal, ugly, beginner")
308
+ submit = gr.Button("Submit")
309
+
310
+ with gr.Column():
311
+ design_image = gr.Image(label="Output Mask", elem_id='img-display-output')
312
+
313
+
314
+ def on_submit(image, text, num_steps, guidance_scale, seed, strength, a_prompt, n_prompt, img_size):
315
+ model.seed = seed
316
+ model.neg_prompt = n_prompt
317
+ model.additional_quality_suffix = a_prompt
318
+
319
+ with torch.no_grad():
320
+ out_img = model.generate_design(image, text, guidance_scale=guidance_scale, num_steps=num_steps, strength=strength, img_size=img_size)
321
+
322
+ return out_img
323
+
324
+ submit.click(on_submit, inputs=[input_image, input_text, num_steps, guidance_scale, seed, strength, a_prompt, n_prompt, img_size], outputs=design_image)
325
+ examples = gr.Examples(examples=[["imgs/bedroom_1.jpg", "An elegantly appointed bedroom in the Art Deco style, featuring a grand king-size bed with geometric bedding, a luxurious velvet armchair, and a mirrored nightstand that reflects the room's opulence. Art Deco-inspired artwork adds a touch of glamour"], ["imgs/bedroom_2.jpg", "A bedroom that exudes French country charm with a soft upholstered bed, walls adorned with floral wallpaper, and a vintage wooden wardrobe. A crystal chandelier casts a warm, inviting glow over the space"], ["imgs/dinning_room_1.jpg", "A cozy dining room that captures the essence of rustic charm with a solid wooden farmhouse table at its core, surrounded by an eclectic mix of mismatched chairs. An antique sideboard serves as a statement piece, and the ambiance is warmly lit by a series of quaint Edison bulbs dangling from the ceiling"], ["imgs/dinning_room_3.jpg", "A dining room that epitomizes contemporary elegance, anchored by a sleek, minimalist dining table paired with stylish modern chairs. Artistic lighting fixtures create a focal point above, while the surrounding minimalist decor ensures the space feels open, airy, and utterly modern"], ["imgs/image_1.jpg", "A glamorous master bedroom in Hollywood Regency style, boasting a plush tufted headboard, mirrored furniture reflecting elegance, luxurious fabrics in rich textures, and opulent gold accents for a touch of luxury."], ["imgs/image_2.jpg", "A vibrant living room with a tropical theme, complete with comfortable rattan furniture, large leafy plants bringing the outdoors in, bright cushions adding pops of color, and bamboo blinds for natural light control."], ["imgs/living_room_1.jpg", "A stylish living room embracing mid-century modern aesthetics, featuring a vintage teak coffee table at its center, complemented by a classic sunburst clock on the wall and a cozy shag rug underfoot, creating a warm and inviting atmosphere"]],
326
+ inputs=[input_image, input_text], cache_examples=False)
327
+
328
+
329
+ controlnet_depth= ControlNetModel.from_pretrained(
330
+ "controlnet_depth", torch_dtype=dtype, use_safetensors=True)
331
+ controlnet_seg = ControlNetModel.from_pretrained(
332
+ "own_controlnet", torch_dtype=dtype, use_safetensors=True)
333
+
334
+ pipe = StableDiffusionControlNetInpaintPipeline.from_pretrained(
335
+ "SG161222/Realistic_Vision_V5.1_noVAE",
336
+ #"models/runwayml--stable-diffusion-inpainting",
337
+ controlnet=[controlnet_depth, controlnet_seg],
338
+ safety_checker=None,
339
+ torch_dtype=dtype
340
+ )
341
+
342
+ pipe.load_ip_adapter("h94/IP-Adapter", subfolder="models",
343
+ weight_name="ip-adapter_sd15.bin")
344
+ pipe.set_ip_adapter_scale(0.4)
345
+ pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
346
+ pipe = pipe.to(device)
347
+ guide_pipe = StableDiffusionXLPipeline.from_pretrained("segmind/SSD-1B",
348
+ torch_dtype=dtype, use_safetensors=True, variant="fp16")
349
+ guide_pipe = guide_pipe.to(device)
350
+
351
+ seg_image_processor, image_segmentor = get_segmentation_pipeline()
352
+ depth_feature_extractor, depth_estimator = get_depth_pipeline()
353
+ depth_estimator = depth_estimator.to(device)
354
+
355
+
356
+ def main():
357
+ model = ControlNetDepthDesignModelMulti()
358
+ print('Models uploaded successfully')
359
+
360
+ title = "# StableDesign"
361
+ description = """
362
+ <p style='font-size: 14px; margin-bottom: 10px;'><a href='https://www.linkedin.com/in/mykola-lavreniuk/'>Mykola Lavreniuk</a>, <a href='https://www.linkedin.com/in/bartosz-ludwiczuk-a677a760/'>Bartosz Ludwiczuk</a></p>
363
+ <p style='font-size: 16px; margin-bottom: 0px; margin-top=0px;'>Official demo for <strong>StableDesign:</strong> 2nd place solution for the Generative Interior Design 2024 <a href='https://www.aicrowd.com/challenges/generative-interior-design-challenge-2024/leaderboards?challenge_round_id=1314'>competition</a>. StableDesign is a deep learning model designed to harness the power of AI, providing innovative and creative tools for designers. Using our algorithms, images of empty rooms can be transformed into fully furnished spaces based on text descriptions. Please refer to our <a href='https://github.com/Lavreniuk/generative-interior-design'>GitHub</a> for more details.</p>
364
+ """
365
+ with gr.Blocks() as demo:
366
+ gr.Markdown(title)
367
+ gr.Markdown(description)
368
+
369
+ create_demo(model)
370
+ gr.HTML('''<br><br><br><center>You can duplicate this Space to skip the queue:<a href="https://huggingface.co/spaces/MykolaL/StableDesign?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a><br>
371
+ <p><img src="https://visitor-badge.glitch.me/badge?page_id=MykolaL/StableDesign" alt="visitors"></p></center>''')
372
+
373
+ demo.queue().launch(share=False)
374
+
375
+
376
+ if __name__ == '__main__':
377
+ main()
colors.py ADDED
@@ -0,0 +1,344 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Color mappings"""
2
+ from typing import List
3
+
4
+ TRIVIA = {
5
+ "#B47878": "building;edifice",
6
+ "#06E6E6": "sky",
7
+ "#04C803": "tree",
8
+ "#8C8C8C": "road;route",
9
+ "#04FA07": "grass",
10
+ "#96053D": "person;individual;someone;somebody;mortal;soul",
11
+ "#CCFF04": "plant;flora;plant;life",
12
+ "#787846": "earth;ground",
13
+ "#FF09E0": "house",
14
+ "#0066C8": "car;auto;automobile;machine;motorcar",
15
+ "#3DE6FA": "water",
16
+ "#FF3D06": "railing;rail",
17
+ "#FF5C00": "arcade;machine",
18
+ "#FFE000": "stairs;steps",
19
+ "#00F5FF": "fan",
20
+ "#FF008F": "step;stair",
21
+ "#1F00FF": "stairway;staircase",
22
+ "#FFD600": "radiator",
23
+ }
24
+
25
+ OBJECTS = {
26
+ "#CC05FF": "bed",
27
+ "#FF0633": "painting;picture",
28
+ "#DCDCDC": "mirror",
29
+ "#00FF14": "box",
30
+ "#FF0000": "flower",
31
+ "#FFA300": "book",
32
+ "#00FFC2": "television;television;receiver;television;set;tv;tv;set;idiot;box;boob;tube;telly;goggle;box",
33
+ "#F500FF": "pot;flowerpot",
34
+ "#00FFCC": "vase",
35
+ "#29FF00": "tray",
36
+ "#8FFF00": "poster;posting;placard;notice;bill;card",
37
+ "#5CFF00": "basket;handbasket",
38
+ "#00ADFF": "screen;door;screen",
39
+ }
40
+
41
+
42
+ SITTING = {
43
+ "#0B66FF": "sofa;couch;lounge",
44
+ "#CC4603": "chair",
45
+ "#07FFE0": "seat",
46
+ "#08FFD6": "armchair",
47
+ "#FFC207": "cushion",
48
+ "#00EBFF": "pillow",
49
+ "#00D6FF": "stool",
50
+ "#1400FF": "blanket;cover",
51
+ "#0A00FF": "swivel;chair",
52
+ "#FF9900": "ottoman;pouf;pouffe;puff;hassock",
53
+ }
54
+
55
+ LIGHTING = {
56
+ "#E0FF08": "lamp",
57
+ "#FFAD00": "light;light;source",
58
+ "#001FFF": "chandelier;pendant;pendent",
59
+ }
60
+
61
+ TABLES = {
62
+ "#FF0652": "table",
63
+ "#0AFF47": "desk",
64
+ }
65
+
66
+ CLOSETS = {
67
+ "#E005FF": "cabinet",
68
+ "#FF0747": "shelf",
69
+ "#07FFFF": "wardrobe;closet;press",
70
+ "#0633FF": "chest;of;drawers;chest;bureau;dresser",
71
+ "#0000FF": "case;display;case;showcase;vitrine",
72
+ }
73
+
74
+
75
+ BATHROOM = {
76
+ "#6608FF": "bathtub;bathing;tub;bath;tub",
77
+ "#00FF85": "toilet;can;commode;crapper;pot;potty;stool;throne",
78
+ "#0085FF": "shower",
79
+ "#FF0066": "towel",
80
+ }
81
+
82
+ WINDOWS = {
83
+ "#FF3307": "curtain;drape;drapery;mantle;pall",
84
+ "#E6E6E6": "windowpane;window",
85
+ "#00FF3D": "awning;sunshade;sunblind",
86
+ "#003DFF": "blind;screen",
87
+ }
88
+
89
+ FLOOR = {
90
+ "#FF095C": "rug;carpet;carpeting",
91
+ "#503232": "floor;flooring",
92
+ }
93
+
94
+ INTERIOR = {
95
+ "#787878": "wall",
96
+ "#787850": "ceiling",
97
+ "#08FF33": "door;double;door",
98
+ }
99
+
100
+ KITCHEN = {
101
+ "#00FF29": "kitchen;island",
102
+ "#14FF00": "refrigerator;icebox",
103
+ "#00A3FF": "sink",
104
+ "#EB0CFF": "counter",
105
+ "#D6FF00": "dishwasher;dish;washer;dishwashing;machine",
106
+ "#FF00EB": "microwave;microwave;oven",
107
+ "#47FF00": "oven",
108
+ "#66FF00": "clock",
109
+ "#00FFB8": "plate",
110
+ "#19C2C2": "glass;drinking;glass",
111
+ "#00FF99": "bar",
112
+ "#00FF0A": "bottle",
113
+ "#FF7000": "buffet;counter;sideboard",
114
+ "#B800FF": "washer;automatic;washer;washing;machine",
115
+ "#00FF70": "coffee;table;cocktail;table",
116
+ "#008FFF": "countertop",
117
+ "#33FF00": "stove;kitchen;stove;range;kitchen;range;cooking;stove",
118
+ }
119
+
120
+ LIVINGROOM = {
121
+ "#FA0A0F": "fireplace;hearth;open;fireplace",
122
+ "#FF4700": "pool;table;billiard;table;snooker;table",
123
+ }
124
+
125
+ OFFICE = {
126
+ "#00FFAD": "computer;computing;machine;computing;device;data;processor;electronic;computer;information;processing;system",
127
+ "#00FFF5": "bookcase",
128
+ "#0633FF": "chest;of;drawers;chest;bureau;dresser",
129
+ "#005CFF": "monitor;monitoring;device",
130
+ }
131
+
132
+
133
+ COLOR_MAPPING_CATEGORY_ = {
134
+ 'keep background': {'#FFFFFF': 'background'},
135
+ 'trivia': TRIVIA,
136
+ 'objects': OBJECTS,
137
+ 'sitting': SITTING,
138
+ 'lighting': LIGHTING,
139
+ 'tables': TABLES,
140
+ 'closets': CLOSETS,
141
+ 'bathroom': BATHROOM,
142
+ 'windows': WINDOWS,
143
+ 'floor': FLOOR,
144
+ 'interior': INTERIOR,
145
+ 'kitchen': KITCHEN,
146
+ 'livingroom': LIVINGROOM,
147
+ 'office': OFFICE}
148
+
149
+
150
+ COLOR_MAPPING_ = {
151
+ '#FFFFFF': 'background',
152
+ "#787878": "wall",
153
+ "#B47878": "building;edifice",
154
+ "#06E6E6": "sky",
155
+ "#503232": "floor;flooring",
156
+ "#04C803": "tree",
157
+ "#787850": "ceiling",
158
+ "#8C8C8C": "road;route",
159
+ "#CC05FF": "bed",
160
+ "#E6E6E6": "windowpane;window",
161
+ "#04FA07": "grass",
162
+ "#E005FF": "cabinet",
163
+ "#EBFF07": "sidewalk;pavement",
164
+ "#96053D": "person;individual;someone;somebody;mortal;soul",
165
+ "#787846": "earth;ground",
166
+ "#08FF33": "door;double;door",
167
+ "#FF0652": "table",
168
+ "#8FFF8C": "mountain;mount",
169
+ "#CCFF04": "plant;flora;plant;life",
170
+ "#FF3307": "curtain;drape;drapery;mantle;pall",
171
+ "#CC4603": "chair",
172
+ "#0066C8": "car;auto;automobile;machine;motorcar",
173
+ "#3DE6FA": "water",
174
+ "#FF0633": "painting;picture",
175
+ "#0B66FF": "sofa;couch;lounge",
176
+ "#FF0747": "shelf",
177
+ "#FF09E0": "house",
178
+ "#0907E6": "sea",
179
+ "#DCDCDC": "mirror",
180
+ "#FF095C": "rug;carpet;carpeting",
181
+ "#7009FF": "field",
182
+ "#08FFD6": "armchair",
183
+ "#07FFE0": "seat",
184
+ "#FFB806": "fence;fencing",
185
+ "#0AFF47": "desk",
186
+ "#FF290A": "rock;stone",
187
+ "#07FFFF": "wardrobe;closet;press",
188
+ "#E0FF08": "lamp",
189
+ "#6608FF": "bathtub;bathing;tub;bath;tub",
190
+ "#FF3D06": "railing;rail",
191
+ "#FFC207": "cushion",
192
+ "#FF7A08": "base;pedestal;stand",
193
+ "#00FF14": "box",
194
+ "#FF0829": "column;pillar",
195
+ "#FF0599": "signboard;sign",
196
+ "#0633FF": "chest;of;drawers;chest;bureau;dresser",
197
+ "#EB0CFF": "counter",
198
+ "#A09614": "sand",
199
+ "#00A3FF": "sink",
200
+ "#8C8C8C": "skyscraper",
201
+ "#FA0A0F": "fireplace;hearth;open;fireplace",
202
+ "#14FF00": "refrigerator;icebox",
203
+ "#1FFF00": "grandstand;covered;stand",
204
+ "#FF1F00": "path",
205
+ "#FFE000": "stairs;steps",
206
+ "#99FF00": "runway",
207
+ "#0000FF": "case;display;case;showcase;vitrine",
208
+ "#FF4700": "pool;table;billiard;table;snooker;table",
209
+ "#00EBFF": "pillow",
210
+ "#00ADFF": "screen;door;screen",
211
+ "#1F00FF": "stairway;staircase",
212
+ "#0BC8C8": "river",
213
+ "#FF5200": "bridge;span",
214
+ "#00FFF5": "bookcase",
215
+ "#003DFF": "blind;screen",
216
+ "#00FF70": "coffee;table;cocktail;table",
217
+ "#00FF85": "toilet;can;commode;crapper;pot;potty;stool;throne",
218
+ "#FF0000": "flower",
219
+ "#FFA300": "book",
220
+ "#FF6600": "hill",
221
+ "#C2FF00": "bench",
222
+ "#008FFF": "countertop",
223
+ "#33FF00": "stove;kitchen;stove;range;kitchen;range;cooking;stove",
224
+ "#0052FF": "palm;palm;tree",
225
+ "#00FF29": "kitchen;island",
226
+ "#00FFAD": "computer;computing;machine;computing;device;data;processor;electronic;computer;information;processing;system",
227
+ "#0A00FF": "swivel;chair",
228
+ "#ADFF00": "boat",
229
+ "#00FF99": "bar",
230
+ "#FF5C00": "arcade;machine",
231
+ "#FF00FF": "hovel;hut;hutch;shack;shanty",
232
+ "#FF00F5": "bus;autobus;coach;charabanc;double-decker;jitney;motorbus;motorcoach;omnibus;passenger;vehicle",
233
+ "#FF0066": "towel",
234
+ "#FFAD00": "light;light;source",
235
+ "#FF0014": "truck;motortruck",
236
+ "#FFB8B8": "tower",
237
+ "#001FFF": "chandelier;pendant;pendent",
238
+ "#00FF3D": "awning;sunshade;sunblind",
239
+ "#0047FF": "streetlight;street;lamp",
240
+ "#FF00CC": "booth;cubicle;stall;kiosk",
241
+ "#00FFC2": "television;television;receiver;television;set;tv;tv;set;idiot;box;boob;tube;telly;goggle;box",
242
+ "#00FF52": "airplane;aeroplane;plane",
243
+ "#000AFF": "dirt;track",
244
+ "#0070FF": "apparel;wearing;apparel;dress;clothes",
245
+ "#3300FF": "pole",
246
+ "#00C2FF": "land;ground;soil",
247
+ "#007AFF": "bannister;banister;balustrade;balusters;handrail",
248
+ "#00FFA3": "escalator;moving;staircase;moving;stairway",
249
+ "#FF9900": "ottoman;pouf;pouffe;puff;hassock",
250
+ "#00FF0A": "bottle",
251
+ "#FF7000": "buffet;counter;sideboard",
252
+ "#8FFF00": "poster;posting;placard;notice;bill;card",
253
+ "#5200FF": "stage",
254
+ "#A3FF00": "van",
255
+ "#FFEB00": "ship",
256
+ "#08B8AA": "fountain",
257
+ "#8500FF": "conveyer;belt;conveyor;belt;conveyer;conveyor;transporter",
258
+ "#00FF5C": "canopy",
259
+ "#B800FF": "washer;automatic;washer;washing;machine",
260
+ "#FF001F": "plaything;toy",
261
+ "#00B8FF": "swimming;pool;swimming;bath;natatorium",
262
+ "#00D6FF": "stool",
263
+ "#FF0070": "barrel;cask",
264
+ "#5CFF00": "basket;handbasket",
265
+ "#00E0FF": "waterfall;falls",
266
+ "#70E0FF": "tent;collapsible;shelter",
267
+ "#46B8A0": "bag",
268
+ "#A300FF": "minibike;motorbike",
269
+ "#9900FF": "cradle",
270
+ "#47FF00": "oven",
271
+ "#FF00A3": "ball",
272
+ "#FFCC00": "food;solid;food",
273
+ "#FF008F": "step;stair",
274
+ "#00FFEB": "tank;storage;tank",
275
+ "#85FF00": "trade;name;brand;name;brand;marque",
276
+ "#FF00EB": "microwave;microwave;oven",
277
+ "#F500FF": "pot;flowerpot",
278
+ "#FF007A": "animal;animate;being;beast;brute;creature;fauna",
279
+ "#FFF500": "bicycle;bike;wheel;cycle",
280
+ "#0ABED4": "lake",
281
+ "#D6FF00": "dishwasher;dish;washer;dishwashing;machine",
282
+ "#00CCFF": "screen;silver;screen;projection;screen",
283
+ "#1400FF": "blanket;cover",
284
+ "#FFFF00": "sculpture",
285
+ "#0099FF": "hood;exhaust;hood",
286
+ "#0029FF": "sconce",
287
+ "#00FFCC": "vase",
288
+ "#2900FF": "traffic;light;traffic;signal;stoplight",
289
+ "#29FF00": "tray",
290
+ "#AD00FF": "ashcan;trash;can;garbage;can;wastebin;ash;bin;ash-bin;ashbin;dustbin;trash;barrel;trash;bin",
291
+ "#00F5FF": "fan",
292
+ "#4700FF": "pier;wharf;wharfage;dock",
293
+ "#7A00FF": "crt;screen",
294
+ "#00FFB8": "plate",
295
+ "#005CFF": "monitor;monitoring;device",
296
+ "#B8FF00": "bulletin;board;notice;board",
297
+ "#0085FF": "shower",
298
+ "#FFD600": "radiator",
299
+ "#19C2C2": "glass;drinking;glass",
300
+ "#66FF00": "clock",
301
+ "#5C00FF": "flag",
302
+ }
303
+
304
+
305
+ def ade_palette() -> List[List[int]]:
306
+ """ADE20K palette that maps each class to RGB values."""
307
+ return [[120, 120, 120], [180, 120, 120], [6, 230, 230], [80, 50, 50],
308
+ [4, 200, 3], [120, 120, 80], [140, 140, 140], [204, 5, 255],
309
+ [230, 230, 230], [4, 250, 7], [224, 5, 255], [235, 255, 7],
310
+ [150, 5, 61], [120, 120, 70], [8, 255, 51], [255, 6, 82],
311
+ [143, 255, 140], [204, 255, 4], [255, 51, 7], [204, 70, 3],
312
+ [0, 102, 200], [61, 230, 250], [255, 6, 51], [11, 102, 255],
313
+ [255, 7, 71], [255, 9, 224], [9, 7, 230], [220, 220, 220],
314
+ [255, 9, 92], [112, 9, 255], [8, 255, 214], [7, 255, 224],
315
+ [255, 184, 6], [10, 255, 71], [255, 41, 10], [7, 255, 255],
316
+ [224, 255, 8], [102, 8, 255], [255, 61, 6], [255, 194, 7],
317
+ [255, 122, 8], [0, 255, 20], [255, 8, 41], [255, 5, 153],
318
+ [6, 51, 255], [235, 12, 255], [160, 150, 20], [0, 163, 255],
319
+ [140, 140, 140], [250, 10, 15], [20, 255, 0], [31, 255, 0],
320
+ [255, 31, 0], [255, 224, 0], [153, 255, 0], [0, 0, 255],
321
+ [255, 71, 0], [0, 235, 255], [0, 173, 255], [31, 0, 255],
322
+ [11, 200, 200], [255, 82, 0], [0, 255, 245], [0, 61, 255],
323
+ [0, 255, 112], [0, 255, 133], [255, 0, 0], [255, 163, 0],
324
+ [255, 102, 0], [194, 255, 0], [0, 143, 255], [51, 255, 0],
325
+ [0, 82, 255], [0, 255, 41], [0, 255, 173], [10, 0, 255],
326
+ [173, 255, 0], [0, 255, 153], [255, 92, 0], [255, 0, 255],
327
+ [255, 0, 245], [255, 0, 102], [255, 173, 0], [255, 0, 20],
328
+ [255, 184, 184], [0, 31, 255], [0, 255, 61], [0, 71, 255],
329
+ [255, 0, 204], [0, 255, 194], [0, 255, 82], [0, 10, 255],
330
+ [0, 112, 255], [51, 0, 255], [0, 194, 255], [0, 122, 255],
331
+ [0, 255, 163], [255, 153, 0], [0, 255, 10], [255, 112, 0],
332
+ [143, 255, 0], [82, 0, 255], [163, 255, 0], [255, 235, 0],
333
+ [8, 184, 170], [133, 0, 255], [0, 255, 92], [184, 0, 255],
334
+ [255, 0, 31], [0, 184, 255], [0, 214, 255], [255, 0, 112],
335
+ [92, 255, 0], [0, 224, 255], [112, 224, 255], [70, 184, 160],
336
+ [163, 0, 255], [153, 0, 255], [71, 255, 0], [255, 0, 163],
337
+ [255, 204, 0], [255, 0, 143], [0, 255, 235], [133, 255, 0],
338
+ [255, 0, 235], [245, 0, 255], [255, 0, 122], [255, 245, 0],
339
+ [10, 190, 212], [214, 255, 0], [0, 204, 255], [20, 0, 255],
340
+ [255, 255, 0], [0, 153, 255], [0, 41, 255], [0, 255, 204],
341
+ [41, 0, 255], [41, 255, 0], [173, 0, 255], [0, 245, 255],
342
+ [71, 0, 255], [122, 0, 255], [0, 255, 184], [0, 92, 255],
343
+ [184, 255, 0], [0, 133, 255], [255, 214, 0], [25, 194, 194],
344
+ [102, 255, 0], [92, 0, 255]]
controlnet_depth/config.json ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "ControlNetModel",
3
+ "_diffusers_version": "0.28.0.dev0",
4
+ "_name_or_path": "lllyasviel/sd-controlnet-depth",
5
+ "act_fn": "silu",
6
+ "addition_embed_type": null,
7
+ "addition_embed_type_num_heads": 64,
8
+ "addition_time_embed_dim": null,
9
+ "attention_head_dim": 8,
10
+ "block_out_channels": [
11
+ 320,
12
+ 640,
13
+ 1280,
14
+ 1280
15
+ ],
16
+ "class_embed_type": null,
17
+ "conditioning_channels": 3,
18
+ "conditioning_embedding_out_channels": [
19
+ 16,
20
+ 32,
21
+ 96,
22
+ 256
23
+ ],
24
+ "controlnet_conditioning_channel_order": "rgb",
25
+ "cross_attention_dim": 768,
26
+ "down_block_types": [
27
+ "CrossAttnDownBlock2D",
28
+ "CrossAttnDownBlock2D",
29
+ "CrossAttnDownBlock2D",
30
+ "DownBlock2D"
31
+ ],
32
+ "downsample_padding": 1,
33
+ "encoder_hid_dim": null,
34
+ "encoder_hid_dim_type": null,
35
+ "flip_sin_to_cos": true,
36
+ "freq_shift": 0,
37
+ "global_pool_conditions": false,
38
+ "in_channels": 4,
39
+ "layers_per_block": 2,
40
+ "mid_block_scale_factor": 1,
41
+ "mid_block_type": "UNetMidBlock2DCrossAttn",
42
+ "norm_eps": 1e-05,
43
+ "norm_num_groups": 32,
44
+ "num_attention_heads": null,
45
+ "num_class_embeds": null,
46
+ "only_cross_attention": false,
47
+ "projection_class_embeddings_input_dim": null,
48
+ "resnet_time_scale_shift": "default",
49
+ "transformer_layers_per_block": 1,
50
+ "upcast_attention": false,
51
+ "use_linear_projection": false
52
+ }
imgs/bedroom_1.jpg ADDED

Git LFS Details

  • SHA256: d08d2d4ccc42ba29a1482c38eb3a932ef69057d367c63e2280eb204a18cb5c97
  • Pointer size: 132 Bytes
  • Size of remote file: 2.36 MB
imgs/bedroom_2.jpg ADDED

Git LFS Details

  • SHA256: 1633f673dd5cc53a97b767e7c2a45ea9476ae7f3c72fa010e8d125bb4978ad87
  • Pointer size: 131 Bytes
  • Size of remote file: 432 kB
imgs/dinning_room_1.jpg ADDED

Git LFS Details

  • SHA256: 413d388107a7c0b5b54ab17b5a6526e6f63ee44dcf9348ec4ecee0744521cdf7
  • Pointer size: 131 Bytes
  • Size of remote file: 268 kB
imgs/dinning_room_3.jpg ADDED

Git LFS Details

  • SHA256: 9342f85cc9b7ff08e7a8ce113dbe7e16bde1c005d39228b020fa296bec054948
  • Pointer size: 131 Bytes
  • Size of remote file: 221 kB
imgs/image_1.jpg ADDED
imgs/image_2.jpg ADDED
imgs/living_room_1.jpg ADDED

Git LFS Details

  • SHA256: b58c299725c99e0671fd6dd86db1088e0d5d55059bb0845dee732d5b59af5c61
  • Pointer size: 131 Bytes
  • Size of remote file: 362 kB
own_controlnet/config.json ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "ControlNetModel",
3
+ "_diffusers_version": "0.21.1",
4
+ "_name_or_path": "BertChristiaens/controlnet-seg-room",
5
+ "act_fn": "silu",
6
+ "addition_embed_type": null,
7
+ "addition_embed_type_num_heads": 64,
8
+ "addition_time_embed_dim": null,
9
+ "attention_head_dim": 8,
10
+ "block_out_channels": [
11
+ 320,
12
+ 640,
13
+ 1280,
14
+ 1280
15
+ ],
16
+ "class_embed_type": null,
17
+ "conditioning_channels": 3,
18
+ "conditioning_embedding_out_channels": [
19
+ 16,
20
+ 32,
21
+ 96,
22
+ 256
23
+ ],
24
+ "controlnet_conditioning_channel_order": "rgb",
25
+ "cross_attention_dim": 768,
26
+ "down_block_types": [
27
+ "CrossAttnDownBlock2D",
28
+ "CrossAttnDownBlock2D",
29
+ "CrossAttnDownBlock2D",
30
+ "DownBlock2D"
31
+ ],
32
+ "downsample_padding": 1,
33
+ "dropout": 0.0,
34
+ "encoder_hid_dim": null,
35
+ "encoder_hid_dim_type": null,
36
+ "flip_sin_to_cos": true,
37
+ "freq_shift": 0,
38
+ "global_pool_conditions": false,
39
+ "in_channels": 4,
40
+ "layers_per_block": 2,
41
+ "mid_block_scale_factor": 1,
42
+ "norm_eps": 1e-05,
43
+ "norm_num_groups": 32,
44
+ "num_attention_heads": null,
45
+ "num_class_embeds": null,
46
+ "only_cross_attention": false,
47
+ "projection_class_embeddings_input_dim": null,
48
+ "resnet_time_scale_shift": "default",
49
+ "sample_size": 32,
50
+ "transformer_layers_per_block": 1,
51
+ "upcast_attention": false,
52
+ "use_linear_projection": false
53
+ }
palette.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict
2
+ from colors import COLOR_MAPPING_, COLOR_MAPPING_CATEGORY_
3
+
4
+
5
+ def convert_hex_to_rgba(hex_code: str) -> str:
6
+ """Convert hex code to rgba.
7
+ Args:
8
+ hex_code (str): hex string
9
+ Returns:
10
+ str: rgba string
11
+ """
12
+ hex_code = hex_code.lstrip('#')
13
+ return "rgba(" + str(int(hex_code[0:2], 16)) + ", " + str(int(hex_code[2:4], 16)) + ", " + str(int(hex_code[4:6], 16)) + ", 1.0)"
14
+
15
+
16
+ def convert_dict_to_rgba(color_dict: Dict) -> Dict:
17
+ """Convert hex code to rgba for all elements in a dictionary.
18
+ Args:
19
+ color_dict (Dict): color dictionary
20
+ Returns:
21
+ Dict: color dictionary with rgba values
22
+ """
23
+ updated_dict = {}
24
+ for k, v in color_dict.items():
25
+ updated_dict[convert_hex_to_rgba(k)] = v
26
+ return updated_dict
27
+
28
+
29
+ def convert_nested_dict_to_rgba(nested_dict):
30
+ updated_dict = {}
31
+ for k, v in nested_dict.items():
32
+ updated_dict[k] = convert_dict_to_rgba(v)
33
+ return updated_dict
34
+
35
+
36
+ COLOR_MAPPING = convert_dict_to_rgba(COLOR_MAPPING_)
37
+ COLOR_MAPPING_CATEGORY = convert_nested_dict_to_rgba(COLOR_MAPPING_CATEGORY_)
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ diffusers==0.25.0
2
+ xformers==0.0.23.post1
3
+ transformers==4.39.1
4
+ torchvision
5
+ accelerate==0.26.1
6
+ opencv-python==4.9.0.80
7
+ scipy==1.11.4
8
+ triton==2.1.0
9
+ altair==4.1.0
10
+ pandas==2.1.4
utils.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gc
2
+
3
+ import numpy as np
4
+ from PIL import Image
5
+ import torch
6
+ from scipy.signal import fftconvolve
7
+
8
+ from palette import COLOR_MAPPING, COLOR_MAPPING_
9
+
10
+
11
+ def to_rgb(color: str) -> tuple:
12
+ """Convert hex color to rgb.
13
+ Args:
14
+ color (str): hex color
15
+ Returns:
16
+ tuple: rgb color
17
+ """
18
+ return tuple(int(color[i:i+2], 16) for i in (1, 3, 5))
19
+
20
+
21
+ def map_colors(color: str) -> str:
22
+ """Map color to hex value.
23
+ Args:
24
+ color (str): color name
25
+ Returns:
26
+ str: hex value
27
+ """
28
+ return COLOR_MAPPING[color]
29
+
30
+
31
+ def map_colors_rgb(color: tuple) -> str:
32
+ return COLOR_MAPPING_RGB[color]
33
+
34
+
35
+ def convolution(mask: Image.Image, size=9) -> Image:
36
+ """Method to blur the mask
37
+ Args:
38
+ mask (Image): masking image
39
+ size (int, optional): size of the blur. Defaults to 9.
40
+ Returns:
41
+ Image: blurred mask
42
+ """
43
+ mask = np.array(mask.convert("L"))
44
+ conv = np.ones((size, size)) / size**2
45
+ mask_blended = fftconvolve(mask, conv, 'same')
46
+ mask_blended = mask_blended.astype(np.uint8).copy()
47
+
48
+ border = size
49
+
50
+ # replace borders with original values
51
+ mask_blended[:border, :] = mask[:border, :]
52
+ mask_blended[-border:, :] = mask[-border:, :]
53
+ mask_blended[:, :border] = mask[:, :border]
54
+ mask_blended[:, -border:] = mask[:, -border:]
55
+
56
+ return Image.fromarray(mask_blended).convert("L")
57
+
58
+
59
+ def flush():
60
+ gc.collect()
61
+ torch.cuda.empty_cache()
62
+
63
+
64
+ def postprocess_image_masking(inpainted: Image, image: Image,
65
+ mask: Image) -> Image:
66
+ """Method to postprocess the inpainted image
67
+ Args:
68
+ inpainted (Image): inpainted image
69
+ image (Image): original image
70
+ mask (Image): mask
71
+ Returns:
72
+ Image: inpainted image
73
+ """
74
+ final_inpainted = Image.composite(inpainted.convert("RGBA"),
75
+ image.convert("RGBA"), mask)
76
+ return final_inpainted.convert("RGB")
77
+
78
+
79
+ COLOR_NAMES = list(COLOR_MAPPING.keys())
80
+ COLOR_RGB = [to_rgb(k) for k in COLOR_MAPPING_.keys()] + [(0, 0, 0),
81
+ (255, 255, 255)]
82
+ INVERSE_COLORS = {v: to_rgb(k) for k, v in COLOR_MAPPING_.items()}
83
+ COLOR_MAPPING_RGB = {to_rgb(k): v for k, v in COLOR_MAPPING_.items()}