Пример #1
0
    def render(self):
        super(SaveGameFrame, self).render()
        if bimpy.begin(self.name,
                       self.opened,
                       flags=bimpy.WindowFlags.NoCollapse
                       | bimpy.WindowFlags.MenuBar):

            if bimpy.begin_menu_bar():
                bimpy.menu_item('Save', 'Cmd+S', self.click_states['save'])
                bimpy.menu_item('Reload', 'Cmd+R', self.click_states['reload'])
                bimpy.menu_item('Export', 'Cmd+E', self.click_states['export'])
                bimpy.menu_item('Reload & Diff', 'Cmd+D',
                                self.click_states['reload_and_diff'])
                bimpy.end_menu_bar()

            if self.diff_string:
                bimpy.columns(2, "hex split")

            bimpy.text('Game: ')
            bimpy.same_line()
            bimpy.text(self.backend.game.value)

            for section_name, section_items in self.items.items():
                if bimpy.collapsing_header(section_name):
                    for item in section_items:
                        item.render_widget()

            if self.diff_string:
                bimpy.next_column()
                for line in self.diff_string.splitlines():
                    bimpy.text(line)

            bimpy.end()
Пример #2
0
def drawPathFinder(columns_count=7, lines_count=5):
    bimpy.columns(columns_count, None, borders_vertical)
    i = 0
    while i != columns_count:
        i += 1
        if borders_horizontal and bimpy.get_column_index == 0:
            bimpy.separator()
        #bimpy.text("{}".format("a"))
        bimpy.button("Auto Path", bimpy.Vec2(100,100))
        bimpy.next_column()
    bimpy.columns(1)
    if borders_horizontal:
        bimpy.separator()
Пример #3
0
def main():
    selected_compiler = bimpy.Int()
    ctx = bimpy.Context()
    ctx.init(WIDTH, HEIGHT, "Virtual enviroment manager")

    environments = getAvailableEnviroments()
    compilers_list = list(data.compilers.keys())

    show_new_env_menu = False

    while (not ctx.should_close()):
        with ctx:
            bimpy.set_next_window_pos(bimpy.Vec2(0, 0), bimpy.Condition.Once)
            bimpy.set_next_window_size(bimpy.Vec2(WIDTH, HEIGHT),
                                       bimpy.Condition.Once)
            bimpy.begin("Enviroments",bimpy.Bool(True), \
                bimpy.WindowFlags.NoCollapse and bimpy.WindowFlags.NoResize)
            bimpy.text(sys.version)
            bimpy.columns(2)
            for enviroment in environments:
                if bimpy.button(enviroment):
                    compiler = list(data.compilers.values())[
                        selected_compiler.
                        value] if selected_compiler.value != 0 else ""
                    subprocess.call(
                        ['start', environments[enviroment], compiler],
                        shell=True)
                bimpy.next_column()
                if bimpy.button("O##" + enviroment):
                    subprocess.Popen(r'explorer /select,' +
                                     os.path.dirname(environments[enviroment]))
                    #os.startfile(os.path.realpath(os.path.dirname(environments[enviroment])))
                bimpy.next_column()
            bimpy.columns(1)
            if bimpy.combo("Compiler", selected_compiler, compilers_list):
                pass

            # if bimpy.button("Add new enviroment"):
            #     new_env_ctx = BimpyContext(WIDTH, HEIGHT, "New enviroment menu")
            #     while(not new_env_ctx.ctx.should_close()):
            #         with new_env_ctx.ctx:
            #             bimpy.begin("dsad")
            #             bimpy.text("d")
            #             bimpy.end()

            # if bimpy.button("Create new enviroment"):

            bimpy.end()
Пример #4
0
    def on_update(self):
        y = 30
        self.text('Window size: %dx%d' % (self.width, self.height), 10, y)
        y += 30
        self.text('World size: %dx%d' % (self.world_width, self.world_height),
                  10, y)
        y += 30
        self.text('Scale %f' % self.scale, 10, y)
        y += 30
        self.text('%f x %f' % self.cursor_pos_world, 10, y)
        y += 30

        self.point(*self.cursor_pos_world, (230, 10, 10, 240), radius=2.)

        plt = vec2(-0.035, -0.045)
        pmt = vec2(0.56, 0.31)
        prt = vec2(0.862, 0.0421)
        plm = vec2(0.039, -0.3)
        prm = vec2(0.87, -0.088)
        plb = vec2(0.31, -0.35)
        pmb = vec2(0.55, -0.35)
        prb = vec2(0.84, -0.25)

        self._ctx.nvgBeginPath()
        self._ctx.nvgScale(vec2(1000.))
        self._ctx.nvgTranslate(vec2(1.))
        self._ctx.nvgScale(vec2(1., -1.))

        self._ctx.nvgMoveTo(plt)
        self._ctx.nvgQuadTo(plm, plb)
        self._ctx.nvgQuadTo(pmb, prb)
        self._ctx.nvgQuadTo(prm, prt)
        self._ctx.nvgQuadTo(pmt, plt)
        self._ctx.nvgClosePath()
        self._ctx.nvgFillColor(vec4(0.73, 0.78, 0.83, 1.))
        self._ctx.nvgFill()

        bimpy.begin('Editor')
        bimpy.columns(2)
        bimpy.begin_child('Scene', bimpy.Vec2(0, 300))
        self.scene_tree()
        bimpy.end_child()
        bimpy.next_column()
        self.object_inspector()
        self.draw()
        bimpy.end()
Пример #5
0
def drawMainTab(columns_count=7, lines_count=5):
    bimpy.columns(columns_count, None, borders_vertical)
    i = 0
    col_c = 0
    while col_c > lines_count:
        col_c += 1
    while i != columns_count:
        if borders_horizontal and bimpy.get_column_index == 0:
            bimpy.separator()
        #bimpy.text("{}".format("a"))
        bimpy.button(field_names[i], bimpy.Vec2(100,100))
        bimpy.next_column()
        i += 1
    columns_count = 0
    bimpy.columns(1)
    if borders_horizontal:
        bimpy.separator()
Пример #6
0
mylist = ["aaa", "bbb", "ccc"]

selectedItem = bimpy.Int()

vals = [0., 0.1, 0.2, 0.1, 0.4, 0.2]

while (not ctx.should_close()):
    ctx.new_frame()

    if opened.value:
        if bimpy.begin("Hello!", opened=opened):
            bimpy.columns(4, "mycolumns")
            bimpy.separator()
            bimpy.text("Some text")
            bimpy.next_column()
            bimpy.text("Some text")
            bimpy.next_column()
            bimpy.text("Some text")
            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)
Пример #7
0
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()
Пример #8
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