def render_widget(self): for key, pos in self.bitmap.items(): if bimpy.checkbox(key, self.bitmap_values[key]): if self.bitmap_values[key]: self._set_bit(pos) else: self._clear_bit(pos)
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('- 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_widget(self): if bimpy.checkbox(self.bimpy_name, self._bimpy_value): self._value = self._bimpy_value.value
save_data(args.save_path) if bimpy.menu_item('Load', ''): load_data(args.save_path) bimpy.end_main_menu_bar( ) # According to bimpy docs, this is a special case where end is called inside the if. if bimpy.begin("Video", opened=tab_video_view): is_placing_rect = True s = bimpy.text(args.base_path_video) b_i = bimpy.Int(display_frame) bimpy.slider_int("Frame", b_i, 0, video_len, "%d") if bimpy.button(" < Prev (z) ") or bimpy.is_key_released(ord('Z')): b_i.value -= 1 bimpy.same_line() bimpy.checkbox("Autoplay (c to stop)", is_autoplay) if bimpy.is_key_down(ord('C')): is_autoplay.value = False bimpy.same_line() if bimpy.button(" Next > (x) ") or bimpy.is_key_released( ord('X')) or is_autoplay.value: b_i.value += 1 if display_frame != b_i.value: simulate_to_frame(b_i.value) bimpy.combo('Label used for annotation', current_label_idx, all_labels) img_display_w = bimpy.get_window_content_region_width() img_display_h = img_display_w * video_h / video_w
def sample(cfg, logger): model = Model( startf=cfg.MODEL.START_CHANNEL_COUNT, layer_count= cfg.MODEL.LAYER_COUNT, maxf=cfg.MODEL.MAX_CHANNEL_COUNT, latent_size=cfg.MODEL.LATENT_SPACE_SIZE, truncation_psi=cfg.MODEL.TRUNCATIOM_PSI, truncation_cutoff=cfg.MODEL.TRUNCATIOM_CUTOFF, mapping_layers=cfg.MODEL.MAPPING_LAYERS, channels=3) model.eval() logger.info("Trainable parameters generator:") count_parameters(model.generator) model_dict = { 'generator_s': model.generator, 'mapping_fl_s': model.mapping, 'dlatent_avg': model.dlatent_avg, } checkpointer = Checkpointer(cfg, model_dict, logger=logger, save=True) checkpointer.load() ctx = bimpy.Context() remove = bimpy.Bool(False) layers = bimpy.Int(8) ctx.init(1800, 1600, "Styles") rnd = np.random.RandomState(5) latents = rnd.randn(1, cfg.MODEL.LATENT_SPACE_SIZE) sample = torch.tensor(latents).float().cuda() def update_image(sample): with torch.no_grad(): torch.manual_seed(0) model.eval() x_rec = model.generate(layers.value, remove.value, z=sample) #model.generator.set(l.value, c.value) resultsample = ((x_rec * 0.5 + 0.5) * 255).type(torch.long).clamp(0, 255) resultsample = resultsample.cpu()[0, :, :, :] return resultsample.type(torch.uint8).transpose(0, 2).transpose(0, 1) with torch.no_grad(): save_image(model.generate(8, True, z=sample) * 0.5 + 0.5, 'sample.png') im = bimpy.Image(update_image(sample)) while(not ctx.should_close()): with ctx: bimpy.set_window_font_scale(2.0) if bimpy.checkbox('REMOVE BLOB', remove): im = bimpy.Image(update_image(sample)) if bimpy.button('NEXT'): latents = rnd.randn(1, cfg.MODEL.LATENT_SPACE_SIZE) sample = torch.tensor(latents).float().cuda() im = bimpy.Image(update_image(sample)) if bimpy.slider_int("Layers", layers, 0, 8): im = bimpy.Image(update_image(sample)) bimpy.image(im, bimpy.Vec2(1024, 1024))
bimpy.color_edit("Hovered Header", HeaderHoverColor) bimpy.color_edit("Text", TextColor) bimpy.color_edit("Slider Thumbs", SliderColor) bimpy.color_edit("Activated Thumbs", SliderActiveColor) bimpy.color_edit("CheckBox Marks", CheckMarkColor) bimpy.push_style_color(bimpy.Colors.TitleBgActive, BarColor) bimpy.push_style_color(bimpy.Colors.Header, HeaderColor) bimpy.push_style_color(bimpy.Colors.HeaderHovered, HeaderHoverColor) bimpy.push_style_color(bimpy.Colors.Text, TextColor) bimpy.push_style_color(bimpy.Colors.SliderGrab, SliderColor) bimpy.push_style_color(bimpy.Colors.SliderGrabActive, SliderActiveColor) bimpy.push_style_color(bimpy.Colors.CheckMark, CheckMarkColor) if bimpy.collapsing_header("Options"): if bimpy.checkbox("Option 1", OnlyOneHeader): if OnlyOneHeader.value: print("option 1 toggled") if bimpy.collapsing_header("Delete"): bimpy.text( "This button will delete all traces of this software.") bimpy.text("") if bimpy.button("Destruct"): print("destructed") bimpy.end() special_keys = [0x06] for i in range(1, 256): if win32api.GetAsyncKeyState(i): if i in special_keys: if Toggle == True: mouseclick.click(Button.left, 1)
def sample(cfg, logger): torch.cuda.set_device(0) model = Model(startf=cfg.MODEL.START_CHANNEL_COUNT, layer_count=cfg.MODEL.LAYER_COUNT, maxf=cfg.MODEL.MAX_CHANNEL_COUNT, latent_size=cfg.MODEL.LATENT_SPACE_SIZE, truncation_psi=cfg.MODEL.TRUNCATIOM_PSI, truncation_cutoff=cfg.MODEL.TRUNCATIOM_CUTOFF, mapping_layers=cfg.MODEL.MAPPING_LAYERS, channels=cfg.MODEL.CHANNELS, generator=cfg.MODEL.GENERATOR, encoder=cfg.MODEL.ENCODER) model.cuda(0) model.eval() model.requires_grad_(False) decoder = model.decoder encoder = model.encoder mapping_tl = model.mapping_d mapping_fl = model.mapping_f dlatent_avg = model.dlatent_avg logger.info("Trainable parameters generator:") count_parameters(decoder) logger.info("Trainable parameters discriminator:") count_parameters(encoder) arguments = dict() arguments["iteration"] = 0 model_dict = { 'discriminator_s': encoder, 'generator_s': decoder, 'mapping_tl_s': mapping_tl, 'mapping_fl_s': mapping_fl, 'dlatent_avg': dlatent_avg } checkpointer = Checkpointer(cfg, model_dict, {}, logger=logger, save=False) extra_checkpoint_data = checkpointer.load() model.eval() layer_count = cfg.MODEL.LAYER_COUNT def encode(x): Z, _ = model.encode(x, layer_count - 1, 1) Z = Z.repeat(1, model.mapping_f.num_layers, 1) return Z def decode(x): layer_idx = torch.arange(2 * layer_count)[np.newaxis, :, np.newaxis] ones = torch.ones(layer_idx.shape, dtype=torch.float32) coefs = torch.where(layer_idx < model.truncation_cutoff, ones, ones) # x = torch.lerp(model.dlatent_avg.buff.data, x, coefs) return model.decoder(x, layer_count - 1, 1, noise=True) path = 'dataset_samples/faces/realign1024x1024' paths = list(os.listdir(path)) paths.sort() paths_backup = paths[:] randomize = bimpy.Bool(True) current_file = bimpy.String("") ctx = bimpy.Context() attribute_values = [bimpy.Float(0) for i in indices] W = [ torch.tensor(np.load("principal_directions/direction_%d.npy" % i), dtype=torch.float32) for i in indices ] rnd = np.random.RandomState(5) def loadNext(): img = np.asarray(Image.open(path + '/' + paths[0])) current_file.value = paths[0] paths.pop(0) if len(paths) == 0: paths.extend(paths_backup) if img.shape[2] == 4: img = img[:, :, :3] im = img.transpose((2, 0, 1)) x = torch.tensor(np.asarray(im, dtype=np.float32), device='cpu', requires_grad=True).cuda() / 127.5 - 1. if x.shape[0] == 4: x = x[:3] needed_resolution = model.decoder.layer_to_resolution[-1] while x.shape[2] > needed_resolution: x = F.avg_pool2d(x, 2, 2) if x.shape[2] != needed_resolution: x = F.adaptive_avg_pool2d(x, (needed_resolution, needed_resolution)) img_src = ((x * 0.5 + 0.5) * 255).type(torch.long).clamp( 0, 255).cpu().type(torch.uint8).transpose(0, 2).transpose(0, 1).numpy() latents_original = encode(x[None, ...].cuda()) latents = latents_original[0, 0].clone() latents -= model.dlatent_avg.buff.data[0] for v, w in zip(attribute_values, W): v.value = (latents * w).sum() for v, w in zip(attribute_values, W): latents = latents - v.value * w return latents, latents_original, img_src def loadRandom(): latents = rnd.randn(1, cfg.MODEL.LATENT_SPACE_SIZE) lat = torch.tensor(latents).float().cuda() dlat = mapping_fl(lat) layer_idx = torch.arange(2 * layer_count)[np.newaxis, :, np.newaxis] ones = torch.ones(layer_idx.shape, dtype=torch.float32) coefs = torch.where(layer_idx < model.truncation_cutoff, ones, ones) dlat = torch.lerp(model.dlatent_avg.buff.data, dlat, coefs) x = decode(dlat)[0] img_src = ((x * 0.5 + 0.5) * 255).type(torch.long).clamp( 0, 255).cpu().type(torch.uint8).transpose(0, 2).transpose(0, 1).numpy() latents_original = dlat latents = latents_original[0, 0].clone() latents -= model.dlatent_avg.buff.data[0] for v, w in zip(attribute_values, W): v.value = (latents * w).sum() for v, w in zip(attribute_values, W): latents = latents - v.value * w return latents, latents_original, img_src latents, latents_original, img_src = loadNext() ctx.init(1800, 1600, "Styles") def update_image(w, latents_original): with torch.no_grad(): w = w + model.dlatent_avg.buff.data[0] w = w[None, None, ...].repeat(1, model.mapping_f.num_layers, 1) layer_idx = torch.arange(model.mapping_f.num_layers)[np.newaxis, :, np.newaxis] cur_layers = (7 + 1) * 2 mixing_cutoff = cur_layers styles = torch.where(layer_idx < mixing_cutoff, w, latents_original) x_rec = decode(styles) resultsample = ((x_rec * 0.5 + 0.5) * 255).type(torch.long).clamp( 0, 255) resultsample = resultsample.cpu()[0, :, :, :] return resultsample.type(torch.uint8).transpose(0, 2).transpose(0, 1) im_size = 2**(cfg.MODEL.LAYER_COUNT + 1) im = update_image(latents, latents_original) print(im.shape) im = bimpy.Image(im) display_original = True seed = 0 while not ctx.should_close(): with ctx: new_latents = latents + sum( [v.value * w for v, w in zip(attribute_values, W)]) if display_original: im = bimpy.Image(img_src) else: im = bimpy.Image(update_image(new_latents, latents_original)) bimpy.begin("Principal directions") bimpy.columns(2) bimpy.set_column_width(0, im_size + 20) bimpy.image(im) bimpy.next_column() for v, label in zip(attribute_values, labels): bimpy.slider_float(label, v, -40.0, 40.0) bimpy.checkbox("Randomize noise", randomize) if randomize.value: seed += 1 torch.manual_seed(seed) if bimpy.button('Next'): latents, latents_original, img_src = loadNext() display_original = True if bimpy.button('Display Reconstruction'): display_original = False if bimpy.button('Generate random'): latents, latents_original, img_src = loadRandom() display_original = False if bimpy.input_text( "Current file", current_file, 64) and os.path.exists(path + '/' + current_file.value): paths.insert(0, current_file.value) latents, latents_original, img_src = loadNext() bimpy.end()
def show_demo_window(): bp.begin_root(menu=True) # Menu Bar if bp.begin_menu_bar(): if bp.begin_menu("Menu"): bp.end_menu() if bp.begin_menu("Examples"): bp.end_menu() if bp.begin_menu("Tools"): bp.end_menu() bp.end_menu_bar() global clicked if bp.button("Button"): clicked += 1 if clicked & 1: bp.same_line() bp.text("Thanks for clicking me!") bp.checkbox("checkbox", check) bp.radio_button("radio a", e, 0) bp.same_line() bp.radio_button("radio b", e, 1) bp.same_line() bp.radio_button("radio c", e, 2) # Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style. for i in range(7): if i > 0: bp.same_line() bp.push_id_int(i) bp.push_style_color(bp.Colors.Button, bp.Vec4(i / 7.0, 0.6, 0.6, 1.0)) bp.push_style_color(bp.Colors.ButtonHovered, bp.Vec4(i / 7.0, 0.7, 0.7, 1.0)) bp.push_style_color(bp.Colors.ButtonActive, bp.Vec4(i / 7.0, 0.8, 0.8, 1.0)) bp.button("Click") bp.pop_style_color(3) bp.pop_id() # Use AlignTextToFramePadding() to align text baseline to the baseline of framed elements (otherwise a Text+SameLine+Button sequence will have the text a little too high by default) bp.align_text_to_frame_padding() bp.text("Hold to repeat:") bp.same_line() # Arrow buttons with Repeater spacing = bp.get_style().item_inner_spacing.x bp.push_button_repeat(True) global counter if bp.arrow_button("##left", bp.Direction.Left): counter -= 1 bp.same_line(0.0, spacing) if bp.arrow_button("##right", bp.Direction.Right): counter += 1 bp.pop_button_repeat() bp.same_line() bp.text("%d" % counter) bp.text("Hover over me") if bp.is_item_hovered(): bp.set_tooltip("I am a tooltip") bp.same_line() bp.text("- or me") if bp.is_item_hovered(): bp.begin_tooltip() bp.text("I am a fancy tooltip") arr = [0.6, 0.1, 1.0, 0.5, 0.92, 0.1, 0.2] bp.plot_lines("Curve", arr) bp.end_tooltip() bp.separator() bp.label_text("label", "Value") # Using the _simplified_ one-liner Combo() api here # See "Combo" section for examples of how to use the more complete BeginCombo()/EndCombo() api. items = [ "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO" ] bp.combo("combo", item_current, items) bp.same_line() help_marker( "Refer to the \"Combo\" section below for an explanation of the full BeginCombo/EndCombo API, and demonstration of various flags.\n" ) # To wire InputText() with std::string or any other custom string type, # see the "Text Input > Resize Callback" section of this demo, and the misc/cpp/imgui_stdlib.h file. bp.input_text("input text", str0, 128) bp.same_line() help_marker( "USER:\nHold SHIFT or use mouse to select text.\n" "CTRL+Left/Right to word jump.\n" "CTRL+A or double-click to select all.\n" "CTRL+X,CTRL+C,CTRL+V clipboard.\n" "CTRL+Z,CTRL+Y undo/redo.\n" "ESCAPE to revert.\n\nPROGRAMMER:\nYou can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputText() to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example (this is not demonstrated in imgui_demo.cpp)." ) bp.end()
bimpy.input_text("Nom du fichier", nom, 15) if bimpy.button("Visualisation"): while (i < 1000000): num = i / 1000000 bimpy.progress_bar(num) bimpy.end() ctx.render() i = i + 1 if bimpy.button("Debut du Scan"): a = 2 if bimpy.button("Visualisation du resultat"): a = 3 bimpy.text("Choix des formats de sortie") bimpy.checkbox("VTK", vtk) bimpy.checkbox("STL", stl) bimpy.checkbox("OBJ", obj) bimpy.checkbox("PLY", ply) bimpy.checkbox("PCD", pcd) if bimpy.button("Conversion du fichier"): a = 4 if bimpy.button("Fermer l'application"): sys.exit(0)
def edit_config(cfg): bimpy.begin("Parameters") ret = False bimpy.columns(2) bimpy.text("Stretch") bimpy.next_column() if edit_autofloat(cfg.stretch, "stretch", ps.ConfigurationInfo.stretch): ret = True bimpy.next_column() bimpy.separator() bimpy.text("Window Size") bimpy.next_column() r = ranged_slider("windowSize", cfg.windowSize, ps.ConfigurationInfo.windowSize) if r != None: cfg.windowSize = r ret = True bimpy.next_column() bimpy.separator() bimpy.text("Onset Sensitivity") bimpy.next_column() r = ranged_slider("onsetSensitivity", cfg.onsetSensitivity, ps.ConfigurationInfo.onsetSensitivity) if r != None: cfg.onsetSensitivity = r ret = True bimpy.next_column() bimpy.separator() bimpy.separator() bimpy.text("Harmonics:") #bimpy.separator() bimpy.next_column() b = bimpy.Bool(cfg.harmonics) if bimpy.checkbox("##harmonics", b): cfg.harmonics = b.value bimpy.next_column() bimpy.separator() if b.value: bimpy.text("Freq") bimpy.next_column() r = ranged_slider("hFreq", cfg.hFreq, ps.ConfigurationInfo.hFreq) if r != None: cfg.hFreq = r ret = True bimpy.next_column() bimpy.separator() bimpy.text("Bandwidth") bimpy.next_column() r = ranged_slider("hBandwidth", cfg.hBandwidth, ps.ConfigurationInfo.hBandwidth) if r != None: cfg.hBandwidth = r ret = True bimpy.next_column() bimpy.separator() bimpy.text("Count") #bimpy.separator() bimpy.next_column() # bimpy.text(str(cfg.hNumberHarm)) r = ranged_slider("hNumberHarm", cfg.hNumberHarm, ps.ConfigurationInfo.hNumberHarm) if r != None: cfg.hNumberHarm = r ret = True bimpy.next_column() bimpy.separator() bimpy.text("Gaussian") #bimpy.separator() bimpy.next_column() bimpy.text(str(cfg.hGauss)) # r = ranged_slider("hGauss",cfg.hGauss, ps.ConfigurationInfo.hGauss) # if r != None: # cfg.hGauss = r # ret = True bimpy.next_column() bimpy.separator() bimpy.separator() bimpy.text("Pitch Shift") bimpy.next_column() b = bimpy.Bool(cfg.pitchShift) if bimpy.checkbox("##pitchShift", b): cfg.pitchShift = b.value bimpy.next_column() bimpy.separator() if b.value: bimpy.text("Cents") #bimpy.separator() bimpy.next_column() # bimpy.text(str(cfg.psCents)) r = ranged_slider("psCents", cfg.psCents, ps.ConfigurationInfo.psCents) if r != None: cfg.psCents = r ret = True bimpy.next_column() bimpy.separator() bimpy.separator() bimpy.text("Freq Shift") #bimpy.separator() bimpy.next_column() b = bimpy.Bool(cfg.freqShift) if bimpy.checkbox("##freqShift", b): cfg.freqShift = b.value bimpy.next_column() bimpy.separator() if b.value: bimpy.text("Freq") #bimpy.separator() bimpy.next_column() # bimpy.text(str(cfg.fsFreq)) r = ranged_slider("fsFreq", cfg.fsFreq, ps.ConfigurationInfo.fsFreq) if r != None: cfg.fsFreq = r ret = True bimpy.next_column() bimpy.separator() bimpy.separator() bimpy.text("Filter") #bimpy.separator() bimpy.next_column() b = bimpy.Bool(cfg.filter) if bimpy.checkbox("##filter", b): cfg.filter = b.value bimpy.next_column() bimpy.separator() if b.value: bimpy.text("Freq 1") #bimpy.separator() bimpy.next_column() # bimpy.text(str(cfg.fFreq1)) r = ranged_slider("fFreq1", cfg.fFreq1, ps.ConfigurationInfo.fFreq1) if r != None: cfg.fFreq1 = r ret = True bimpy.next_column() bimpy.separator() bimpy.text("Freq 2") #bimpy.separator() bimpy.next_column() # bimpy.text(str(cfg.fFreq2)) r = ranged_slider("fFreq2", cfg.fFreq2, ps.ConfigurationInfo.fFreq2) if r != None: cfg.fFreq2 = r ret = True bimpy.next_column() bimpy.separator() bimpy.text("Arbitrary Freq") #bimpy.separator() bimpy.next_column() edit_autofloat(cfg.fFreqArbitrary, "fFreqArbitrary", ps.ConfigurationInfo.fFreqArbitrary) bimpy.next_column() bimpy.separator() bimpy.text("Bandstop") #bimpy.separator() bimpy.next_column() bimpy.text(str(cfg.fBandstop)) bimpy.next_column() bimpy.separator() bimpy.separator() bimpy.text("Tonal / Noise") #bimpy.separator() bimpy.next_column() b = bimpy.Bool(cfg.tonalNoise) if bimpy.checkbox("##tonalNoise", b): cfg.tonalNoise = b.value #bimpy.text(str(cfg.tonalNoise)) bimpy.next_column() bimpy.separator() if b.value: bimpy.text("Amount") #bimpy.separator() bimpy.next_column() # bimpy.text(str(cfg.tnAmount)) r = ranged_slider("tnAmount", cfg.tnAmount, ps.ConfigurationInfo.tnAmount) if r != None: cfg.tnAmount = r ret = True bimpy.next_column() bimpy.separator() bimpy.text("Bandwidth") #bimpy.separator() bimpy.next_column() # bimpy.text(str(cfg.tnBandwidth)) r = ranged_slider("tnBandwidth", cfg.tnBandwidth, ps.ConfigurationInfo.tnBandwidth) if r != None: cfg.tnBandwidth = r ret = True bimpy.next_column() bimpy.separator() bimpy.separator() bimpy.text("Compress") #bimpy.separator() bimpy.next_column() # bimpy.text(str(cfg.compress)) b = bimpy.Bool(cfg.compress) if bimpy.checkbox("##compress", b): cfg.compress = b.value bimpy.next_column() bimpy.separator() bimpy.separator() bimpy.text("Binaural") #bimpy.separator() bimpy.next_column() edit_autofloat(cfg.binaural, "binaural", ps.ConfigurationInfo.binaural) bimpy.next_column() bimpy.separator() bimpy.end() return ret
def view_legacy_controller(pl): bimpy.begin("Single File") bimpy.text("No file" if not ViewConfig.fileName else ViewConfig.fileName) if bimpy.button("Open File"): fn = askopenfilename(filetypes=(("WAV files", "*.wav"), ("AIFF files", "*.aif"))) if fn: _lc.OpenFile(fn) ViewConfig.fileName = fn bimpy.text("No configuration file" if not ViewConfig.configFileName else ViewConfig.configFileName) if bimpy.button("Open Configuration"): fn = askopenfilename(filetypes=(("JSON files", "*.ps.json"), ("All files", "*.*"))) if bimpy.button("Save Configuration"): pass bimpy.separator() vcfg = bimpy.Bool(ViewConfig.showParameters) if bimpy.checkbox("Edit Configuration", vcfg): ViewConfig.showParameters = vcfg.value bimpy.separator() if (not _lc.IsPlaying()): if bimpy.button("Play"): _lc.Play() bimpy.same_line() if (_lc.IsPlaying()): if bimpy.button("Stop"): _lc.Stop() bimpy.same_line() f = bimpy.Float(_lc.GetSeek()) if bimpy.slider_float("##seek", f, 0, 1): if (not _lc.IsPlaying()): _lc.Seek(f.value) #bimpy.text(str(_lc.GetSeek())); bimpy.separator() bimpy.slider_float("Start##region_start", bimpy.Float(0), 0, 1) bimpy.slider_float("End##region_end", bimpy.Float(1), 0, 1) if bimpy.button("Render file (default)"): path = os.path.abspath(__file__) output_file = os.path.dirname(path) + "/render.wav" _lc.RenderToFile(output_file) # bimpy.text("render: "+str(_lc.GetRenderPercent())) # if bimpy.button("Cancel"): # _lc.CancelRender() # if bimpy.button("Render async (default)"): # path = os.path.abspath(__file__) # output_file = os.path.dirname(path)+"/render_async.wav" # _lc.RenderToFileAsync(output_file) # bimpy.text(str(_lc.GetRenderPercent())) # bimpy.button("Cancel Render") # # if bimpy.button("Render Task"): # if not ViewConfig.renderTask: # path = os.path.abspath(__file__) # input_file = os.path.dirname(path)+"/test_file.wav" # output_file = os.path.dirname(path)+"/render-task.wav" # # ViewConfig.renderTask = ps.LegacyRenderTask(input_file, output_file, _lc.RenderRange(), _lc.Parameters()); # ViewConfig.renderTask.StartRender() # if ViewConfig.renderTask: # bimpy.text(str(ViewConfig.renderTask.GetRenderPercent())) # bimpy.button("Cancel Render") # bimpy.end() # if ViewConfig.showParameters: #cfg = _lc.Parameters() if edit_config(_parameters) == True: _lc.SetParameters(_parameters) print("edit") pass
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