def __init__(self, classes, class_agnostic):
        super(_fasterRCNN, self).__init__()
        self.classes = classes
        self.n_classes = len(classes)
        self.class_agnostic = class_agnostic
        # loss
        self.RCNN_loss_cls = 0
        self.RCNN_loss_bbox = 0

        # define rpn
        self.RCNN_rpn = _RPN(self.dout_base_model,
                             anchor_scales=cfg.RCNN_COMMON.ANCHOR_SCALES,
                             anchor_ratios=cfg.RCNN_COMMON.ANCHOR_RATIOS,
                             feat_stride=cfg.RCNN_COMMON.FEAT_STRIDE[0])

        self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes)
        self.RCNN_roi_pool = _RoIPooling(cfg.RCNN_COMMON.POOLING_SIZE,
                                         cfg.RCNN_COMMON.POOLING_SIZE,
                                         1.0 / 16.0)
        self.RCNN_roi_align = RoIAlignAvg(cfg.RCNN_COMMON.POOLING_SIZE,
                                          cfg.RCNN_COMMON.POOLING_SIZE,
                                          1.0 / 16.0)

        self.grid_size = cfg.RCNN_COMMON.POOLING_SIZE * 2 if cfg.RCNN_COMMON.CROP_RESIZE_WITH_MAX_POOL else cfg.RCNN_COMMON.POOLING_SIZE
        self.RCNN_roi_crop = _RoICrop()
Example #2
0
    def __init__(self, classes, class_agnostic, feat_name, feat_list=('conv4',), pretrained = True):

        super(fasterRCNN, self).__init__(classes, class_agnostic, feat_name, feat_list, pretrained)
        ##### Important to set model to eval mode before evaluation ####
        self.FeatExt.eval()
        rand_img = torch.Tensor(1, 3, 224, 224)
        rand_feat = self.FeatExt(rand_img)
        self.FeatExt.train()
        self.dout_base_model = rand_feat.size(1)

        self.RCNN_loss_cls = 0
        self.RCNN_loss_bbox = 0

        # define rpn
        self.RCNN_rpn = _RPN(self.dout_base_model,
                             anchor_scales=cfg.RCNN_COMMON.ANCHOR_SCALES,
                             anchor_ratios=cfg.RCNN_COMMON.ANCHOR_RATIOS,
                             feat_stride=cfg.RCNN_COMMON.FEAT_STRIDE[0])

        self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes)
        self.RCNN_roi_pool = _RoIPooling(cfg.RCNN_COMMON.POOLING_SIZE, cfg.RCNN_COMMON.POOLING_SIZE, 1.0/16.0)
        self.RCNN_roi_align = RoIAlignAvg(cfg.RCNN_COMMON.POOLING_SIZE, cfg.RCNN_COMMON.POOLING_SIZE, 1.0/16.0)

        self.grid_size = cfg.RCNN_COMMON.POOLING_SIZE * 2 if cfg.RCNN_COMMON.CROP_RESIZE_WITH_MAX_POOL else cfg.RCNN_COMMON.POOLING_SIZE
        self.RCNN_roi_crop = _RoICrop()

        self.iter_counter = 0
Example #3
0
    def __init__(self, classes, class_agnostic):
        super(_All_in_One, self).__init__()
        self.classes = classes
        self.n_classes = len(classes)
        self.class_agnostic = class_agnostic

        self._fs = cfg.FCGN.FEAT_STRIDE[0]
        # for resnet
        if self.dout_base_model is None:
            if self._fs == 16:
                self.dout_base_model = 256 * self.expansions
            elif self._fs == 32:
                self.dout_base_model = 512 * self.expansions

        # loss
        self.VMRN_obj_loss_cls = 0
        self.VMRN_obj_loss_bbox = 0

        # define rpn
        self.VMRN_obj_rpn = _RPN(self.dout_base_model,
                             anchor_scales=cfg.RCNN_COMMON.ANCHOR_SCALES,
                             anchor_ratios=cfg.RCNN_COMMON.ANCHOR_RATIOS,
                             feat_stride=self._fs)

        self.VMRN_obj_proposal_target = _ProposalTargetLayer(self.n_classes)
        self.VMRN_obj_roi_pool = _RoIPooling(cfg.RCNN_COMMON.POOLING_SIZE, cfg.RCNN_COMMON.POOLING_SIZE, 1.0 / 16.0)
        self.VMRN_obj_roi_align = RoIAlignAvg(cfg.RCNN_COMMON.POOLING_SIZE, cfg.RCNN_COMMON.POOLING_SIZE, 1.0 / 16.0)

        self.grid_size = cfg.RCNN_COMMON.POOLING_SIZE * 2 if cfg.RCNN_COMMON.CROP_RESIZE_WITH_MAX_POOL else cfg.RCNN_COMMON.POOLING_SIZE
        self.VMRN_obj_roi_crop = _RoICrop()

        self._isex = cfg.TRAIN.VMRN.ISEX
        self.VMRN_rel_op2l = _OP2L(cfg.VMRN.OP2L_POOLING_SIZE, cfg.VMRN.OP2L_POOLING_SIZE, 1.0 / 16.0, self._isex)

        self._train_iter_conter = 0

        self._MGN_as = cfg.FCGN.ANCHOR_SCALES
        self._MGN_ar = cfg.FCGN.ANCHOR_RATIOS
        self._MGN_aa = cfg.FCGN.ANCHOR_ANGLES

        # grasp detection components
        self.MGN_classifier = _Classifier(self.dout_base_model, 5, self._MGN_as,
                                          self._MGN_ar, self._MGN_aa)
        self.MGN_proposal_target = _GraspTargetLayer(self._fs, self._MGN_ar,
                                                     self._MGN_as, self._MGN_aa)
        self._MGN_anchors = torch.from_numpy(generate_oriented_anchors(base_size=self._fs,
                                                       scales=np.array(self._MGN_as),
                                                       ratios=np.array(self._MGN_ar),
                                                       angles=np.array(self._MGN_aa))).float()
        self._MGN_num_anchors = self._MGN_anchors.size(0)
        # [x1, y1, x2, y2] -> [xc, yc, w, h]
        self._MGN_anchors = torch.cat([
            0 * self._MGN_anchors[:, 0:1],
            0 * self._MGN_anchors[:, 1:2],
            self._MGN_anchors[:, 2:3] - self._MGN_anchors[:, 0:1] + 1,
            self._MGN_anchors[:, 3:4] - self._MGN_anchors[:, 1:2] + 1,
            self._MGN_anchors[:, 4:5]
        ], dim=1)
        self._MGN_USE_POOLED_FEATS = cfg.MGN.USE_POOLED_FEATS
Example #4
0
    def __init__(self, classes, class_agnostic):
        super(_fastRCNN, self).__init__()
        self.classes = classes
        self.n_classes = len(classes)
        self.class_agnostic = class_agnostic

        # loss
        self.RCNN_loss_cls = 0
        self.RCNN_loss_bbox = 0

        self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes)
        self.RCNN_roi_pool = _RoIPooling(cfg.POOLING_SIZE, cfg.POOLING_SIZE,
                                         1.0 / 16.0)
        self.RCNN_roi_align = RoIAlignAvg(cfg.POOLING_SIZE, cfg.POOLING_SIZE,
                                          1.0 / 16.0)

        self.grid_size = cfg.POOLING_SIZE * 2 if cfg.CROP_RESIZE_WITH_MAX_POOL else cfg.POOLING_SIZE
        self.RCNN_roi_crop = _RoICrop()
Example #5
0
    def __init__(self, model_path = None):
        super(LVRN, self).__init__()
        self.up_sample = nn.UpsamplingBilinear2d(scale_factor = 2)
        self.maxpooling = nn.MaxPool2d(2,2)

        self.grid_size = 14
        self.roi_crop = _RoICrop()

        self.features = self.load_model(model_path)
        self.fc_score = nn.Sequential(
            nn.Linear(512 * 49, 1024),
            nn.ReLU(True),
            nn.Dropout(),
            nn.Linear(1024, 512),
            nn.ReLU(True),
            nn.Dropout(),
            nn.Linear(512, 1)
        )

        self.param_init()
        print(self)