adversarial_autoencoder.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:AAE-tensorflow 作者: gitmatti 项目源码 文件源码
def _make_latent_exploration_op(self):
        """
        Code adapted from https://github.com/fastforwardlabs/vae-tf/blob/master/plot.py
        """
        # ops for exploration of latent space
        nx = 30
        ny = nx
        z_dim = self.target_dist.dim

        if self.latent_dist.dim==2:
            range_ = (0, 1)
            min_, max_ = range_
            zs = np.rollaxis(np.mgrid[max_:min_:ny*1j, min_:max_:nx*1j], 0, 3)
            if isinstance(self.target_dist, Gaussian):
                from scipy.stats import norm
                DELTA = 1E-8 # delta to avoid +/- inf at 0, 1 boundaries
                zs = np.array([norm.ppf(np.clip(z, TINY, 1 - TINY),
                                        scale=self.target_dist.stddev)
                               for z in zs])
        else:
            raise NotImplementedError

        zs = tf.constant(zs.reshape((nx*ny, z_dim)),
                         dtype=tf.float32)

        self.zs = tf.placeholder_with_default(zs,
                                              shape=[None, z_dim],
                                              name="zs")

        hs_decoded = self.decoder_template.construct(z_in=self.zs,
                                                     phase=pt.Phase.test).tensor
        xs_dist_info = self.output_dist.activate_dist(hs_decoded)
        xs = self.output_dist.sample(xs_dist_info)

        imgs = tf.reshape(xs, [nx, ny] + list(self.dataset.image_shape))
        stacked_img = []
        for row in xrange(nx):
            row_img = []
            for col in xrange(ny):
                row_img.append(imgs[row, col, :, :, :])
            stacked_img.append(tf.concat(axis=1, values=row_img))
        self.latent_exploration_op = tf.concat(axis=0, values=stacked_img)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号