-
Notifications
You must be signed in to change notification settings - Fork 0
/
defs_.py
122 lines (103 loc) · 4.13 KB
/
defs_.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from utils_ import error
import inspect
# constants, like C defines. Nesting indicates just convenient hierarchy.
class defs:
# checks non full def names
def check(arg, should_belong_to, do_boolean = False ):
parts = arg.split(".")
belongs_ok = False
if not parts[0] == "defs":
error("Invalid def : %s" % arg)
else:
curr_class = defs
parts = parts[1:]
for part in parts:
if not belongs_ok:
belongs_ok = should_belong_to == curr_class
fields = inspect.getmembers(curr_class, lambda a:not(inspect.isroutine(a)))
fields = [v[0] for v in fields if not(v[0].startswith('__') or v[0].endswith('__'))]
if not part in fields:
if not do_boolean:
error('Parameter [%s] is not defined for [%s]' % (part, curr_class))
else:
return (False, None)
else:
curr_class = getattr(curr_class, part)
if not belongs_ok:
if not do_boolean:
error("Supplied parameter [%s] should be a child of def [%s]" % (arg, should_belong_to))
else:
return (False, None)
if do_boolean:
return (True, curr_class)
else:
return curr_class
class representation:
dcnn, fc, nop = "dcnn", "fc", "nop"
class classifier:
fc, lstm = "fc", "lstm"
# run phase
class phase:
train, val ="train", "val"
# input mode is framewise dataset vs videowise, each video having n frames
class input_mode:
video, image, vectors = "video", "image", "vectors"
class net_input:
visual, labels = "visual", "labels"
class dataset_tag:
main, aux = "main", "aux"
# direct reading from disk or from packed tfrecord format
class data_format:
raw, tfrecord = "raw", "tfrecord"
class rnn_visual_mode:
state_bias, input_bias, input_concat = "state_bias", "input_bias", "input_concat"
# sequence fusion methods
class fusion_method:
avg, last, concat, reshape, state, ibias, maximum = "avg", "last", "concat", "reshape", "state", "ibias", "maximum"
# early/late fusion
class fusion_type:
early, late, none, main, aux = "early", "late", "none", "main", "aux"
# how the video's frames are structured
class clipframe_mode:
rand_frames, rand_clips, iterative = "rand_frames", "rand_clips", "iterative"
# what to do if clip generation fails
class generation_error:
abort, compromise, report = "abort", "compromise", "report"
class batch_item:
default, clip = "default", "clip"
class optim:
sgd, rmsprop, adam = "sgd", "rmsprop", "adam"
def adapts_lr(optimizer):
return optimizer in [defs.optim.rmsprop, defs.optim.adam]
def uses_momentum(optimizer):
return optimizer not in [defs.optim.sgd]
# learning rate decay parameters
class decay:
exp, staircase = "exp", "staircase"
# periodicity
class periodicity:
interval, drops = "interval", "drops"
class label_type:
single, multiple = "single", "multiple"
class caption_search:
max = "max"
class eval_type:
coco = "coco"
class names:
global_step, latest_savefile = "global_step", "latest"
class return_type:
argmax_index, standard = "argmax_index", "standard"
class imgproc:
rand_mirror, rand_crop, center_crop, resize, raw_resize, sub_mean = \
"rand_mirror", "rand_crop", "center_crop", "resize", "raw_resize", "sub_mean"
def to_str(vec):
res = []
if defs.imgproc.rand_mirror in vec: res.append("rm")
if defs.imgproc.rand_crop in vec: res.append("rc")
if defs.imgproc.center_crop in vec: res.append("cc")
if defs.imgproc.resize in vec: res.append("rs")
if defs.imgproc.raw_resize in vec: res.append("rr")
if defs.imgproc.sub_mean in vec: res.append("sm")
return "-".join(res)
train_idx, val_idx = 0, 1
image, label = 0, 1