Python network 模块,FC 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用network.FC

项目:faster_rcnn_pytorch    作者:longcw    | 项目源码 | 文件源码
def __init__(self, classes=None, debug=False):
        super(FasterRCNN, self).__init__()

        if classes is not None:
            self.classes = classes
            self.n_classes = len(classes)

        self.rpn = RPN()
        self.roi_pool = RoIPool(7, 7, 1.0/16)
        self.fc6 = FC(512 * 7 * 7, 4096)
        self.fc7 = FC(4096, 4096)
        self.score_fc = FC(4096, self.n_classes, relu=False)
        self.bbox_fc = FC(4096, self.n_classes * 4, relu=False)

        # loss
        self.cross_entropy = None
        self.loss_box = None

        # for log
        self.debug = debug
项目:pytorch_RFCN    作者:PureDiors    | 项目源码 | 文件源码
def __init__(self, classes=None, debug=False):
        super(FasterRCNN, self).__init__()

        if classes is not None:
            self.classes = classes
            self.n_classes = len(classes)

        self.rpn = RPN()
        self.roi_pool = RoIPool(7, 7, 1.0/16)
        self.fc6 = FC(1024 * 7 * 7, 4096)
        self.fc7 = FC(4096, 4096)
        self.score_fc = FC(4096, self.n_classes, relu=False)
        self.bbox_fc = FC(4096, self.n_classes * 4, relu=False)

        # loss
        self.cross_entropy = None
        self.loss_box = None

        # for log
        self.debug = debug
项目:MSDN    作者:yikang-li    | 项目源码 | 文件源码
def __init__(self, ninput, nembed, nhidden, nlayers, bias, dropout):
        super(Img_Encoder_Structure, self).__init__()
        self.image_encoder = FC(ninput, nembed, relu=True)
        self.rnn = nn.LSTM(nembed, nhidden, nlayers, bias=bias, dropout=dropout)
项目:crowdcount-cascaded-mtl    作者:svishwa    | 项目源码 | 文件源码
def __init__(self, bn=False, num_classes=10):
        super(CMTL, self).__init__()

        self.num_classes = num_classes        
        self.base_layer = nn.Sequential(Conv2d( 1, 16, 9, same_padding=True, NL='prelu', bn=bn),                                     
                                        Conv2d(16, 32, 7, same_padding=True, NL='prelu', bn=bn))

        self.hl_prior_1 = nn.Sequential(Conv2d( 32, 16, 9, same_padding=True, NL='prelu', bn=bn),
                                     nn.MaxPool2d(2),
                                     Conv2d(16, 32, 7, same_padding=True, NL='prelu', bn=bn),
                                     nn.MaxPool2d(2),
                                     Conv2d(32, 16, 7, same_padding=True, NL='prelu', bn=bn),
                                     Conv2d(16, 8,  7, same_padding=True, NL='prelu', bn=bn))

        self.hl_prior_2 = nn.Sequential(nn.AdaptiveMaxPool2d((32,32)),
                                        Conv2d( 8, 4, 1, same_padding=True, NL='prelu', bn=bn))

        self.hl_prior_fc1 = FC(4*1024,512, NL='prelu')
        self.hl_prior_fc2 = FC(512,256,    NL='prelu')
        self.hl_prior_fc3 = FC(256, self.num_classes,     NL='prelu')


        self.de_stage_1 = nn.Sequential(Conv2d( 32, 20, 7, same_padding=True, NL='prelu', bn=bn),
                                     nn.MaxPool2d(2),
                                     Conv2d(20, 40, 5, same_padding=True, NL='prelu', bn=bn),
                                     nn.MaxPool2d(2),
                                     Conv2d(40, 20, 5, same_padding=True, NL='prelu', bn=bn),
                                     Conv2d(20, 10, 5, same_padding=True, NL='prelu', bn=bn))

        self.de_stage_2 = nn.Sequential(Conv2d( 18, 24, 3, same_padding=True, NL='prelu', bn=bn),
                                        Conv2d( 24, 32, 3, same_padding=True, NL='prelu', bn=bn),                                        
                                        nn.ConvTranspose2d(32,16,4,stride=2,padding=1,output_padding=0,bias=True),
                                        nn.PReLU(),
                                        nn.ConvTranspose2d(16,8,4,stride=2,padding=1,output_padding=0,bias=True),
                                        nn.PReLU(),
                                        Conv2d(8, 1, 1, same_padding=True, NL='relu', bn=bn))
项目:intel-cervical-cancer    作者:wangg12    | 项目源码 | 文件源码
def __init__(self, classes=None, debug=False, arch='vgg16'):
        super(FasterRCNN, self).__init__()

        if classes is not None:
            self.classes = classes
            self.n_classes = len(classes)
        print('n_classes: {}\n{}'.format(self.n_classes, self.classes))

        if arch == 'vgg16':
            cnn_arch = models.vgg16(pretrained=False) # w/o bn
            self.rpn = RPN(features=cnn_arch.features)
            self.fcs = nn.Sequential(
                nn.Linear(512 * 7 * 7, 4096),
                nn.ReLU(True),
                nn.Dropout(),
                nn.Linear(4096, 4096),
                nn.ReLU(True),
                nn.Dropout()
            )

        self.roi_pool = RoIPool(7, 7, 1.0/16)
        # self.fc6 = FC(512 * 7 * 7, 4096)
        # self.fc7 = FC(4096, 4096)
        self.score_fc = FC(4096, self.n_classes, relu=False)
        self.bbox_fc = FC(4096, self.n_classes * 4, relu=False)

        # loss
        self.cross_entropy = None
        self.loss_box = None

        # for log
        self.debug = debug
项目:MSDN    作者:yikang-li    | 项目源码 | 文件源码
def __init__(self,nhidden, n_object_cats, n_predicate_cats, n_vocab, voc_sign, 
                 max_word_length, MPS_iter, use_language_loss, object_loss_weight, 
                 predicate_loss_weight, 
                 dropout=False, 
                 use_kmeans_anchors=False, 
                 gate_width=128, 
                 nhidden_caption=256, 
                 nembedding = 256,
                 rnn_type='LSTM_normal', 
                 rnn_droptout=0.0, rnn_bias=False, 
                 use_region_reg=False, use_kernel=False):

        super(Hierarchical_Descriptive_Model, self).__init__(nhidden, n_object_cats, n_predicate_cats, n_vocab, voc_sign, 
                 max_word_length, MPS_iter, use_language_loss, object_loss_weight, predicate_loss_weight, 
                 dropout, use_kmeans_anchors, nhidden_caption, nembedding, rnn_type, use_region_reg)

        self.rpn = RPN(use_kmeans_anchors)
        self.roi_pool_object = RoIPool(7, 7, 1.0/16)
        self.roi_pool_phrase = RoIPool(7, 7, 1.0/16)
        self.roi_pool_region = RoIPool(7, 7, 1.0/16)
        self.fc6_obj = FC(512 * 7 * 7, nhidden, relu=True)
        self.fc7_obj = FC(nhidden, nhidden, relu=False)
        self.fc6_phrase = FC(512 * 7 * 7, nhidden, relu=True)
        self.fc7_phrase = FC(nhidden, nhidden, relu=False)
        self.fc6_region = FC(512 * 7 * 7, nhidden, relu=True)
        self.fc7_region = FC(nhidden, nhidden, relu=False)
        if MPS_iter == 0:
            self.mps = None
        else:
            self.mps = Hierarchical_Message_Passing_Structure(nhidden, dropout, 
                            gate_width=gate_width, use_kernel_function=use_kernel) # the hierarchical message passing structure
            network.weights_normal_init(self.mps, 0.01)   

        self.score_obj = FC(nhidden, self.n_classes_obj, relu=False)
        self.bbox_obj = FC(nhidden, self.n_classes_obj * 4, relu=False)
        self.score_pred = FC(nhidden, self.n_classes_pred, relu=False)
        if self.use_region_reg:
            self.bbox_region = FC(nhidden, 4, relu=False)
            network.weights_normal_init(self.bbox_region, 0.01)
        else:
            self.bbox_region = None

        self.objectiveness = FC(nhidden, 2, relu=False)

        if use_language_loss:
            self.caption_prediction = \
                Language_Model(rnn_type=self.rnn_type, ntoken=self.n_vocab, nimg=self.nhidden, nhidden=self.nhidden_caption, 
                                nembed=self.nembedding, nlayers=2, nseq=self.max_word_length, voc_sign = self.voc_sign, 
                                bias=rnn_bias, dropout=rnn_droptout) 
        else:
            self.caption_prediction = Language_Model(rnn_type=self.rnn_type, ntoken=self.n_vocab, nimg=1, nhidden=1, 
                                nembed=1, nlayers=1, nseq=1, voc_sign = self.voc_sign) # just to make the program run

        network.weights_normal_init(self.score_obj, 0.01)
        network.weights_normal_init(self.bbox_obj, 0.005)
        network.weights_normal_init(self.score_pred, 0.01)
        network.weights_normal_init(self.objectiveness, 0.01)

        self.objectiveness_loss = None