Skip to content
Closed
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
24 changes: 23 additions & 1 deletion ldm/simplet2i.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand Down