MCPcopy
hub / github.com/deep-floyd/IF / to_images

Method to_images

deepfloyd_if/modules/base.py:291–310  ·  view source on GitHub ↗
(self, generations, disable_watermark=False)

Source from the content-addressed store, hash-verified

289 return '-'
290
291 def to_images(self, generations, disable_watermark=False):
292 bs, c, h, w = generations.shape
293 coef = min(h / self.pil_img_size, w / self.pil_img_size)
294 img_h, img_w = (int(h / coef), int(w / coef)) if coef < 1 else (h, w)
295
296 S1, S2 = 1024 ** 2, img_w * img_h
297 K = (S2 / S1) ** 0.5
298 wm_size, wm_x, wm_y = int(K * 62), img_w - int(14 * K), img_h - int(14 * K)
299
300 wm_img = self.wm_pil_img.resize(
301 (wm_size, wm_size), getattr(Image, 'Resampling', Image).BICUBIC, reducing_gap=None)
302
303 pil_images = []
304 for image in ((generations + 1) * 127.5).round().clamp(0, 255).to(torch.uint8).cpu():
305 pil_img = torchvision.transforms.functional.to_pil_image(image).convert('RGB')
306 pil_img = pil_img.resize((img_w, img_h), getattr(Image, 'Resampling', Image).NEAREST)
307 if not disable_watermark:
308 pil_img.paste(wm_img, box=(wm_x - wm_size, wm_y - wm_size, wm_x, wm_y), mask=wm_img.split()[-1])
309 pil_images.append(pil_img)
310 return pil_images
311
312 def show(self, pil_images, nrow=None, size=10):
313 if nrow is None:

Callers 4

style_transferFunction · 0.80
super_resolutionFunction · 0.80
inpaintingFunction · 0.80
dreamFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected