I am using Alexnet as a feature extractor on a 9 channel image (3 images concatenated). So I need to modify the first conv2d layer to receive 9 channel inputs. What I tried:
model_conv = torchvision.models.alexnet(pretrained=True) new_features = nn.Sequential(*list(model_conv.features.children())) model_conv.features = new_features new_9_tensor = torch.cat((new_features.state_dict().get('0.weight'), new_features.state_dict().get('0.weight'), new_features.state_dict().get('0.weight')), 1) new_features.state_dict().__setitem__('0.weight', new_9_tensor) print("named modules", list(new_features.named_modules()))
Although the state_dict is modified to show the required 64x9x11x11 tensor, the output of last line (list of named modules) shows no change in conv2d layer. Can someone please help me on what changes do I need to make to make Alexnet work for a 9 channel input? Is there a easier way to do this without accessing private attributes?
Is there a way to remove first layer and initialize it with Conv2d(9, 64, kernel_size=(11, 11), stride=(4, 4), padding=(2, 2))
Any sort of help is really appreciated. Thanks!