コード例 #1
0
def initialize():
    index = 0

    all_features = np.empty((data_size, feature_length))
    all_output_labels = np.empty(
        (data_size, size_of_output_labels_vector)
    )  #  loop through all words, call word_to_index[word] and assign it to np.zeros
    all_words = {}

    for filename in os.listdir(directory):

        if os.path.isdir(directory + "/" + filename):

            for filename2 in os.listdir(os.path.join(directory, filename)):

                if os.path.isdir(directory + "/" + filename + "/" + filename2):

                    for filename3 in os.listdir(
                            os.path.join(directory, filename, filename2)):

                        if filename3 == "cache-file":
                            with open(
                                    os.path.join(directory, filename,
                                                 filename2, filename3),
                                    'rd') as f:
                                for line in f:

                                    audioFilePath = os.path.join(
                                        directory, filename, filename2,
                                        line.split(' ')[0])
                                    word = line.split(' ')[1]
                                    startTime = float(line.split(' ')[2])
                                    endTime = float(line.split(' ')[3])

                                    with open(audioFilePath, 'rd') as a:
                                        timelinedWord = WordWithTimeline(
                                            word, startTime, endTime)

                                        try:
                                            all_features[
                                                index, :] = FeaturesExtractor.getFeaturesFFT(
                                                    timelinedWord,
                                                    audioFilePath,
                                                    feature_length)
                                            all_output_labels[
                                                index, :] = np.zeros(
                                                    size_of_output_labels_vector
                                                )

                                            all_words[index] = word

                                            all_output_labels[
                                                index, word_to_index[word]] = 1
                                            index += 1

                                        except ValueError:
                                            print("skipping word, all zeros")

                                        if index >= data_size:
                                            return all_output_labels, all_features, all_words
コード例 #2
0
ファイル: Main-test.py プロジェクト: p-Mart/ML_Project
with open(os.path.join(directory, "cache-file"), 'rd') as f:

    while numOfWords > 0:
        line = f.readline()

        words[5 - numOfWords] = line.split(' ')[1]

        audioFilePath = os.path.join(directory, line.split(' ')[0])
        startTime = float(line.split(' ')[2])
        endTime = float(line.split(' ')[3])

        # with open(audioFilePath, 'rd') as a:
        timelinedWord = WordWithTimeline(
            line.split(' ')[1], startTime, endTime)
        features[5 - numOfWords, :] = FeaturesExtractor.getFeaturesFFT(
            timelinedWord, audioFilePath, feature_length)

        numOfWords -= 1

for i in range(5):
    outputs[i] = generateDicArray(words, words[i])

# print(words)
# print(outputs)
# print(features)

n_classes = 5

x = int(np.sqrt(feature_length))

layer_1 = Convolutional(input_shape=(x, x, 1),