I am not familiar with Deep learning and Pytorch. And I want to know how to deal, in general with such a situation. So, I was wondering if I used a pretrained model (EfficientNet for example) if I want to change the _fc attribute and use conv2d in it, how can I recover a 2D structure? Because the pretrained model flattens it just before _fc.
for example, the pretrained model outputs a flattened feature vector of 1280 elements what I did is the following:
self.efficient_net._fc = nn.Sequential(
nn.Linear(1280, 1225),
nn.Unflatten(dim=1, unflattened_size=(1, 35, 35)),
nn.Conv2d(1, 35, kernel_size=1),
...,
)
I didn't have a specific height and width to recover in the 2D structure, so I assumed that h = w = some size and I use a linear layer whose output is equal to the square of the "some size". In the example above 35² = 1225. I am not sure if the unflatten is the correct way to do this. Then I added the conv2d. My code works but it doesn't give good results which probably means that the 2D structure I recovered does not capture any meaningful information. Can anyone enlighten me with general knowledge about how things are done in my situation, or give me some comments? Thank you!