Facebook
From Gracious Cassowary, 4 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 131
  1. def show(image_index, threshold=0.000000001):
  2.     imgs = [trans(Image.open(image_list[image_index]))]
  3.     for i in range(1, 4):
  4.         aged_face = trans(Image.open('FaceAging/evaluation/imgs/0-{}-morph-ProgressiveGAN-{}.png'.format(i, image_names[image_index])))
  5.         if i == 1:
  6.             j = 0
  7.         elif i == 2:
  8.             j = 1
  9.         elif i == 3:
  10.             j = 3
  11.         aging_effct = aged_face - imgs[j]
  12.         aging_effct[torch.abs(aging_effct) < threshold] = 0
  13. #         aging_effct = torch.mean(aging_effct, dim=0).unsqueeze(0).repeat(3, 1, 1)
  14.         aging_effct = torch.mean(aging_effct, dim=0)
  15. #         aging_effct = torch.mean(torch.abs(aging_effct), dim=0)
  16. #         aging_effct[aging_effct < threshold] = 0
  17.         aging_effct = aging_effct.numpy()
  18. #         pmin = np.min(aging_effct)
  19. #         pmax = np.max(aging_effct)
  20. #         aging_effct = ((aging_effct - pmin) / (pmax - pmin))
  21.         aging_effct = Image.fromarray(np.uint8(cm.Greys(aging_effct) * 255)).convert('RGB')
  22.         aging_effct = trans(aging_effct)
  23.         aging_effct = aging_effct.float()
  24.         imgs.extend([aged_face, aging_effct])
  25.     imgs = torchvision.utils.make_grid(imgs, nrow=7, pad_value=1, padding=0)
  26.     imgs = torchvision.transforms.ToPILImage()(imgs)
  27.     return imgs