ais-lab / d2s

[RAL 2024] D2S: Representing sparse descriptors and 3D coordinates for camera relocalization
https://thpjp.github.io/d2s/
Apache License 2.0
65 stars 5 forks source link

stack expects each tensor to be equal size, but got [256,835] at entry 0 and [256,829] at entry 1 #9

Closed SunJ1025 closed 4 months ago

SunJ1025 commented 5 months ago

Thanks for your Great Work! When I try to train the model, I get the following error:“stack expects each tensor to be equal size, but got [256,835] at entry 0 and [256,829] at entry 1”. it should be that the input data size is not consistent, how should I correct it?

Thanks in advance for your answer!

SunJ1025 commented 5 months ago

I found the descriptors are not the same size, do you konw which step is wrong, leading to a different descriptor sizes?

thuanaislab commented 5 months ago

Thank you for your interest in our work. The issue you got shows that you probably forgot to keep the threshold with Superpoint when running Hloc. Note that only when you have the same number of descriptors per image, you can train the framework with batch size > 1 (in the code the batch size is 8) Another simple solution is: change the batch size to 1 when training. It will work but I'm not sure it gonna show the best results.

You can change the config of superpoint as follows to get the same number of descriptors:

class SuperPoint(nn.Module):
    default_config = {
        'descriptor_dim': 256,
        'nms_radius': 4,
        'refinement_radius': 0,
        'do_quadratic_refinement': 0,
        'keypoint_threshold': 0.005, # please change to 0.0
        'max_keypoints': -1, # please change to number keypoints you need, ex: 2048
        'remove_borders': 4,
    }
SunJ1025 commented 5 months ago

Thank you for your quick response!I'll have a try.

SunJ1025 commented 5 months ago

Sorry to bother you again, but I still have the same problem after modifying max_keypoints=2048, it seems that it's because too few descriptors are fetched, for example [256,835] [256,829], so max_keypoints can't be limited uniformly, do you have any idea about the reason for this?

thuanaislab commented 5 months ago

I think you forgot to change the threshold of 'keypoint_threshold': 0.005 to 'keypoint_threshold': 0.0. Additionally, please change the config in Hloc at the parents configuration, the example I have shown above is just for a fast response but would not correctly set the Superpoint parameters for entire Hloc framework. This is why you still received the number of descriptors per image around 835 keypoints.

SunJ1025 commented 5 months ago

Hello, I have tried to set 'keypoint_threshold': 0.0 in the configs of Hloc, I think the set of configs are right. Maybe it's that 2048 keypoints cannot be extracted from a single image, even if the threshold is set to 0. I‘m not sure if I understand correctly ?

thuanaislab commented 5 months ago

As long as your image size is not too small, you can manage to get specific number of keypoints as you want.