Skip to content

Vectorize kernel creation #18

@iKintosh

Description

@iKintosh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions