def show(image_index, threshold=0.000000001): imgs = [trans(Image.open(image_list[image_index]))] for i in range(1, 4): aged_face = trans(Image.open('FaceAging/evaluation/imgs/0-{}-morph-ProgressiveGAN-{}.png'.format(i, image_names[image_index]))) if i == 1: j = 0 elif i == 2: j = 1 elif i == 3: j = 3 aging_effct = aged_face - imgs[j] aging_effct[torch.abs(aging_effct) < threshold] = 0 # aging_effct = torch.mean(aging_effct, dim=0).unsqueeze(0).repeat(3, 1, 1) aging_effct = torch.mean(aging_effct, dim=0) # aging_effct = torch.mean(torch.abs(aging_effct), dim=0) # aging_effct[aging_effct < threshold] = 0 aging_effct = aging_effct.numpy() # pmin = np.min(aging_effct) # pmax = np.max(aging_effct) # aging_effct = ((aging_effct - pmin) / (pmax - pmin)) aging_effct = Image.fromarray(np.uint8(cm.Greys(aging_effct) * 255)).convert('RGB') aging_effct = trans(aging_effct) aging_effct = aging_effct.float() imgs.extend([aged_face, aging_effct]) imgs = torchvision.utils.make_grid(imgs, nrow=7, pad_value=1, padding=0) imgs = torchvision.transforms.ToPILImage()(imgs) return imgs