Esempio n. 1
0
      xP=[x.replace('lfw','lfw_aegan') for x in P]
      xQ=[x.replace('lfw','lfw_aegan') for x in Q]
      PF=model.mean_F(utils.image_feed(xP[:K],image_dims))
      QF=model.mean_F(utils.image_feed(xQ[:K],image_dims))
      if config.scaling=='beta':
        WF=(QF-PF)/((QF-PF)**2).mean()
      elif config.scaling=='none':
        WF=(QF-PF)
      max_iter=config.iter
      init=o
      # for each interpolation step
      for delta in delta_params:
        print(xX,b,delta)
        t2=time.time()
        Y=model.F_inverse(XF+WF*delta,max_iter=max_iter,initial_image=init)
        t3=time.time()
        print('{} minutes to reconstruct'.format((t3-t2)/60.0))
        result[-1].append(Y)
        max_iter=config.iter//2
        init=Y
  result=numpy.asarray(result)
  original=numpy.asarray(original)
  if 'color' in postprocess:
    result=utils.color_match(numpy.expand_dims(original,1),result)
  m=imageutils.montage(numpy.concatenate([numpy.expand_dims(original,1),result],axis=1))
  imageutils.write('results/demo1.png',m)
  print('Output is results/demo1.png')
  t1=time.time()
  print('{} minutes ({} minutes per image).'.format((t1-t0)/60.0,(t1-t0)/60.0/result.shape[0]/result.shape[1]))

Esempio n. 2
0
            WF = (QF - PF) / ((QF - PF)**2).mean()
        elif config.scaling == 'none':
            WF = (QF - PF)
        max_iter = config.iter
        init = o
        # for each interpolation step
        for delta in delta_params:
            print(xX, delta)
            t2 = time.time()
            Y = model.F_inverse(XF + WF * delta,
                                max_iter=max_iter,
                                initial_image=init)
            t3 = time.time()
            print('{} minutes to reconstruct'.format((t3 - t2) / 60.0))
            result[-1].append(Y)
            max_iter = config.iter // 2
            init = Y
    result = numpy.asarray(result)
    original = numpy.asarray(original)
    if 'color' in postprocess:
        result = utils.color_match(numpy.expand_dims(original, 1), result)
    m = imageutils.montage(
        numpy.concatenate([numpy.expand_dims(original, 1), result],
                          axis=1).transpose(1, 0, 2, 3, 4))
    imageutils.write('results/demo3.png', m)
    print('Output is results/demo3.png')
    t1 = time.time()
    print('{} minutes ({} minutes per image).'.format(
        (t1 - t0) / 60.0,
        (t1 - t0) / 60.0 / result.shape[0] / result.shape[1]))
Esempio n. 3
0
      caption='psnr {:.4}, ssim {:.4}'.format(psnr,ssim)
      subprocess.check_call('convert {root_dir2}/{basename}_original.png {root_dir2}/{basename}_actual.png -size {w}x -font Arial-Italic -pointsize 12 caption:{caption} -append {root_dir2}/eval_{basename}.png'.format(root_dir2=pipes.quote(root_dir2),basename=pipes.quote(basename),caption=pipes.quote(caption),w=A.shape[1],h=A.shape[0]//10),shell=True)
      all_psnr.append(psnr)
      all_ssim.append(ssim)
  
    print(tname,'psnr',psnr)
    print(tname,'ssim',ssim)
    mean_psnr=np.asarray(all_psnr).mean()
    mean_ssim=np.asarray(all_ssim).mean()
    with open('{}/autoencoder.txt'.format(root_dir),'a') as f:
      f.write('{},{},{},{}\n'.format(model,tname,mean_psnr,mean_ssim))

  t1=time.time()
  print('Finished in {} minutes.'.format((t1-t0)/60.0))
  return root_dir,np.asarray(all_results)

if __name__=='__main__':
  filelist=['images/lfw/Aaron_Eckhart/Aaron_Eckhart_0001.jpg']
  targetlist=[
    #('c3c4c5',['conv3_1','conv4_1','conv5_1'],[1,1,1]),
    ('c3',['conv3_1'],[1]),
    ('c4',['conv4_1'],[1]),
    ('c5',['conv5_1'],[1]),
  ]
  for model in ['vgg','vggface']:
    root_dir,result=invert_model(filelist,targetlist,model,image_dims=[100,100],max_iter=3000,tv_lambda=0.001,tv_beta=2,desc='invert_{}'.format(model),device_id=0)
    original=np.asarray([skimage.io.imread(x)/255.0 for x in filelist*len(targetlist)])
    m=np.asarray([original,result])
    skimage.io.imsave('{}/montage.png'.format(root_dir),imageutils.montage(m))

Esempio n. 4
0
        file_name = '.'.join(file_name)
        numpy.savez('{}/{}_{}.npz'.format(file_save_path, file_name,
                                          config.effect),
                    WF=WF)

        if config.save_image:  # True: make and save a image and then exit, False: just build npz files
            max_iter = 500
            init = original
            # for each interpolation step
            result = []
            for delta in delta_params:
                print(xX, image_dims, delta, len(xP), len(xQ))
                t2 = time.time()
                Y = model.F_inverse(XF + WF * delta,
                                    max_iter=max_iter,
                                    initial_image=init)
                t3 = time.time()
                print('{} minutes to reconstruct'.format((t3 - t2) / 60.0))
                result.append(Y)
                max_iter = 500 // 2
                init = Y
            result = numpy.asarray([result])
            original = numpy.asarray([original])
            #m=imageutils.montage(numpy.concatenate([numpy.expand_dims(original,1),result],axis=1))
            m = imageutils.montage(result)
            opath = '{}_{}_{}{}.{}'.format(prefix_path, timestamp,
                                           config.effect, '_', 'jpg')
            print('--> opath:', opath)
            imageutils.write(opath, m)
            break