I’have implemented the same network in Keras and I expect to get the exact same results in pytorch, but during training I see no progress. I suspect that my layers are not connected the way I expect them to be. When I check layer’s shape for layer in final.children() I only get one print which is [(1,1)]
class MyModel(nn.Module):
def __init__(self):
super(MyModel, self).__init__()
self.conv1 = nn.Conv2d(256, 1, 1)
self.flatten = nn.Flatten()
self.fc1 = nn.Linear(14*14, 1)
def forward(self, x):
output1 = F.sigmoid(self.conv1(x))
output2 = F.sigmoid(self.fc1(output1))
return output2
class Final(nn.Module):
def __init__(self):
super(Final, self).__init__()
pretrained_model = torch.hub.load('pytorch/vision:v0.6.0', 'densenet201', pretrained=True)
model = MyModel()
list_of_layers = list(pretrained_model.features)[:8]
list_of_layers.extend(list(model.children()))
self.final_model = nn.Sequential(*list_of_layers)
def forward(self, x):
outputs = list()
for ii, model in enumerate(self.final_model):
x = model(x)
if ii == 8 or ii == 10:
outputs.append(x)
return outputs