Hey,
I am interested in building a network having multiple inputs. I understand that when calling the forward
function, only one Variable
is taken in parameter. I have two possible use case here :
- the same image at multiple resolutions is used
- different images are used
I would like some advice to design a nn.Module
in the same fashion as alexnet for example.
I have no idea how to :
- give multiple inputs to the
nn.Module
- join the fc layers together
I am following the example of imagenet, which looks like this :
class SimpleConv(nn.Module):
def __init__(self, num_classes):
super(SimpleConv, self).__init__()
self.features = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=11, stride=4, padding=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(64, 192, kernel_size=5, padding=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(192, 384, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(384, 256, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(256, 256, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
)
self.classifier = nn.Sequential(
nn.Dropout(),
nn.Linear(256 * 6 * 6, 4096),
nn.ReLU(inplace=True),
nn.Dropout(),
nn.Linear(4096, 4096),
nn.ReLU(inplace=True),
nn.Linear(4096, num_classes),
)
def forward(self, x):
x = self.features(x)
x = x.view(x.size(0), 256 * 6 * 6)
x = self.classifier(x)
return x
def simple_conv(pretrained=False, num_classes=140):
model = SimpleConv(num_classes)
# if pretrained:
# model.load_state_dict(model_zoo.load_url(model_urls['alexnet']))
return model
I hope it’s clear
Thanks