Example #1
0
def run_eval(model, eval_loader, args, output_suffix=''):

  for sub_dir in ['codes', 'images']:
    cur_eval_dir = os.path.join(args.out_dir, output_suffix, sub_dir)
    if not os.path.exists(cur_eval_dir):
      print("Creating directory %s." % cur_eval_dir)
      os.makedirs(cur_eval_dir)

  all_losses, all_msssim, all_psnr = [], [], []

  start_time = time.time()
  for i, (batch, ctx_frames, filenames,id_num) in enumerate(eval_loader):
      with torch.no_grad():
      	batch = Variable(batch.cuda())

      original, out_imgs, losses, code_batch = eval_forward(
          model, (batch, ctx_frames,id_num), args)

      losses, msssim, psnr = finish_batch(
          args, filenames, original, out_imgs, 
          losses, code_batch, output_suffix)

      all_losses += losses
      all_msssim += msssim
      all_psnr += psnr

      if i % 10 == 0:
        print('\tevaluating iter %d (%f seconds)...' % (
          i, time.time() - start_time))

  return (np.array(all_losses).mean(axis=0),
          np.array(all_msssim).mean(axis=0),
          np.array(all_psnr).mean(axis=0))
Example #2
0
def run_eval(model, eval_loader, args, output_suffix=''):

    for sub_dir in ['codes', 'images']:
        cur_eval_dir = os.path.join(args.out_dir, output_suffix, sub_dir)
        if not os.path.exists(cur_eval_dir):
            print("Creating directory %s." % cur_eval_dir)
            os.makedirs(cur_eval_dir)

    #all_losses, all_msssim, all_psnr = [], [], []

    #start_time = time.time()
    for i, (batch, ctx_frames, filenames) in enumerate(eval_loader):

        batch = Variable(batch.cuda(), volatile=True)

        codes = eval_forward(model, (batch, ctx_frames), args)
        save_codes(name='initial' + str(i),
                   codes=codes,
                   args=args,
                   output_suffix=output_suffix)
        '''
Example #3
0
def run_eval(model, eval_loader, args, output_suffix=''):
    with torch.no_grad():
        for sub_dir in ['codes', 'images']:
            cur_eval_dir = os.path.join(args.out_dir, output_suffix, sub_dir)
            if not os.path.exists(cur_eval_dir):
                print("Creating directory %s." % cur_eval_dir)
                os.makedirs(cur_eval_dir)

        all_losses, all_msssim, all_psnr = [], [], []
        total_baseline_scores = np.array([0., 0.])

        start_time = time.time()
        for i, (batch, ctx_frames, filenames) in enumerate(eval_loader):
            # f1, f2 = batch[:, :3].numpy(), batch[:, 6:9].numpy()
            batch = batch.cuda()

            original, out_imgs, losses, code_batch, baseline_scores = eval_forward(
                model, (batch, ctx_frames), args)

            losses, msssim, psnr = finish_batch(args, filenames, original,
                                                out_imgs, losses, code_batch,
                                                output_suffix)

            all_losses += losses
            all_msssim += msssim
            all_psnr += psnr

            if i % 10 == 0:
                print('\tevaluating iter %d (%f seconds)...' %
                      (i, time.time() - start_time))

            total_baseline_scores += baseline_scores

        return (np.array(all_losses).mean(axis=0),
                np.array(all_msssim).mean(axis=0),
                np.array(all_psnr).mean(axis=0),
                total_baseline_scores / len(eval_loader))