(self, data, label=None, aux_label=None)
return F.log_softmax(pred_out[-1], dim=1)
>> Block we have 4 conv1 conv2 conv3 conv4
        conv1 -> 256 1/4
        conv2 -> 512 1/8
        conv3 ->1024 1/16
        conv4 ->2048 1/32
>> Block we have 4 conv1 conv2 conv3 conv4
        conv1 -> 256 1/4
        conv2 -> 512 1/8
        conv3 ->1024 1/16
        conv4 ->2048 1/32
>> Block we have 4 conv1 conv2 conv3 conv4 conv1 - > 256 1 / 4 conv2 - > 512 1 / 8 conv3 - > 1024 1 / 16 conv4 - > 2048 1 / 32
def forward(self, data, label=None, aux_label=None):
        blocks = self.backbone(data)


        '''
        >> Block we have 4 conv1 conv2 conv3 conv4
        conv1 -> 256 1/4
        conv2 -> 512 1/8
        conv3 ->1024 1/16
        conv4 ->2048 1/32
        '''
        blocks.reverse()

        #understanding the global context meaning:

        global_context = self.global_context(blocks[0])
        #global: ->(bs,512,1,1)
        #equal to squeeze bar
        global_context = F.interpolate(global_context,
                                       size=blocks[0].size()[2:],
                                       mode='bilinear', align_corners=True)
        #this part using for smooth model ,this part sometime is important, U must carefully

        last_fm = global_context
        #last_fm --->(bs,512,1/32,1/32)
        pred_out = []

        for i, (fm, pre_rrb,
                cab, aft_rrb, head) in enumerate(zip(blocks,
                                                     self.smooth_pre_rrbs,
                                                     self.cabs,
                                                     self.smooth_aft_rrbs,
                                                     self.smooth_heads)):
            #step RRB model
            fm = pre_rrb(fm)
            #CAB para: low_level,hight_level
            fm = cab(fm, last_fm)
            fm = aft_rrb(fm)
            #RRB model ,next using to next low level , we must up sample

            #what is head mean?
            pred_out.append(head(fm))
            if i != 3:
                last_fm = F.interpolate(fm, scale_factor=2, mode='bilinear',
                                        align_corners=True)


        #every conv# have a predict label (bs,num_label,input_size,input_size)
        blocks.reverse()
        #change blocks from bottom to top
        last_fm = None
        boder_out = []
        #struct like follow border
        '''
        conv1 ---RRB------------>head
                       |
        conv2 ---RRB---+--RRB--->head
                            |
        conv3 ---RRB---+--RRB--->head
                            |
        conv4 ---RRB---+--RRB--->head
        '''
        for i, (fm, pre_rrb,
                aft_rrb, head) in enumerate(zip(blocks,
                                                self.border_pre_rrbs,
                                                self.border_aft_rrbs,
                                                self.border_heads)):
            fm = pre_rrb(fm)
            if last_fm is not None:
                fm = F.interpolate(fm, scale_factor=2 ** i, mode='bilinear',
                                   align_corners=True)
                last_fm = last_fm + fm
                last_fm = aft_rrb(last_fm)

            else:
                last_fm = fm
            boder_out.append(head(last_fm))

        #if train: loss have 4 layer
        #else print the smooth_layer.
        #this method is good , we must learning this step
        if label is not None and aux_label is not None:
            loss0 = self.criterion(pred_out[0], label)
            loss1 = self.criterion(pred_out[1], label)
            loss2 = self.criterion(pred_out[2], label)
            loss3 = self.criterion(pred_out[3], label)

            aux_loss0 = self.aux_criterion(boder_out[0], aux_label)
            aux_loss1 = self.aux_criterion(boder_out[1], aux_label)
            aux_loss2 = self.aux_criterion(boder_out[2], aux_label)
            aux_loss3 = self.aux_criterion(boder_out[3], aux_label)

            loss = loss0 + loss1 + loss2 + loss3
            aux_loss = aux_loss0 + aux_loss1 + aux_loss2 + aux_loss3
            return loss + self.alpha * aux_loss

        return F.log_softmax(pred_out[-1], dim=1)
def forward ( self , data , label = None , aux_label = None ) : blocks = self . backbone ( data ) blocks . reverse ( ) #understanding the global context meaning: global_context = self . global_context ( blocks [ 0 ] ) #global: ->(bs,512,1,1) #equal to squeeze bar global_context = F . interpolate ( global_context , size = blocks [ 0 ] . size ( ) [ 2 : ] , mode = 'bilinear' , align_corners = True ) #this part using for smooth model ,this part sometime is important, U must carefully last_fm = global_context #last_fm --->(bs,512,1/32,1/32) pred_out = [ ] for i , ( fm , pre_rrb , cab , aft_rrb , head ) in enumerate ( zip ( blocks , self . smooth_pre_rrbs , self . cabs , self . smooth_aft_rrbs , self . smooth_heads ) ) : #step RRB model fm = pre_rrb ( fm ) #CAB para: low_level,hight_level fm = cab ( fm , last_fm ) fm = aft_rrb ( fm ) #RRB model ,next using to next low level , we must up sample #what is head mean? pred_out . append ( head ( fm ) ) if i != 3 : last_fm = F . interpolate ( fm , scale_factor = 2 , mode = 'bilinear' , align_corners = True ) #every conv# have a predict label (bs,num_label,input_size,input_size) blocks . reverse ( ) #change blocks from bottom to top last_fm = None boder_out = [ ] #struct like follow border '''
        conv1 ---RRB------------>head
                       |
        conv2 ---RRB---+--RRB--->head
                            |
        conv3 ---RRB---+--RRB--->head
                            |
        conv4 ---RRB---+--RRB--->head
        ''' for i , ( fm , pre_rrb , aft_rrb , head ) in enumerate ( zip ( blocks , self . border_pre_rrbs , self . border_aft_rrbs , self . border_heads ) ) : fm = pre_rrb ( fm ) if last_fm is not None : fm = F . interpolate ( fm , scale_factor = 2 ** i , mode = 'bilinear' , align_corners = True ) last_fm = last_fm + fm last_fm = aft_rrb ( last_fm ) else : last_fm = fm boder_out . append ( head ( last_fm ) ) #if train: loss have 4 layer #else print the smooth_layer. #this method is good , we must learning this step if label is not None and aux_label is not None : loss0 = self . criterion ( pred_out [ 0 ] , label ) loss1 = self . criterion ( pred_out [ 1 ] , label ) loss2 = self . criterion ( pred_out [ 2 ] , label ) loss3 = self . criterion ( pred_out [ 3 ] , label ) aux_loss0 = self . aux_criterion ( boder_out [ 0 ] , aux_label ) aux_loss1 = self . aux_criterion ( boder_out [ 1 ] , aux_label ) aux_loss2 = self . aux_criterion ( boder_out [ 2 ] , aux_label ) aux_loss3 = self . aux_criterion ( boder_out [ 3 ] , aux_label ) loss = loss0 + loss1 + loss2 + loss3 aux_loss = aux_loss0 + aux_loss1 + aux_loss2 + aux_loss3 return loss + self . alpha * aux_loss return F . log_softmax ( pred_out [ - 1 ] , dim = 1 )