Beispiel #1
0
 def _build_encoder(self):
     if self._config:
         model_config = self._config
     else:
         path_to_model = os.path.join(PATH_TO_CONFIG, "encoder_{}.yaml".format(self.num_layers),)
         model_config = OmegaConf.load(path_to_model)
     ModelFactory.resolve_model(model_config, self.num_features, self._kwargs)
     modules_lib = sys.modules[__name__]
     return MinkowskiEncoder(model_config, None, None, modules_lib, **self.kwargs)
 def _build_unet(self):
     if self._config:
         model_config = self._config
     else:
         path_to_model = os.path.join(PATH_TO_CONFIG, "unet_{}.yaml".format(self.num_layers))
         model_config = OmegaConf.load(path_to_model)
     ModelFactory.resolve_model(model_config, self.num_features, self._kwargs)
     modules_lib = sys.modules[__name__]
     return SparseConv3dUnet(model_config, None, None, modules_lib, **self.kwargs)
Beispiel #3
0
 def _build_unet(self):
     if self._config:
         model_config = self._config
     else:
         path_to_model = os.path.join(
             PATH_TO_CONFIG, "unet_{}_{}.yaml".format(self.num_layers, "ms" if self.kwargs["multiscale"] else "ss")
         )
         model_config = OmegaConf.load(path_to_model)
     ModelFactory.resolve_model(model_config, self.num_features, self._kwargs)
     modules_lib = sys.modules[__name__]
     return PointNet2Unet(model_config, None, None, modules_lib, **self.kwargs)
Beispiel #4
0
    def __init__(self,
                 original: bool = True,
                 backbone: str = "pointnet2",
                 input_nc: int = None,
                 num_classes: int = None,
                 mean_size_arr=[],
                 compute_loss=False,
                 *args,
                 **kwargs):
        """Initialize this model class.
        Parameters:
            opt -- training/test options
        A few things can be done here.
        - (required) call the initialization function of BaseModel
        - define loss function, visualization images, model names, and optimizers
        """
        assert input_nc is not None, "VoteNet requieres input_nc to be defined"
        assert num_classes is not None, "VoteNet requieres num_classes to be defined"
        try:
            self._backbone = MAPPING_BACKBONES_TO_API_NAMES[backbone.lower()]
        except:
            raise Exception("Backbone should be within {}".format(
                MAPPING_BACKBONES_TO_API_NAMES.keys()))

        if original:
            option = OmegaConf.load(
                os.path.join(PATH_TO_CONFIG, "votenet.yaml"))
        else:
            option = OmegaConf.load(
                os.path.join(PATH_TO_CONFIG, "votenet_backbones.yaml"))

        ModelFactory.resolve_model(option, input_nc, kwargs)

        self._original = original
        self._kwargs = kwargs
        self._compute_loss = compute_loss

        super(VoteNet, self).__init__(option)

        # 1 - CREATE BACKBONE MODEL
        if original:
            backbone_option = option.backbone
            backbone_cls = getattr(models, backbone_option.model_type)
            self.backbone_model = backbone_cls(architecture="unet",
                                               input_nc=input_nc,
                                               config=backbone_option)
        else:
            backbone_cls = getattr(models, self._backbone)
            voting_option = option.voting
            self.backbone_model = backbone_cls(
                architecture="unet",
                input_nc=input_nc,
                num_layers=4,
                output_nc=self._get_attr(voting_option, "feat_dim"),
                **kwargs,
            )
            self._kpconv_backbone = self._backbone == "KPConv"
            self.sampler = RandomSamplerToDense(
                num_to_sample=voting_option.num_points_to_sample)

        self.conv_type = self.backbone_model.conv_type
        self.is_dense_format = self.conv_type == "DENSE"

        # 2 - CREATE VOTING MODEL
        voting_option = option.voting
        voting_cls = getattr(votenet_module, voting_option.module_name)
        self.voting_module = voting_cls(
            vote_factor=self._get_attr(voting_option, "vote_factor"),
            seed_feature_dim=self._get_attr(voting_option, "feat_dim"),
        )

        # 3 - CREATE PROPOSAL MODULE
        proposal_option = option.proposal
        proposal_cls = getattr(votenet_module, proposal_option.module_name)
        self.proposal_cls_module = proposal_cls(
            num_class=num_classes,
            vote_aggregation_config=proposal_option.vote_aggregation,
            num_heading_bin=proposal_option.num_heading_bin,
            mean_size_arr=mean_size_arr,
            num_proposal=proposal_option.num_proposal,
            sampling=proposal_option.sampling,
        )

        # Loss params
        self.loss_params = option.loss_params
        self.loss_params.num_heading_bin = proposal_option.num_heading_bin
        if isinstance(mean_size_arr, np.ndarray):
            self.loss_params.mean_size_arr = mean_size_arr.tolist()
        else:
            self.loss_params.mean_size_arr = mean_size_arr

        self.losses_has_been_added = False
        self.loss_names = []