Two-output model architecture
In this exercise, you will construct a multi-output neural network architecture capable of predicting the character and the alphabet.
Recall the general structure: in the .__init__()
method, you define layers to be used in the forward pass later. In the forward()
method, you will first pass the input image through a couple of layers to obtain its embedding, which in turn is fed into two separate classifier layers, one for each output.
torch.nn
is already imported under its usual alias, so let's build a model!
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__()
self.image_layer = nn.Sequential(
nn.Conv2d(1, 16, kernel_size=3, padding=1),
nn.MaxPool2d(kernel_size=2),
nn.ELU(),
nn.Flatten(),
nn.Linear(16*32*32, 128)
)
# Define the two classifier layers
____ = ____
____ = ____