def __init__(self,
                 alignsize=8,
                 reddim=32,
                 loadweight=True,
                 model=None,
                 downsample=4):
        super(crop_model_multi_scale_shared, self).__init__()

        if model == 'shufflenetv2':
            self.Feat_ext = shufflenetv2_base(loadweight, downsample)
            self.DimRed = nn.Conv2d(812, reddim, kernel_size=1, padding=0)
        elif model == 'mobilenetv2':
            self.Feat_ext = mobilenetv2_base(loadweight, downsample)
            self.DimRed = nn.Conv2d(448, reddim, kernel_size=1, padding=0)
        elif model == 'vgg16':
            self.Feat_ext = vgg_base(loadweight, downsample)
            self.DimRed = nn.Conv2d(1536, reddim, kernel_size=1, padding=0)
        elif model == 'resnet50':
            self.Feat_ext = resnet50_base(loadweight, downsample)
            self.DimRed = nn.Conv2d(3584, reddim, kernel_size=1, padding=0)

        self.downsample2 = nn.UpsamplingBilinear2d(scale_factor=1.0 / 2.0)
        self.upsample2 = nn.UpsamplingBilinear2d(scale_factor=2.0)
        self.RoIAlign = RoIAlignAvg(alignsize, alignsize, 1.0 / 2**downsample)
        self.RoDAlign = RoDAlignAvg(alignsize, alignsize, 1.0 / 2**downsample)
        self.FC_layers = fc_layers(reddim * 2, alignsize)
    def __init__(self, alignsize = 8, reddim = 8, loadweight = True, model = None, downsample=4):
        super(crop_model_single_scale, self).__init__()

        if model == 'shufflenetv2':
            self.Feat_ext = shufflenetv2_base(loadweight,downsample)
            if downsample == 4:
                self.DimRed = nn.Conv2d(232, reddim, kernel_size=1, padding=0)
            else:
                self.DimRed = nn.Conv2d(464, reddim, kernel_size=1, padding=0)
        elif model == 'mobilenetv2':
            self.Feat_ext = mobilenetv2_base(loadweight,downsample)
            if downsample == 4:
                self.DimRed = nn.Conv2d(96, reddim, kernel_size=1, padding=0)
            else:
                self.DimRed = nn.Conv2d(320, reddim, kernel_size=1, padding=0)
        elif model == 'vgg16':
            self.Feat_ext = vgg_base(loadweight,downsample)
            self.DimRed = nn.Conv2d(512, reddim, kernel_size=1, padding=0)
        elif model == 'resnet50':
            self.Feat_ext = resnet50_base(loadweight,downsample)
            self.DimRed = nn.Conv2d(1024, reddim, kernel_size=1, padding=0)

        self.RoIAlign = RoIAlignAvg(alignsize, alignsize, 1.0/2**downsample)
        self.RoDAlign = RoDAlignAvg(alignsize, alignsize, 1.0/2**downsample)
        self.FC_layers = fc_layers(reddim*2, alignsize)
    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()
    def __init__(self,
                 alignsize=8,
                 reddim=32,
                 loadweight=True,
                 model=None,
                 downsample=4):
        super(crop_model_multi_scale_individual, self).__init__()

        if model == 'shufflenetv2':
            self.Feat_ext1 = shufflenetv2_base(loadweight, downsample)
            self.Feat_ext2 = shufflenetv2_base(loadweight, downsample)
            self.Feat_ext3 = shufflenetv2_base(loadweight, downsample)
            self.DimRed = nn.Conv2d(232, reddim, kernel_size=1, padding=0)
        elif model == 'mobilenetv2':
            self.Feat_ext1 = mobilenetv2_base(loadweight, downsample)
            self.Feat_ext2 = mobilenetv2_base(loadweight, downsample)
            self.Feat_ext3 = mobilenetv2_base(loadweight, downsample)
            self.DimRed = nn.Conv2d(96, reddim, kernel_size=1, padding=0)
        elif model == 'vgg16':
            self.Feat_ext1 = vgg_base(loadweight, downsample)
            self.Feat_ext2 = vgg_base(loadweight, downsample)
            self.Feat_ext3 = vgg_base(loadweight, downsample)
            self.DimRed = nn.Conv2d(512, reddim, kernel_size=1, padding=0)

        self.downsample2 = nn.UpsamplingBilinear2d(scale_factor=1.0 / 2.0)
        self.upsample2 = nn.UpsamplingBilinear2d(scale_factor=2.0)
        self.RoIAlign = RoIAlignAvg(alignsize, alignsize, 1.0 / 2**downsample)
        self.RoDAlign = RoDAlignAvg(alignsize, alignsize, 1.0 / 2**downsample)
        self.FC_layers = fc_layers(reddim * 2, alignsize)
Esempio n. 5
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
Esempio n. 6
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
    def __init__(self, classes, class_agnostic):
        super(_FPN, 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 rpns
        self._share_rpn = cfg.FPN.SHARE_RPN
        self._share_header = cfg.FPN.SHARE_HEADER

        self._num_pyramid_layers = len(cfg.RCNN_COMMON.FEAT_STRIDE)
        if self._share_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)
        else:
            self.RCNN_rpns = nn.ModuleList()
            for i in range(len(cfg.RCNN_COMMON.FEAT_STRIDE)):
                self.RCNN_rpns.append(
                    _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[i])
                )

        self.RCNN_roi_aligns = nn.ModuleList()
        self.RCNN_roi_pools = nn.ModuleList()
        for i in range(len(cfg.RCNN_COMMON.FEAT_STRIDE)):
            self.RCNN_roi_aligns.append(
                RoIAlignAvg(cfg.RCNN_COMMON.POOLING_SIZE,
                            cfg.RCNN_COMMON.POOLING_SIZE,
                            1.0 / float(cfg.RCNN_COMMON.FEAT_STRIDE[i]))
            )

            self.RCNN_roi_pools.append(
                _RoIPooling(cfg.RCNN_COMMON.POOLING_SIZE,
                            cfg.RCNN_COMMON.POOLING_SIZE,
                            1.0 / float(cfg.RCNN_COMMON.FEAT_STRIDE[i]))
            )

        self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes)
Esempio n. 8
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()
Esempio n. 9
0
    def __init__(self,
                 classes,
                 class_agnostic,
                 feat_name,
                 feat_list=('conv2', 'conv3', 'conv4', 'conv5'),
                 pretrained=True):
        super(FPN, 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.n_channels = [f.size(1) for f in rand_feat]

        self.dout_base_model = 256

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

        self._num_pyramid_layers = len(cfg.RCNN_COMMON.FEAT_STRIDE)
        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)

        self.RCNN_roi_aligns = nn.ModuleList()
        self.RCNN_roi_pools = nn.ModuleList()
        for i in range(len(cfg.RCNN_COMMON.FEAT_STRIDE)):
            self.RCNN_roi_aligns.append(
                RoIAlignAvg(cfg.RCNN_COMMON.POOLING_SIZE,
                            cfg.RCNN_COMMON.POOLING_SIZE,
                            1.0 / float(cfg.RCNN_COMMON.FEAT_STRIDE[i])))

            self.RCNN_roi_pools.append(
                _RoIPooling(cfg.RCNN_COMMON.POOLING_SIZE,
                            cfg.RCNN_COMMON.POOLING_SIZE,
                            1.0 / float(cfg.RCNN_COMMON.FEAT_STRIDE[i])))

        self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes)
        self.iter_counter = 0