Skip to content

Instantly share code, notes, and snippets.

@bdsaglam
Last active June 26, 2022 15:13
Show Gist options
  • Select an option

  • Save bdsaglam/b16de6ae6662e7a783e06e58e2c5185a to your computer and use it in GitHub Desktop.

Select an option

Save bdsaglam/b16de6ae6662e7a783e06e58e2c5185a to your computer and use it in GitHub Desktop.
Depthwise 2D Convolution PyTorch
import torch
class DepthwiseConv2d(torch.nn.Conv2d):
def __init__(self,
in_channels,
depth_multiplier=1,
kernel_size=3,
stride=1,
padding=0,
dilation=1,
bias=True,
padding_mode='zeros'
):
out_channels = in_channels * depth_multiplier
super().__init__(
in_channels=in_channels,
out_channels=out_channels,
kernel_size=kernel_size,
stride=stride,
padding=padding,
dilation=dilation,
groups=in_channels,
bias=bias,
padding_mode=padding_mode
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment