예제 #1
0
def generate_latent_grid(z_dim,
                         rows,
                         cols,
                         fan,
                         gradient,
                         spherical,
                         gaussian,
                         anchors,
                         anchor_images,
                         mine,
                         chain,
                         spacing,
                         analogy,
                         rand_uniform=False):
    if fan:
        z = create_fan_grid(z_dim, cols, rows)
    elif gradient:
        z = create_gradient_grid(rows, cols, z_dim, analogy, anchors,
                                 spherical, gaussian)
    elif mine:
        z = create_mine_grid(rows, cols, z_dim, spacing, anchors, spherical,
                             gaussian)
    elif chain:
        z = create_chain_grid(rows, cols, z_dim, spacing, anchors, spherical,
                              gaussian)
    else:
        if rand_uniform:
            z = np.random.uniform(-1, 1, size=(rows * cols, z_dim))
        else:
            # print("Generating random grid with seed ", np.random.get_state()[1][:5])
            z = np.random.normal(loc=0, scale=1, size=(rows * cols, z_dim))

    return z
예제 #2
0
 def do(self, callback_name, *args):
     """Sample the model and save images to disk
     """
     dmodel = self.interface(model=self.main_loop.model)
     anchors = dmodel.encode_images(self.anchor_images)
     z = create_chain_grid(self.rows,
                           self.cols,
                           self.z_dim,
                           self.spacing,
                           anchors=anchors,
                           spherical=True,
                           gaussian=False)
     grid_from_latents(z,
                       dmodel,
                       rows=self.rows,
                       cols=self.cols,
                       anchor_images=None,
                       tight=False,
                       shoulders=False,
                       save_path=self.epoch_src,
                       batch_size=12)
     if os.path.exists(self.epoch_src):
         epoch_dst = "{0}/epoch-{1:03d}.png".format(self.save_subdir,
                                                    self.iteration)
         self.iteration = self.iteration + 1
         shutil.copy2(self.epoch_src, epoch_dst)
         os.system(
             "convert -delay 5 -loop 1 {0}/epoch-*.png {0}/training.gif".
             format(self.save_subdir))
예제 #3
0
 def do(self, callback_name, *args):
     """Sample the model and save images to disk
     """
     dmodel = self.interface(model=self.main_loop.model)
     anchors = dmodel.encode_images(self.anchor_images)
     z = create_chain_grid(self.rows, self.cols, self.z_dim, self.spacing, anchors=anchors, spherical=True, gaussian=False)
     grid_from_latents(z, dmodel, rows=self.rows, cols=self.cols, anchor_images=None, tight=False, shoulders=False, save_path=self.epoch_src, batch_size=12)
     if os.path.exists(self.epoch_src):
         epoch_dst = "{0}/epoch-{1:03d}.png".format(self.save_subdir, self.iteration)
         self.iteration = self.iteration + 1
         shutil.copy2(self.epoch_src, epoch_dst)
         os.system("convert -delay 5 -loop 1 {0}/epoch-*.png {0}/training.gif".format(self.save_subdir))
예제 #4
0
파일: sample.py 프로젝트: dribnet/discgen
def generate_latent_grid(z_dim, rows, cols, fan, gradient, spherical, gaussian, anchors, anchor_images, mine, chain, spacing, analogy, rand_uniform=False):
    if fan:
        z = create_fan_grid(z_dim, cols, rows)
    elif gradient:
        z = create_gradient_grid(rows, cols, z_dim, analogy, anchors, spherical, gaussian)
    elif mine:
        z = create_mine_grid(rows, cols, z_dim, spacing, anchors, spherical, gaussian)
    elif chain:
        z = create_chain_grid(rows, cols, z_dim, spacing, anchors, spherical, gaussian)
    else:
        if rand_uniform:
            z = np.random.uniform(-1, 1, size=(rows * cols, z_dim))
        else:
            z = np.random.normal(loc=0, scale=1, size=(rows * cols, z_dim))

    return z