fkodom / fft-conv-pytorch Goto Github PK
View Code? Open in Web Editor NEWImplementation of 1D, 2D, and 3D FFT convolutions in PyTorch. Much faster than direct convolutions for large kernel sizes.
License: MIT License
Implementation of 1D, 2D, and 3D FFT convolutions in PyTorch. Much faster than direct convolutions for large kernel sizes.
License: MIT License
Hi,
Thanks for putting this together - complex number support is starting to get pretty advanced in pytorch, is there any chance you'd consider changing things here to allow for it?
Cheers,
Stephen
Thank you for this code. How can I specify the stride just like a normal conv layer? Thanks.
x=torch.randn(1,3,32,128)
net1=nn.Conv2d(3, 64, 1, (2,1), 1)
net2=FFTConv2d(3,64,1,(2,1),1)
out1=net1(x)
out2=net2(x)
print(out1.shape,out2.shape)
out!=out2
Thank you for open sourcing your implementation.
I tested the FFTConv2d vs the pytorch nn.Conv2d layer using a simple LeNet5 architecture on MNIST with the Adam optimizer with lr=1e-3. By using pytorch's nn.Conv2d I am able to reach ~98% after 1 epoch and I reach ~99% after around 10 epochs whilst using FFTConv2d with the exact same architecture and parameters I get ~92% after 1 epoch and only get up to ~97% after 10 epochs.
I thought this might be due to some aliasing effects so I padded the kernel and the input using the "s" argument in rfftn but I still get the same subpar performance.
The exact architecture is as below:
class LeNet5(nn.Module):
def __init__(self, num_classes=10):
super().__init__()
pad = 0
self.conv1 = nn.Sequential(
FFTConv2d(1, 6, kernel_size=5, stride=1, padding=pad),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2)
)
self.conv2 = nn.Sequential(
FFTConv2d(6, 16, kernel_size=5, stride=1, padding=pad),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2)
)
self.conv3 = nn.Sequential(
FFTConv2d(16, 120, kernel_size=5, stride=1, padding=pad),
nn.ReLU()
)
self.transform_output = nn.Flatten(start_dim=1)
self.fc = nn.Sequential(
nn.Linear(120, 84),
nn.ReLU(),
nn.Linear(84, num_classes)
)
def forward(self, x):
out = self.conv1(x)
out = self.conv2(out)
out = self.conv3(out)
out = self.transform_output(out)
out = self.fc(out)
return out
Any idea why this is the case?
Line 155 in bbe43cd
In L184 and L189, why the condition statement is *_channels % 2 != 0
but not *_channels % groups != 0
?
Seems not match with the error message.
Thanks a lot for sharing your code. It helps me a lot ! I have a question about complex matrix multiplication. I notice that you made some comments on this part saying that "This is fairly hacky but necessary for PyTorch 1.7.0, because Autograd is not enabled for complex matrix operations yet." But when I using Pytorch 1.7.0 , I just use 'c = a * b ' directly. It seems that autograd works quite well ? I'm not sure now... Would you like to do some experiments to double check it ? Thanks a lot !
I'm trying to package this for conda-forge, any information on the license?
Thank you
Best,
Mark
xref: yoyololicon#9
Hi fkodom,
I was trying to experiment with your fftconv implementation but I saw that just after 2 layers the error becomes quite large. Is it due to a malinterpretation of your code from my part? Might it be that the FFT + IFFT simply introduce too much error when concatenated?
Thank you in advance for your help! :)
David
SOLUTION:
The problem is that the convolution was growing very largely, for which a difference of 1e-3 was not that big. In short the method works fantastically good :)
Hello,
Thank you for the effort you put into making this work, however I am very confused. When I want to apply this "FFTCONV2D" layer to a network (Resnet for example), in GPU I always get the error 'CUDA OUT OF MEMORY......'. It's due to the "complex_matmul" function which needs a lot of resources, how can I solve this problem please?
Dear authors,
I am interested in this work and thanks for your share. I find this function can't work on GPU. Is it true?
Dear authors,
Thank you for the contribution. Is there any implementation of depth-wise convolution like a general conv layer?
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.