How to concatenate CNN features and reduce size

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?

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),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 function. To fix it, you can change that line to add brackets:

x =[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