def render(self, is_lock): bimpy.indent(10) bimpy.text('- Plane') bimpy.same_line() bimpy_tools.help_marker( 'generate with random points\n' \ '* plane random: random on whole plane\n' \ '* balanced random: balanced positive and negative samples' ) bimpy.push_item_width(140) if bimpy.begin_combo('strategy##plane_random_generator', self._select_strategy): for item in self._strategy_list: is_selected = bimpy.Bool(self._select_strategy == item) if bimpy.selectable(item, is_selected) and not is_lock: self._select_strategy = item if is_selected.value: bimpy.set_item_default_focus() bimpy.end_combo() bimpy.pop_item_width() bimpy.unindent(10)
def render(self, is_lock): bimpy.set_next_tree_node_open(True, bimpy.Condition.FirstUseEver) if not bimpy.tree_node('convex points##convex_component'): return bimpy.same_line() bimpy_tools.help_marker('Convex points should be presented in counter-clockwise order') flags = bimpy.InputTextFlags.EnterReturnsTrue if is_lock: flags |= bimpy.InputTextFlags.ReadOnly last_convex_number_value = self._convex_number.value if bimpy.input_int('number##convex_component', self._convex_number, 1, 1, flags): self._convex_number.value = max(3, self._convex_number.value) if last_convex_number_value > self._convex_number.value: self._convex_data = self._convex_data[:self._convex_number.value] # cut back points else: self._convex_data.extend([ [bimpy.Float(0), bimpy.Float(0)] for _ in range(last_convex_number_value, self._convex_number.value) ]) # show convex value setting bimpy.set_next_tree_node_open(self._convex_number.value < 10, bimpy.Condition.FirstUseEver) if bimpy.tree_node('convex value ({})##convex_component'.format(self._convex_number.value)): for index in range(self._convex_number.value): bimpy.push_item_width(210) bimpy.input_float2( '{:<3d}'.format(index), self._convex_data[index][0], self._convex_data[index][1], flags=flags ) bimpy.pop_item_width() bimpy.tree_pop() # draw part bimpy.new_line() if bimpy.button('draw convex##convex_component') and not is_lock: self._convex_data_backup = [[item[0].value, item[1].value] for item in self._convex_data] self._convex_draw_flag = True self._convex_data = [] self._convex_number.value = 0 bimpy.tree_pop()
def show(self, ctx): # Add a layer to the MLP bimpy.push_item_width(80) bimpy.input_int("nr neurons", self.ui.nr_neurons) bimpy.same_line() bimpy.combo("transfer", self.ui.transfer, self.ui.transfer_names) if (self.ui.nr_neurons.value > 0): bimpy.same_line() if (bimpy.button("add layer")): transfer = self.ui.transfer_names[self.ui.transfer.value] self.model.add_layer(transfer, self.ui.nr_neurons.value) bimpy.pop_item_width() self.model.show(ctx) show_io_plot(self.ui.input, self.model)
def render(self, is_lock): bimpy.indent(10) bimpy.text('- SGD') bimpy.same_line() bimpy_tools.help_marker('torch.optim.SGD') flags = bimpy.InputTextFlags.EnterReturnsTrue if is_lock: flags |= bimpy.InputTextFlags.ReadOnly bimpy.push_item_width(120) if bimpy.input_float('lr##sgd_optimizer', self._lr, flags=flags): self._lr.value = max(0.0, self._lr.value) if bimpy.input_float('momentum##sgd_optimizer', self._momentum, flags=flags): self._momentum.value = max(0.0, self._momentum.value) if bimpy.input_float('dampening##sgd_optimizer', self._dampening, flags=flags): self._dampening.value = max(0.0, self._dampening.value) if bimpy.input_float('weight_decay##sgd_optimizer', self._weight_decay, flags=flags): self._weight_decay.value = max(0.0, self._weight_decay.value) if bimpy.checkbox('nesterov##sgd_optimizer', self._nesterov): self._hint_nesterov = False if self._nesterov.value: if self._momentum.value == 0 or self._dampening.value > 0: self._nesterov.value = False self._hint_nesterov = True bimpy.same_line() bimpy_tools.help_marker( 'Nesterov momentum requires a momentum and zero dampening', self._hint_nesterov) bimpy.pop_item_width() bimpy.unindent(10)
def render(self, is_lock): bimpy.set_next_tree_node_open(True, bimpy.Condition.FirstUseEver) if not bimpy.tree_node('trainning##train_component'): return flags = bimpy.InputTextFlags.EnterReturnsTrue if is_lock: flags |= bimpy.InputTextFlags.ReadOnly bimpy.push_item_width(120) if bimpy.input_int('epoch##train_component', self._epoch, 0, 0, flags=flags): self._epoch.value = max(1, self._epoch.value) if bimpy.input_int('batch_size##train_component', self._batch_size, 0, 0, flags=flags): self._batch_size.value = max(1, self._batch_size.value) if bimpy.input_int('batch_per_epoch##train_component', self._batch_per_epoch, 0, 0, flags=flags): self._batch_per_epoch.value = max(1, self._batch_per_epoch.value) if bimpy.input_int('valid_size##train_component', self._valid_size, 0, 0, flags=flags): self._valid_size.value = max(0, self._valid_size.value) bimpy.pop_item_width() bimpy.tree_pop()
def render(self, is_lock): bimpy.indent(10) bimpy.text('- Linear layer init') bimpy.same_line() bimpy_tools.help_marker( 'Initializer used in torch.nn.Linear, use Kaiming uniform') bimpy.push_item_width(120) flags = bimpy.InputTextFlags.EnterReturnsTrue if is_lock: flags |= bimpy.InputTextFlags.ReadOnly if bimpy.input_float('a##sgd_optimizer', self._a, flags=flags): self._a.value = max(0.0, self._a.value) if bimpy.begin_combo('mode##linear_layer_init', self._select_mode): for item in self._mode_list: is_selected = bimpy.Bool(self._select_mode == item) if bimpy.selectable(item, is_selected) and not is_lock: self._select_mode = item if is_selected.value: bimpy.set_item_default_focus() bimpy.end_combo() if bimpy.begin_combo('nonlinearity##linear_layer_init', self._select_nonlinearity): for item in self._nonlinearity_list: is_selected = bimpy.Bool(self._select_nonlinearity == item) if bimpy.selectable(item, is_selected) and not is_lock: self._select_nonlinearity = item if is_selected.value: bimpy.set_item_default_focus() bimpy.end_combo() bimpy.pop_item_width() bimpy.unindent(10)
def render(self, is_lock): bimpy.indent(10) bimpy.text('- MSE loss') bimpy.same_line() bimpy_tools.help_marker('torch.nn.MSELoss') bimpy.push_item_width(120) if bimpy.begin_combo('reduction##mse_loss_fn', self._select_redution): for item in self._reduction_list: is_selected = bimpy.Bool(self._select_redution == item) if bimpy.selectable(item, is_selected) and not is_lock: self._select_redution = item if is_selected.value: bimpy.set_item_default_focus() bimpy.end_combo() bimpy.pop_item_width() bimpy.unindent(10)
def render(self, is_lock): bimpy.indent(10) bimpy.text('- Adam') bimpy.same_line() bimpy_tools.help_marker('torch.optim.Adam') flags = bimpy.InputTextFlags.EnterReturnsTrue if is_lock: flags |= bimpy.InputTextFlags.ReadOnly bimpy.push_item_width(140) if bimpy.input_float('lr##adam_optimizer', self._lr, flags=flags): self._lr.value = max(0.0, self._lr.value) if bimpy.input_float2('momentum##adam_optimizer', self._betas_first, self._betas_second, flags=flags): self._betas_first.value = max(0.0, self._betas_first.value) self._betas_second.value = max(0.0, self._betas_second.value) if bimpy.input_float('eps##adam_optimizer', self._eps, decimal_precision=8, flags=flags): self._dampening.value = max(0.0, self._eps.value) if bimpy.input_float('weight_decay##adam_optimizer', self._weight_decay, flags=flags): self._weight_decay.value = max(0.0, self._weight_decay.value) bimpy.checkbox('amsgrad##adam_optimizer', self._amsgrad) bimpy.pop_item_width() bimpy.unindent(10)
def render(self, is_lock): bimpy.indent(10) bimpy.text('- Raw Point') bimpy.same_line() bimpy_tools.help_marker('generate with raw points') bimpy.push_item_width(120) if bimpy.begin_combo('strategy##raw_point_generator', self._select_strategy): for item in self._strategy_list: is_selected = bimpy.Bool(self._select_strategy == item) if bimpy.selectable(item, is_selected) and not is_lock: self._select_strategy = item if is_selected.value: bimpy.set_item_default_focus() bimpy.end_combo() bimpy.pop_item_width() bimpy.unindent(10)
bimpy.next_column() bimpy.text("Some text") bimpy.separator() bimpy.columns(1) if bimpy.button("Some button"): a = 0 print("!!!") bimpy.progress_bar(a) bimpy.combo("Combo!", selectedItem, mylist) bimpy.push_item_width(-10.0) bimpy.plot_lines("Some plot", vals, graph_size=bimpy.Vec2(0, 300)) bimpy.pop_item_width() a += 0.01 bimpy.end() if bimpy.begin("Hello2!", flags=(bimpy.WindowFlags.AlwaysAutoResize | bimpy.WindowFlags.NoTitleBar)): bimpy.text("Some text") if bimpy.button("Some button"): print("!!!") bimpy.combo("Combo2!", selectedItem, mylist) bimpy.end()
def render(self, is_lock): bimpy.set_next_tree_node_open(True, bimpy.Condition.FirstUseEver) if not bimpy.tree_node('lines##lines_component'): return # number setting flags = bimpy.InputTextFlags.EnterReturnsTrue if is_lock: flags |= bimpy.InputTextFlags.ReadOnly if bimpy.input_int('number##lines_component', self._line_number, 1, 1, flags): self._line_number.value = max(3, self._line_number.value) if self._last_line_number_value > self._line_number.value: self._line_data = self._line_data[:self._line_number.value] # cut back points else: self._line_data.extend([ [bimpy.Float(0), bimpy.Float(0), bimpy.Float(0)] for _ in range(self._last_line_number_value, self._line_number.value) ]) self._last_line_number_value = self._line_number.value # print('line number change to {}'.format(self._line_number.value)) # show line value setting bimpy.set_next_tree_node_open(self._line_number.value < 10, bimpy.Condition.FirstUseEver) self._highlight_line_index = None if bimpy.tree_node('line value ({})'.format(self._line_number.value)): for index in range(self._line_number.value): bimpy.push_item_width(210) bimpy.input_float3( '{:<3d}'.format(index), self._line_data[index][0], self._line_data[index][1], self._line_data[index][2], flags=flags ) bimpy.pop_item_width() if bimpy.is_item_hovered(): self._highlight_line_index = index bimpy.same_line() if bimpy.button('rev##lines_component{}'.format(index)) and not is_lock: for j in range(3): self._line_data[index][j].value = -self._line_data[index][j].value if bimpy.is_item_hovered(): self._highlight_line_index = index bimpy.same_line() if bimpy.button('draw##lines_component{}'.format(index)) and not is_lock: self._waitting_draw_line_index = index bimpy.set_window_focus('canvas window##canvas') if bimpy.is_item_hovered(): self._highlight_line_index = index bimpy.tree_pop() # random setting bimpy.new_line() if bimpy.button('random##lines_component') and not is_lock: initializer = self.initializer_component.build_initializer() random_lines = initializer.random(self._line_number.value) for index in range(self._line_number.value): self._line_data[index][0].value = random_lines[index].a self._line_data[index][1].value = random_lines[index].b self._line_data[index][2].value = random_lines[index].c self.initializer_component.render(is_lock) bimpy.tree_pop()
def render(self, ctx, windows_info): # calculate autoly self.pos = bimpy.Vec2( windows_info['file_brewswer_ui']['x'] + windows_info['file_brewswer_ui']['w'] + conf.margin, conf.margin) self.size = bimpy.Vec2( ctx.width() - self.pos.x - conf.margin, ctx.height() - 3 * conf.margin - conf.meta_info_height) bimpy.set_next_window_pos(self.pos, bimpy.Condition.Always) bimpy.set_next_window_size(self.size, bimpy.Condition.Always) bimpy.begin( LANG.image_shower_ui_title, bimpy.Bool(True), bimpy.WindowFlags.NoCollapse | bimpy.WindowFlags.NoMove | bimpy.WindowFlags.NoResize | bimpy.WindowFlags.HorizontalScrollbar) ###########UI########### # modal part if self.im is not None: bimpy.set_cursor_pos(bimpy.Vec2(0.0, conf.margin * 3)) bimpy.image(self.im) # if image is loaded if self.labels is not None: for i, label in enumerate(self.labels): color = self.COLORS[self.classes.index(label)] # print((self.bbox[i][0], self.bbox[i][1] - 10)) # show on the left bottom of the picture bimpy.set_cursor_pos( bimpy.Vec2(self.bbox[i][0] + 10, self.bbox[i][3] + 10)) # set style bimpy.push_id_int(i) if conf.show_yolo_confience: bimpy.button( label + ' ' + str(format(self.confidence[i] * 100, '.2f')) + '%') else: bimpy.button(label) if bimpy.is_item_hovered(i): s = "{} ({})\n{}" label = label[0].upper() + label[1:] s = s.format( label, str(format(self.confidence[i] * 100, '.2f')) + '%', LANG.click_to_view_more) bimpy.set_tooltip(s) if bimpy.is_item_active(): self.select_label = label bimpy.pop_id() # bimpy.set_cursor_pos(bimpy.Vec2(conf.margin, self.size.y - conf.margin * 2)) bimpy.set_cursor_pos(bimpy.Vec2(conf.margin, conf.margin * 1.5)) if bimpy.button(LANG.smart_analyse) == True: self.object_detection() bimpy.same_line() bimpy.checkbox(LANG.auto, self.auto) ### Resize ### bimpy.same_line() bimpy.push_item_width(150) bimpy.drag_float(LANG.drag, self.scale, 1.0, 10, 1000) bimpy.pop_item_width() if abs(self.last_scale - self.scale.value) > 4.: xx = self.size.x * self.scale.value / 100. yy = (self.size.y - 45 - 40) * self.scale.value / 100. im = self.i_s.resize(self.raw_im, xx, yy) self.now_im = im self.set_im(im) # set to save computation self.last_scale = self.scale.value # if selected obj if self.select_label != '': # print(self.select_label) windows_info['retrival_ui'][ 'self'].select_label = self.select_label bimpy.open_popup('{}: {}'.format(LANG.retrieve, self.select_label)) # reset self.select_label = '' windows_info['retrival_ui']['self'].retrival() ######################## t = { 'x': bimpy.get_window_pos().x, 'y': bimpy.get_window_pos().y, 'w': bimpy.get_window_size().x, 'h': bimpy.get_window_size().y, 'self': self, } bimpy.end() return t