SuperGlue使用pytorch训练遇到的问题:pytorch RuntimeError: Expected object of scalar type Double but got scalar

最近在做superglue论文的复现.
参考GitHub上面的superglue训练方法:
(https://github.com/HeatherJiaZG/SuperGlue-pytorch)

但是在训练网络时遇到了以下报错:

pytorch RuntimeError: Expected object of scalar type Double but got scalar type Float for argument #1 'sensors'

这个问题的解决方法主要是参考了这个博客:[https://cloud.tencent.com/developer/ask/sof/1483010/answer/2029233]

pytorch框架对数据进行训练时,输入数据一般默认为float类型,所以可以通过调用.float()来转换你的输入张量。

我的解决方法是:
在train.py文件中将double改为float
同时在load_data.py中将下面的double改为float

        if len(kp1) < 1 or len(kp2) < 1:
            return{
                # torch.double
                'keypoints0': torch.zeros([0, 0, 2], dtype=torch.float),
                'keypoints1': torch.zeros([0, 0, 2], dtype=torch.float),
                'descriptors0': torch.zeros([0, 2], dtype=torch.float),
                'descriptors1': torch.zeros([0, 2], dtype=torch.float),
                'image0': image,
                'image1': warped,
                'file_name': file_name
            } 

最后在superglue.py中将double改为float

    def forward(self, data):
        """Run SuperGlue on a pair of keypoints and descriptors"""
        desc0, desc1 = data['descriptors0'].float(), data['descriptors1'].float()
        kpts0, kpts1 = data['keypoints0'].float(), data['keypoints1'].float()

你可能感兴趣的:(pytorch,python)