forked from arikpoz/deep-visualization-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bindings.py
148 lines (127 loc) · 5.54 KB
/
bindings.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Define key bindings
from keys import key_patterns
class Bindings(object):
def __init__(self, key_patterns):
self._tag_to_key_labels = {}
self._tag_to_help = {}
self._key_label_to_tag = {}
self._key_patterns = key_patterns
self._cache_keycode_to_tag = {}
def get_tag(self, keycode):
'''Gets tag for keycode, returns None if no tag found.'''
if keycode is None:
return None
if not keycode in self._cache_keycode_to_tag:
label = self.get_key_label_from_keycode(keycode)
self._cache_keycode_to_tag[keycode] = self.get_tag_from_key_label(label)
return self._cache_keycode_to_tag[keycode]
def get_tag_from_key_label(self, label):
'''Get tag using key label, if no match, returns None.'''
return self._key_label_to_tag.get(label, None)
def get_key_label_from_keycode(self, keycode, extra_info = False):
'''Get tag using keycode, if no match, returns None.'''
label = None
for mask in reversed(sorted(self._key_patterns.keys())):
masked_keycode = keycode & mask
if masked_keycode in self._key_patterns[mask]:
label = self._key_patterns[mask][masked_keycode]
break
if extra_info:
return label, [keycode & mask for mask in reversed(sorted(self._key_patterns.keys()))]
else:
return label
def add(self, tag, key, help_text):
self.add_multikey(tag, (key,), help_text)
def add_multikey(self, tag, key_labels, help_text):
for key_label in key_labels:
assert key_label not in self._key_label_to_tag, (
'Key "%s" cannot be bound to "%s" because it is already bound to "%s"' %
(key_label, tag, self._key_label_to_tag[key_label])
)
self._key_label_to_tag[key_label] = tag
self._tag_to_key_labels[tag] = key_labels
self._tag_to_help[tag] = help_text
def get_key_help(self, tag):
return (self._tag_to_key_labels[tag], self._tag_to_help[tag])
_ = Bindings(key_patterns)
# Core
_.add('freeze_cam', 'f',
'Freeze or unfreeze camera capture')
_.add('toggle_input_mode', 'c',
'Toggle between camera and static files')
_.add_multikey('static_file_increment', ['e', 'pgdn'],
'Load next static file')
_.add_multikey('static_file_decrement', ['w', 'pgup'],
'Load previous static file')
_.add('help_mode', 'h',
'Toggle this help screen')
_.add('stretch_mode', '0',
'Toggle between cropping and stretching static files to be square')
_.add('debug_level', '5',
'Cycle debug level between 0 (quiet), 1 (some timing info) and 2 (all timing info)')
_.add('quit', 'q',
'Quit')
# Caffevis
_.add_multikey('reset_state', ['esc'],
'Reset: turn off backprop, reset to layer 0, unit 0, default boost.')
_.add_multikey('sel_left', ['left', 'j'],
'')
_.add_multikey('sel_right', ['right', 'l'],
'')
_.add_multikey('sel_down', ['down', 'k'],
'')
_.add_multikey('sel_up', ['up', 'i'],
'')
_.add('sel_left_fast', 'J',
'')
_.add('sel_right_fast', 'L',
'')
_.add('sel_down_fast', 'K',
'')
_.add('sel_up_fast', 'I',
'')
_.add_multikey('sel_layer_left', ['u', 'U'],
'Select previous layer without moving cursor')
_.add_multikey('sel_layer_right', ['o', 'O'],
'Select next layer without moving cursor')
_.add('zoom_mode', 'z',
'Cycle zooming through {currently selected unit, backprop results, none}')
_.add('next_pattern_mode', 's',
'Cycle channels overlay (max opt, max input, weights hist, max hist, correlation, off)')
_.add('prev_pattern_mode', 'S',
'Cycle patterns overlay (max opt, max input, weights hist, max hist, correlation, off)')
_.add('pattern_first_only', '1',
'Toggle pattern loading first image only or loading all available images')
_.add('next_ez_back_mode_loop', 'b',
'Cycle through backprop modes (grad, deconv zf, deconv gb, off)')
_.add('prev_ez_back_mode_loop', 'B',
'Cycle through backprop modes (grad, deconv zf, deconv gb, off)')
_.add('freeze_back_unit', 'd',
'Freeze the bprop/deconv origin to be the currently selected unit')
_.add('show_back', 'a',
'Toggle between showing forward activations and back/deconv diffs')
_.add('next_back_view_option', 'n',
'Cycle through backprop view options (raw, gray, norm, normblur, sum>0, histogram)')
_.add('prev_back_view_option', 'N',
'Cycle through backprop view options (raw, gray, norm, normblur, sum>0, histogram)')
_.add('next_color_map', 'm',
'Cycle through colormaps options (grayscale, jet, plasma)')
_.add('prev_color_map', 'M',
'Cycle through colormaps options (grayscale, jet, plasma)')
_.add('boost_gamma', 't',
'Boost contrast using gamma correction')
_.add('boost_individual', 'T',
'Boost contrast by scaling each channel to use more of its individual range')
_.add('toggle_label_predictions', '8',
'Turn on or off display of prob label values')
_.add('toggle_unit_jpgs', '9',
'Turn on or off display of loaded jpg visualization')
_.add('siamese_view_mode', 'v',
'Cycle between siamese view modes {first image, second image, both images}')
_.add('toggle_maximal_score', 'r',
'Toggle showing maximal score overlays {on, off}')
_.add('next_input_overlay', 'y',
'Cycle input overlay {off, over active, over inactive}')
_.add('prev_input_overlay', 'Y',
'Cycle input overlay {off, over active, over inactive}')
bindings = _