          model.save()
          trainer.clear_tensorboard()
          self._stop = True
  
      def _monitor(self, thread):
          """ Monitor the background :func:`_training` thread for key presses and errors.
  
          Returns
          -------
          bool
              ``True`` if there has been an error in the background thread otherwise ``False``
          """
          logger.debug("Launching Monitor")
          logger.info("===================================================")
          logger.info("  Starting")
          if self._args.preview:
              logger.info("  Using live preview")
 
</s> remove         model.save()
 </s> add         model.save(is_exit=True) </s> remove     def _preview_monitor(self, key_press):
 </s> add     def _do_preview(self, window_created: bool) -> bool:
        """" Display an image preview in a resizable window

        Parameters
        ----------
        window_created: bool
            ``True`` if a preview window has been created otherwise ``False``

        Returns
        -------
        bool
            ``True`` if a preview window has been created otherwise ``False``
        """
        with self._lock:
            for name, image in self._preview_buffer.items():
                if not window_created:
                    self._create_resizable_window(name, image.shape)
                cv2.imshow(name, image)  # pylint: disable=no-member
            window_created = bool(self._preview_buffer) if not window_created else window_created
        return window_created

    def _check_keypress(self, keypress: KBHit) -> bool:
        """ Check if a keypress has been detected.

        Parameters
        ----------
        keypress: :class:`lib.keypress.KBHit`
            The keypress monitor

        Returns
        -------
        bool
            ``True`` if an exit keypress has been detected otherwise ``False``
        """
        retval = False
        if keypress.kbhit():
            console_key = keypress.getch()
            if console_key in ("\n", "\r"):
                logger.debug("Exit requested")
                retval = True
            if console_key in ("s", "S"):
                logger.info("Save requested")
                self._save_now = True
        return retval

    def _preview_monitor(self, key_press: str) -> bool: </s> remove         keypress = KBHit(is_gui=self._args.redirect_gui)
        window_created = False
        err = False
        while True:
            try:
                if self._args.preview:
                    with self._lock:
                        for name, image in self._preview_buffer.items():
                            if not window_created:
                                self._create_resizable_window(name, image.shape)
                            cv2.imshow(name, image)  # pylint: disable=no-member
                        if not window_created:
                            window_created = bool(self._preview_buffer)
                    cv_key = cv2.waitKey(1000)  # pylint: disable=no-member
                else:
                    cv_key = None

                if thread.has_error:
                    logger.debug("Thread error detected")
                    err = True
                    break
                if self._stop:
                    logger.debug("Stop received")
                    break

                # Preview Monitor
                if not self._preview_monitor(cv_key):
                    break

                # Console Monitor
                if keypress.kbhit():
                    console_key = keypress.getch()
                    if console_key in ("\n", "\r"):
                        logger.debug("Exit requested")
                        break
                    if console_key in ("s", "S"):
                        logger.info("Save requested")
                        self._save_now = True

                # GUI Preview trigger update monitor
                self._process_gui_triggers()

                sleep(1)
            except KeyboardInterrupt:
                logger.debug("Keyboard Interrupt received")
                break
        keypress.set_normal_term()
        logger.debug("Closed Monitor")
        return err

 </s> add 
    def _output_startup_info(self):
        """ Print the startup information to the console. """
          model.save()
          trainer.clear_tensorboard()
          self._stop = True
  
    def _output_startup_info(self):
        """ Print the startup information to the console. """
    def _output_startup_info(self):
        """ Print the startup information to the console. """
    def _output_startup_info(self):
        """ Print the startup information to the console. """
    def _output_startup_info(self):
        """ Print the startup information to the console. """
    def _output_startup_info(self):
        """ Print the startup information to the console. """
    def _output_startup_info(self):
        """ Print the startup information to the console. """
    def _output_startup_info(self):
        """ Print the startup information to the console. """
    def _output_startup_info(self):
        """ Print the startup information to the console. """
          logger.debug("Launching Monitor")
          logger.info("===================================================")
          logger.info("  Starting")
          if self._args.preview:
              logger.info("  Using live preview")
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep
 Training: Add setting option to save optimizer weights 
scripts/train.py