How to concatenate CNN features and reduce size

hi,
suppose I have vgg features of images like 4096 and some other features 2048, so I need to concatenate both together and reduce the feature size to 512. how can I do that?
f1=4096,f2=2048

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        
        self.fc1 = nn.Linear(4096,2048)
        self.fc2 = nn.Linear(4096,512)
        
    def forward(self, f1,f2):
        x1 = self.fc1(f1)
        x=torch.cat(x1,f2,1)
        x = F.relu(self.fc1(x))
       
        return x

and after starting the training process, do we need set feature x before feed the proposed model;
x=Variable(x) ? //(from torch.autograd import Variable)

It looks to me like you’re having trouble with your torch.cat function. To fix it, you can change that line to add brackets:

x = torch.cat([x1, f2], dim=1)

Thank you. what about autograd?

What about it? Anything you pass through torch objects are caught in the graph unless you explicitly .detach() them.

1 Like