Tony Lian commited on
Commit
ec7f11c
1 Parent(s): 9668cda

Allow using different schedulers and negative prompts

Browse files
Files changed (6) hide show
  1. app.py +19 -4
  2. baseline.py +5 -4
  3. generation.py +7 -16
  4. models/models.py +4 -7
  5. models/pipelines.py +4 -4
  6. shared.py +6 -2
app.py CHANGED
@@ -8,6 +8,7 @@ from utils.parse import filter_boxes
8
  from generation import run as run_ours
9
  from baseline import run as run_baseline
10
  import torch
 
11
  from examples import stage1_examples, stage2_examples
12
 
13
  print(f"Is CUDA available: {torch.cuda.is_available()}")
@@ -87,7 +88,7 @@ def get_layout_image(response):
87
  def get_layout_image_gallery(response):
88
  return [get_layout_image(response)]
89
 
90
- def get_ours_image(response, seed, num_inference_steps, fg_seed_start, fg_blending_ratio=0.1, frozen_step_ratio=0.4, gligen_scheduled_sampling_beta=0.3, show_so_imgs=False, scale_boxes=False):
91
  if response == "":
92
  response = layout_placeholder
93
  gen_boxes, bg_prompt = parse_input(response)
@@ -98,10 +99,18 @@ def get_ours_image(response, seed, num_inference_steps, fg_seed_start, fg_blendi
98
  'gen_boxes': gen_boxes,
99
  'bg_prompt': bg_prompt
100
  }
 
 
 
 
 
 
101
  image_np, so_img_list = run_ours(
102
  spec, bg_seed=seed, fg_seed_start=fg_seed_start,
103
  fg_blending_ratio=fg_blending_ratio,frozen_step_ratio=frozen_step_ratio,
104
- gligen_scheduled_sampling_beta=gligen_scheduled_sampling_beta, num_inference_steps=num_inference_steps)
 
 
105
  images = [image_np]
106
  if show_so_imgs:
107
  images.extend([np.asarray(so_img) for so_img in so_img_list])
@@ -110,7 +119,10 @@ def get_ours_image(response, seed, num_inference_steps, fg_seed_start, fg_blendi
110
  def get_baseline_image(prompt, seed):
111
  if prompt == "":
112
  prompt = prompt_placeholder
113
- image_np = run_baseline(prompt, bg_seed=seed)
 
 
 
114
  return [image_np]
115
 
116
  def parse_input(text=None):
@@ -232,17 +244,20 @@ with gr.Blocks(
232
  with gr.Accordion("Advanced options", open=False):
233
  seed = gr.Slider(0, 10000, value=0, step=1, label="Seed")
234
  num_inference_steps = gr.Slider(1, 50, value=20, step=1, label="Number of inference steps")
 
235
  fg_seed_start = gr.Slider(0, 10000, value=20, step=1, label="Seed for foreground variation")
236
  fg_blending_ratio = gr.Slider(0, 1, value=0.1, step=0.01, label="Variations added to foreground for single object generation (0: no variation, 1: max variation)")
237
  frozen_step_ratio = gr.Slider(0, 1, value=0.4, step=0.1, label="Foreground frozen steps ratio (higher: preserve object attributes; lower: higher coherence; set to 0: (almost) equivalent to vanilla GLIGEN except details)")
238
  gligen_scheduled_sampling_beta = gr.Slider(0, 1, value=0.3, step=0.1, label="GLIGEN guidance steps ratio (the beta value)")
 
 
239
  show_so_imgs = gr.Checkbox(label="Show annotated single object generations", show_label=False)
240
  with gr.Column(scale=1):
241
  gallery = gr.Gallery(
242
  label="Generated image", show_label=False, elem_id="gallery"
243
  ).style(columns=[1], rows=[1], object_fit="contain", preview=True)
244
  visualize_btn.click(fn=get_layout_image_gallery, inputs=response, outputs=gallery, api_name="visualize-layout")
245
- generate_btn.click(fn=get_ours_image, inputs=[response, seed, num_inference_steps, fg_seed_start, fg_blending_ratio, frozen_step_ratio, gligen_scheduled_sampling_beta, show_so_imgs], outputs=gallery, api_name="layout-to-image")
246
 
247
  gr.Examples(
248
  stage2_examples,
 
8
  from generation import run as run_ours
9
  from baseline import run as run_baseline
10
  import torch
11
+ from shared import DEFAULT_SO_NEGATIVE_PROMPT, DEFAULT_OVERALL_NEGATIVE_PROMPT
12
  from examples import stage1_examples, stage2_examples
13
 
14
  print(f"Is CUDA available: {torch.cuda.is_available()}")
 
88
  def get_layout_image_gallery(response):
89
  return [get_layout_image(response)]
90
 
91
+ def get_ours_image(response, seed, num_inference_steps, dpm_scheduler, fg_seed_start, fg_blending_ratio=0.1, frozen_step_ratio=0.4, gligen_scheduled_sampling_beta=0.3, so_negative_prompt="", overall_negative_prompt="", show_so_imgs=False, scale_boxes=False):
92
  if response == "":
93
  response = layout_placeholder
94
  gen_boxes, bg_prompt = parse_input(response)
 
99
  'gen_boxes': gen_boxes,
100
  'bg_prompt': bg_prompt
101
  }
102
+
103
+ if dpm_scheduler:
104
+ scheduler_key = "dpm_scheduler"
105
+ else:
106
+ scheduler_key = "scheduler"
107
+
108
  image_np, so_img_list = run_ours(
109
  spec, bg_seed=seed, fg_seed_start=fg_seed_start,
110
  fg_blending_ratio=fg_blending_ratio,frozen_step_ratio=frozen_step_ratio,
111
+ gligen_scheduled_sampling_beta=gligen_scheduled_sampling_beta, num_inference_steps=num_inference_steps, scheduler_key=scheduler_key,
112
+ so_negative_prompt=so_negative_prompt, overall_negative_prompt=overall_negative_prompt
113
+ )
114
  images = [image_np]
115
  if show_so_imgs:
116
  images.extend([np.asarray(so_img) for so_img in so_img_list])
 
119
  def get_baseline_image(prompt, seed):
120
  if prompt == "":
121
  prompt = prompt_placeholder
122
+
123
+ scheduler_key = "dpm_scheduler"
124
+
125
+ image_np = run_baseline(prompt, bg_seed=seed, scheduler_key=scheduler_key)
126
  return [image_np]
127
 
128
  def parse_input(text=None):
 
244
  with gr.Accordion("Advanced options", open=False):
245
  seed = gr.Slider(0, 10000, value=0, step=1, label="Seed")
246
  num_inference_steps = gr.Slider(1, 50, value=20, step=1, label="Number of inference steps")
247
+ dpm_scheduler = gr.Checkbox(label="Use DPM scheduler (unchecked: DDIM scheduler, may have better coherence, recommend 50 inference steps)", show_label=False, value=True)
248
  fg_seed_start = gr.Slider(0, 10000, value=20, step=1, label="Seed for foreground variation")
249
  fg_blending_ratio = gr.Slider(0, 1, value=0.1, step=0.01, label="Variations added to foreground for single object generation (0: no variation, 1: max variation)")
250
  frozen_step_ratio = gr.Slider(0, 1, value=0.4, step=0.1, label="Foreground frozen steps ratio (higher: preserve object attributes; lower: higher coherence; set to 0: (almost) equivalent to vanilla GLIGEN except details)")
251
  gligen_scheduled_sampling_beta = gr.Slider(0, 1, value=0.3, step=0.1, label="GLIGEN guidance steps ratio (the beta value)")
252
+ so_negative_prompt = gr.Textbox(lines=1, label="Negative prompt for single object generation", value=DEFAULT_SO_NEGATIVE_PROMPT)
253
+ overall_negative_prompt = gr.Textbox(lines=1, label="Negative prompt for overall generation", value=DEFAULT_OVERALL_NEGATIVE_PROMPT)
254
  show_so_imgs = gr.Checkbox(label="Show annotated single object generations", show_label=False)
255
  with gr.Column(scale=1):
256
  gallery = gr.Gallery(
257
  label="Generated image", show_label=False, elem_id="gallery"
258
  ).style(columns=[1], rows=[1], object_fit="contain", preview=True)
259
  visualize_btn.click(fn=get_layout_image_gallery, inputs=response, outputs=gallery, api_name="visualize-layout")
260
+ generate_btn.click(fn=get_ours_image, inputs=[response, seed, num_inference_steps, dpm_scheduler, fg_seed_start, fg_blending_ratio, frozen_step_ratio, gligen_scheduled_sampling_beta, so_negative_prompt, overall_negative_prompt, show_so_imgs], outputs=gallery, api_name="layout-to-image")
261
 
262
  gr.Examples(
263
  stage2_examples,
baseline.py CHANGED
@@ -3,7 +3,7 @@
3
  import torch
4
  import models
5
  from models import pipelines
6
- from shared import model_dict
7
 
8
  vae, tokenizer, text_encoder, unet, scheduler, dtype = model_dict.vae, model_dict.tokenizer, model_dict.text_encoder, model_dict.unet, model_dict.scheduler, model_dict.dtype
9
 
@@ -17,9 +17,10 @@ batch_size = 1
17
  # h, w
18
  image_scale = (512, 512)
19
 
20
- bg_negative = 'artifacts, blurry, smooth texture, bad quality, distortions, unrealistic, distorted image, bad proportions, duplicate'
21
 
22
- def run(prompt, bg_seed=1, num_inference_steps=20):
 
23
  print(f"prompt: {prompt}")
24
  generator = torch.Generator(models.torch_device).manual_seed(bg_seed)
25
 
@@ -34,7 +35,7 @@ def run(prompt, bg_seed=1, num_inference_steps=20):
34
  pipelines.gligen_enable_fuser(model_dict['unet'], enabled=False)
35
  _, images = pipelines.generate(
36
  model_dict, latents, input_embeddings, num_inference_steps,
37
- guidance_scale=guidance_scale
38
  )
39
 
40
  return images[0]
 
3
  import torch
4
  import models
5
  from models import pipelines
6
+ from shared import model_dict, DEFAULT_OVERALL_NEGATIVE_PROMPT
7
 
8
  vae, tokenizer, text_encoder, unet, scheduler, dtype = model_dict.vae, model_dict.tokenizer, model_dict.text_encoder, model_dict.unet, model_dict.scheduler, model_dict.dtype
9
 
 
17
  # h, w
18
  image_scale = (512, 512)
19
 
20
+ bg_negative = DEFAULT_OVERALL_NEGATIVE_PROMPT
21
 
22
+ # Using dpm scheduler by default
23
+ def run(prompt, scheduler_key='dpm_scheduler', bg_seed=1, num_inference_steps=20):
24
  print(f"prompt: {prompt}")
25
  generator = torch.Generator(models.torch_device).manual_seed(bg_seed)
26
 
 
35
  pipelines.gligen_enable_fuser(model_dict['unet'], enabled=False)
36
  _, images = pipelines.generate(
37
  model_dict, latents, input_embeddings, num_inference_steps,
38
+ guidance_scale=guidance_scale, scheduler_key=scheduler_key
39
  )
40
 
41
  return images[0]
generation.py CHANGED
@@ -1,17 +1,15 @@
1
  version = "v3.0"
2
 
3
- from PIL import Image
4
  import torch
5
  import models
6
- from models import load_sd
7
  import utils
8
  from models import pipelines, sam
9
  from utils import parse, latents
10
- from shared import model_dict, sam_model_dict
11
 
12
  verbose = False
13
 
14
- vae, tokenizer, text_encoder, unet, scheduler, dtype = model_dict.vae, model_dict.tokenizer, model_dict.text_encoder, model_dict.unet, model_dict.scheduler, model_dict.dtype
15
 
16
  model_dict.update(sam_model_dict)
17
 
@@ -37,14 +35,14 @@ run_ind = None
37
 
38
  def generate_single_object_with_box(prompt, box, phrase, word, input_latents, input_embeddings,
39
  sam_refine_kwargs, num_inference_steps, gligen_scheduled_sampling_beta=0.3,
40
- verbose=False, visualize=True):
41
 
42
  bboxes, phrases, words = [box], [phrase], [word]
43
 
44
  latents, single_object_images, single_object_pil_images_box_ann, latents_all = pipelines.generate_gligen(
45
  model_dict, input_latents, input_embeddings, num_inference_steps, bboxes, phrases, gligen_scheduled_sampling_beta=gligen_scheduled_sampling_beta,
46
  guidance_scale=guidance_scale, return_saved_cross_attn=False,
47
- return_box_vis=True, save_all_latents=True
48
  )
49
 
50
  mask_selected, conf_score_selected = sam.sam_refine_box(sam_input_image=single_object_images[0], box=box, model_dict=model_dict, verbose=verbose, **sam_refine_kwargs)
@@ -78,7 +76,7 @@ def get_masked_latents_all_list(so_prompt_phrase_word_box_list, input_latents_li
78
 
79
  def run(
80
  spec, bg_seed = 1, fg_seed_start = 20, frozen_step_ratio=0.4, gligen_scheduled_sampling_beta = 0.3, num_inference_steps = 20,
81
- so_center_box = False, fg_blending_ratio = 0.1, so_horizontal_center_only = True,
82
  align_with_overall_bboxes = False, horizontal_shift_only = True
83
  ):
84
  """
@@ -106,13 +104,6 @@ def run(
106
  print(f"centered so_prompt_phrase_word_box_list: {so_prompt_phrase_word_box_list}")
107
  so_boxes = [item[-1] for item in so_prompt_phrase_word_box_list]
108
 
109
- if True:
110
- so_negative_prompt = "artifacts, blurry, smooth texture, bad quality, distortions, unrealistic, distorted image, bad proportions, duplicate, two, many, group, occlusion, occluded, side, border, collate"
111
- overall_negative_prompt = "artifacts, blurry, smooth texture, bad quality, distortions, unrealistic, distorted image, bad proportions, duplicate"
112
- else:
113
- so_negative_prompt = ""
114
- overall_negative_prompt = ""
115
-
116
  sam_refine_kwargs = dict(
117
  discourage_mask_below_confidence=discourage_mask_below_confidence, discourage_mask_below_coarse_iou=discourage_mask_below_coarse_iou,
118
  height=height, width=width, H=H, W=W
@@ -139,7 +130,7 @@ def run(
139
  latents_all_list, mask_tensor_list, so_img_list = get_masked_latents_all_list(
140
  so_prompt_phrase_word_box_list, input_latents_list,
141
  gligen_scheduled_sampling_beta=gligen_scheduled_sampling_beta,
142
- sam_refine_kwargs=sam_refine_kwargs, so_input_embeddings=so_input_embeddings, num_inference_steps=num_inference_steps, verbose=verbose
143
  )
144
 
145
 
@@ -166,7 +157,7 @@ def run(
166
  model_dict, composed_latents, overall_input_embeddings, num_inference_steps,
167
  overall_bboxes_flattened, overall_phrases_flattened, guidance_scale=guidance_scale,
168
  gligen_scheduled_sampling_beta=gligen_scheduled_sampling_beta,
169
- frozen_steps=frozen_steps, frozen_mask=frozen_mask
170
  )
171
 
172
  print(f"Generation with spatial guidance from input latents and first {frozen_steps} steps frozen (directly from the composed latents input)")
 
1
  version = "v3.0"
2
 
 
3
  import torch
4
  import models
 
5
  import utils
6
  from models import pipelines, sam
7
  from utils import parse, latents
8
+ from shared import model_dict, sam_model_dict, DEFAULT_SO_NEGATIVE_PROMPT, DEFAULT_OVERALL_NEGATIVE_PROMPT
9
 
10
  verbose = False
11
 
12
+ vae, tokenizer, text_encoder, unet, dtype = model_dict.vae, model_dict.tokenizer, model_dict.text_encoder, model_dict.unet, model_dict.dtype
13
 
14
  model_dict.update(sam_model_dict)
15
 
 
35
 
36
  def generate_single_object_with_box(prompt, box, phrase, word, input_latents, input_embeddings,
37
  sam_refine_kwargs, num_inference_steps, gligen_scheduled_sampling_beta=0.3,
38
+ verbose=False, scheduler_key=None, visualize=True):
39
 
40
  bboxes, phrases, words = [box], [phrase], [word]
41
 
42
  latents, single_object_images, single_object_pil_images_box_ann, latents_all = pipelines.generate_gligen(
43
  model_dict, input_latents, input_embeddings, num_inference_steps, bboxes, phrases, gligen_scheduled_sampling_beta=gligen_scheduled_sampling_beta,
44
  guidance_scale=guidance_scale, return_saved_cross_attn=False,
45
+ return_box_vis=True, save_all_latents=True, scheduler_key=scheduler_key
46
  )
47
 
48
  mask_selected, conf_score_selected = sam.sam_refine_box(sam_input_image=single_object_images[0], box=box, model_dict=model_dict, verbose=verbose, **sam_refine_kwargs)
 
76
 
77
  def run(
78
  spec, bg_seed = 1, fg_seed_start = 20, frozen_step_ratio=0.4, gligen_scheduled_sampling_beta = 0.3, num_inference_steps = 20,
79
+ so_center_box = False, fg_blending_ratio = 0.1, scheduler_key='dpm_scheduler', so_negative_prompt = DEFAULT_SO_NEGATIVE_PROMPT, overall_negative_prompt = DEFAULT_OVERALL_NEGATIVE_PROMPT, so_horizontal_center_only = True,
80
  align_with_overall_bboxes = False, horizontal_shift_only = True
81
  ):
82
  """
 
104
  print(f"centered so_prompt_phrase_word_box_list: {so_prompt_phrase_word_box_list}")
105
  so_boxes = [item[-1] for item in so_prompt_phrase_word_box_list]
106
 
 
 
 
 
 
 
 
107
  sam_refine_kwargs = dict(
108
  discourage_mask_below_confidence=discourage_mask_below_confidence, discourage_mask_below_coarse_iou=discourage_mask_below_coarse_iou,
109
  height=height, width=width, H=H, W=W
 
130
  latents_all_list, mask_tensor_list, so_img_list = get_masked_latents_all_list(
131
  so_prompt_phrase_word_box_list, input_latents_list,
132
  gligen_scheduled_sampling_beta=gligen_scheduled_sampling_beta,
133
+ sam_refine_kwargs=sam_refine_kwargs, so_input_embeddings=so_input_embeddings, num_inference_steps=num_inference_steps, scheduler_key=scheduler_key, verbose=verbose
134
  )
135
 
136
 
 
157
  model_dict, composed_latents, overall_input_embeddings, num_inference_steps,
158
  overall_bboxes_flattened, overall_phrases_flattened, guidance_scale=guidance_scale,
159
  gligen_scheduled_sampling_beta=gligen_scheduled_sampling_beta,
160
+ frozen_steps=frozen_steps, frozen_mask=frozen_mask, scheduler_key=scheduler_key
161
  )
162
 
163
  print(f"Generation with spatial guidance from input latents and first {frozen_steps} steps frozen (directly from the composed latents input)")
models/models.py CHANGED
@@ -8,7 +8,7 @@ import numpy as np
8
  from utils.latents import get_unscaled_latents, get_scaled_latents, blend_latents
9
  from utils import torch_device
10
 
11
- def load_sd(key="runwayml/stable-diffusion-v1-5", use_fp16=False, load_inverse_scheduler=True, use_dpm_multistep_scheduler=False):
12
  """
13
  Keys:
14
  key = "CompVis/stable-diffusion-v1-4"
@@ -22,7 +22,6 @@ def load_sd(key="runwayml/stable-diffusion-v1-5", use_fp16=False, load_inverse_s
22
  ```
23
 
24
  use_fp16: fp16 might have degraded performance
25
- use_dpm_multistep_scheduler: DPMSolverMultistepScheduler
26
  """
27
 
28
  # run final results in fp32
@@ -37,12 +36,10 @@ def load_sd(key="runwayml/stable-diffusion-v1-5", use_fp16=False, load_inverse_s
37
  tokenizer = CLIPTokenizer.from_pretrained(key, subfolder="tokenizer", revision=revision, torch_dtype=dtype)
38
  text_encoder = CLIPTextModel.from_pretrained(key, subfolder="text_encoder", revision=revision, torch_dtype=dtype).to(torch_device)
39
  unet = UNet2DConditionModel.from_pretrained(key, subfolder="unet", revision=revision, torch_dtype=dtype).to(torch_device)
40
- if use_dpm_multistep_scheduler:
41
- scheduler = DPMSolverMultistepScheduler.from_pretrained(key, subfolder="scheduler", revision=revision, torch_dtype=dtype)
42
- else:
43
- scheduler = DDIMScheduler.from_pretrained(key, subfolder="scheduler", revision=revision, torch_dtype=dtype)
44
 
45
- model_dict = EasyDict(vae=vae, tokenizer=tokenizer, text_encoder=text_encoder, unet=unet, scheduler=scheduler, dtype=dtype)
46
 
47
  if load_inverse_scheduler:
48
  inverse_scheduler = DDIMInverseScheduler.from_config(scheduler.config)
 
8
  from utils.latents import get_unscaled_latents, get_scaled_latents, blend_latents
9
  from utils import torch_device
10
 
11
+ def load_sd(key="runwayml/stable-diffusion-v1-5", use_fp16=False, load_inverse_scheduler=True):
12
  """
13
  Keys:
14
  key = "CompVis/stable-diffusion-v1-4"
 
22
  ```
23
 
24
  use_fp16: fp16 might have degraded performance
 
25
  """
26
 
27
  # run final results in fp32
 
36
  tokenizer = CLIPTokenizer.from_pretrained(key, subfolder="tokenizer", revision=revision, torch_dtype=dtype)
37
  text_encoder = CLIPTextModel.from_pretrained(key, subfolder="text_encoder", revision=revision, torch_dtype=dtype).to(torch_device)
38
  unet = UNet2DConditionModel.from_pretrained(key, subfolder="unet", revision=revision, torch_dtype=dtype).to(torch_device)
39
+ dpm_scheduler = DPMSolverMultistepScheduler.from_pretrained(key, subfolder="scheduler", revision=revision, torch_dtype=dtype)
40
+ scheduler = DDIMScheduler.from_pretrained(key, subfolder="scheduler", revision=revision, torch_dtype=dtype)
 
 
41
 
42
+ model_dict = EasyDict(vae=vae, tokenizer=tokenizer, text_encoder=text_encoder, unet=unet, scheduler=scheduler, dpm_scheduler=dpm_scheduler, dtype=dtype)
43
 
44
  if load_inverse_scheduler:
45
  inverse_scheduler = DDIMInverseScheduler.from_config(scheduler.config)
models/pipelines.py CHANGED
@@ -53,8 +53,8 @@ def decode(vae, latents):
53
  return images
54
 
55
  @torch.no_grad()
56
- def generate(model_dict, latents, input_embeddings, num_inference_steps, guidance_scale = 7.5, no_set_timesteps=False):
57
- vae, tokenizer, text_encoder, unet, scheduler, dtype = model_dict.vae, model_dict.tokenizer, model_dict.text_encoder, model_dict.unet, model_dict.scheduler, model_dict.dtype
58
  text_embeddings, uncond_embeddings, cond_embeddings = input_embeddings
59
 
60
  if not no_set_timesteps:
@@ -93,11 +93,11 @@ def generate_gligen(model_dict, latents, input_embeddings, num_inference_steps,
93
  frozen_steps=20, frozen_mask=None,
94
  return_saved_cross_attn=False, saved_cross_attn_keys=None, return_cond_ca_only=False, return_token_ca_only=None,
95
  offload_cross_attn_to_cpu=False, offload_latents_to_cpu=True,
96
- return_box_vis=False, show_progress=True, save_all_latents=False):
97
  """
98
  The `bboxes` should be a list, rather than a list of lists (one box per phrase, we can have multiple duplicated phrases).
99
  """
100
- vae, tokenizer, text_encoder, unet, scheduler, dtype = model_dict.vae, model_dict.tokenizer, model_dict.text_encoder, model_dict.unet, model_dict.scheduler, model_dict.dtype
101
  text_embeddings, uncond_embeddings, cond_embeddings = input_embeddings
102
 
103
  if latents.dim() == 5:
 
53
  return images
54
 
55
  @torch.no_grad()
56
+ def generate(model_dict, latents, input_embeddings, num_inference_steps, guidance_scale = 7.5, no_set_timesteps=False, scheduler_key='dpm_scheduler'):
57
+ vae, tokenizer, text_encoder, unet, scheduler, dtype = model_dict.vae, model_dict.tokenizer, model_dict.text_encoder, model_dict.unet, model_dict[scheduler_key], model_dict.dtype
58
  text_embeddings, uncond_embeddings, cond_embeddings = input_embeddings
59
 
60
  if not no_set_timesteps:
 
93
  frozen_steps=20, frozen_mask=None,
94
  return_saved_cross_attn=False, saved_cross_attn_keys=None, return_cond_ca_only=False, return_token_ca_only=None,
95
  offload_cross_attn_to_cpu=False, offload_latents_to_cpu=True,
96
+ return_box_vis=False, show_progress=True, save_all_latents=False, scheduler_key='dpm_scheduler'):
97
  """
98
  The `bboxes` should be a list, rather than a list of lists (one box per phrase, we can have multiple duplicated phrases).
99
  """
100
+ vae, tokenizer, text_encoder, unet, scheduler, dtype = model_dict.vae, model_dict.tokenizer, model_dict.text_encoder, model_dict.unet, model_dict[scheduler_key], model_dict.dtype
101
  text_embeddings, uncond_embeddings, cond_embeddings = input_embeddings
102
 
103
  if latents.dim() == 5:
shared.py CHANGED
@@ -1,11 +1,15 @@
1
  from models import load_sd, sam
2
 
 
 
 
 
 
3
  use_fp16 = False
4
- use_dpm = True
5
 
6
  sd_key = "gligen/diffusers-generation-text-box"
7
 
8
  print(f"Using SD: {sd_key}")
9
- model_dict = load_sd(key=sd_key, use_fp16=use_fp16, use_dpm_multistep_scheduler=use_dpm, load_inverse_scheduler=False)
10
 
11
  sam_model_dict = sam.load_sam()
 
1
  from models import load_sd, sam
2
 
3
+
4
+ DEFAULT_SO_NEGATIVE_PROMPT = "artifacts, blurry, smooth texture, bad quality, distortions, unrealistic, distorted image, bad proportions, duplicate, two, many, group, occlusion, occluded, side, border, collate"
5
+ DEFAULT_OVERALL_NEGATIVE_PROMPT = "artifacts, blurry, smooth texture, bad quality, distortions, unrealistic, distorted image, bad proportions, duplicate"
6
+
7
+
8
  use_fp16 = False
 
9
 
10
  sd_key = "gligen/diffusers-generation-text-box"
11
 
12
  print(f"Using SD: {sd_key}")
13
+ model_dict = load_sd(key=sd_key, use_fp16=use_fp16, load_inverse_scheduler=False)
14
 
15
  sam_model_dict = sam.load_sam()