0
\$\begingroup\$

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?

\$\endgroup\$
2
  • \$\begingroup\$ "right approach?" Does your code work correctly, do you see de-noised video results? I really do appreciate that you tried to offer a reprex. But torch.rand(100, 32, 32) is just a TV tuned to a station that went off the air. Consider replacing it with a proper telegraph process. \$\endgroup\$ Commented Sep 28, 2023 at 17:43
  • \$\begingroup\$ @J_H I do see denoised results on my confidential data I'm working with. I'll think about coming up with a reasonable minimal example. \$\endgroup\$ Commented Sep 28, 2023 at 20:15

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.