-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CDDIMParameters.py
56 lines (51 loc) · 1.48 KB
/
CDDIMParameters.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class CDDIMParameters:
def __init__(self, stochasticity, stddev, K, clipping=None, projectNoise=False):
self.stochasticity = stochasticity
self.stddev = stddev
self.K = K
self.clipping = clipping
self.projectNoise = projectNoise
pass
def toStats(self):
return {
'stochasticity': self.stochasticity,
'noise stddev': self.stddev,
'steps skip type': 'uniform',
'K': self.K,
'clipping': self.clipping is not None,
'project noise': self.projectNoise,
}
def toModelConfig(self):
return {
'model': {
'restorator': {
'sampler': {
'name': 'DDIM',
'stochasticity': self.stochasticity,
'noise stddev': self.stddev,
'steps skip type': { 'name': 'uniform', 'K': self.K },
'clipping': self.clipping,
'project noise': self.projectNoise,
}
}
}
}
@staticmethod
def fromStats(stats):
clipping = None
if stats['clipping']:
clipping = dict(min=-1.0, max=1.0)
return CDDIMParameters(
stochasticity=stats['stochasticity'],
stddev=stats['noise stddev'],
K=stats['K'],
clipping=clipping,
projectNoise=stats['project noise']
)
# End of CDDIMParameters
def DDIMParameters(stochasticity, stddev, K, clipping=None, projectNoise=False):
params = CDDIMParameters(stochasticity, stddev, K, clipping, projectNoise)
return (
params.toModelConfig(),
params.toStats()
)