@@ -67,11 +67,11 @@ def blend_mode(cls, img1, img2, mode):
6767 def g (cls , x ):
6868 return torch .where (x <= 0.25 , ((16 * x - 12 ) * x + 4 ) * x , torch .sqrt (x ))
6969
70- def gaussian_kernel (kernel_size : int , sigma : float , device = None ):
70+ def gaussian_kernel (kernel_size : int , sigma : float , device = None , dtype = torch . float32 ):
7171 x , y = torch .meshgrid (torch .linspace (- 1 , 1 , kernel_size , device = device ), torch .linspace (- 1 , 1 , kernel_size , device = device ), indexing = "ij" )
7272 d = torch .sqrt (x * x + y * y )
7373 g = torch .exp (- (d * d ) / (2.0 * sigma * sigma ))
74- return g / g .sum ()
74+ return ( g / g .sum ()). to ( dtype )
7575
7676class Blur (io .ComfyNode ):
7777 @classmethod
@@ -99,7 +99,7 @@ def execute(cls, image: torch.Tensor, blur_radius: int, sigma: float) -> io.Node
9999 batch_size , height , width , channels = image .shape
100100
101101 kernel_size = blur_radius * 2 + 1
102- kernel = gaussian_kernel (kernel_size , sigma , device = image .device ).repeat (channels , 1 , 1 ).unsqueeze (1 )
102+ kernel = gaussian_kernel (kernel_size , sigma , device = image .device , dtype = image . dtype ).repeat (channels , 1 , 1 ).unsqueeze (1 )
103103
104104 image = image .permute (0 , 3 , 1 , 2 ) # Torch wants (B, C, H, W) we use (B, H, W, C)
105105 padded_image = F .pad (image , (blur_radius ,blur_radius ,blur_radius ,blur_radius ), 'reflect' )
@@ -200,7 +200,7 @@ def execute(cls, image: torch.Tensor, sharpen_radius: int, sigma:float, alpha: f
200200 image = image .to (comfy .model_management .get_torch_device ())
201201
202202 kernel_size = sharpen_radius * 2 + 1
203- kernel = gaussian_kernel (kernel_size , sigma , device = image .device ) * - (alpha * 10 )
203+ kernel = gaussian_kernel (kernel_size , sigma , device = image .device , dtype = image . dtype ) * - (alpha * 10 )
204204 kernel = kernel .to (dtype = image .dtype )
205205 center = kernel_size // 2
206206 kernel [center , center ] = kernel [center , center ] - kernel .sum () + 1.0
0 commit comments