def _collect_running_batch_states(self):
        self.running_acc.append(self._compute_acc().item())

        m = len(self.dataloaders['train'])
        if self.is_training is False:
            m = len(self.dataloaders['val'])

        if np.mod(self.batch_id, 100) == 1 or self.batch_id == m - 1:
            print(
                'Is_training: %s. [%d,%d][%d,%d], G_loss: %.8f, D_loss: %.8f, running_acc: %.8f (%s),'
                % (self.is_training, self.epoch_id, self.max_num_epochs - 1,
                   self.batch_id, m, self.G_loss.item(), self.D_loss.item(),
                   np.mean(self.running_acc), self.metric))

        if np.mod(self.batch_id, 1000) == 1 or self.batch_id == m - 1:
            vis_input = utils.make_numpy_grid(self.batch['input'])
            vis_pred1 = utils.make_numpy_grid(self.G_pred1)
            vis_pred2 = utils.make_numpy_grid(self.G_pred2)
            if self.output_auto_enhance:
                vis_pred1 = vis_pred1 * 1.5
                vis_pred2 = vis_pred2 * 1.5
            vis = np.concatenate([vis_input, vis_pred1, vis_pred2], axis=0)
            vis = np.clip(vis, a_min=0.0, a_max=1.0)
            file_name = os.path.join(
                self.vis_dir, 'istrain_' + str(self.is_training) + '_' +
                str(self.epoch_id) + '_' + str(self.batch_id) + '.jpg')
            plt.imsave(file_name, vis)
Ejemplo n.º 2
0
    def _collect_running_batch_states(self):
        self.running_acc.append(self._compute_acc().item())

        m = len(self.dataloaders['train'])
        if self.is_training is False:
            m = len(self.dataloaders['val'])

        if np.mod(self.batch_id, 100) == 1:
            print(
                'Is_training: %s. [%d,%d][%d,%d], G_loss: %.5f, running_acc: %.5f'
                % (self.is_training, self.epoch_id, self.max_num_epochs - 1,
                   self.batch_id, m, self.G_loss.item(),
                   np.mean(self.running_acc)))

        if np.mod(self.batch_id, 1000) == 1:
            vis_pred_foreground = utils.make_numpy_grid(self.G_pred_foreground)
            vis_gt_foreground = utils.make_numpy_grid(self.batch['B'])
            vis_pred_alpha = utils.make_numpy_grid(self.G_pred_alpha)
            vis_gt_alpha = utils.make_numpy_grid(self.batch['ALPHA'])
            vis = np.concatenate([
                vis_pred_foreground, vis_gt_foreground, vis_pred_alpha,
                vis_gt_alpha
            ],
                                 axis=0)
            vis = np.clip(vis, a_min=0.0, a_max=1.0)
            file_name = os.path.join(
                self.vis_dir, 'istrain_' + str(self.is_training) + '_' +
                str(self.epoch_id) + '_' + str(self.batch_id) + '.jpg')
            plt.imsave(file_name, vis)
    def _visualize_batch_and_prediction(self):

        if np.mod(self.batch_id, 100) == 1:
            vis_input = utils.make_numpy_grid(self.batch['stereogram'])
            vis_pred = utils.make_numpy_grid(self.G_pred)
            vis_gt = utils.make_numpy_grid(self.batch['dmap'])
            vis = np.concatenate([vis_input, vis_pred, vis_gt], axis=0)
            vis = np.clip(vis, a_min=0.0, a_max=1.0)
            file_name = os.path.join(
                self.vis_dir, 'istrain_' + str(self.is_training) + '_' +
                str(self.epoch_id) + '_' + str(self.batch_id) + '.jpg')
            plt.imsave(file_name, vis)