masadcv / FastGeodis

Fast Implementation of Generalised Geodesic Distance Transform for CPU (OpenMP) and GPU (CUDA)
https://fastgeodis.readthedocs.io
BSD 3-Clause "New" or "Revised" License
90 stars 14 forks source link

[FEATURE] multiple batch input for generalised_geodesic2d #55

Open londumas opened 8 months ago

londumas commented 8 months ago

ValueError: FastGeodis currently only supports single batch input. when using FastGeodis.generalised_geodesic2d, v=1.0e10, lamb=0.0, iter=1

masadcv commented 8 months ago

The current algorithm can only optimize for a single batch (i.e. independent inputs). Therefore, the support for multiple batches will at best do the same as you are currently doing and may not give improved/optimized execution (although it may help with cleaner code). If this is of interest, I can look into including this within the library.

londumas commented 8 months ago

Thanks for the answer @masadcv,

although it may help with cleaner code

This is alread a good reason, what do you think ? If it can be used, here is my code BTW:

batch_size = image.shape[0]
dist_trans = torch.cat(
            [
                 FastGeodis.generalised_geodesic2d(image[i : i + 1], image[i : i + 1], v=v, lamb=lamb, iter=iter)
                for i in range(batch_size)
            ],
            axis=0,
        )
jasam-sheja commented 6 months ago

One more reason is to reduce memory footprint. Using concatenation incurs unnecessary copies.