neuralnet-pytorch icon indicating copy to clipboard operation
neuralnet-pytorch copied to clipboard

Fail to process batch data using EMD loss

Open zhangmozhe opened this issue 5 years ago • 3 comments
trafficstars

Hi, I met error "The size of tensor a (2048) must match the size of tensor b (4096) at non-singleton dimension 1" when I run the following code:

points1 = torch.rand(2, 2048, 3, requires_grad=True).cuda() points2 = torch.rand(2, 2048, 3).cuda() geomloss.SamplesLoss(loss='sinkhorn', p=2, blur=0.05)(points1 , points2)

It seems that the code does not process one batch input well. I wonder how to solve it. Thanks!

zhangmozhe avatar Jun 04 '20 09:06 zhangmozhe

Hello @zhangmozhe. First of all, I am not sure if you should ask me about geomloss here, as I do not maintain it. But anw, to answer your question, could you please try setting the backend argument to tensorized explicitly? Also, just fyi in case you miss it, EMD and Sinkhorn have slightly different formulation. Please beware of it so you don't mistakenly use this function.

justanhduc avatar Jun 04 '20 13:06 justanhduc

Hi @justanhduc, thanks for your reply. I wonder what's the problem when using Sinkhorn? I had thought Sinkhorn is a fast approximation of EMD, and it seems that it's like a substitution of CUDA EMD implementation in your code (https://github.com/justanhduc/neuralnet-pytorch/blob/86060879cfe1b0834f54504b407f3e2448ea88b3/neuralnet_pytorch/metrics.py#L148). Thanks for your help very much!

zhangmozhe avatar Jun 05 '20 02:06 zhangmozhe

Hello. Yes and no. Yes because it is an iterated method, but no because Sinkhorn has an entropy regularization term, and thanks to the regularization, it has a nice solution like that. Just keep that in mind and consider whether this regularization is significant to your problem or not. Probably I was quite irresponsible when including them under one roof like that.

justanhduc avatar Jun 05 '20 15:06 justanhduc