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=True,
                         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(faster_rcnn, 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
Exemple #2
0
 def __init__(self, nhidden, dropout):
     super(Concat, self).__init__()
     self.conv1 = Conv2d(3 * nhidden, nhidden, 1)
     self.conv2 = Conv2d(nhidden, 256, 1)
     self.conv3 = Conv2d(256, 128, 1)
     self.compress = FC(640, nhidden, relu=True)
     self.compress_r = FC(640, nhidden, relu=True)
     self.dropout = dropout
Exemple #3
0
 def __init__(self, nhidden, dropout):
     super(ConcatEmbedding, self).__init__()
     self.linear = nn.Linear(3 * nhidden, nhidden)
     self.fc1 = FC(nhidden, 256, relu=True)
     self.fc2 = FC(256, 128, relu=True)
     self.fc3 = FC(128, 128, relu=True)
     self.compress = FC(640, nhidden, relu=True)
     self.compress_r = FC(640, nhidden, relu=True)
     self.dropout = dropout
Exemple #4
0
 def __init__(self, nhidden):
     super(DualMask, self).__init__()
     self.conv1 = Conv2d(2, 96, kernel_size=5)
     self.conv2 = Conv2d(96, 128, kernel_size=5)
     self.conv3 = Conv2d(128, 64, kernel_size=8)
     self.fc1_dm = FC(18496, nhidden, relu=True)
     self.fc2_dm = FC(25600, 2 * nhidden, relu=True)
     faster_rcnn.network.weights_normal_init(self.fc1_dm, 0.01)
     faster_rcnn.network.weights_normal_init(self.fc2_dm, 0.01)
Exemple #5
0
    def __init__(self, nhidden, dropout):
        super(GraphicalModel, self).__init__()
        self.f = FC(nhidden, nhidden, relu=True)
        self.g = FC(nhidden, nhidden, relu=True)

        self.conv1 = Conv2d(3 * nhidden, nhidden, 1)
        self.conv2 = Conv2d(nhidden, 256, 1)
        self.conv3 = Conv2d(256, 128, 1)
        self.conv1_r = Conv2d(3 * nhidden, nhidden, 1)
        self.conv2_r = Conv2d(nhidden, 256, 1)
        self.conv3_r = Conv2d(256, 128, 1)
        self.compress = FC(640, nhidden, relu=True)
        self.compress_r = FC(640, nhidden, relu=True)
        self.dropout = dropout
    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
    def __init__(self, classes=None, debug=False):
        super(FasterRCNN, self).__init__()

        self.classes = np.asarray(classes)
        self.n_classes = len(classes)

        self.rpn = RPN(debug=debug)
        self.proposal_target_layer = proposal_target_layer_py(self.n_classes)
        if cfg.POOLING_MODE == 'align':
            self.roi_pool = RoIAlign(7, 7, 1.0 / 16)
        elif cfg.POOLING_MODE == 'pool':
            self.roi_pool = RoIPool(7, 7, 1.0 / 16)
        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 = 0
        self.loss_box = 0
        self.triplet_loss = 0
        # for log
        self.debug = debug
        if cfg.TRIPLET.IS_TRUE:
            self.fc_sim = FC(512 * 7 * 7, 4096, relu=False)
            pos_weight = torch.ones(3)
            pos_weight[0] = 2.0
            if self.debug:
                self.set = 0
                self.match = 0
            if cfg.TRIPLET.LOSS == 'euc':
                self.loss_triplet = tpl.euclidean_distance_loss
            elif cfg.TRIPLET.LOSS == 'log':
                self.loss_triplet = tpl.cross_entropy_l2_dist
                self.relu = nn.ReLU(inplace=True)
                self.BCELoss = nn.BCELoss(weight=pos_weight,
                                          size_average=False)
            elif cfg.TRIPLET.LOSS == 'cls':
                self.loss_triplet = tpl.cross_entropy_cosine_sim
                self.relu = nn.ReLU(inplace=True)
                self.BCELoss = nn.BCELoss(weight=pos_weight,
                                          size_average=False)
        self.init_module = self._init_faster_rcnn_vgg16
Exemple #8
0
 def __init__(self, nhidden, dropout):
     super(TranslationEmbedding, self).__init__()
     self.linear_s = nn.Linear(nhidden, nhidden)
     self.linear_o = nn.Linear(nhidden, nhidden)
     self.fc = FC(2 * nhidden, nhidden, relu=True)
     self.dropout = dropout
Exemple #9
0
 def __init__(self, nhidden, dropout):
     super(LstmStructure, self).__init__()
     self.brnn = nn.LSTM(nhidden, nhidden, 1, bidirectional=True)
     self.compress = FC(3 * nhidden, nhidden, relu=True)
     self.compress_r = FC(3 * nhidden, nhidden, relu=True)
     self.dropout = dropout
Exemple #10
0
 def __init__(self, nhidden, dropout):
     super(IterativeStructure, self).__init__()
     self.linear_s_p_o = FC(nhidden, 128, relu=True)
     self.fc_p = FC(768, nhidden, relu=True)
     self.linear_p = FC(nhidden, 128, relu=True)
     self.linear = FC(640, nhidden, relu=True)
Exemple #11
0
 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)
Exemple #12
0
    def __init__(self, input, nhidden):
        super(GaussianMixtureModel, self).__init__()

        self.fc_gmm = FC(input, 2 * nhidden, relu=True)
        faster_rcnn.network.weights_normal_init(self.fc_gmm, 0.01)
Exemple #13
0
 def __init__(self, nhidden, dropout):
     super(GeometricSpatialFeature, self).__init__()
     self.fc = FC(640, nhidden, relu=True)
     self.fc_r = FC(640, nhidden, relu=True)
     self.dropout = dropout