def __init__(self, cfg): super().__init__() self.device = torch.device(cfg.MODEL.DEVICE) # fmt: off self.num_classes = cfg.MODEL.FCOS.NUM_CLASSES self.in_features = cfg.MODEL.FCOS.IN_FEATURES self.fpn_strides = cfg.MODEL.FCOS.FPN_STRIDES # Loss parameters: self.focal_loss_alpha = cfg.MODEL.FCOS.FOCAL_LOSS_ALPHA self.focal_loss_gamma = cfg.MODEL.FCOS.FOCAL_LOSS_GAMMA self.iou_loss_type = cfg.MODEL.FCOS.IOU_LOSS_TYPE self.center_sampling_radius = cfg.MODEL.FCOS.CENTER_SAMPLING_RADIUS self.budget_loss_lambda = cfg.MODEL.FCOS.BUDGET_LOSS_LAMBDA # Inference parameters: self.score_threshold = cfg.MODEL.FCOS.SCORE_THRESH_TEST self.topk_candidates = cfg.MODEL.FCOS.TOPK_CANDIDATES_TEST self.nms_threshold = cfg.MODEL.FCOS.NMS_THRESH_TEST self.nms_type = cfg.MODEL.NMS_TYPE self.max_detections_per_image = cfg.TEST.DETECTIONS_PER_IMAGE # fmt: on self.backbone = cfg.build_backbone( cfg, input_shape=ShapeSpec(channels=len(cfg.MODEL.PIXEL_MEAN))) backbone_shape = self.backbone.output_shape() feature_shapes = [backbone_shape[f] for f in self.in_features] self.head = cfg.build_head(cfg, feature_shapes) self.shift_generator = cfg.build_shift_generator(cfg, feature_shapes) self.is_dynamic_head = isinstance(self.head, FCOSDynamicHead) if self.is_dynamic_head: self.head_complexity_buffer = None # Matching and loss self.shift2box_transform = Shift2BoxTransform( weights=cfg.MODEL.FCOS.BBOX_REG_WEIGHTS) self.object_sizes_of_interest = cfg.MODEL.FCOS.OBJECT_SIZES_OF_INTEREST pixel_mean = torch.Tensor(cfg.MODEL.PIXEL_MEAN).to(self.device).view( 3, 1, 1) pixel_std = torch.Tensor(cfg.MODEL.PIXEL_STD).to(self.device).view( 3, 1, 1) self.normalizer = lambda x: (x - pixel_mean) / pixel_std self.to(self.device)
def __init__(self, cfg): super().__init__() self.device = torch.device(cfg.MODEL.DEVICE) # fmt: off self.num_classes = cfg.MODEL.FCOS.NUM_CLASSES self.in_features = cfg.MODEL.FCOS.IN_FEATURES self.fpn_strides = cfg.MODEL.FCOS.FPN_STRIDES # Loss parameters: self.focal_loss_alpha = cfg.MODEL.FCOS.FOCAL_LOSS_ALPHA self.focal_loss_gamma = cfg.MODEL.FCOS.FOCAL_LOSS_GAMMA self.iou_loss_type = cfg.MODEL.FCOS.IOU_LOSS_TYPE # Inference parameters: self.score_threshold = cfg.MODEL.FCOS.SCORE_THRESH_TEST self.topk_candidates = cfg.MODEL.FCOS.TOPK_CANDIDATES_TEST self.nms_threshold = cfg.MODEL.FCOS.NMS_THRESH_TEST self.max_detections_per_image = cfg.TEST.DETECTIONS_PER_IMAGE # fmt: on self.backbone = cfg.build_backbone( cfg, input_shape=ShapeSpec(channels=len(cfg.MODEL.PIXEL_MEAN))) backbone_shape = self.backbone.output_shape() feature_shapes = [backbone_shape[f] for f in self.in_features] self.head = FCOSHead(cfg, feature_shapes) self.shift_generator = cfg.build_shift_generator(cfg, feature_shapes) # Matching and loss self.shift2box_transform = Shift2BoxTransform( weights=cfg.MODEL.FCOS.BBOX_REG_WEIGHTS) self.object_sizes_of_interest = cfg.MODEL.FCOS.OBJECT_SIZES_OF_INTEREST self.norm_sync = cfg.MODEL.FCOS.NORM_SYNC pixel_mean = torch.Tensor(cfg.MODEL.PIXEL_MEAN).to(self.device).view( 3, 1, 1) pixel_std = torch.Tensor(cfg.MODEL.PIXEL_STD).to(self.device).view( 3, 1, 1) self.normalizer = lambda x: (x - pixel_mean) / pixel_std self.to(self.device) self.sinkhorn = SinkhornDistance(eps=cfg.MODEL.OTA.SINKHORN_EPS, max_iter=cfg.MODEL.OTA.SINKHORN_ITER) self.reg_weight = cfg.MODEL.OTA.REG_WEIGHT self.top_candidates = cfg.MODEL.OTA.TOP_CANDIDATES
def __init__(self, cfg): super(AutoAssign, self).__init__() self.device = torch.device(cfg.MODEL.DEVICE) # fmt: off self.num_classes = cfg.MODEL.FCOS.NUM_CLASSES self.in_features = cfg.MODEL.FCOS.IN_FEATURES self.fpn_strides = cfg.MODEL.FCOS.FPN_STRIDES # Loss parameters: self.focal_loss_alpha = cfg.MODEL.FCOS.FOCAL_LOSS_ALPHA self.focal_loss_gamma = cfg.MODEL.FCOS.FOCAL_LOSS_GAMMA self.iou_loss_type = cfg.MODEL.FCOS.IOU_LOSS_TYPE self.reg_weight = cfg.MODEL.FCOS.REG_WEIGHT # Inference parameters: self.score_threshold = cfg.MODEL.FCOS.SCORE_THRESH_TEST self.topk_candidates = cfg.MODEL.FCOS.TOPK_CANDIDATES_TEST self.nms_threshold = cfg.MODEL.FCOS.NMS_THRESH_TEST self.max_detections_per_image = cfg.TEST.DETECTIONS_PER_IMAGE # fmt: on self.backbone = cfg.build_backbone( cfg, input_shape=ShapeSpec(channels=len(cfg.MODEL.PIXEL_MEAN))) backbone_shape = self.backbone.output_shape() feature_shapes = [backbone_shape[f] for f in self.in_features] self.head = AutoAssignHead(cfg, feature_shapes) self.shift_generator = cfg.build_shift_generator(cfg, feature_shapes) # Matching and loss self.shift2box_transform = Shift2BoxTransform( weights=cfg.MODEL.FCOS.BBOX_REG_WEIGHTS) self.mu = nn.Parameter(torch.zeros(80, 2)) self.sigma = nn.Parameter(torch.ones(80, 2)) pixel_mean = torch.Tensor(cfg.MODEL.PIXEL_MEAN).to(self.device).view( 3, 1, 1) pixel_std = torch.Tensor(cfg.MODEL.PIXEL_STD).to(self.device).view( 3, 1, 1) self.normalizer = lambda x: (x - pixel_mean) / pixel_std self.to(self.device)
def __init__(self, cfg): super().__init__() self.device = torch.device(cfg.MODEL.DEVICE) # fmt: off self.num_classes = cfg.MODEL.FCOS.NUM_CLASSES self.in_features = cfg.MODEL.FCOS.IN_FEATURES self.fpn_strides = cfg.MODEL.FCOS.FPN_STRIDES self.iou_smooth = cfg.MODEL.FCOS.IOU_SMOOTH # Condinst parameters self.mask_out_stride = cfg.MODEL.CONDINST.MASK_OUT_STRIDE self.max_proposals = cfg.MODEL.CONDINST.MAX_PROPOSALS self.topk_proposals_per_im = cfg.MODEL.CONDINST.TOPK_PROPOSALS_PER_IM assert (self.max_proposals != -1) ^ (self.topk_proposals_per_im != -1),\ "MAX_PROPOSALS and TOPK_PROPOSALS_PER_IM " \ "cannot be set to -1 or enabled at the same time." self.disable_rel_coords = cfg.MODEL.CONDINST.MASK_HEAD.DISABLE_REL_COORDS self.mask_center_sample = cfg.MODEL.CONDINST.MASK_CENTER_SAMPLE # Loss parameters: self.focal_loss_alpha = cfg.MODEL.FCOS.FOCAL_LOSS_ALPHA self.focal_loss_gamma = cfg.MODEL.FCOS.FOCAL_LOSS_GAMMA self.iou_loss_type = cfg.MODEL.FCOS.IOU_LOSS_TYPE self.center_sampling_radius = cfg.MODEL.FCOS.CENTER_SAMPLING_RADIUS # Inference parameters: self.thresh_with_centerness = cfg.MODEL.FCOS.THRESH_WITH_CENTERNESS self.score_threshold = cfg.MODEL.FCOS.SCORE_THRESH_TEST self.topk_candidates = cfg.MODEL.FCOS.TOPK_CANDIDATES_TEST self.nms_threshold = cfg.MODEL.FCOS.NMS_THRESH_TEST self.nms_type = cfg.MODEL.NMS_TYPE self.max_detections_per_image = cfg.TEST.DETECTIONS_PER_IMAGE self.infer_mask_threshold = cfg.MODEL.CONDINST.INFER_MASK_THRESH # fmt: on self.backbone = cfg.build_backbone( cfg, input_shape=ShapeSpec(channels=len(cfg.MODEL.PIXEL_MEAN))) backbone_shape = self.backbone.output_shape() feature_shapes = [backbone_shape[f] for f in self.in_features] self.dynamic_mask_head = DynamicMaskHead(cfg) self.num_gen_params = self.dynamic_mask_head.num_gen_params self.mask_branch = MaskBranch(cfg, backbone_shape) self.mask_branch_out_stride = self.mask_branch.out_stride self.mask_out_level_ind = self.fpn_strides.index( self.mask_branch_out_stride) self.head = CondInstHead(cfg, self.num_gen_params, feature_shapes) self.shift_generator = cfg.build_shift_generator(cfg, feature_shapes) # Matching and loss self.shift2box_transform = Shift2BoxTransform( weights=cfg.MODEL.FCOS.BBOX_REG_WEIGHTS) self.object_sizes_of_interest = cfg.MODEL.FCOS.OBJECT_SIZES_OF_INTEREST pixel_mean = torch.Tensor(cfg.MODEL.PIXEL_MEAN).to( self.device).reshape(3, 1, 1) pixel_std = torch.Tensor(cfg.MODEL.PIXEL_STD).to(self.device).reshape( 3, 1, 1) self.normalizer = lambda x: (x - pixel_mean) / pixel_std self.to(self.device)