def __init__(self, option, model_type, dataset, modules): super(PointGroup, self).__init__(option) backbone_options = option.get("backbone", {"architecture": "unet"}) self.Backbone = Minkowski( backbone_options.architecture, input_nc=dataset.feature_dimension, num_layers=4, config=backbone_options.config, ) self.BackboneHead = Seq().append(FastBatchNorm1d(self.Backbone.output_nc)).append(torch.nn.ReLU()) self._scorer_is_encoder = option.scorer.architecture == "encoder" self._activate_scorer = option.scorer.activate self.Scorer = Minkowski( option.scorer.architecture, input_nc=self.Backbone.output_nc, num_layers=option.scorer.depth ) self.ScorerHead = Seq().append(torch.nn.Linear(self.Scorer.output_nc, 1)).append(torch.nn.Sigmoid()) self.Offset = Seq().append(MLP([self.Backbone.output_nc, self.Backbone.output_nc], bias=False)) self.Offset.append(torch.nn.Linear(self.Backbone.output_nc, 3)) self.Semantic = ( Seq() .append(MLP([self.Backbone.output_nc, self.Backbone.output_nc], bias=False)) .append(torch.nn.Linear(self.Backbone.output_nc, dataset.num_classes)) .append(torch.nn.LogSoftmax()) ) self.loss_names = ["loss", "offset_norm_loss", "offset_dir_loss", "semantic_loss", "score_loss"] stuff_classes = dataset.stuff_classes if is_list(stuff_classes): stuff_classes = torch.Tensor(stuff_classes).long() self._stuff_classes = torch.cat([torch.tensor([IGNORE_LABEL]), stuff_classes])
def __init__(self, option, model_type, dataset, modules): super(PointGroup, self).__init__(option) self.Backbone = Minkowski("unet", input_nc=dataset.feature_dimension, num_layers=4) self._scorer_is_encoder = option.scorer.architecture == "encoder" self.Scorer = Minkowski(option.scorer.architecture, input_nc=self.Backbone.output_nc, num_layers=2) self.ScorerHead = Seq().append( torch.nn.Linear(self.Scorer.output_nc, 1)).append(torch.nn.Sigmoid()) self.Offset = Seq().append( MLP([self.Backbone.output_nc, self.Backbone.output_nc], bias=False)) self.Offset.append(torch.nn.Linear(self.Backbone.output_nc, 3)) self.Semantic = (Seq().append( torch.nn.Linear(self.Backbone.output_nc, dataset.num_classes)).append( torch.nn.LogSoftmax())) self.loss_names = [ "loss", "offset_norm_loss", "offset_dir_loss", "semantic_loss", "score_loss" ] self._stuff_classes = torch.cat( [torch.tensor([IGNORE_LABEL]), dataset.stuff_classes])
def __init__(self, option, model_type, dataset, modules): super(PointGroup, self).__init__(option) backbone_options = option.get("backbone", {"architecture": "unet"}) self.Backbone = Minkowski( backbone_options.get("architecture", "unet"), input_nc=dataset.feature_dimension, num_layers=4, config=backbone_options.get("config", {}), ) self._scorer_type = option.get("scorer_type", "encoder") cluster_voxel_size = option.get("cluster_voxel_size", 0.05) if cluster_voxel_size: self._voxelizer = GridSampling3D(cluster_voxel_size, quantize_coords=True, mode="mean") else: self._voxelizer = None self.ScorerUnet = Minkowski("unet", input_nc=self.Backbone.output_nc, num_layers=4, config=option.scorer_unet) self.ScorerEncoder = Minkowski("encoder", input_nc=self.Backbone.output_nc, num_layers=4, config=option.scorer_encoder) self.ScorerMLP = MLP([ self.Backbone.output_nc, self.Backbone.output_nc, self.ScorerUnet.output_nc ]) self.ScorerHead = Seq().append( torch.nn.Linear(self.ScorerUnet.output_nc, 1)).append(torch.nn.Sigmoid()) self.Offset = Seq().append( MLP([self.Backbone.output_nc, self.Backbone.output_nc], bias=False)) self.Offset.append(torch.nn.Linear(self.Backbone.output_nc, 3)) self.Semantic = (Seq().append( MLP([self.Backbone.output_nc, self.Backbone.output_nc], bias=False)).append( torch.nn.Linear(self.Backbone.output_nc, dataset.num_classes)).append( torch.nn.LogSoftmax(dim=-1))) self.loss_names = [ "loss", "offset_norm_loss", "offset_dir_loss", "semantic_loss", "score_loss" ] stuff_classes = dataset.stuff_classes if is_list(stuff_classes): stuff_classes = torch.Tensor(stuff_classes).long() self._stuff_classes = torch.cat( [torch.tensor([IGNORE_LABEL]), stuff_classes])
def test_minkowski(self): from torch_points3d.applications.minkowski import Minkowski input_nc = 3 num_layers = 4 in_feat = 16 model = Minkowski( architecture="encoder", input_nc=input_nc, in_feat=in_feat, num_layers=num_layers, config=None, ) dataset = MockDatasetGeometric(input_nc, transform=GridSampling3D( 0.01, quantize_coords=True), num_points=128) self.assertEqual(len(model._modules["down_modules"]), num_layers) self.assertEqual(len(model._modules["inner_modules"]), 1) self.assertFalse(model.has_mlp_head) self.assertEqual(model.output_nc, 8 * in_feat) try: data_out = model.forward(dataset[0]) # self.assertEqual(data_out.x.shape[1], 8 * in_feat) except Exception as e: print("Model failing:") print(model) raise e input_nc = 3 num_layers = 4 grid_sampling = 0.02 in_feat = 32 output_nc = 5 model = Minkowski( architecture="encoder", input_nc=input_nc, output_nc=output_nc, in_feat=in_feat, in_grid_size=grid_sampling, num_layers=num_layers, config=None, ) dataset = MockDatasetGeometric(input_nc, transform=GridSampling3D( 0.01, quantize_coords=True), num_points=128) self.assertEqual(len(model._modules["down_modules"]), num_layers) self.assertEqual(len(model._modules["inner_modules"]), 1) self.assertTrue(model.has_mlp_head) self.assertEqual(model.output_nc, output_nc) try: data_out = model.forward(dataset[0]) self.assertEqual(data_out.x.shape[1], output_nc) except Exception as e: print("Model failing:") print(model) raise e
def __init__(self, option, model_type, dataset, modules): # call the initialization method of UnetBasedModel super().__init__(option) self.model = Minkowski("unet", dataset.feature_dimension, 4, output_nc=dataset.num_classes) self.loss_names = ["loss_seg"]