Thanks for you attention. I am not quite familiar with PyTorch and wondering is it possible to mix weights defined by my self (not weights like that in torch.nn.conv2d
, but like self.filter
in the below example) into torch.nn.Module
.
If that is possible. I have two questions:
- How can I bring it to the model.parameter and bring it to cuda?
- How can I add it to optimizer?
Thanks in advance!
A sample,
class myModel(torch.nn.Module):
def __init__(self):
super(myModel, self).__init__()
self.filter = torch.randn(8, 4, 3, 3)
def forward(self, x):
return torch.nn.functional.conv2d(x, self.filter)
inputs = torch.randn(1, 4, 5, 5).cuda()
model = myModel().cuda() # it doesn't work (1)
optimizer = torch.optim.SGD([model.filter], lr=0.01, momentum=0.9) # will it work? (2)
# result
>>> [i for i in model.parameters()]
[]