Skip to content

seungjunlee96/Depthwise-Separable-Convolution_Pytorch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Depthwise Separable Convolution_Pytorch

Implementation of Depthwise Separable Convolution

Depthwise Separable Convolution was first introduced in Xception: Deep Learning with Depthwise Separable Convolutions

Installation

git clone https://github.com/seungjunlee96/DepthwiseSeparableConvolution_Pytorch.git
cd DepthwiseSeparableConvolution_Pytorch/
python3 setup.py install --user

Usage

from DepthwiseSeparableConvolution import depthwise_separable_conv

## In your Network
depthwise_separable_conv(nin, nout, kernel_size = 3, padding = 1, bias=False)

Explanation on Depthwise Separable Convolution

1.Depthwise Convolution

depthwise

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

2.Pointwise Convolution

pointwise

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

3.Depthwise Separable Convoltion

DepthwiseSeparable

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

To Do

For example usage, please refer to ./example/Xception.py.

references

About

Implementation of Depthwise Separable Convolution (pytorch)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages