Ejemplo n.º 1
0
 def _backward_x_sty(self):
     canvas = utils.patches2img(
         self.G_final_pred_canvas, self.m_grid, to_numpy=False).to(device)
     self.G_loss = self.args.beta_L1 * self._pxl_loss(
         canvas=self.G_final_pred_canvas, gt=self.img_batch, ignore_color=True)
     self.G_loss += self.args.beta_sty * self._style_loss(canvas, self.style_img)
     self.G_loss.backward()
Ejemplo n.º 2
0
 def _style_transfer_step_states(self):
     acc = self._compute_acc().item()
     print(
         'running style transfer... iteration step %d, G_loss: %.5f, step_psnr: %.5f'
         % (self.step_id, self.G_loss.item(), acc))
     vis2 = utils.patches2img(self.G_final_pred_canvas,
                              self.m_grid).clip(min=0, max=1)
     cv2.imshow('G_pred', vis2[:, :, ::-1])
     cv2.imshow('input', self.img_[:, :, ::-1])
     cv2.waitKey(1)
Ejemplo n.º 3
0
 def _drawing_step_states(self):
     acc = self._compute_acc().item()
     print(
         'iteration step %d, G_loss: %.5f, step_acc: %.5f, grid_scale: %d / %d, strokes: %d / %d'
         % (self.step_id, self.G_loss.item(), acc, self.m_grid,
            self.max_divide, self.anchor_id, self.m_strokes_per_block))
     vis2 = utils.patches2img(self.G_final_pred_canvas,
                              self.m_grid).clip(min=0, max=1)
     cv2.imshow('G_pred', vis2[:, :, ::-1])
     cv2.imshow('input', self.img_[:, :, ::-1])
     cv2.waitKey(1)
Ejemplo n.º 4
0
 def _drawing_step_states(self):
     acc = self._compute_acc().item()
     print('iteration step %d, G_loss: %.5f, step_psnr: %.5f, strokes: %d / %d'
           % (self.step_id, self.G_loss.item(), acc,
              (self.anchor_id+1)*self.m_grid*self.m_grid,
              self.max_m_strokes))
     vis2 = utils.patches2img(self.G_final_pred_canvas, self.m_grid).clip(min=0, max=1)
     if self.args.disable_preview:
         pass
     else:
         cv2.imshow('G_pred', vis2[:,:,::-1])
         cv2.imshow('input', self.img_[:, :, ::-1])
         cv2.waitKey(1)
Ejemplo n.º 5
0
 def _style_transfer_step_states(self):
     acc = self._compute_acc().item()
     print(
         'running style transfer... iteration step %d, G_loss: %.5f, step_psnr: %.5f'
         % (self.step_id, self.G_loss.item(), acc))
     vis2 = utils.patches2img(self.G_final_pred_canvas,
                              self.m_grid).clip(min=0, max=1)
     if self.args.disable_preview:
         pass
     else:
         cv2.namedWindow('G_pred', cv2.WINDOW_NORMAL)
         cv2.namedWindow('input', cv2.WINDOW_NORMAL)
         cv2.namedWindow('style_img', cv2.WINDOW_NORMAL)
         cv2.imshow('G_pred', vis2[:, :, ::-1])
         cv2.imshow('input', self.img_[:, :, ::-1])
         cv2.imshow('style_img', self.style_img_[:, :, ::-1])
         cv2.waitKey(1)
Ejemplo n.º 6
0
 def _drawing_step_states(self):
     acc = self._compute_acc().item()
     print(
         "iteration step %d, G_loss: %.5f, step_acc: %.5f, grid_scale: %d / %d, strokes: %d / %d"
         % (
             self.step_id,
             self.G_loss.item(),
             acc,
             self.m_grid,
             self.max_divide,
             self.anchor_id + 1,
             self.m_strokes_per_block,
         ))
     vis2 = utils.patches2img(self.G_final_pred_canvas,
                              self.m_grid).clip(min=0, max=1)
     if self.args.disable_preview:
         pass
     else:
         cv2.namedWindow("G_pred", cv2.WINDOW_NORMAL)
         cv2.namedWindow("input", cv2.WINDOW_NORMAL)
         cv2.imshow("G_pred", vis2[:, :, ::-1])
         cv2.imshow("input", self.img_[:, :, ::-1])
         cv2.waitKey(1)