I have a black & white video as a tensor with the shape [Time, Width, Height] with popcorn noise and I would like to reduce the noise by naively convolving along the time dimension.
Using a Pytorch forum post as a starting point, I wrote the following function:
import torch
from torch import nn
# dummy input tensor
input_tensor = torch.rand(100, 32, 32)
with torch.no_grad():
t = input_tensor.view(1, *input_tensor.shape).transpose(1, 2) # swap seq and channels dim -> SHAPE: [C, T, H, W]
# define the low-pass filter kernel
kernel_size = 5
kernel = torch.ones(kernel_size) / kernel_size
# convolve along the time dimension
conv_temp = nn.Conv3d(1, 1, kernel_size=(kernel_size, 1, 1), bias=False)
conv_temp.weight.data = kernel.view(1, 1, kernel_size, 1, 1)
output_tensor = conv_temp(t).squeeze(0).transpose(0, 1)
Is this the right approach? Am I using the API correctly?