forked from despoisj/DeepAudioClassification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
48 lines (34 loc) · 1.68 KB
/
model.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
# -*- coding: utf-8 -*-
import numpy as np
import tflearn
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.estimator import regression
from tflearn.optimizers import SGD
from tflearn.optimizers import RMSProp
from config import learningRate
def createModel(nbClasses,imageSize, sliceHeight):
print("[+] Creating model...")
convnet = input_data(shape=[None, imageSize, sliceHeight, 1], name='input')
convnet = conv_2d(convnet, 32, 2, activation='elu', weights_init="Xavier")
convnet = max_pool_2d(convnet, 2)
convnet = conv_2d(convnet, 64, 2, activation='elu', weights_init="Xavier")
convnet = max_pool_2d(convnet, 2)
convnet = conv_2d(convnet, 128, 2, activation='elu', weights_init="Xavier")
convnet = max_pool_2d(convnet, 2)
convnet = conv_2d(convnet, 256, 2, activation='elu', weights_init="Xavier")
convnet = max_pool_2d(convnet, 2)
convnet = conv_2d(convnet, 512, 2, activation='elu', weights_init="Xavier")
convnet = max_pool_2d(convnet, 2)
convnet = conv_2d(convnet, 1024, 2, activation='elu', weights_init="Xavier")
convnet = max_pool_2d(convnet, 2)
convnet = fully_connected(convnet, 2048, activation='elu')
convnet = dropout(convnet, 0.5)
convnet = fully_connected(convnet, nbClasses, activation='softmax')
rmsprop = RMSProp(learning_rate=learningRate, decay=0.999)
# sgd = SGD(learning_rate=learningRate, lr_decay=0.96, decay_step=100)
convnet = regression(convnet, optimizer='rmsprop', loss='categorical_crossentropy')
# convnet = regression(convnet, optimizer='sgd', loss='categorical_crossentropy')
model = tflearn.DNN(convnet)
print(" Model created! ✅")
return model