Esempio n. 1
0
 def evaluate_epoch(self):
     """
     evaluating in a epoch
     :return: 
     """
     self.eval_losses = utils.AverageMeter()
     self.eval_top1 = utils.AverageMeter()
     self.eval_top5 = utils.AverageMeter()
     # Set the model to be in testing mode (for dropout and batchnorm)
     self.model.net.eval()
     for batch_idx, (batch_x, batch_y) in enumerate(self.val_loader):
         if torch.cuda.is_available():
             batch_x, batch_y = batch_x.cuda(
                 async=self.config['async_loading']), batch_y.cuda(
                     async=self.config['async_loading'])
         batch_x_var, batch_y_var = Variable(batch_x), Variable(batch_y)
         self.evaluate_step(batch_x_var, batch_y_var)
         utils.view_bar(batch_idx + 1, len(self.val_loader))
Esempio n. 2
0
 def load_gt_rois(self):
     # load the ground truth regions of image set
     cache_file = os.path.join(self.cache_path, self.name + '_gt_roidb.pkl')
     if os.path.exists(cache_file):
         print('Load gt roidb from {}'.format(cache_file))
         with open(cache_file, 'rb') as f:
             gt_roidb = pickle.load(f)
         print('Load finished')
         return gt_roidb
     gt_roidb = []
     for i in range(len(self.image_index)):
         gt_roi = self.load_gt_roi(self.image_index[i])
         gt_roidb.append(gt_roi)
         utils.view_bar(
             'Load gt roidb from {}'.format(self.image_index[i] + '.xml'),
             i, len(self.image_index))
     with open(cache_file, 'wb') as f:
         pickle.dump(gt_roidb, f, pickle.HIGHEST_PROTOCOL)
     print('Write gt roidb to {}'.format(cache_file))
     return gt_roidb
 def evaluate_accuracy(self, data_iterator, net):
     """
     compute top-1 accuracy
     :param data_iterator: 
     :param net: 
     :return: 
     """
     loss = utils.AverageMeter()
     acc = mx.metric.Accuracy()
     for idx, (d, l) in enumerate(data_iterator):
         data = d.as_in_context(self.ctx[0])
         label = l.as_in_context(self.ctx[0])
         output = net(data)
         _loss = self.get_loss(output, label)
         curr_loss = nd.mean(_loss).asscalar()
         loss.update(curr_loss, data.shape[0])
         predictions = nd.argmax(output, axis=1)
         acc.update(preds=predictions, labels=label)
         utils.view_bar(idx + 1, len(data_iterator))  # view_bar
     return acc.get()[1], loss.avg
Esempio n. 4
0
        bic_s0[i] = S0_BIC
        bic_dolp[i] = DoLP_BIC
        bic_aop[i] = AoP_BIC

        # Calculate the PSNR of S0, DoLP and AoP obtained through PDCNN method
        total_S0_PSNR[i]=  psnr(S0_true, S0_hat_test, 2)
        total_DoLP_PSNR[i] = psnr(DoLP_true, DoLP_hat_test, 1)
        total_AoP_PSNR[i] = psnr(AoP_true, AoP_hat_test, math.pi/2.)

        # Calculate the PSNR of S0, DoLP and AoP obtained through BICUBIC method
        total_S0_PSNR_BIC[i] = psnr(S0_true, S0_BIC, 2)
        total_DoLP_PSNR_BIC[i] = psnr(DoLP_true, DoLP_BIC, 1)
        total_AoP_PSNR_BIC[i] = psnr(AoP_true, AoP_BIC, math.pi/2.)

        # show the progress bar
        view_bar(i, IMG_NUM)

    print('\n========================================Testing=======================================' +
          '\n ————————————————————————————————————————————————————————————————————————————————' +
          '\n| PSNR of S_0 using SRCNN: %.5f    |   PSNR of S_0 using BICUBIC: %.5f   |' % (np.mean(total_S0_PSNR), np.mean(total_S0_PSNR_BIC)) +
          '\n| PSNR of DoLP using PDCNN: %.5f   |   PSNR of DoLP using BICUBIC: %.5f  |' % (np.mean(total_DoLP_PSNR), np.mean(total_DoLP_PSNR_BIC)) +
          '\n| PSNR of AoP using SRCNN: %.5f    |   PSNR of AoP using BICUBIC: %.5f   |' % (np.mean(total_AoP_PSNR), np.mean(total_AoP_PSNR_BIC)) +
          '\n ————————————————————————————————————————————————————————————————————————————————')

    print('\nSRCNN time: {} sec'.format(total_time / IMG_NUM))

    for j in output_images:

        imgio.imsave("./images/bic_s0_{}_{}.jpg".format(j, total_S0_PSNR_BIC[j-1]), bic_s0[j-1, 390:-470, 690:-490])
        imgio.imsave("./images/pred_s0_3_path_{}_{}.jpg".format(j, total_S0_PSNR[j-1]), pred_s0[j-1, 200:-80, 325:-275])
        imgio.imsave("./images/org_s0_{}.jpg".format(j), origin_s0[j-1, 390:-470, 690:-490])
            fig = plt.gcf()
            height, width = AoP_hat_test.shape
            fig.set_size_inches(width/300, height/300)
            plt.gca().xaxis.set_major_locator(plt.NullLocator())
            plt.gca().yaxis.set_major_locator(plt.NullLocator())
            plt.subplots_adjust(top=1, bottom=0, left=0, right=1, hspace=0, wspace=0)
            plt.margins(0, 0)
            plt.imshow(AoP_hat_test, cmap=cm.jet)
            hm = fig2array(fig)

        S0_hat_test = np.uint8(normalize(S0_hat_test, 0, 255))
        DoLP_hat_test = np.uint8(normalize(DoLP_hat_test, 0, 255))

        S0_hat_test = np.stack([S0_hat_test] *3 , axis=-1)
        DoLP_hat_test = np.stack([DoLP_hat_test] * 3, axis=-1)

        s0_writer.write(S0_hat_test)
        dolp_writer.write(DoLP_hat_test)

        view_bar(cur_frame-1, total_frame)
        cur_frame += 1

    test_video.release()
    s0_writer.release()
    dolp_writer.release()
    cv2.destroyAllWindows()