|
""" |
|
这是带注释的,我用中文写了 |
|
""" |
|
|
|
import numpy as np |
|
from tensorflow.keras.models import Sequential |
|
from tensorflow.keras.layers import Dense, Dropout |
|
from tensorflow.keras.losses import binary_crossentropy |
|
from tensorflow.keras.optimizers import Adam |
|
from sklearn.metrics import roc_curve |
|
from scipy.interpolate import interp1d |
|
from scipy.optimize import brentq |
|
import matplotlib.pyplot as plt |
|
from scipy.io.wavfile import read |
|
from sklearn.preprocessing import normalize |
|
from generate_array_feature import mald_feature, get_filelist |
|
import time |
|
|
|
|
|
|
|
|
|
|
|
batch_size = 10 |
|
feature_len = 110 |
|
loss_function = binary_crossentropy |
|
no_epochs = 150 |
|
optimizer = Adam() |
|
verbosity = 1 |
|
model = Sequential() |
|
model.add(Dense(64, input_dim=feature_len, activation='relu')) |
|
model.add(Dropout(0.2)) |
|
model.add(Dense(32, activation='relu')) |
|
model.add(Dropout(0.2)) |
|
model.add(Dense(16, activation='relu')) |
|
model.add(Dense(1, activation='sigmoid')) |
|
model.compile(loss=loss_function, optimizer=optimizer, metrics=['accuracy']) |
|
|
|
model.load_weights(r"/home/fazhong/Github/czx/model.hdf5") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data_npy = np.load('./data.npy',allow_pickle=True) |
|
labels_npy = np.load('./labels.npy',allow_pickle=True) |
|
|
|
data = data_npy.tolist() |
|
labels_org = labels_npy.tolist() |
|
labels = [] |
|
for x in labels_org: |
|
labels.append(x[0]) |
|
|
|
|
|
voice = [] |
|
|
|
X = [] |
|
y = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
X = data |
|
Y = labels |
|
|
|
norm_X = normalize(X, axis=0, norm='max') |
|
|
|
X = np.asarray(norm_X) |
|
y = np.asarray(y) |
|
|
|
|
|
scores = model.evaluate(X, y) |
|
y_pred = np.round(model.predict(X)) |
|
print(y_pred) |
|
acc = 0 |
|
for i in range(len(y)): |
|
if y_pred[i] == y: acc+=1 |
|
print(acc/len(y)) |