6
6
if 'sinc' in dir (torch ):
7
7
sinc = torch .sinc
8
8
else :
9
- # This code is adopted from adefossez's julius.core.sinc
10
- # https://adefossez.github.io/julius/julius/core.html
9
+ # This code is adopted from adefossez's julius.core.sinc
10
+ # https://adefossez.github.io/julius/julius/core.html
11
11
def sinc (x : torch .Tensor ):
12
12
"""
13
13
Implementation of sinc, i.e. sin(pi * x) / (pi * x)
@@ -26,8 +26,9 @@ def __init__(self,
26
26
half_width = 0.6 ,
27
27
stride : int = 1 ,
28
28
pad : bool = True ,
29
- kernel_size = 12 ): # kernel_size should be even number for stylegan3 setup,
30
- # in this implementation, odd number is also possible.
29
+ kernel_size = 12
30
+ ): # kernel_size should be even number for stylegan3 setup,
31
+ # in this implementation, odd number is also possible.
31
32
super ().__init__ ()
32
33
if cutoff < - 0. :
33
34
raise ValueError ("Minimum cutoff must be larger than zero." )
@@ -54,7 +55,7 @@ def __init__(self,
54
55
if self .even :
55
56
time = (torch .arange (- self .half_size , self .half_size ) + 0.5 )
56
57
else :
57
- time = torch .arange (self .kernel_size ) - self .half_size
58
+ time = torch .arange (self .kernel_size ) - self .half_size
58
59
if cutoff == 0 :
59
60
filter_ = torch .zeros_like (time )
60
61
else :
@@ -71,11 +72,10 @@ def forward(self, x):
71
72
new_shape = shape [:- 1 ] + [- 1 ]
72
73
x = x .view (- 1 , 1 , shape [- 1 ])
73
74
if self .pad :
74
- x = F .pad (
75
- x ,
76
- (self .half_size , self .half_size ),
77
- mode = 'constant' , value = 0 ) # empirically, it is better than replicate
78
- #mode='replicate')
75
+ x = F .pad (x , (self .half_size , self .half_size ),
76
+ mode = 'constant' ,
77
+ value = 0 ) # empirically, it is better than replicate
78
+ #mode='replicate')
79
79
if self .even :
80
80
out = F .conv1d (x , self .filter , stride = self .stride )[..., :- 1 ]
81
81
else :
@@ -90,7 +90,7 @@ def __init__(self,
90
90
stride : int = 1 ,
91
91
pad : bool = True ,
92
92
kernel_size = 12 ): # kernel_size should be even number
93
- # in this implementation, odd number is also possible.
93
+ # in this implementation, odd number is also possible.
94
94
super ().__init__ ()
95
95
if cutoff < - 0. :
96
96
raise ValueError ("Minimum cutoff must be larger than zero." )
@@ -115,15 +115,15 @@ def __init__(self,
115
115
116
116
#rotation equivariant grid
117
117
if self .even :
118
- time = ( torch .stack (torch .meshgrid (
119
- torch .arange (- self .half_size , self .half_size ) + 0.5 ,
120
- torch .arange (- self .half_size , self .half_size ) + 0.5 ),
121
- dim = - 1 ) )
118
+ time = torch .stack (torch .meshgrid (
119
+ torch .arange (- self .half_size , self .half_size ) + 0.5 ,
120
+ torch .arange (- self .half_size , self .half_size ) + 0.5 ),
121
+ dim = - 1 )
122
122
else :
123
- time = ( torch .stack (torch .meshgrid (
124
- torch .arange (self .kernel_size ) - self .half_size ,
125
- torch .arange (self .kernel_size ) - self .half_size ,
126
- dim = - 1 ) )
123
+ time = torch .stack (torch .meshgrid (
124
+ torch .arange (self .kernel_size ) - self .half_size ,
125
+ torch .arange (self .kernel_size ) - self .half_size ) ,
126
+ dim = - 1 )
127
127
128
128
time = torch .norm (time , dim = - 1 )
129
129
#rotation equivariant window
@@ -148,10 +148,12 @@ def forward(self, x):
148
148
shape = list (x .shape )
149
149
x = x .view (- 1 , 1 , shape [- 2 ], shape [- 1 ])
150
150
if self .pad :
151
- x = F .pad (x , (self .half_size , self .half_size , self .half_size ,
152
- self .half_size ),
153
- mode = 'constant' , value = 0 ) # empirically, it is better than replicate or reflect
154
- #mode='replicate')
151
+ x = F .pad (
152
+ x , (self .half_size , self .half_size , self .half_size ,
153
+ self .half_size ),
154
+ mode = 'constant' ,
155
+ value = 0 ) # empirically, it is better than replicate or reflect
156
+ #mode='replicate')
155
157
if self .even :
156
158
out = F .conv2d (x , self .filter , stride = self .stride )[..., :- 1 , :- 1 ]
157
159
else :
0 commit comments