# Codeblock 11 class EncoderTorch(nn.Module): def __init__(self): super().__init__() self.patcher = Patcher() self.learnable_embedding = LearnableEmbedding() #(1) encoder_block = nn.TransformerEncoderLayer(d_model=EMBED_DIM, nhead=NUM_HEADS, dim_feedforward=HIDDEN_DIM, dropout=DROP_PROB, batch_first=True) #(2) self.encoder_blocks = nn.TransformerEncoder(encoder_layer=encoder_block, num_layers=NUM_ENCODER_BLOCKS) def forward(self, images): print(f'images\t\t\t: {images.size()}') features = self.patcher(images) print(f'after patcher\t\t: {features.size()}') features = features + self.learnable_embedding() print(f'after learn embed\t: {features.size()}') features = self.encoder_blocks(features) #(3) print(f'after encoder blocks\t: {features.size()}') return features