Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ldm/simplet2i.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def img2img(self,prompt,outdir=None,init_img=None,batch_size=None,iterations=Non

model = self.load_model() # will instantiate the model or return it from cache

precision_scope = autocast if self.precision=="autocast" else nullcontext

# grid and individual are mutually exclusive, with individual taking priority.
# not necessary, but needed for compatability with dream bot
if (grid is None):
Expand All @@ -279,7 +281,8 @@ def img2img(self,prompt,outdir=None,init_img=None,batch_size=None,iterations=Non
assert os.path.isfile(init_img)
init_image = self._load_img(init_img).to(self.device)
init_image = repeat(init_image, '1 ... -> b ...', b=batch_size)
init_latent = model.get_first_stage_encoding(model.encode_first_stage(init_image)) # move to latent space
with precision_scope("cuda"):
init_latent = model.get_first_stage_encoding(model.encode_first_stage(init_image)) # move to latent space

sampler.make_schedule(ddim_num_steps=steps, ddim_eta=ddim_eta, verbose=False)

Expand All @@ -292,7 +295,6 @@ def img2img(self,prompt,outdir=None,init_img=None,batch_size=None,iterations=Non
t_enc = int(strength * steps)
print(f"target t_enc is {t_enc} steps")

precision_scope = autocast if self.precision=="autocast" else nullcontext
images = list()
seeds = list()

Expand Down Expand Up @@ -401,6 +403,7 @@ def _load_model_from_config(self, config, ckpt):
m, u = model.load_state_dict(sd, strict=False)
model.cuda()
model.eval()
model.half()
return model

def _load_img(self,path):
Expand Down