Skip to content

Commit

Permalink
Added all relevant files
Browse files Browse the repository at this point in the history
  • Loading branch information
novice03 authored May 13, 2021
0 parents commit 382446f
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
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)
```
1 change: 1 addition & 0 deletions build/lib/tucker_conv/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from tucker_conv.conv import TuckerConv
47 changes: 47 additions & 0 deletions build/lib/tucker_conv/conv.py
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
47 changes: 47 additions & 0 deletions build/lib/tucker_conv/tucker_conv.py
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 added dist/tucker_conv-1.0.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/tucker_conv-1.0.0.tar.gz
Binary file not shown.
15 changes: 15 additions & 0 deletions setup.cfg
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
32 changes: 32 additions & 0 deletions tucker_conv.egg-info/PKG-INFO
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
8 changes: 8 additions & 0 deletions tucker_conv.egg-info/SOURCES.txt
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
1 change: 1 addition & 0 deletions tucker_conv.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions tucker_conv.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tucker_conv
1 change: 1 addition & 0 deletions tucker_conv/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from tucker_conv.conv import TuckerConv
47 changes: 47 additions & 0 deletions tucker_conv/conv.py
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

0 comments on commit 382446f

Please sign in to comment.