Pretrained VGG16 with 2 input features

Viewed 24

I want to implement pretrained VGG16 modifying it to take image and gender tensors as input features for age prediction problem but not sure how to do that. I wrote something like this

# Custom Convolution Neural Network architecture based on VGG16
class AgePredictor(nn.Module):
    
    # Define and Initialize Layers
    def __init__(self):
        
        super(AgePredictor, self).__init__()
        # VGG 
        vgg  = models.vgg16(pretrained=True)
        self.feature = nn.Sequential(*list(vgg.children())[:-1])
        
    
        
        self.classifier = nn.Sequential(
            nn.Linear(16+400,200),
            nn.ReLU(),
            nn.Dropout(),
            nn.Linear(200,1),
            nn.Sigmoid())
        

    # Forward Pass. x = Image tensor, y = gender tensor
    def forward(self, x, y):

        x = self.feature(x)
        x = self.avgpool(x)
        x = x.view(x.size()[0], -1)
        x = self.classifier(x)
        
        y = ...
        
        z = torch.cat((x,y), dim = 1)
        ...
        ...

        return z

Can anyone help me how to go about this ?

0 Answers
Related