The torchvision Gaussian function runs on the CPU even if your tensor is on the GPU. Here's a blur function that guarantees the blur will run very quickly on the GPU. Some adaptation for the tensor shape may need to be made; this one works for the latent tensor format:
`def gaussian_blur(tensor, kernel_size=5, sigma=1.0):
if len(tensor.shape) == 4: # Batch of images
batch_size, channels, height, width = tensor.shape
else:
raise ValueError("Expected a 4D tensor [B, C, H, W]")
The torchvision Gaussian function runs on the CPU even if your tensor is on the GPU. Here's a blur function that guarantees the blur will run very quickly on the GPU. Some adaptation for the tensor shape may need to be made; this one works for the latent tensor format:
`def gaussian_blur(tensor, kernel_size=5, sigma=1.0): if len(tensor.shape) == 4: # Batch of images batch_size, channels, height, width = tensor.shape else: raise ValueError("Expected a 4D tensor [B, C, H, W]")