Skip to content

Instantly share code, notes, and snippets.

@jinglescode
Created November 2, 2020 09:32
Show Gist options
  • Save jinglescode/bdc45510de9a4283ccfb3b79eb2d3c22 to your computer and use it in GitHub Desktop.
Save jinglescode/bdc45510de9a4283ccfb3b79eb2d3c22 to your computer and use it in GitHub Desktop.
class TestConv1d(nn.Module):
def __init__(self):
super(TestConv1d, self).__init__()
self.conv = nn.Conv1d(in_channels=1, out_channels=1, kernel_size=3, dilation=2, bias=False)
self.init_weights()
def forward(self, x):
return self.conv(x)
def init_weights(self):
new_weights = torch.ones(self.conv.weight.shape) * 2.
self.conv.weight = torch.nn.Parameter(new_weights, requires_grad=False)
in_x = torch.tensor([[[1,2,3,4,5,6]]]).float()
print("in_x.shape", in_x.shape)
print(in_x)
net = TestConv1d()
out_y = net(in_x)
print("out_y.shape", out_y.shape)
print(out_y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment