def read_main_session_file(session_file_path: str):
        """
        - Reads the file that contains the session details.
        
        :param session_file_path: Path to the file that contains the session
                                  details.

        :return: 
        """

        if fe.is_file(path=session_file_path):
            session_details = SessionRW.read_main_session_file(
                session_file_path=session_file_path)

            session_details.session_current_path = fe.remove_last_entry_from_path(
                path=session_file_path)

            session_details.main_data_set_file = \
                session_details.data_set_directory \
                + '/' \
                + session_details.data_set_name \
                + g_const.GLOBAL_DATA_SET_FILE_EXTENSION

            return session_details
        else:
            raise FileNotFoundError('"' + session_file_path +
                                    '" does not exists.')
    def is_valid(self):
        """
        - Checks if valid

        :return: - True if valid
                 - False otherwise
        """

        if not isinstance(self.directory_path, str) \
                or not isinstance(self.description, str) \
                or not isinstance(self.file_name, str):
            return False

        if self.directory_path == '' \
                or self.description == '' \
                or self.file_name == '':
            return False

        file_path = self.directory_path + '/' + self.file_name

        if not fe.is_directory(self.directory_path) \
                or not fe.is_file(file_path):
            return False

        return True
Exemple #3
0
    def session_details_input_are_valid(self):
        """
        - Checks if all the input properties are valid.

        :return: - True if all the input properties are valid.
                 - False otherwise.
        """

        if self._k_fold_cv_session:
            if not isinstance(self.number_of_folds, int) \
                    or self.number_of_folds not in const.TSDI_K_FOLD_CV_OPTIONS:
                return False

        if not isinstance(self._data_set_name, str) \
                or not isinstance(self.examples_per_batch, int) \
                or not isinstance(self.number_of_epochs, int) \
                or not isinstance(self.neural_network, str) \
                or not isinstance(self.image_size, int):
            return False

        if self.examples_per_batch not in const.TSDI_BATCH_SIZE_OPTIONS \
                or self.number_of_epochs not in const.TSDI_EPOCHS_NBR_OPTIONS \
                or self.neural_network not in const.TSDI_NN_MODEL_OPTIONS \
                or self.image_size not in const.TSDI_IMAGE_SIZE_OPTIONS \
                or not fe.is_file(self.main_data_set_file):
            return False

        return True
Exemple #4
0
    def main_data_set_file(
            self,
            value: str):

        if not isinstance(value, str) \
                or not fe.is_file(value):
            raise ValueError('Data set location must be a string and also a '
                             'valid file path.\n But got: ' + str(value))

        self._main_data_set_file = value
    def update_sha512(self, path_to_file: str):
        """
        - Updates the file's SHA512.
        
        :param path_to_file: Path to the directory that contains the file.
        """

        file_name = path_to_file + '/' + self.file_name

        if fe.is_file(file_name):
            self._sha512 = fe.file_sha512(file_name)
        else:
            raise ValueError(self.file_name + ' does not exist.')

        print('\n====\n' + file_name + '\n' + str(self))
Exemple #6
0
    def check_file_existence(self):
        """
        - Checks if all the data set files exist.

        :return:    - True if all the files exist.
                    - False otherwise.
        """

        for file in self._data_set_files:
            file_path = self._path_to_files + '/' + file.file_name

            if not fe.is_file(path=file_path):
                return False

        return True
    def read_main_data_set_file(file_path: str):
        """
        - Reads the main file of a data set.
        - Raises:
                    * FileNotFoundError
                    * CorruptMainDataSetFile

        :param file_path: Path to a main data set file.

        :return: DataSetDetails instance.
        """

        if fe.is_file(path=file_path):
            data_set_details = DataSetReader.read_main_data_set_file(
                path=file_path)

            return data_set_details
        else:
            raise FileNotFoundError('"' + file_path + '" does not exists.')
    def cifar10_files_exist_and_are_valid():
        """
        - Checks if the Cifar10 files are valid.

        :return:    - True if the train and test data set file are valid.
                    - False otherwise.
        """

        for i in range(len(const.CIFAR10_FILE_SHA512)):
            if not fe.is_file(const.CIFAR10_FILE_PATHS[i]):
                return False

            file_sha512 = fe.file_sha512(const.CIFAR10_FILE_PATHS[i])
            correct_sha512 = const.CIFAR10_FILE_SHA512[i]

            if correct_sha512 != file_sha512:
                return False

        return True
    def check_if_download_is_needed():
        """
        :return:    - True if the download is required.
                    - False otherwise.
        """

        if fe.is_file(const.CIFAR10_ARCHIVE_PATH):
            # If the Cifar10 archive exists.

            file_md5sum = fe.file_md5sum(const.CIFAR10_ARCHIVE_PATH)

            if not const.CIFAR10_ARCHIVE_MD5SUM == file_md5sum:
                # If the Cifar10 archive is corrupted.
                fe.delete_file(const.CIFAR10_ARCHIVE_PATH)

                return True
        else:
            # If the Cifar10 archive does not exist.

            return True

        return False