Ejemplo n.º 1
0
    def __init__(self, cfg):  #Slowfast constructor
        """
        The `__init__` method of any subclass should also contain these
            arguments.
        Args:
            cfg (CfgNode): model building configs, details are in the
                comments of the config file.
        """
        super(SlowFast, self).__init__()
        #Standard line at the beginning of every NN definition. super(Classname, self).__init__()

        self.norm_module = get_norm(cfg)
        #The normalization used in our case is usually batch normalization. Normalizing the values within a certain range ([0, 1]) can help
        #Speed up the convergence. Batch normalization does this for values in the hidden layer as well as the input layer. It basically allows each layer in a
        #deep network to learn independently. Watch : https://www.youtube.com/watch?v=nUUqwaxLnWs

        self.enable_detection = cfg.DETECTION.ENABLE
        self.num_pathways = 3
        #The number of pathways in the architecture, in this case we have 2 pathways, slow and fast.

        self._construct_network(cfg)
        #Function call

        init_helper.init_weights(self, cfg.MODEL.FC_INIT_STD,
                                 cfg.RESNET.ZERO_INIT_FINAL_BN)
    def __init__(self, cfg):
        """
        The `__init__` method of any subclass should also contain these
            arguments.

        Args:
            cfg (CfgNode): model building configs, details are in the
                comments of the config file.
        """
        super(X3D, self).__init__()
        self.norm_module = get_norm(cfg)
        self.enable_detection = cfg.DETECTION.ENABLE
        self.num_pathways = 1

        exp_stage = 2.0
        self.dim_c1 = cfg.X3D.DIM_C1

        self.dim_res2 = (round_width(self.dim_c1, exp_stage, divisor=8)
                         if cfg.X3D.SCALE_RES2 else self.dim_c1)
        self.dim_res3 = round_width(self.dim_res2, exp_stage, divisor=8)
        self.dim_res4 = round_width(self.dim_res3, exp_stage, divisor=8)
        self.dim_res5 = round_width(self.dim_res4, exp_stage, divisor=8)

        self.block_basis = [
            # blocks, c, stride
            [1, self.dim_res2, 2],
            [2, self.dim_res3, 2],
            [5, self.dim_res4, 2],
            [3, self.dim_res5, 2],
        ]
        self._construct_network(cfg)
        init_helper.init_weights(self, cfg.MODEL.FC_INIT_STD,
                                 cfg.RESNET.ZERO_INIT_FINAL_BN)
Ejemplo n.º 3
0
    def init_weights(self, init_std, ll_generator=None):
        # Init all weights
        init_helper.init_weights(self, init_std, False)

        if ll_generator is not None:
            self.head.rt_projection.weight.data.normal_(mean=0.0,
                                                        std=init_std,
                                                        generator=ll_generator)
            self.head.rt_projection.bias.data.zero_()
Ejemplo n.º 4
0
 def __init__(self, cfg):
     super(X3D, self).__init__()
     self.norm_module = get_norm(cfg)
     self.enable_detection = cfg.DETECTION.ENABLE
     self.num_pathways = 1
     self._construct_network(cfg)
     init_helper.init_weights(
         self, cfg.MODEL.FC_INIT_STD, cfg.RESNET.ZERO_INIT_FINAL_BN
     )
 def __init__(self, cfg):
     """
     The `__init__` method of any subclass should also contain these
         arguments.
     Args:
         cfg (CfgNode): model building configs, details are in the
             comments of the config file.
     """
     super(SlowFastModel, self).__init__()
     self.num_pathways = 2
     self._construct_network(cfg)
     init_helper.init_weights(self, cfg.MODEL.FC_INIT_STD,
                              cfg.RESNET.ZERO_INIT_FINAL_BN)
 def __init__(self, cfg):
     """
     The `__init__` method of any subclass should also contain these
         arguments.
     Args:
         cfg (CfgNode): model building configs, details are in the
             comments of the config file.
     """
     super(CNNCatLSTM, self).__init__()
     # self.norm_module = get_norm(cfg)
     # self.enable_detection = cfg.DETECTION.ENABLE
     self.num_pathways = 1
     self._construct_network(cfg)
     init_helper.init_weights(self, cfg.MODEL.FC_INIT_STD,
                              cfg.RESNET.ZERO_INIT_FINAL_BN)
Ejemplo n.º 7
0
 def __init__(self, cfg):
     """
     The `__init__` method of any subclass should also contain these
         arguments.
     Args:
         cfg (CfgNode): model building configs, details are in the
             comments of the config file.
     """
     super(Student_SlowFast_MobileNetV3, self).__init__()
     self.norm_module = nn.BatchNorm2d
     self.enable_detection = cfg.DETECTION.ENABLE
     self.num_pathways = 2
     self.cfg = cfg
     self._construct_network(cfg)
     init_helper.init_weights(self, cfg.MODEL.FC_INIT_STD,
                              cfg.RESNET.ZERO_INIT_FINAL_BN)
Ejemplo n.º 8
0
 def __init__(self, cfg):
     """
     The `__init__` method of any subclass should also contain these
         arguments.
     Args:
         cfg (CfgNode): model building configs, details are in the
             comments of the config file.
     """
     super(SlowFast, self).__init__()
     self.extract_mstcn_features = cfg.TEST.EXTRACT_MSTCN_FEATURES
     self.extract_features = cfg.TEST.EXTRACT_FEATURES
     self.enable_detection = cfg.DETECTION.ENABLE
     self.num_pathways = 2
     self._construct_network(cfg)
     init_helper.init_weights(self, cfg.MODEL.FC_INIT_STD,
                              cfg.RESNET.ZERO_INIT_FINAL_BN)
Ejemplo n.º 9
0
 def __init__(self,
              cfg,
              detection_header=head_helper.ResNetRoIHead,
              recognition_header=head_helper.ResNetBasicHead):
     """
     The `__init__` method of any subclass should also contain these
         arguments.
     Args:
         cfg (CfgNode): model building configs, details are in the
             comments of the config file.
     """
     super(SlowFastModel, self).__init__()
     self.enable_detection = cfg.DETECTION.ENABLE
     self.num_pathways = 2
     self.detection_header = detection_header
     self.recognition_header = recognition_header
     self._construct_network(cfg)
     init_helper.init_weights(self, cfg.MODEL.FC_INIT_STD,
                              cfg.RESNET.ZERO_INIT_FINAL_BN)
Ejemplo n.º 10
0
    def __init__(self, cfg):
        """
        The `__init__` method of any subclass should also contain these
            arguments.
        Args:
            cfg (CfgNode): model building configs, details are in the
                comments of the config file.
        """
        self.temp_crops = cfg.SWAV_nmb_frame_views
        self.spat_crops_list = cfg.SWAV_nmb_crops
        self.spat_crops_size = cfg.SWAV_size_crops
        self.shuffle = cfg.SWAV_shuffle
        super(SlowFastSWAV, self).__init__()
        self.norm_module = get_norm(cfg)
        self.enable_detection = cfg.DETECTION.ENABLE
        self.num_pathways = 2
        self._construct_network(cfg)

        init_helper.init_weights(self, cfg.MODEL.FC_INIT_STD,
                                 cfg.RESNET.ZERO_INIT_FINAL_BN)
Ejemplo n.º 11
0
    def __init__(self, cfg):
        super(SlowFastBbox, self).__init__()
        self.cfg = cfg
        self.num_pathways = 2
        self.slow_fast = SlowFast(cfg)
        self.slow_fast.head = nn.Identity()
        pool_size = _POOL1[cfg.MODEL.ARCH]
        slow_pool_size = [
            [
                cfg.DATA.NUM_FRAMES // cfg.SLOWFAST.ALPHA // pool_size[0][0],
                cfg.DATA.CROP_SIZE // 32 // pool_size[0][1],
                cfg.DATA.CROP_SIZE // 32 // pool_size[0][2],
            ],
            [
                cfg.DATA.NUM_FRAMES // cfg.SLOWFAST.ALPHA // pool_size[0][0],
                1,
                1,
            ],
        ]
        fast_pool_size = [
            [
                cfg.DATA.NUM_FRAMES // pool_size[1][0],
                cfg.DATA.CROP_SIZE // 32 // pool_size[1][1],
                cfg.DATA.CROP_SIZE // 32 // pool_size[1][2],
            ],
            [
                cfg.DATA.NUM_FRAMES // pool_size[1][0],
                1,
                1,
            ],
        ]
        model_pool_size = [slow_pool_size, fast_pool_size]
        if cfg.EPICKITCHENS.ROI_BRANCH == 1:
            roi_type = [[0], [1]]
        elif cfg.EPICKITCHENS.ROI_BRANCH == 0:
            roi_type = [[1], [0]]
        elif cfg.EPICKITCHENS.ROI_BRANCH == 2:
            roi_type = [[0, 1], [1]]
        elif cfg.EPICKITCHENS.ROI_BRANCH == 3:
            roi_type = [[0, 1], [0]]
        elif cfg.EPICKITCHENS.ROI_BRANCH == 4:
            roi_type = [[0], [0, 1]]
        elif cfg.EPICKITCHENS.ROI_BRANCH == 5:
            roi_type = [[0, 1], [0, 1]]
        else:
            roi_type = [[0], [0]]

        dim_in = [cfg.RESNET.WIDTH_PER_GROUP * 32] * len(roi_type[0]) + [
            cfg.RESNET.WIDTH_PER_GROUP * 32 // cfg.SLOWFAST.BETA_INV
        ] * len(roi_type[1])

        self.bbox_head = head_helper.ResNetBboxClassifierHead(
            dim_in=dim_in,
            num_classes=cfg.MODEL.NUM_CLASSES,
            pool_size=model_pool_size,
            roi_type=roi_type,
            resolution=[[cfg.DETECTION.ROI_XFORM_RESOLUTION] * 2] * 2,
            scale_factor=[
                cfg.DATA.CROP_SIZE // cfg.DETECTION.ROI_XFORM_RESOLUTION
            ] * 2,
            act_func="softmax",
            aligned=cfg.DETECTION.ALIGNED,
        )
        self.roi_type = roi_type
        init_helper.init_weights(self.bbox_head, cfg.MODEL.FC_INIT_STD,
                                 cfg.RESNET.ZERO_INIT_FINAL_BN)