Parskatt / DKM

[CVPR 2023] DKM: Dense Kernelized Feature Matching for Geometry Estimation
https://parskatt.github.io/DKM/
Other
378 stars 28 forks source link

`numpy.random.choice` to pytorch? #27

Closed ducha-aiki closed 1 year ago

ducha-aiki commented 1 year ago

Hi,

I have quickly checked the possibility to strip out training code and integrate the bare DKM into kornia. It seems that the main blocker is numpy.random.choice

https://github.com/Parskatt/DKM/blob/b3311e203038d117bf288fdfa0e3144d8effe95a/dkm/models/dkm.py#L585

And the Pytorch doesn't have it https://github.com/pytorch/pytorch/issues/16897

Is there a way we can use existing pytorch functionality to get a similar thing?

Parskatt commented 1 year ago
torch.multinomial(certainty, num_samples = min(expansion_factor*num, len(certainty)), replacement=False)

Seems like a good option

Parskatt commented 1 year ago

I think the main issue with np.random.choice missing in Pytorch is that you have to pipeline multinomial -> indexing instead of having it as a single function. However, as I'm just using it for indexes here anyway I think there is no major issue.

ducha-aiki commented 1 year ago

Could you please check if that works? And, btw, DKM is very welcomed in the shortly upcoming Image Matching Challenge 2023 (CVPR & Kaggle)

Parskatt commented 1 year ago

Sure, I'll check, and we'll provide a DKM baseline kernel to run for IMC. By the way @ducha-aiki, is Kaggle python 3.7 only? e.g. PyTorch 2.0 doesn't seem to have any binaries for cp37?

ducha-aiki commented 1 year ago

@Parskatt well, I more meant to take part and win the challenge :) Regarding Python 3.7 - kaggle kernel is 3.7 only now, but given the EOL soon, we can safely bet they will upgrade in month or two.

Parskatt commented 1 year ago

Multinomial seems fine, should be in here https://github.com/Parskatt/DKM/pull/22 .