-
Notifications
You must be signed in to change notification settings - Fork 0
/
eplon_voice_predict.py
69 lines (49 loc) · 1.84 KB
/
eplon_voice_predict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from keras import optimizers, losses
from keras.layers import *
from keras.models import Model, model_from_json
from keras.backend import int_shape
from keras.utils import to_categorical, plot_model
import numpy as np
import glob
import tqdm
DIR_PREDICT_OUTPUT = "./predict_441kHz_output"
#入力ファイル名とラベル・ラベル番号付け
LABELSETS = [
[0,"normal"],
[1,"happy"],
]
#予測データの読み込み
def eplon_voice_deeplearning_input_predict_data(pathname):
file_num = len(glob.glob(pathname+"/*"))
print("total file numbers: ",file_num)
data_X = np.zeros([file_num, 28, 28])
for n in tqdm.tqdm(range(file_num)):
data_X[n,:,:] = np.load(pathname+"/"+str(n+1)+".npy")
print("data_X shape:",data_X.shape)
return data_X
#予測の表示出力
def eplon_voice_deeplearning_print_prediction(predict):
i=0
result = np.zeros(len(LABELSETS))
for pred in predict:
result[pred.argmax()] = result[pred.argmax()] + 1
for pred in result:
print(LABELSETS[i][1]+" : "+str(int(pred*1000/predict.shape[0])))
i = i + 1
def eplon_voice_predict(netname):
model = model_from_json(open(netname+'.json').read())
# 学習結果を読み込む
model.load_weights(netname+'.h5')
#print(model.summary())
# Training configuration
model.compile(loss=losses.categorical_crossentropy,
optimizer=optimizers.Adam(),
metrics=['accuracy'])
X_test = eplon_voice_deeplearning_input_predict_data(DIR_PREDICT_OUTPUT)
# 配列の整形と,色の範囲を0-255 -> 0-1に変換
X_test = X_test / 127
X_test = X_test.reshape(X_test.shape[0], 28, 28, 1)
# Evaluation
result = model.predict(X_test, X_test.shape[0], 1)
print("Prediction: ", result)
eplon_voice_deeplearning_print_prediction(result)