add sampling to cvae norm

This commit is contained in:
2023-07-12 15:22:58 +02:00
parent 5a2138b45b
commit 80b1c668b1
+6 -17
View File
@@ -36,27 +36,16 @@ class CVAENorm(nn.Module):
self.latent_shape = (config['cvae']['latent_dim'], 8, 4) self.latent_shape = (config['cvae']['latent_dim'], 8, 4)
def sample(self, uv_template, uv_body_posed, uv_curv, uv_mask, noise=None, add_noise=False): def sample(self, uv_template, uv_body_posed, uv_mask, noise=None):
if noise is None: if noise is None:
eps = tf.random.normal(shape=(uv_template.shape[0], 8, 4, self.latent_dim)) eps = torch.randn(uv_template.shape[0], self.latent_shape[0], self.latent_shape[1], self.latent_shape[2]).to(uv_template.device)
else: else:
eps = noise eps = noise
z_cond = self.encode_conds(uv_template, uv_body_posed, uv_curv, training=False) z_cond = self.encode_conds(uv_template, uv_body_posed)
if add_noise: z = torch.cat([eps, z_cond], dim=1)
z_cond = z_cond + (tf.random.uniform(z_cond.shape, maxval=self.noise_amount * 2) - self.noise_amount) x = self.decoder(z)
x = x * uv_mask[:,None,:,:]
z = tf.concat([eps, z_cond], axis=-1)
x = self.decoder(z, training=False)
if self.avg_garment is not None:
x = x + self.avg_garment[tf.newaxis,:,:,:]
if self.use_offsets_over_body:
x = x + uv_body_posed
x = x * uv_mask[:,:,:,tf.newaxis]
return x return x