Repository navigation
Expand file tree
/
Copy pathutils.py
More file actions
72 lines (59 loc) · 2.65 KB
/
Copy pathutils.py
File metadata and controls
72 lines (59 loc) · 2.65 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import pickle as pk
from argparse import ArgumentParser
def gen_todo_list(directory, check = None):
files = os.listdir(directory)
todo_list = []
for f in files:
fullpath = os.path.join(directory, f)
if os.path.isfile(fullpath):
if check is not None:
if check(f):
todo_list.append(fullpath)
else:
todo_list.append(fullpath)
return todo_list
def dump(data, filename):
with open(filename, 'wb') as f:
pk.dump(data, f)
def load(filename):
with open(filename, 'rb') as f:
data = pk.load(f)
return data
def get_args():
parser = ArgumentParser()
#parser.add_argument("pos1", help="positional argument 1")
parser.add_argument("-m", "--mode", help="trainer mode [train/test]", dest="mode", default="train")
parser.add_argument("-n", "--name", help="model name [model]", dest="model_name", default="model")
parser.add_argument("-t", "--model_type", help="model type [cnn/sae]", dest="model_type", default="cnn")
parser.add_argument("-tt", "--task_type", help="task type [app/class]", dest="task_type", default="app")
parser.add_argument("-bs", "--batch-size", help="batch size [256]", dest="batch_size", default=256, type=int)
parser.add_argument("-db", "--debug", help="debug [False]", dest="debug", action="store_true")
parser.add_argument("-l", "--load", help="load [False]", dest="load", action="store_true")
args = parser.parse_args()
return args
from keras import backend as K
def f1_score(y_true, y_pred):
def recall(y_true, y_pred):
"""Recall metric.
Only computes a batch-wise average of recall.
Computes the recall, a metric for multi-label classification of
how many relevant items are selected.
"""
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(y_true, y_pred):
"""Precision metric.
Only computes a batch-wise average of precision.
Computes the precision, a metric for multi-label classification of
how many selected items are relevant.
"""
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
precision = precision(y_true, y_pred)
recall = recall(y_true, y_pred)
return 2*((precision*recall)/(precision+recall+K.epsilon()))