-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
234 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from keras import backend as K | ||
|
||
|
||
def recall_m(y_true, y_pred): | ||
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1))) | ||
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1))) | ||
recall = true_positives / (possible_positives + K.epsilon()) | ||
return recall | ||
|
||
|
||
def precision_m(y_true, y_pred): | ||
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1))) | ||
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1))) | ||
precision = true_positives / (predicted_positives + K.epsilon()) | ||
return precision | ||
|
||
|
||
def f1_m(y_true, y_pred): | ||
precision = precision_m(y_true, y_pred) | ||
recall = recall_m(y_true, y_pred) | ||
return 2 * ((precision * recall) / (precision + recall + K.epsilon())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from keras.layers import Input, Dense, Dropout | ||
from keras.models import Model | ||
|
||
|
||
def get_model(num_feats, class_nbs): | ||
x = Input(shape=(num_feats, )) | ||
shared = Dense(64, activation="relu")(x) # x | ||
sub1 = Dense(32, activation="relu")(shared) | ||
#sub1 = Dropout(0.5)(sub1) | ||
|
||
sub2 = Dense(32, activation="relu")(shared) | ||
#sub2 = Dropout(0.5)(sub2) | ||
|
||
sub3 = Dense(32, activation="relu")(shared) | ||
#sub3 = Dropout(0.5)(sub3) | ||
|
||
out1 = Dense(class_nbs[0], activation="softmax")(sub1) | ||
out2 = Dense(class_nbs[1], activation="softmax")(sub2) | ||
out3 = Dense(class_nbs[2], activation="softmax")(sub3) | ||
|
||
model = Model(inputs=x, outputs=[out1, out2, out3]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.