-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_model.py
More file actions
51 lines (45 loc) · 1.54 KB
/
test_model.py
File metadata and controls
51 lines (45 loc) · 1.54 KB
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
# TODO test tagger performance function
import os
import time
import h5py
import sys
from keras import backend as K
from keras.optimizers import SGD
import numpy as np
from keras.utils import np_utils
from math import floor
from sklearn.metrics import confusion_matrix
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
from matplotlib import pyplot as plt
from tsne import bh_sne
from numpy import array
from keras.utils import plot_model
import dataset_manager
import config
import utils
if config.SELECT_DEEP_MODELS:
import model_deep as m
else:
import model as m
tags= utils.load(config.GENRES_FILE)
nb_classes= len(tags)
if config.LOAD_MELSPECS:
x_test, y_test, num_frames_test = utils.load_h5(config.TESTING_MELSPEC_FILE)
else:
print "Error : No testing data to load"
sys.exit()
if config.LOAD_WEIGHTS:
y_test_categories = np_utils.to_categorical(y_test, nb_classes)
model = m.MusicTaggerCRNN(config.MODEL_WEIGHTS_FILE, input_tensor=(1, 96, 1366), num_genres=nb_classes )
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
model.summary()
plot_model(model,to_file='model.png', show_shapes=True, show_layer_names=True)
# Evaluate shape is not correct : we need to fix it from 190,1 to none, 10 --- fromh here 1) 2) incremental tsne.
scores = model.evaluate(x_test, y_test_categories, batch_size=config.BATCH_SIZE)
print('Test Loss:', scores[0])
print('Test Accuracy:', 100*scores[1])
else:
print 'Error: there is no model to predict'