Mulai sekarangMulai gratis

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!

Latihan ini merupakan bagian dari kursus

Intermediate Deep Learning with PyTorch

Lihat Kursus

Latihan interaktif langsung praktik

Cobalah latihan ini dengan melengkapi kode contoh ini.

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
        ____ = ____
        ____ = ____
Edit dan Jalankan Kode