-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalsampler.py
29 lines (21 loc) · 1.06 KB
/
normalsampler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import torch
class NormalSampler:
def __init__(self, morphableModel):
self.morphableModel = morphableModel
def _sample(self, n, variance, std_multiplier = 1):
std = torch.sqrt(variance) * std_multiplier
std = std.expand((n, std.shape[0]))
q = torch.distributions.Normal(torch.zeros_like(std).to(std.device), std * std_multiplier)
samples = q.rsample()
return samples
def sampleShape(self, n, std_multiplier = 1):
return self._sample(n, self.morphableModel.shapePcaVar, std_multiplier)
def sampleExpression(self, n, std_multiplier=1):
return self._sample(n, self.morphableModel.expressionPcaVar, std_multiplier)
def sampleAlbedo(self, n, std_multiplier=1):
return self._sample(n, self.morphableModel.diffuseAlbedoPcaVar, std_multiplier)
def sample(self, shapeNumber = 1):
shapeCoeff = self.sampleShape(shapeNumber)
expCoeff = self.sampleExpression(shapeNumber)
albedoCoeff = self.sampleAlbedo(shapeNumber)
return shapeCoeff, expCoeff, albedoCoeff