XuyangBai / D3Feat

[TensorFlow] Official implementation of CVPR'20 oral paper - D3Feat: Joint Learning of Dense Detection and Description of 3D Local Features https://arxiv.org/abs/2003.03164
MIT License
259 stars 38 forks source link

About the circle loss #47

Closed HWLMX closed 2 years ago

HWLMX commented 2 years ago

Hi, Thank you for your excellent work. I wonder what is the circle loss in code,the paper only mentions triplet loss and contractive loss.

XuyangBai commented 2 years ago

Hi, as mentioned in readme

Training Loss: We have found that circle loss provides an insightful idea for the metric learning area and shows better and fast convergence for training D3Feat. To enable it, please change the loss_type to 'circle_loss' in KPFCNN_model.py, and the hyper-paramters for circle loss can be changed in loss.py.

HWLMX commented 2 years ago

Hi, thank you for your prompt reply。 Actually, we ran into this problem during our training. Accuracy and other parameters drop precipitously after about 40 epochs. In it you mentioned that it may be related to the circle loss. However, we did not use circle loss in the process of training and this still happened. However, in the process of our training without the use of circular loss, this problem still occurred. Do you have any suggestions for this problem? Best regards, Mengxuan Liu

XuyangBai commented 2 years ago

Hi, a long time ago I spent some time trying to find the reason for this network collapse problem but it can not be reproduced consistently in my setting. My suggestions are

  1. stop the training earlier. I remember that often happens at the late stage of the training, you may evaluate the model checkpoint just before breaking down.
  2. tune the grad_clip_norm parameter, a smaller value usually brings a smoother training process (but may also bring a slower convergence. https://github.com/XuyangBai/D3Feat/blob/476df5362bb398a0104266f4d1598cc54de21712/training_3DMatch.py#L108 You can also try to skip the iterator with grad_norm larger than this value. The following code can be used to skip inf grad in pytorch, you may perform a similar check in tensorflow
            # backward
            loss.backward()
            do_step = True
            for param in self.model.parameters():
                if param.grad is not None:
                    if (1 - torch.isfinite(param.grad).long()).sum() > 0:
                        do_step = False
                        break
            if do_step is True:
                self.optimizer.step()