Пример #1
0
    def clear_logs(self, force=False):
        if force:
            do_clear = True
        else:
            # Ask user if they really want to clear
            while True:
                do_clear = Notification(
                    DEEP_NOTIF_INPUT,
                    "Are you sure you want to clear logs from session : %s ? (yes / no)"
                    % self.config.project.session).get()
                if do_clear.lower() in ["yes", "y"]:
                    do_clear = True
                    break
                elif do_clear.lower() in ["no", "n"]:
                    do_clear = False
                    break

        if do_clear:
            Notification(
                DEEP_NOTIF_INFO,
                DEEP_MSG_BRAIN_CLEAR_LOGS % self.config.project.session)
            path = "/".join((self.config.project.session, "logs"))
            try:
                for file in os.listdir(path):
                    os.remove("/".join((path, file)))
            except FileNotFoundError:
                pass
            Notification(
                DEEP_NOTIF_SUCCESS,
                DEEP_MSG_BRAIN_CLEARED_LOGS % self.config.project.session)
Пример #2
0
 def clear(self, force=False):
     """
     :return:
     """
     if force:
         do_clear = True
     else:
         # Ask user if they really want to clear
         while True:
             do_clear = Notification(
                 DEEP_NOTIF_INPUT,
                 "Are you sure you want to clear this session : %s ? (yes / no)"
                 % self.config.project.session).get()
             if do_clear.lower() in ["yes", "y"]:
                 do_clear = True
                 break
             elif do_clear.lower() in ["no", "n"]:
                 do_clear = False
                 break
     if do_clear:
         Notification(
             DEEP_NOTIF_INFO,
             DEEP_MSG_BRAIN_CLEAR_ALL % self.config.project.session)
         for directory in DEEP_LOG_RESULT_DIRECTORIES:
             path = "/".join((self.config.project.session, directory))
             try:
                 for file in os.listdir(path):
                     os.remove("/".join((path, file)))
             except FileNotFoundError:
                 pass
         Notification(
             DEEP_NOTIF_SUCCESS,
             DEEP_MSG_BRAIN_CLEARED_ALL % self.config.project.session)
Пример #3
0
 def __check_exists(self, project_path):
     """
     Author: SW
     Checks that the project does not exist already
     If the project exists already, the user is asked if the existing project should be overwritten
     If the project does not exist already, the project directory is made
     :param project_path: str: absolute path to the main project directory
     :return: bool: whether or not project generation should continue
     """
     if os.path.isdir(project_path) and not self.force_overwrite:
         while True:
             Notification(DEEP_NOTIF_WARNING, DEEP_MSG_PROJECT_ALREADY_EXISTS % project_path, log=False)
             proceed = Notification(DEEP_NOTIF_INPUT, DEEP_MSG_CONTINUE, log=False).get()
             if proceed.lower() in ["y", "yes"]:
                 return True
             elif proceed.lower() in ["n", "no"]:
                 return False
     else:
         os.makedirs(project_path, exist_ok=True)
         return True
Пример #4
0
    def __continue_training(self):
        """
        AUTHORS:
        --------

        :author: Alix Leroy

        DESCRIPTION:
        ------------

        Ask if we want to continue once the training ended

        PARAMETERS:
        -----------

        None

        RETURN:
        -------

        :return: None
        """
        continue_training = ""
        # Ask if the user want to continue the training
        while continue_training.lower() not in ["y", "n"]:
            continue_training = Notification(DEEP_NOTIF_INPUT, "Would you like to continue the training ? (Y/N) ").get()
        # If yes ask the number of epochs
        if continue_training.lower() == "y":
            while True:
                epochs = Notification(DEEP_NOTIF_INPUT, "Number of epochs ? ").get()
                try:
                    epochs = int(epochs)
                    break
                except ValueError:
                    Notification(DEEP_NOTIF_WARNING, "Number of epochs must be an integer").get()
            if epochs > 0:
                self.initial_epoch = self.num_epochs + 1
                self.num_epochs += epochs
                # Resume the training
                self.fit(first_training=False)
        else:
            pass
Пример #5
0
    def set_len_dataset(self, length_data : int) -> None:
        """
        AUTHORS:
        --------

        author: Alix Leroy

        DESCRIPTION:
        ------------

        Set the length of the dataset

        PARAMETERS:
        -----------

        :param length_data -> Integer:  Desired length of the dataset

        RETURN:
        -------

        None
        """
        # If the given length is smaller than the number of instances already available in the dataset
        if length_data < len(self.data):
            res = ""
            # Ask the user to confirm the given length
            while res.lower() not in ["y", "yes", "no", "n"]:
                res = Notification(DEEP_NOTIF_INPUT, "Dataset contains {0} instances, are you sure you want to only use {1} instances ? (Y/N) ".format(len(self.data), length_data)).get()
            if res.lower() == "y":
                self.len_data = length_data
            # If not confirmed, keep the current size of the dataset as default
            else:
                self.len_data = len(self.data)
        # If there isn't any issue of length set the length given as argument
        else:
            self.len_data = length_data
Пример #6
0
    def __handle_error_saving(self, name: str, model: Module) -> None:
        """
        AUTHORS:
        --------

        :author: Alix Leroy

        DESCRIPTION:
        ------------

        Handle the error.
        Suggest solutions:
            - Retry to save the model
            - Change the save format
        Exit the program if no solution found

        :param model->Module: The model to save

        RETURN:
        -------

        :return: None
        """
        Notification(
            DEEP_NOTIF_ERROR,
            "Please make sure you have the permission to write for this following file : "
            + str(name))
        response = ""

        while response.lower() != ("y" or "n"):
            response = Notification(
                DEEP_NOTIF_INPUT,
                "Would you try to try again to save? (y/n)").get()

        if response.lower() == "y":
            self.save_model(model)
        else:
            response = ""

            while response.lower() != ("y" or "n"):
                response = Notification(
                    DEEP_NOTIF_INPUT,
                    "Would you like to save in another format, if not Deeplodocus will be closed ? (y/n)"
                ).get()

            if response.lower() == "n":
                response = ""

                while response.lower() != ("y" or "n"):
                    Notification(
                        DEEP_NOTIF_WARNING,
                        "You will lose all your data if Deeplodocus is closed !"
                    )
                    response = Notification(
                        DEEP_NOTIF_INPUT,
                        "Are you sure to close Deeplodocus (y/n)").get()

                if response.lower() == "n":
                    self.__handle_error_saving()
                else:
                    End(error=False)  #Exiting the program
            else:
                response = ""

                while response.lower() != ("pytorch" or "onnx"):
                    response = Notification(
                        DEEP_NOTIF_INPUT,
                        "What format would you like to save ? (pytorch/onnx)"
                    ).get()

                if response.lower() == "pytorch":
                    self.save_model_method = DEEP_SAVE_NET_FORMAT_PYTORCH
                elif response.lower() == "onnx":
                    self.save_model_method = DEEP_SAVE_NET_FORMAT_ONNX

                self.save_model(model)