Implementation of Depthwise Separable Convolution
Depthwise Separable Convolution was first introduced in Xception: Deep Learning with Depthwise Separable Convolutions
git clone https://github.com/seungjunlee96/DepthwiseSeparableConvolution_Pytorch.git
cd DepthwiseSeparableConvolution_Pytorch/
python3 setup.py install --user
from DepthwiseSeparableConvolution import depthwise_separable_conv
## In your Network
depthwise_separable_conv(nin, nout, kernel_size = 3, padding = 1, bias=False)
class depthwise_conv(nn.Module):
def __init__(self, nin, kernels_per_layer):
super(depthwise_separable_conv, self).__init__()
self.depthwise = nn.Conv2d(nin, nin * kernels_per_layer, kernel_size=3, padding=1, groups=nin)
def forward(self, x):
out = self.depthwise(x)
return out
class pointwise_conv(nn.Module):
def __init__(self, nin, nout):
super(depthwise_separable_conv, self).__init__()
self.pointwise = nn.Conv2d(nin, nout, kernel_size=1)
def forward(self, x):
out = self.pointwise(x)
return out
class depthwise_separable_conv(nn.Module):
def __init__(self, nin, kernels_per_layer, nout):
super(depthwise_separable_conv, self).__init__()
self.depthwise = nn.Conv2d(nin, nin * kernels_per_layer, kernel_size=3, padding=1, groups=nin)
self.pointwise = nn.Conv2d(nin * kernels_per_layer, nout, kernel_size=1)
def forward(self, x):
out = self.depthwise(x)
out = self.pointwise(out)
return out
For example usage, please refer to ./example/Xception.py
.