nibuiro / condconv-pytorch Goto Github PK
View Code? Open in Web Editor NEWunofficial implementation of CondConv: Conditionally Parameterized Convolutions for Efficient Inference in PyTorch.
License: MIT License
unofficial implementation of CondConv: Conditionally Parameterized Convolutions for Efficient Inference in PyTorch.
License: MIT License
RT. Thanks for your re-implement.
Dear author,
Can this code implement one-dimensional convolution?
Thanks.
When the batch size > 1, will get a error of mismatch size for shape. The reason is beacuse the operation of flatten and dropout in defination of _routing
. Hope you can fix this bug.
import torch
from condconv import CondConv2D
inp = torch.rand((2,3,12,12))
f = CondConv2D(3, 6, (3,3), stride=1,
padding=1, dilation=1, groups=1,
bias=True, padding_mode='replicate', num_experts=3, dropout_rate=0.2)
f(inp)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[354], line 1
----> 1 f(inp).shape
File ~/miniconda3/envs/license-plate/lib/python3.8/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, **kwargs)
1496 # If we don't have any hooks, we want to skip the rest of the logic in
1497 # this function, and just call forward.
1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1499 or _global_backward_pre_hooks or _global_backward_hooks
1500 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1501 return forward_call(*args, **kwargs)
1502 # Do not call functions when jit is used
1503 full_backward_hooks, non_full_backward_hooks = [], []
Cell In[348], line 82, in CondConv2D.forward(self, inputs)
80 routing_weights = self._routing_fn(pooled_inputs)
81 kernels = torch.sum(routing_weights[: ,None, None, None, None] * self.weight, 0)
---> 82 out = self._conv_forward(input, kernels)
83 res.append(out)
84 return torch.cat(res, dim=0)
Cell In[348], line 68, in CondConv2D._conv_forward(self, input, weight)
66 def _conv_forward(self, input, weight):
67 if self.padding_mode != 'zeros':
---> 68 return F.conv2d(F.pad(input, self._padding_repeated_twice, mode=self.padding_mode),
69 weight, self.bias, self.stride,
70 _pair(0), self.dilation, self.groups)
71 return F.conv2d(input, weight, self.bias, self.stride,
72 self.padding, self.dilation, self.groups)
File ~/miniconda3/envs/license-plate/lib/python3.8/site-packages/torch/nn/modules/module.py:1614, in Module.__getattr__(self, name)
1612 if name in modules:
1613 return modules[name]
-> 1614 raise AttributeError("'{}' object has no attribute '{}'".format(
1615 type(self).__name__, name))
AttributeError: 'CondConv2D' object has no attribute '_padding_repeated_twice'
class Model(nn.Module):
def init(self, num_experts):
super(Model, self).init()
self.condconv2d = CondConv2D(10, 128, kernel_size=1)
def forward(self, x):
x = self.condconv2d(x)
if name == "main":
"""Testing
"""
inputs = torch.rand(1,3,224,224)
model=Model(num_experts=3)
y = model(inputs)
print(y)
print(model)
I got the following error:
RuntimeError: size mismatch, m1: [1 x 3], m2: [10 x 3] at ..\aten\src\TH/generic/THTensorMath.cpp:961
could you tell me how to solve it? Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.