Hi;
I have images taken from two separate cameras (camera1 and camera2). I am planning to use two separate pre-trained Resnet18βs to for images from each source. Further I plan to concatenate/ club the penultimate layer features both networks before I perform classification.
As of now I have written this piece of code for the same
pretrained_model = models.resnet18(pretrained=True)
my_model1 = nn.Sequential(*list(pretrained_model.children())[:-1])
my_model2 = nn.Sequential(*list(pretrained_model.children())[:-1])
class Net(nn.Module):
def init(self):
super(Net, self).init()
self.feature1 = my_model1
self.feature2 = my_model2
self.fc = nn.Linear(1024, 117)
def forward(self, x,y):
x1= self.feature1(x)
x2= self.feature2(y)
x3 = torch.cat((x1,x2),1)
x3 = x3.view(x3.size(0), -1)
x3 = self.fc(x3)
return x3
net=Net()
p=Variable(torch.rand(4,3,240,240))
q=Variable(torch.rand(4,3,240,240))
o=net(p,q)
As of now I dont get any error. It would be great if someone could let me know if I am doing this write.