(self, src, lengths=None)
return hidden_t, out
See :obj:`onmt.encoders.encoder.EncoderBase.forward()`
See :obj:`onmt.encoders.encoder.EncoderBase.forward()`
See : obj : onmt . encoders . encoder . EncoderBase . forward ()
def forward(self, src, lengths=None):
        "See :obj:`onmt.encoders.encoder.EncoderBase.forward()`"

        batch_size = src.size(0)
        # (batch_size, 64, imgH, imgW)
        # layer 1
        src = F.relu(self.layer1(src[:, :, :, :] - 0.5), True)

        # (batch_size, 64, imgH/2, imgW/2)
        src = F.max_pool2d(src, kernel_size=(2, 2), stride=(2, 2))

        # (batch_size, 128, imgH/2, imgW/2)
        # layer 2
        src = F.relu(self.layer2(src), True)

        # (batch_size, 128, imgH/2/2, imgW/2/2)
        src = F.max_pool2d(src, kernel_size=(2, 2), stride=(2, 2))

        #  (batch_size, 256, imgH/2/2, imgW/2/2)
        # layer 3
        # batch norm 1
        src = F.relu(self.batch_norm1(self.layer3(src)), True)

        # (batch_size, 256, imgH/2/2, imgW/2/2)
        # layer4
        src = F.relu(self.layer4(src), True)

        # (batch_size, 256, imgH/2/2/2, imgW/2/2)
        src = F.max_pool2d(src, kernel_size=(1, 2), stride=(1, 2))

        # (batch_size, 512, imgH/2/2/2, imgW/2/2)
        # layer 5
        # batch norm 2
        src = F.relu(self.batch_norm2(self.layer5(src)), True)

        # (batch_size, 512, imgH/2/2/2, imgW/2/2/2)
        src = F.max_pool2d(src, kernel_size=(2, 1), stride=(2, 1))

        # (batch_size, 512, imgH/2/2/2, imgW/2/2/2)
        src = F.relu(self.batch_norm3(self.layer6(src)), True)

        # # (batch_size, 512, H, W)
        all_outputs = []
        for row in range(src.size(2)):
            inp = src[:, :, row, :].transpose(0, 2) \
                .transpose(1, 2)
            row_vec = torch.Tensor(batch_size).type_as(inp.data) \
                .long().fill_(row)
            pos_emb = self.pos_lut(row_vec)
            with_pos = torch.cat(
                (pos_emb.view(1, pos_emb.size(0), pos_emb.size(1)), inp), 0)
            outputs, hidden_t = self.rnn(with_pos)
            all_outputs.append(outputs)
        out = torch.cat(all_outputs, 0)

        return hidden_t, out
def forward ( self , src , lengths = None ) : batch_size = src . size ( 0 ) # (batch_size, 64, imgH, imgW) # layer 1 src = F . relu ( self . layer1 ( src [ : , : , : , : ] - 0.5 ) , True ) # (batch_size, 64, imgH/2, imgW/2) src = F . max_pool2d ( src , kernel_size = ( 2 , 2 ) , stride = ( 2 , 2 ) ) # (batch_size, 128, imgH/2, imgW/2) # layer 2 src = F . relu ( self . layer2 ( src ) , True ) # (batch_size, 128, imgH/2/2, imgW/2/2) src = F . max_pool2d ( src , kernel_size = ( 2 , 2 ) , stride = ( 2 , 2 ) ) #  (batch_size, 256, imgH/2/2, imgW/2/2) # layer 3 # batch norm 1 src = F . relu ( self . batch_norm1 ( self . layer3 ( src ) ) , True ) # (batch_size, 256, imgH/2/2, imgW/2/2) # layer4 src = F . relu ( self . layer4 ( src ) , True ) # (batch_size, 256, imgH/2/2/2, imgW/2/2) src = F . max_pool2d ( src , kernel_size = ( 1 , 2 ) , stride = ( 1 , 2 ) ) # (batch_size, 512, imgH/2/2/2, imgW/2/2) # layer 5 # batch norm 2 src = F . relu ( self . batch_norm2 ( self . layer5 ( src ) ) , True ) # (batch_size, 512, imgH/2/2/2, imgW/2/2/2) src = F . max_pool2d ( src , kernel_size = ( 2 , 1 ) , stride = ( 2 , 1 ) ) # (batch_size, 512, imgH/2/2/2, imgW/2/2/2) src = F . relu ( self . batch_norm3 ( self . layer6 ( src ) ) , True ) # # (batch_size, 512, H, W) all_outputs = [ ] for row in range ( src . size ( 2 ) ) : inp = src [ : , : , row , : ] . transpose ( 0 , 2 ) . transpose ( 1 , 2 ) row_vec = torch . Tensor ( batch_size ) . type_as ( inp . data ) . long ( ) . fill_ ( row ) pos_emb = self . pos_lut ( row_vec ) with_pos = torch . cat ( ( pos_emb . view ( 1 , pos_emb . size ( 0 ) , pos_emb . size ( 1 ) ) , inp ) , 0 ) outputs , hidden_t = self . rnn ( with_pos ) all_outputs . append ( outputs ) out = torch . cat ( all_outputs , 0 ) return hidden_t , out