コード例 #1
0
ファイル: UtilsFunctions.py プロジェクト: e2tovar/Consciences
def load_4_numpy_files(path_to_load, names_to_load_4):
    # TODO (@gabvaztor) Docs
    npy_extension = Dictionary.string_npy_extension
    for i in range(0, 4):
        folders.file_exists_in_path_or_create_path(path_to_load +
                                                   names_to_load_4[i])
    file_1 = np.load(path_to_load + names_to_load_4[0] + npy_extension)
    file_2 = np.load(path_to_load + names_to_load_4[1] + npy_extension)
    file_3 = np.load(path_to_load + names_to_load_4[2] + npy_extension)
    file_4 = np.load(path_to_load + names_to_load_4[3] + npy_extension)

    return file_1, file_2, file_3, file_4
コード例 #2
0
ファイル: UtilsFunctions.py プロジェクト: e2tovar/Consciences
def write_string_to_pathfile(string, filepath):
    """
    Write a string to a path file
    :param string: string to write
    :param path: path where write
    """
    try:
        folders.create_directory_from_fullpath(filepath)
        file = open(filepath, 'w+')
        file.write(str(string))
    except:
        raise ValueError(Errors.write_string_to_file)
コード例 #3
0
 def load_actual_information(self):
     """
     Information path contains best accuracy to compare before save.
     """
     # TODO (@gabvaztor) DOCs
     configuration = None
     folders.create_directory_from_fullpath(self.information_path)
     folders.create_file_from_fullpath(self.information_path)
     if os.stat(self.information_path).st_size != 0:
         with open(self.information_path) as json_configuration:
             dict = json.load(json_configuration)
             configuration = Configuration(dict)
     return configuration
コード例 #4
0
ファイル: UtilsFunctions.py プロジェクト: e2tovar/Consciences
def get_temp_file_from_fullpath(fullpath):
    """
    Create and return the temp fullpath from another fullpath

    Args:
        fullpath: the fullpath

    Returns: the created temp fullpath
    """
    basename = os.path.basename(fullpath)
    path = os.path.dirname(fullpath) + "\\temp\\"
    folders.create_directory_from_fullpath(path)

    return path + basename
コード例 #5
0
ファイル: UtilsFunctions.py プロジェクト: e2tovar/Consciences
def check_file_exists_and_change_name(path, char="", index=None):
    """
    Check if file exists and, if exists, try to change the name to another with a higher 'index'. Example:
    --> filename = 'name(id).png'. If exists, then try to create a new filename with a new index.
    --> new filename = 'name(id)_1.png)'. This has '_' as 'char'. If not char, then go only the index.
    Args:
        path: filepath
        char: char to add
        index: actual index
    Returns: new path
    """
    if folders.file_exists_in_path_or_create_path(path):
        name = os.path.splitext(path)[0]
        extension = os.path.splitext(path)[1]
        if index == 0 or is_none(index):
            index = 1
            chars_to_delete = None
        else:
            chars_to_delete = number_of_digits(index)
            index = int(name[-chars_to_delete:]) + 1
            if char:
                chars_to_delete += len(char)
        if chars_to_delete:
            new_path = name[:-chars_to_delete] + char + str(index) + extension
        else:
            new_path = name + char + str(index) + extension
        pt("new_path", path)
        path = check_file_exists_and_change_name(path=new_path,
                                                 char=char,
                                                 index=index)
    return path
コード例 #6
0
ファイル: UtilsFunctions.py プロジェクト: e2tovar/Consciences
def load_accuracies_and_losses(path_to_load, flag_restore_model=False):
    """
    
    :param path_to_load: path to load the numpy accuracies and losses
    :return: accuracies_train, accuracies_validation, loss_train, loss_validation
    """
    # TODO (@gabvaztor) Docs
    accuracies_train, accuracies_validation, loss_train, loss_validation = [], [], [], []
    if flag_restore_model:
        try:
            npy_extension = Dictionary.string_npy_extension
            filename_train_accuracies = Dictionary.filename_train_accuracies + npy_extension
            filename_validation_accuracies = Dictionary.filename_validation_accuracies + npy_extension
            filename_train_losses = Dictionary.filename_train_losses + npy_extension
            filename_validation_losses = Dictionary.filename_validation_losses + npy_extension
            if folders.file_exists_in_path_or_create_path(
                    path_to_load + filename_train_accuracies):
                accuracies_train = list(
                    np.load(path_to_load + filename_train_accuracies))
                accuracies_validation = list(
                    np.load(path_to_load + filename_validation_accuracies))
                loss_train = list(np.load(path_to_load +
                                          filename_train_losses))
                loss_validation = list(
                    np.load(path_to_load + filename_validation_losses))
        except Exception:
            pt("Could not load accuracies and losses")
            accuracies_train, accuracies_validation, loss_train, loss_validation = [], [], [], []

    return accuracies_train, accuracies_validation, loss_train, loss_validation
コード例 #7
0
 def load_actual_configuration(self):
     """
     :return: configuration
     """
     # TODO (@gabvaztor) DOCS
     configuration = None
     folders.create_directory_from_fullpath(self.configuration_path)
     folders.create_file_from_fullpath(self.configuration_path)
     try:
         if os.stat(self.configuration_path).st_size != 0:
             with open(self.configuration_path) as json_configuration:
                 dict = json.load(json_configuration)
                 configuration = Configuration(dict)
     except Exception:
         input(
             "Configuration problem: There is not a Configuration json file or this has nothing. Press Ok to"
             "continue the execution and the file will be created automatically or stop the program and create for"
             "your own")
     return configuration
コード例 #8
0
ファイル: UtilsFunctions.py プロジェクト: e2tovar/Consciences
def save_and_restart(path_to_backup):
    """
    Save and restart all progress. Create a "Zip" file from "Models" folder and, after that, remove it.
    Args:
        path_to_backup:  Path to do a backup and save it in a different folder
    """
    actual_time = str(
        time.strftime("%Y-%m-%d_%Hh%Mm%Ss", time.gmtime(time.time())))
    to_copy = folders.get_directory_from_filepath(path_to_backup) + "\\"
    to_paste = folders.get_directory_from_filepath(
        folders.get_directory_from_filepath(
            to_copy)) + "\\" + "Models_Backup(" + actual_time + ")"
    pt("Doing Models backup ...")
    # Do backup
    shutil.make_archive(to_paste, 'zip', to_copy)
    pt("Backup done successfully")
    # Do remove
    pt("Removing Models folder...")
    shutil.rmtree(to_copy)
    pt("Models removed successfully")
コード例 #9
0
ファイル: UtilsFunctions.py プロジェクト: e2tovar/Consciences
def create_historic_folder(filepath, type_file, test_accuracy=""):
    """
    Used when filepath exists to create a folder with actual_time to historicize
    :param filepath: file to save  
    :param type_file: Type of file (Information or Configuration)
    """

    # TODO (gabvaztor) Using new SettingObject path
    actual_time = str(
        time.strftime("%Y-%m-%d_%Hh%Mm%Ss", time.gmtime(time.time())))
    directory = os.path.dirname(filepath)
    filename = actual_time + "_" + os.path.basename(filepath)
    low_stripe = ""
    if test_accuracy and test_accuracy is not "":
        low_stripe = "_"
    information_folder = "\\History_Information\\" + type_file + "\\" + str(test_accuracy) + low_stripe + \
                         actual_time + "\\"
    folder = directory + information_folder
    folders.create_directory_from_fullpath(folder)
    return folder + filename
コード例 #10
0
ファイル: UtilsFunctions.py プロジェクト: e2tovar/Consciences
def save_numpy_arrays_generic(folder_to_save,
                              numpy_files,
                              names=None,
                              **kwargs):
    """
    Save the accuracies and losses into a type_file folder.
    names and numpy_files are two list.
    :param folder_to_save:
    :param numpy_files:
    :param names: Must have same size than numpy_files

    """
    debug_mode = kwargs["DEBUG"] if "DEBUG" in kwargs else False
    # TODO (@gabvaztor) finish Docs
    folders.create_directory_from_fullpath(folder_to_save)
    for index in range(len(numpy_files)):
        if names:
            np.save(folder_to_save + names[index], numpy_files[index])
        else:
            name_file = Dictionary.filename_numpy_default
            np.save(folder_to_save + name_file + str(index + 1),
                    numpy_files[index])
    if not debug_mode:
        print("Files has been saved in numpy format")
コード例 #11
0
ファイル: UtilsFunctions.py プロジェクト: e2tovar/Consciences
def load_numpy_arrays_generic(path_to_load, names):
    """
    :param path_to_load: 
    :param names: 
    :return: 
    """
    # TODO (@gabvaztor) DOCS
    files_to_return = []
    npy_extension = Dictionary.string_npy_extension
    for i in range(len(names)):
        if folders.file_exists_in_path_or_create_path(path_to_load + names[i] +
                                                      npy_extension):
            file = np.load(path_to_load + names[i] + npy_extension)
            files_to_return.append(file)
        else:
            raise Exception("File does not exist")
    return files_to_return
コード例 #12
0
ファイル: TkinterUI.py プロジェクト: e2tovar/Consciences
 def _create_button(self):
     folders.copy_entire_directory_to_path(
         path_to_be_copied=GP.DEFAULT_PROJECT_ID_PATH,
         path_to_be_paste=GP.PROJECTS_PATH + "new\\")
     self.input_code.insert(tk.END, "\nCOPIED!")
     self._exit_top()