-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 382446f
Showing
13 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## Tucker Convolutional Layers | ||
|
||
PyTorch implementation of Tucker Convolutional Layers as introduced in [MobileDets: Searching for Object Detection Architectures for Mobile Accelerators](https://arxiv.org/abs/2004.14525v3). Ross Wightman's timm library has been used for some helper functions and inspiration for syntax style. | ||
|
||
## Installation | ||
|
||
```bash | ||
$ pip install tucker-conv | ||
``` | ||
|
||
## Usage | ||
|
||
```python | ||
from tucker_conv.conv import TuckerConv | ||
import torch | ||
|
||
tucker = TuckerConv(30, 30, in_comp_ratio = 0.25, out_comp_ratio = 0.75) | ||
input = torch.randn([1, 30, 512, 512]) | ||
|
||
output = tucker(input) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from tucker_conv.conv import TuckerConv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import torch.nn as nn | ||
from timm.models.efficientnet_blocks import make_divisible | ||
from timm.models.layers import create_conv2d | ||
|
||
class TuckerConv(nn.Module): | ||
def __init__(self, in_chs, out_chs, in_comp_ratio = 0.25, out_comp_ratio = 0.75, act_layer = nn.ReLU6, | ||
norm_layer = nn.BatchNorm2d, comp_kernel_size = 1, reg_kernel_size = 3, pad_type = '', residual = True): | ||
super(TuckerConv, self).__init__() | ||
self.residual = residual | ||
comp_chs = make_divisible(in_comp_ratio * in_chs) | ||
reg_chs = make_divisible(out_comp_ratio * out_chs) | ||
|
||
# Point - wise compression | ||
self.conv_pw = create_conv2d(in_chs, comp_chs, comp_kernel_size, padding = pad_type) | ||
self.bn1 = norm_layer(comp_chs) | ||
self.act1 = act_layer(inplace = True) | ||
|
||
# Regular convolution | ||
self.conv_reg = create_conv2d(comp_chs, reg_chs, reg_kernel_size, padding = pad_type) | ||
self.bn2 = norm_layer(reg_chs) | ||
self.act2 = act_layer(inplace = True) | ||
|
||
# Point - wise linear projection | ||
self.conv_pwl = create_conv2d(reg_chs, out_chs, comp_kernel_size, padding = pad_type) | ||
self.bn3 = norm_layer(out_chs) | ||
|
||
def forward(self, x): | ||
shortcut = x | ||
|
||
# Point - wise compression | ||
x = self.conv_pw(x) | ||
x = self.bn1(x) | ||
x = self.act1(x) | ||
|
||
# Regular convolution | ||
x = self.conv_reg(x) | ||
x = self.bn2(x) | ||
x = self.act2(x) | ||
|
||
# Point - wise linear projection | ||
x = self.conv_pwl(x) | ||
x = self.bn3(x) | ||
|
||
if self.residual: | ||
x = x + shortcut | ||
|
||
return x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import torch.nn as nn | ||
from timm.models.efficientnet_blocks import make_divisible | ||
from timm.models.layers import create_conv2d | ||
|
||
class TuckerConv(nn.Module): | ||
def __init__(self, in_chs, out_chs, in_comp_ratio = 0.25, out_comp_ratio = 0.75, act_layer = nn.ReLU6, | ||
norm_layer = nn.BatchNorm2d, comp_kernel_size = 1, reg_kernel_size = 3, pad_type = '', residual = True): | ||
super(TuckerConv, self).__init__() | ||
self.residual = residual | ||
comp_chs = make_divisible(in_comp_ratio * in_chs) | ||
reg_chs = make_divisible(out_comp_ratio * out_chs) | ||
|
||
# Point - wise compression | ||
self.conv_pw = create_conv2d(in_chs, comp_chs, comp_kernel_size, padding = pad_type) | ||
self.bn1 = norm_layer(comp_chs) | ||
self.act1 = act_layer(inplace = True) | ||
|
||
# Regular convolution | ||
self.conv_reg = create_conv2d(comp_chs, reg_chs, reg_kernel_size, padding = pad_type) | ||
self.bn2 = norm_layer(reg_chs) | ||
self.act2 = act_layer(inplace = True) | ||
|
||
# Point - wise linear projection | ||
self.conv_pwl = create_conv2d(reg_chs, out_chs, comp_kernel_size, padding = pad_type) | ||
self.bn3 = norm_layer(out_chs) | ||
|
||
def forward(self, x): | ||
shortcut = x | ||
|
||
# Point - wise compression | ||
x = self.conv_pw(x) | ||
x = self.bn1(x) | ||
x = self.act1(x) | ||
|
||
# Regular convolution | ||
x = self.conv_reg(x) | ||
x = self.bn2(x) | ||
x = self.act2(x) | ||
|
||
# Point - wise linear projection | ||
x = self.conv_pwl(x) | ||
x = self.bn3(x) | ||
|
||
if self.residual: | ||
x = x + shortcut | ||
|
||
return x |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[metadata] | ||
name = tucker_conv | ||
version = 1.0.0 | ||
author = Pranav Pulijala | ||
description = Implementation of Tucker Convolution Layer | ||
long_description = file: README.md | ||
long_description_content_type = text/markdown | ||
url = https://github.com/novice03/tucker-conv | ||
classifiers = | ||
Programming Language :: Python :: 3 | ||
Operating System :: OS Independent | ||
|
||
[options] | ||
packages = find: | ||
include_package_data = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Metadata-Version: 2.1 | ||
Name: tucker-conv | ||
Version: 1.0.0 | ||
Summary: Implementation of Tucker Convolution Layer | ||
Home-page: https://github.com/novice03/tucker-conv | ||
Author: Pranav Pulijala | ||
License: UNKNOWN | ||
Description: ## Tucker Convolutional Layers | ||
|
||
PyTorch implementation of Tucker Convolutional Layers as introduced in [MobileDets: Searching for Object Detection Architectures for Mobile Accelerators](https://arxiv.org/abs/2004.14525v3). Ross Wightman's timm library has been used for some helper functions and inspiration for syntax style. | ||
|
||
## Installation | ||
|
||
```bash | ||
$ pip install tucker-conv | ||
``` | ||
|
||
## Usage | ||
|
||
```python | ||
from tucker_conv.conv import TuckerConv | ||
import torch | ||
|
||
tucker = TuckerConv(30, 30, in_comp_ratio = 0.25, out_comp_ratio = 0.75) | ||
input = torch.randn([1, 30, 512, 512]) | ||
|
||
output = tucker(input) | ||
``` | ||
Platform: UNKNOWN | ||
Classifier: Programming Language :: Python :: 3 | ||
Classifier: Operating System :: OS Independent | ||
Description-Content-Type: text/markdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
README.md | ||
setup.cfg | ||
tucker_conv/__init__.py | ||
tucker_conv/conv.py | ||
tucker_conv.egg-info/PKG-INFO | ||
tucker_conv.egg-info/SOURCES.txt | ||
tucker_conv.egg-info/dependency_links.txt | ||
tucker_conv.egg-info/top_level.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tucker_conv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from tucker_conv.conv import TuckerConv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import torch.nn as nn | ||
from timm.models.efficientnet_blocks import make_divisible | ||
from timm.models.layers import create_conv2d | ||
|
||
class TuckerConv(nn.Module): | ||
def __init__(self, in_chs, out_chs, in_comp_ratio = 0.25, out_comp_ratio = 0.75, act_layer = nn.ReLU6, | ||
norm_layer = nn.BatchNorm2d, comp_kernel_size = 1, reg_kernel_size = 3, pad_type = '', residual = True): | ||
super(TuckerConv, self).__init__() | ||
self.residual = residual | ||
comp_chs = make_divisible(in_comp_ratio * in_chs) | ||
reg_chs = make_divisible(out_comp_ratio * out_chs) | ||
|
||
# Point - wise compression | ||
self.conv_pw = create_conv2d(in_chs, comp_chs, comp_kernel_size, padding = pad_type) | ||
self.bn1 = norm_layer(comp_chs) | ||
self.act1 = act_layer(inplace = True) | ||
|
||
# Regular convolution | ||
self.conv_reg = create_conv2d(comp_chs, reg_chs, reg_kernel_size, padding = pad_type) | ||
self.bn2 = norm_layer(reg_chs) | ||
self.act2 = act_layer(inplace = True) | ||
|
||
# Point - wise linear projection | ||
self.conv_pwl = create_conv2d(reg_chs, out_chs, comp_kernel_size, padding = pad_type) | ||
self.bn3 = norm_layer(out_chs) | ||
|
||
def forward(self, x): | ||
shortcut = x | ||
|
||
# Point - wise compression | ||
x = self.conv_pw(x) | ||
x = self.bn1(x) | ||
x = self.act1(x) | ||
|
||
# Regular convolution | ||
x = self.conv_reg(x) | ||
x = self.bn2(x) | ||
x = self.act2(x) | ||
|
||
# Point - wise linear projection | ||
x = self.conv_pwl(x) | ||
x = self.bn3(x) | ||
|
||
if self.residual: | ||
x = x + shortcut | ||
|
||
return x |