NVIDIA / MinkowskiEngine

Minkowski Engine is an auto-diff neural network library for high-dimensional sparse tensors
https://nvidia.github.io/MinkowskiEngine
Other
2.43k stars 360 forks source link

MinkowskiMaxPooling does not change input tensor dimension #493

Closed GrantZheng86 closed 2 years ago

GrantZheng86 commented 2 years ago

Hello,

I was doing experiments with the max pooling layer but somehow tensors passed through the layer does not seem to change dimension. I'm not sure if I am using this function correctly. The documentation page only has a place holder example that is irrelevant to the max pooling. Here's what I've done to generate a testing tensor and the max pooling layer

    coords = 100*np.random.uniform(0, 1, (10, 2))
    feats = np.random.uniform(0, 5, (10, 1))
    coords, feats = ME.utils.sparse_collate([coords], [feats])
    content_sparse = ME.SparseTensor(feats, coords)
    content_dense = content_sparse.dense()[0]
    pooling_layer_torch = torch.nn.MaxPool2d(kernel_size=[50, 50])
    pooling_layer = ME.MinkowskiMaxPooling(kernel_size=[15, 20], dimension=2)
    content_sparse_pooled = pooling_layer(content_sparse)

The original tensor content_sparse and the pooled tensor content_sparse_pooled have the same dimension, but I was expecting it do be different. I was expecting it to output a (dense) tensor that are in the same shape as the one output from a torch.nn.MaxPool2D([50, 50]) The original content_sparse:

SparseTensor(
  coordinates=tensor([[ 0, 29, 62],
        [ 0, 84, 17],
        [ 0, 10, 65],
        [ 0, 72, 45],
        [ 0, 39, 45],
        [ 0,  1, 69],
        [ 0, 71, 75],
        [ 0, 56, 97],
        [ 0, 11, 39],
        [ 0, 34, 55]], dtype=torch.int32)
  features=tensor([[0.2770],
        [1.9264],
        [4.5422],
        [2.9774],
        [2.7599],
        [2.3560],
        [4.6194],
        [0.2213],
        [3.2029],
        [1.6482]], dtype=torch.float64)
  coordinate_map_key=coordinate map key:[1, 1]
  coordinate_manager=CoordinateMapManagerCPU(
    [1, 1]: CoordinateMapCPU:10x3
    [1, 1]->[1, 1]: cpu_kernel_map: number of unique maps:2500, kernel map size:20
    algorithm=MinkowskiAlgorithm.DEFAULT
  )
  spatial dimension=2)

The output, however, looks the same as the input:

SparseTensor(
  coordinates=tensor([[ 0, 29, 62],
        [ 0, 84, 17],
        [ 0, 10, 65],
        [ 0, 72, 45],
        [ 0, 39, 45],
        [ 0,  1, 69],
        [ 0, 71, 75],
        [ 0, 56, 97],
        [ 0, 11, 39],
        [ 0, 34, 55]], dtype=torch.int32)
  features=tensor([[4.6194],
        [1.9264],
        [4.5422],
        [2.9774],
        [4.6194],
        [2.3560],
        [4.6194],
        [0.2213],
        [3.2029],
        [4.6194]], dtype=torch.float64)
  coordinate_map_key=coordinate map key:[1, 1]
  coordinate_manager=CoordinateMapManagerCPU(
    [1, 1]: CoordinateMapCPU:10x3
    [1, 1]->[1, 1]: cpu_kernel_map: number of unique maps:2500, kernel map size:20
    algorithm=MinkowskiAlgorithm.DEFAULT
  )
  spatial dimension=2)

I've also tried some global pooling and convolution function, they all output shapes as expected, just this maxpooling is not doing anything. Only local pooing methods (sum, max, etc.) is not changing the dimension.

Any help is greatly appreciated!

GrantZheng86 commented 2 years ago

Issue resolved, it was caused by the kernel being too small.