Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vectorize kernel creation #18

Open
iKintosh opened this issue Aug 31, 2020 · 0 comments
Open

Vectorize kernel creation #18

iKintosh opened this issue Aug 31, 2020 · 0 comments
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@iKintosh
Copy link
Owner

iKintosh commented Aug 31, 2020

Remove loops

def calculate_weights(self):
for i in range(self.conv_layer.out_channels):
for j in range(self.conv_layer.in_channels):
sigma = self.sigma[i, j].expand_as(self.y)
freq = self.freq[i, j].expand_as(self.y)
theta = self.theta[i, j].expand_as(self.y)
psi = self.psi[i, j].expand_as(self.y)
rotx = self.x * torch.cos(theta) + self.y * torch.sin(theta)
roty = -self.x * torch.sin(theta) + self.y * torch.cos(theta)
g = torch.exp(
-0.5 * ((rotx ** 2 + roty ** 2) / (sigma + self.delta) ** 2)
)
g = g * torch.cos(freq * rotx + psi)
g = g / (2 * math.pi * sigma ** 2)
self.conv_layer.weight.data[i, j] = g

@iKintosh iKintosh added help wanted Extra attention is needed question Further information is requested labels Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant