@@ -512,15 +512,13 @@ def dense(self, shape=None, min_coordinate=None, contract_stride=True):
512
512
tensor_stride = torch .IntTensor (self .tensor_stride )
513
513
return dense_F , min_coordinate , tensor_stride
514
514
515
- def slice (self , X , slicing_mode = 0 ):
515
+ def slice (self , X ):
516
516
r"""
517
517
518
518
Args:
519
519
:attr:`X` (:attr:`MinkowskiEngine.SparseTensor`): a sparse tensor
520
520
that discretized the original input.
521
521
522
- :attr:`slicing_mode`: For future updates.
523
-
524
522
Returns:
525
523
:attr:`tensor_field` (:attr:`MinkowskiEngine.TensorField`): the
526
524
resulting tensor field contains features on the continuous
@@ -530,7 +528,7 @@ def slice(self, X, slicing_mode=0):
530
528
531
529
>>> # coords, feats from a data loader
532
530
>>> print(len(coords)) # 227742
533
- >>> tfield = ME.TensorField(coords =coords, feats =feats, quantization_mode=SparseTensorQuantizationMode.UNWEIGHTED_AVERAGE)
531
+ >>> tfield = ME.TensorField(coordinates =coords, features =feats, quantization_mode=SparseTensorQuantizationMode.UNWEIGHTED_AVERAGE)
534
532
>>> print(len(tfield)) # 227742
535
533
>>> sinput = tfield.sparse() # 161890 quantization results in fewer voxels
536
534
>>> soutput = MinkUNet(sinput)
@@ -545,9 +543,7 @@ def slice(self, X, slicing_mode=0):
545
543
SparseTensorQuantizationMode .RANDOM_SUBSAMPLE ,
546
544
SparseTensorQuantizationMode .UNWEIGHTED_AVERAGE ,
547
545
], "slice only available for sparse tensors with quantization RANDOM_SUBSAMPLE or UNWEIGHTED_AVERAGE"
548
- assert (
549
- X .coordinate_map_key == self .coordinate_map_key
550
- ), "Slice can only be applied on the same coordinates (coordinate_map_key)"
546
+
551
547
from MinkowskiTensorField import TensorField
552
548
553
549
if isinstance (X , TensorField ):
@@ -557,23 +553,28 @@ def slice(self, X, slicing_mode=0):
557
553
coordinate_manager = X .coordinate_manager ,
558
554
quantization_mode = X .quantization_mode ,
559
555
)
560
- else :
556
+ elif isinstance (X , SparseTensor ):
557
+ assert (
558
+ X .coordinate_map_key == self .coordinate_map_key
559
+ ), "Slice can only be applied on the same coordinates (coordinate_map_key)"
561
560
return TensorField (
562
561
self .F [X .inverse_mapping ],
563
562
coordinates = self .C [X .inverse_mapping ],
564
- coordinate_manager = X .coordinate_manager ,
565
- quantization_mode = X .quantization_mode ,
563
+ coordinate_manager = self .coordinate_manager ,
564
+ quantization_mode = self .quantization_mode ,
565
+ )
566
+ else :
567
+ raise ValueError (
568
+ "Invalid input. The input must be an instance of TensorField or SparseTensor."
566
569
)
567
570
568
- def cat_slice (self , X , slicing_mode = 0 ):
571
+ def cat_slice (self , X ):
569
572
r"""
570
573
571
574
Args:
572
575
:attr:`X` (:attr:`MinkowskiEngine.SparseTensor`): a sparse tensor
573
576
that discretized the original input.
574
577
575
- :attr:`slicing_mode`: For future updates.
576
-
577
578
Returns:
578
579
:attr:`tensor_field` (:attr:`MinkowskiEngine.TensorField`): the
579
580
resulting tensor field contains the concatenation of features on the
@@ -584,7 +585,7 @@ def cat_slice(self, X, slicing_mode=0):
584
585
585
586
>>> # coords, feats from a data loader
586
587
>>> print(len(coords)) # 227742
587
- >>> sinput = ME.SparseTensor(coords =coords, feats =feats, quantization_mode=SparseTensorQuantizationMode.UNWEIGHTED_AVERAGE)
588
+ >>> sinput = ME.SparseTensor(coordinates =coords, features =feats, quantization_mode=SparseTensorQuantizationMode.UNWEIGHTED_AVERAGE)
588
589
>>> print(len(sinput)) # 161890 quantization results in fewer voxels
589
590
>>> soutput = network(sinput)
590
591
>>> print(len(soutput)) # 161890 Output with the same resolution
@@ -596,29 +597,30 @@ def cat_slice(self, X, slicing_mode=0):
596
597
SparseTensorQuantizationMode .RANDOM_SUBSAMPLE ,
597
598
SparseTensorQuantizationMode .UNWEIGHTED_AVERAGE ,
598
599
], "slice only available for sparse tensors with quantization RANDOM_SUBSAMPLE or UNWEIGHTED_AVERAGE"
599
- assert (
600
- X .coordinate_map_key == self .coordinate_map_key
601
- ), "Slice can only be applied on the same coordinates (coordinate_map_key)"
600
+
602
601
from MinkowskiTensorField import TensorField
603
602
604
603
features = torch .cat ((self .F [X .inverse_mapping ], X .F ), dim = 1 )
605
604
if isinstance (X , TensorField ):
606
605
return TensorField (
607
606
features ,
608
- coordinate_map_key = X .coordinate_map_key ,
609
607
coordinate_field_map_key = X .coordinate_field_map_key ,
610
608
coordinate_manager = X .coordinate_manager ,
611
- inverse_mapping = X .inverse_mapping ,
612
609
quantization_mode = X .quantization_mode ,
613
610
)
614
- else :
611
+ elif isinstance (X , SparseTensor ):
612
+ assert (
613
+ X .coordinate_map_key == self .coordinate_map_key
614
+ ), "Slice can only be applied on the same coordinates (coordinate_map_key)"
615
615
return TensorField (
616
616
features ,
617
617
coordinates = self .C [X .inverse_mapping ],
618
- coordinate_map_key = X .coordinate_map_key ,
619
- coordinate_manager = X .coordinate_manager ,
620
- inverse_mapping = X .inverse_mapping ,
621
- quantization_mode = X .quantization_mode ,
618
+ coordinate_manager = self .coordinate_manager ,
619
+ quantization_mode = self .quantization_mode ,
620
+ )
621
+ else :
622
+ raise ValueError (
623
+ "Invalid input. The input must be an instance of TensorField or SparseTensor."
622
624
)
623
625
624
626
def features_at_coordinates (self , query_coordinates : torch .Tensor ):
0 commit comments