예제 #1
0
    def make_frame(t):
        frame_idx = int(np.clip(np.round(t * mp4_fps), 0, num_frames - 1))

        section = frame_idx // transition_frames

        start = latents[section]
        end = latents[(section + 1) % len(latents)]

        transition_i = frame_idx - section * transition_frames
        maxindex = transition_frames - 1.0
        # mu1 = min(max(0, (transition_i*1.0/maxindex) ), 1)                             # linear interpolation
        # mu1 = min(max(0, (transition_i*1.0/maxindex)*(transition_i*1.0/maxindex) ), 1) # quadratic interpolation
        mu1 = min(max(0, 1 - math.cos(math.pi * transition_i / maxindex)),
                  2) / 2  # sine interpolation
        lat = np.multiply(start, 1.0 - mu1) + np.multiply(end, mu1)
        labels = np.zeros([lat.shape[0], 0], np.float32)
        images = Gs.run(lat,
                        labels,
                        minibatch_size=minibatch_size,
                        num_gpus=1,
                        out_mul=127.5,
                        out_add=127.5,
                        out_shrink=image_shrink,
                        out_dtype=np.uint8,
                        randomize_noise=False)
        grid = misc.create_image_grid(images, grid_size).transpose(1, 2,
                                                                   0)  # HWC
        if image_zoom > 1:
            grid = scipy.ndimage.zoom(grid, [image_zoom, image_zoom, 1],
                                      order=0)
        if grid.shape[2] == 1:
            grid = grid.repeat(3, 2)  # grayscale => RGB
        return grid
예제 #2
0
 def make_frame(t):
     frame_idx = int(np.clip(np.round(t * mp4_fps), 0, num_frames - 1))
     latents = all_latents[frame_idx]
     labels = np.zeros([latents.shape[0], 0], np.float32)
     classes = list(range(0, 32))
     classes = tf.one_hot(classes, 32)
     sess = tf.Session()
     labels = sess.run(classes[30])
     labels = labels.reshape(1, labels.shape[0])
     sess.close()
     embeddings = np.load('datasets/50k_sorted_tf-rxx.embeddings')
     embeddings = embeddings.astype('float32')
     embedding = embeddings[54200]
     embedding = embedding.reshape(1, embedding.shape[0])
     images = Gs.run(latents,
                     labels,
                     embedding,
                     minibatch_size=minibatch_size,
                     num_gpus=config.num_gpus,
                     out_mul=127.5,
                     out_add=127.5,
                     out_shrink=image_shrink,
                     out_dtype=np.uint8)
     grid = misc.create_image_grid(images, grid_size).transpose(1, 2,
                                                                0)  # HWC
     if image_zoom > 1:
         grid = scipy.ndimage.zoom(grid, [image_zoom, image_zoom, 1],
                                   order=0)
     if grid.shape[2] == 1:
         grid = grid.repeat(3, 2)  # grayscale => RGB
     return grid
 def make_frame(t):
     frame_idx = int(np.clip(np.round(t * mp4_fps), 0, num_frames - 1))
     latents = all_latents[frame_idx]
     labels = np.zeros([latents.shape[0], 0], np.float32)
     images = Gs.run(latents, labels, minibatch_size=minibatch_size, num_gpus=config.num_gpus, out_mul=127.5, out_add=127.5, out_shrink=image_shrink, out_dtype=np.uint8)
     grid = misc.create_image_grid(images, grid_size).transpose(1, 2, 0) # HWC
     if image_zoom > 1:
         grid = scipy.ndimage.zoom(grid, [image_zoom, image_zoom, 1], order=0)
     if grid.shape[2] == 1:
         grid = grid.repeat(3, 2) # grayscale => RGB
     return grid
 def make_frame(t):
     frame_idx = int(np.clip(np.round(t * mp4_fps), 0, num_frames - 1))
     latents = all_latents[frame_idx]
     labels = np.zeros([latents.shape[0], 0], np.float32)
     images = Gs.run(latents, labels, minibatch_size=minibatch_size, num_gpus=config.num_gpus, out_mul=127.5, out_add=127.5, out_shrink=image_shrink, out_dtype=np.uint8)
     grid = misc.create_image_grid(images, grid_size).transpose(1, 2, 0) # HWC
     if image_zoom > 1:
         grid = scipy.ndimage.zoom(grid, [image_zoom, image_zoom, 1], order=0)
     if grid.shape[2] == 1:
         grid = grid.repeat(3, 2) # grayscale => RGB
     return grid
def generate_test_image_with_corresponding_z(run_id,
                                             snapshot=None,
                                             grid_size=[1, 1],
                                             image_shrink=1,
                                             image_zoom=1,
                                             num_frames=None,
                                             random_seed=1000,
                                             minibatch_size=8):
    network_pkl = misc.locate_network_pkl(run_id, snapshot)
    if num_frames is None:
        num_frames = 4
    random_state = np.random.RandomState(random_seed)

    print('Loading network from "%s"...' % network_pkl)
    G, D, Gs = misc.load_network_pkl(run_id, snapshot)

    print('Generating latent vectors...')
    shape = [num_frames, np.prod(grid_size)
             ] + Gs.input_shape[1:]  # [frame, image, channel, component]
    all_latents = random_state.randn(*shape).astype(np.float32)
    #all_latents = scipy.ndimage.gaussian_filter(all_latents, [smoothing_sec * mp4_fps] + [0] * len(Gs.input_shape), mode='wrap')
    all_latents /= np.sqrt(np.mean(np.square(all_latents)))

    # Generate images.
    result_subdir = misc.create_result_subdir(config.result_dir, config.desc)
    for idx, latent in enumerate(all_latents):
        labels = np.zeros([latent.shape[0], 0], np.float32)
        images = Gs.run(latent,
                        labels,
                        minibatch_size=minibatch_size,
                        num_gpus=config.num_gpus,
                        out_mul=127.5,
                        out_add=127.5,
                        out_shrink=image_shrink,
                        out_dtype=np.uint8)
        grid = misc.create_image_grid(images, grid_size).transpose(1, 2,
                                                                   0)  # HWC
        if image_zoom > 1:
            grid = scipy.ndimage.zoom(grid, [image_zoom, image_zoom, 1],
                                      order=0)
        if grid.shape[2] == 1:
            grid = grid.repeat(3, 2)  # grayscale => RGB
        np.save(os.path.join(result_subdir, 'z_' + str(idx)), latent)
        filename = 'im_' + str(idx) + '.png'
        scipy.misc.imsave(os.path.join(result_subdir, filename), grid)