-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtempoMAGE.py
88 lines (64 loc) · 3.71 KB
/
tempoMAGE.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/python
""" TempMAGE model architecture """
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.layers import Conv2D,MaxPool2D,Flatten,Conv1D,MaxPooling1D,Dense,Dropout
def set_metrics():
""" metrics used to evaluate the model's perfromance """
METRICS = [
keras.metrics.TruePositives(name='tp'),
keras.metrics.FalsePositives(name='fp'),
keras.metrics.TrueNegatives(name='tn'),
keras.metrics.FalseNegatives(name='fn'),
keras.metrics.BinaryAccuracy(name='accuracy'),
keras.metrics.Precision(name='precision'),
keras.metrics.Recall(name='recall'),
keras.metrics.AUC(name='ROC_auc'),
keras.metrics.AUC(name='PR_auc', curve = "PR"),
keras.losses.BinaryCrossentropy(from_logits=True, name='binary_crossentropy')
]
return METRICS
def tempoMAGE(metrics, output_bias= None):
if output_bias is not None:
output_bias = tf.keras.initializers.Constant(output_bias)
seq_input = keras.Input(shape=(400,5,1), name='sequence_conv')
x = keras.layers.Conv2D(filters=32, kernel_size=(10,5), padding='valid', activation='relu',
kernel_regularizer=tf.keras.regularizers.l2(0.0001))(seq_input)
x = keras.layers.MaxPooling2D(pool_size=(2,1))(x)
x = keras.layers.Conv2D(filters=64, kernel_size=(2,1), padding='valid', activation='relu',
kernel_regularizer=tf.keras.regularizers.l2(0.0005))(x)
x = keras.layers.MaxPooling2D(pool_size=(2,1))(x)
x = keras.layers.Conv2D(filters=128, kernel_size=(2,1), padding='valid', activation='relu',
kernel_regularizer=tf.keras.regularizers.l2(0.0005) )(x)
x = keras.layers.MaxPooling2D(pool_size=(2,1))(x)
sequence_features = keras.layers.Flatten()(x)
depth_input = keras.Input(shape=(400,1), name= 'depth')
x = keras.layers.Conv1D(filters= 32, kernel_size=(5), padding='valid', activation='relu',
kernel_regularizer=tf.keras.regularizers.l2(0.0001))(depth_input)
x = keras.layers.MaxPooling1D(pool_size=(2))(x)
x = keras.layers.Conv1D(filters= 64, kernel_size=(2), padding='valid', activation='relu',
kernel_regularizer=tf.keras.regularizers.l2(0.0005))(x)
x = keras.layers.MaxPooling1D(pool_size=(2))(x)
x = keras.layers.Conv1D(filters= 128, kernel_size=(2), padding='valid', activation='relu',
kernel_regularizer=tf.keras.regularizers.l2(0.0005))(x)
x = keras.layers.MaxPooling1D(pool_size=(2))(x)
depth_features = keras.layers.Flatten()(x)
x = layers.concatenate([sequence_features, depth_features])
conv_dense = keras.layers.Dense(108, activation = 'relu')(x)
expression_input = keras.Input(shape=(20,1), name= 'expression')
expression_features = keras.layers.Flatten()(expression_input)
weight_input = keras.Input(shape=(1,1), name= 'weight')
weight_features = keras.layers.Flatten()(weight_input)
x = layers.concatenate([expression_features, weight_features])
data_dense = keras.layers.Dense(20,activation = 'relu')(x)
x = layers.concatenate([conv_dense, data_dense])
x = keras.layers.Dense(128, activation = 'relu',
kernel_regularizer=tf.keras.regularizers.l2(0.0005))(x)
x = keras.layers.Dropout(0.3)(x)
seq_pred = keras.layers.Dense(1, activation='sigmoid',bias_initializer= output_bias)(x)
model = keras.Model(inputs=[seq_input,depth_input,expression_input, weight_input], outputs= seq_pred)
model.compile(loss='binary_crossentropy',
optimizer=keras.optimizers.Adam(0.001),
metrics= metrics)
return model