diff --git a/ldm/simplet2i.py b/ldm/simplet2i.py index 4737d90ba70..da46c57ab44 100644 --- a/ldm/simplet2i.py +++ b/ldm/simplet2i.py @@ -69,6 +69,7 @@ import math import re import traceback +import PIL from ldm.util import instantiate_from_config from ldm.models.diffusion.ddim import DDIMSampler @@ -301,6 +302,9 @@ def img2img(self,prompt,outdir=None,init_img=None,batch_size=None,iterations=Non iterations = iterations or self.iterations strength = strength or self.strength embedding_path = embedding_path or self.embedding_path + width = width or self.width + height = height or self.height + assert strength<1.0 and strength>=0.0, "strength (-f) must be >=0.0 and <1.0" assert cfg_scale>1.0, "CFG_Scale (-C) must be >1.0" @@ -426,6 +430,7 @@ def img2img(self,prompt,outdir=None,init_img=None,batch_size=None,iterations=Non return images def _make_grid(self,samples,seeds,batch_size,iterations,outdir): + images = list() n_rows = batch_size if batch_size>1 else int(math.sqrt(batch_size * iterations)) # save as grid @@ -502,7 +507,24 @@ def _load_model_from_config(self, config, ckpt): model.half() return model - def _load_img(self,path): + def _load_img(self,path,width=None,height=None): + + width = width or self.width + height = height or self.height + + #if self.custominitsize: + '''image = Image.open(path).convert("RGB") + w, h = image.size + #print(f"loaded input image of size ({w}, {h}) from {path}") + #w, h = map(lambda x: x - x % 32, (w, h)) # resize to integer multiple of 32 + #image = image.resize((w, h), resample=PIL.Image.LANCZOS) + image = image.resize((self.width, self.height), resample=PIL.Resampling.LANCZOS) + image = np.array(image).astype(np.float32) / 255.0 + image = image[None].transpose(0, 3, 1, 2) + image = torch.from_numpy(image) + return 2.*image - 1.''' + + #else: image = Image.open(path).convert("RGB") w, h = image.size print(f"loaded input image of size ({w}, {h}) from {path}")