def get_loss(self, image):

        recon_mean, latent_mean, latent_log_std, latent_samples = \
            self.forward(image)

        # kl term
        kl_q = modeling_lib.get_kl_q_standard_normal(latent_mean, latent_log_std)

        # bernoulli likelihood
        loglik = modeling_lib.get_bernoulli_loglik(recon_mean, image)

        return -loglik + kl_q
Exemplo n.º 2
0
    def get_loss(self, image):

        recon_mean, latent_mean, latent_log_std, latent_samples = \
            self.forward(image)

        # kl term
        kl_q = modeling_lib.get_kl_q_standard_normal(latent_mean,
                                                     latent_log_std)

        # bernoulli likelihood
        loglik = modeling_lib.get_bernoulli_loglik(recon_mean, image)

        return -loglik + kl_q
Exemplo n.º 3
0
    def get_loss_cond_pixel_1d(self, image, pixel_1d):

        # forward
        recon_mean, latent_mean, latent_log_std, latent_samples, pixel_2d = \
                        self.forward_cond_pixel_1d(image, pixel_1d)

        # kl term
        kl_latent = \
            modeling_lib.get_kl_q_standard_normal(latent_mean, latent_log_std)

        # bernoulli likelihood
        loglik = modeling_lib.get_bernoulli_loglik(recon_mean, image)

        return -loglik + kl_latent
    def get_loss_cond_pixel_1d(self, image, pixel_1d):

        # forward
        recon_mean, latent_mean, latent_log_std, latent_samples, pixel_2d = \
                        self.forward_cond_pixel_1d(image, pixel_1d)

        # kl term
        kl_latent = \
            modeling_lib.get_kl_q_standard_normal(latent_mean, latent_log_std)

        # bernoulli likelihood
        loglik = modeling_lib.get_bernoulli_loglik(recon_mean, image)

        return -loglik + kl_latent
    def get_loss_cond_pixel_1d(self, one_hot_pixel, image, \
                                        use_cached_image = False):

        # forward
        if use_cached_image:
            image_ = None
        else:
            image_ = image
        recon_mean, latent_mean, latent_log_std, latent_samples = \
                        self.forward_cond_pixel_1d(one_hot_pixel, image_)

        # kl term
        kl_latent = \
            modeling_lib.get_kl_q_standard_normal(latent_mean, latent_log_std)

        # bernoulli likelihood
        loglik = modeling_lib.get_bernoulli_loglik(recon_mean, image)

        return -loglik + kl_latent