Beispiel #1
0
 def sample_latent(self, batch_size):
     syntax_latent = to_var(torch.randn([batch_size, self.latent_size]))
     semantic_latent = to_var(torch.randn([batch_size, self.latent_size]))
     return {
         "syn_z": syntax_latent,
         "sem_z": semantic_latent,
     }
Beispiel #2
0
 def sampling(mean, logv):
     if is_sampling:
         std = torch.exp(0.5 * logv)
         z = to_var(torch.randn([batch_size, self.latent_size]))
         z = z * std + mean
     else:
         z = mean
     return z
Beispiel #3
0
 def hidden_to_latent(self, ret, is_sampling=True):
     hidden = ret['hidden']
     batch_size = hidden.size(1)
     hidden = hidden.permute(1, 0, 2).contiguous()
     if self.hidden_factor > 1:
         hidden = hidden.view(batch_size, self.hidden_size * self.hidden_factor)
     else:
         hidden = hidden.squeeze()
     mean = self.hidden2mean(hidden)
     logv = self.hidden2logv(hidden)
     if is_sampling:
         std = torch.exp(0.5 * logv)
         z = to_var(torch.randn([batch_size, self.latent_size]))
         z = z * std + mean
     else:
         z = mean
     ret["latent"] = z
     ret["mean"] = mean
     ret['logv'] = logv
     return ret
Beispiel #4
0
 def sample_latent(self, batch_size):
     z = to_var(torch.randn([batch_size, self.latent_size]))
     return {
         "latent": z
     }