Пример #1
0
    def dict2array(self, directory_files_feature_dict: dict, label_list: list, normalize: bool):
        """
        :param directory_files_feature_dict:
        :param label_list:
        :param normalize:
        :return: expert_feature_2d_array: Extracted feature with expert system (Numpy 2D array)
        :return mel_spectrogram_array: Extracted mel-spectrogram (Numpy 3D array)
        :return list_array: Labels in numpy array
        """
        # Convert extracted feature and label to numpy array
        expert_feature_array, mel_spectrogram_array = self.AFE.dict2array(directory_files_feature_dict)
        label_array = np.array(label_list)

        # Normalize expert feature
        if normalize is True:
            # Remove NaNs from array
            expert_feature_array, mel_spectrogram_array, label_array = DataProcess.remove_nan_from_array(expert_feature_array,
                                                                                                         mel_spectrogram_array,
                                                                                                         label_array)

            # Take stats from expert feature
            DataProcess.take_dataset_stats(expert_feature_array, 'backend/expert_feature_mean_list.txt')
            expert_feature_array = DataProcess.min_max_normalize(expert_feature_array)

        # Convert dimension of mel-spectrogram array
        mel_spectrogram_array = mel_spectrogram_array.reshape(mel_spectrogram_array.shape[0],
                                                              mel_spectrogram_array.shape[1],
                                                              mel_spectrogram_array.shape[2],
                                                              1)
        return expert_feature_array, mel_spectrogram_array, label_array
Пример #2
0
    def save_data(self, expert_feature_array, mel_spectrogram_array, label_array):
        """
        Save extracted feature into directories.
        :param expert_feature_array: Extracted feature with expert system (Numpy 2D array)
        :param mel_spectrogram_array: Extracted mel-spectrogram (Numpy 3D array)
        :param label_array:
        :return:
        """
        # Remove NaNs from array
        expert_feature_array = DataProcess.remove_nan_from_array(expert_feature_array)

        # Take stats from expert feature
        DataProcess.take_dataset_stats(expert_feature_array, 'backend/normalized_expert_feature_mean_list.txt')

        # Save data
        np.save(os.path.join('backend/feature/expert', "data"), expert_feature_array)
        np.save(os.path.join('backend/feature/expert', "label"), label_array)
        np.save(os.path.join('backend/feature/mel_spectrogram', "data"), expert_feature_array)
        np.save(os.path.join('backend/feature/mel_spectrogram', "label"), label_array)

        return expert_feature_array, mel_spectrogram_array, label_array