                  trainer.toggle_mask()
                  self._toggle_preview_mask = False
                  self._refresh_preview = True
  
              if save_iteration or self._save_now or self._refresh_preview:
                  viewer = display_func
              else:
                  viewer = None
              timelapse = self._timelapse if save_iteration else {}
              trainer.train_one_step(viewer, timelapse)
 
</s> remove                 self._toggle_preview_mask = False
                self._refresh_preview = True
 </s> add                 self._preview.request_refresh() </s> remove             if self._toggle_preview_mask:
 </s> add             if self._preview.should_toggle_mask(): </s> remove             if self._refresh_preview and viewer is not None:
                if self._args.redirect_gui:  # Remove any gui trigger files following an update
                    print("\n")
                    logger.info("[Preview Updated]")
                self._refresh_preview = False

            if save_iteration:
                logger.debug("Save Iteration: (iteration: %s", iteration)
                model.save(is_exit=False)
            elif self._save_now:
                logger.debug("Save Requested: (iteration: %s", iteration)
 </s> add             if save_iteration or self._save_now:
                logger.debug("Saving (save_iterations: %s, save_now: %s) Iteration: "
                             "(iteration: %s)", save_iteration, self._save_now, iteration) </s> remove                     self._do_preview(window_created)
                    cv_key = cv2.waitKey(1000)  # pylint: disable=no-member
                else:
                    cv_key = None
 </s> add                     self._preview.display_preview() </s> remove         self._scaling = scaling
 </s> add 
            if self._preview.should_refresh():
                  trainer.toggle_mask()
                  self._toggle_preview_mask = False
                  self._refresh_preview = True
  
            if self._preview.should_refresh():
                  viewer = display_func
              else:
                  viewer = None
              timelapse = self._timelapse if save_iteration else {}
              trainer.train_one_step(viewer, timelapse)
keep keep keep keep replace keep keep keep keep keep
 Live Preview - Replace cv2 with matplotlib viewer 
scripts/train.py