Two-input model
With the data ready, it's time to build the two-input model architecture! To do so, you will set up a model class with the following methods:
.__init__()
, in which you will define sub-networks by grouping layers; this is where you define the two layers for processing the two inputs, and the classifier that returns a classification score for each class.forward()
, in which you will pass both inputs through corresponding pre-defined sub-networks, concatenate the outputs, and pass them to the classifier.
torch.nn
is already imported for you as nn
. Let's do it!
This exercise is part of the course
Intermediate Deep Learning with PyTorch
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
class Net(nn.Module):
def __init__(self):
super().__init__()
# Define sub-networks as sequential models
____ = ____(
nn.Conv2d(1, 16, kernel_size=3, padding=1),
nn.MaxPool2d(kernel_size=2),
nn.ELU(),
nn.Flatten(),
nn.Linear(16*32*32, 128)
)
____ = ____(
nn.Linear(30, 8),
nn.ELU(),
)
____ = ____(
nn.Linear(128 + 8, 964),
)