├── README.md ├── codes ├── sosnet_example.py └── sosnet_model.py └── sosnet-weights ├── sosnet_32x32_hpatches_a.pth ├── sosnet_32x32_liberty.pth ├── sosnet_32x32_notredame.pth └── sosnet_32x32_yosemite.pth /README.md: -------------------------------------------------------------------------------- 1 | # SOSNet:Second Order Similarity Regularization for Local Descriptor Learning 2 | 3 | This is a pytorch implementation of SOSNet presented in [1]. 4 | 5 | Training codes are available [here](https://github.com/yuruntian/HyNet). 6 | 7 | [1]Yurun Tian, Xin Yu, Bin Fan, Fuchao Wu, Huub Heijnen, Vassileios Balntas. "SOSNet:Second Order Similarity Regularization for Local Descriptor Learning", CVPR, 2019. 8 | -------------------------------------------------------------------------------- /codes/sosnet_example.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import sosnet_model 3 | import os 4 | device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") 5 | torch.set_grad_enabled(False) 6 | 7 | sosnet32 = sosnet_model.SOSNet32x32() 8 | net_name = 'liberty' 9 | sosnet32.load_state_dict(torch.load(os.path.join('sosnet-weights', "sosnet-32x32-" + net_name + ".pth"))) 10 | sosnet32.cuda().eval() 11 | 12 | patches = torch.rand(100, 1, 32, 32).to(device) 13 | descrs = sosnet32(patches) 14 | -------------------------------------------------------------------------------- /codes/sosnet_model.py: -------------------------------------------------------------------------------- 1 | 2 | import torch.nn as nn 3 | 4 | eps_fea_norm = 1e-5 5 | eps_l2_norm = 1e-10 6 | 7 | 8 | class SOSNet32x32(nn.Module): 9 | """ 10 | 128-dimensional SOSNet model definition trained on 32x32 patches 11 | """ 12 | def __init__(self, dim_desc=128, drop_rate=0.1): 13 | super(SOSNet32x32, self).__init__() 14 | self.dim_desc = dim_desc 15 | self.drop_rate = drop_rate 16 | 17 | norm_layer = nn.BatchNorm2d 18 | activation = nn.ReLU() 19 | 20 | self.layers = nn.Sequential( 21 | nn.InstanceNorm2d(1, affine=False, eps=eps_fea_norm), 22 | nn.Conv2d(1, 32, kernel_size=3, padding=1, bias=False), 23 | norm_layer(32, affine=False, eps=eps_fea_norm), 24 | activation, 25 | nn.Conv2d(32, 32, kernel_size=3, padding=1, bias=False), 26 | norm_layer(32, affine=False, eps=eps_fea_norm), 27 | activation, 28 | 29 | nn.Conv2d(32, 64, kernel_size=3, stride=2, padding=1, bias=False), 30 | norm_layer(64, affine=False, eps=eps_fea_norm), 31 | activation, 32 | nn.Conv2d(64, 64, kernel_size=3, padding=1, bias=False), 33 | norm_layer(64, affine=False, eps=eps_fea_norm), 34 | activation, 35 | 36 | nn.Conv2d(64, 128, kernel_size=3, stride=2, padding=1, bias=False), 37 | norm_layer(128, affine=False, eps=eps_fea_norm), 38 | activation, 39 | nn.Conv2d(128, 128, kernel_size=3, padding=1, bias=False), 40 | norm_layer(128, affine=False, eps=eps_fea_norm), 41 | activation, 42 | 43 | nn.Dropout(self.drop_rate), 44 | nn.Conv2d(128, self.dim_desc, kernel_size=8, bias=False), 45 | norm_layer(128, affine=False, eps=eps_fea_norm), 46 | ) 47 | 48 | self.desc_norm = nn.Sequential( 49 | nn.LocalResponseNorm(2 * self.dim_desc, alpha=2 * self.dim_desc, beta=0.5, k=0) 50 | ) 51 | 52 | return 53 | 54 | def forward(self, patch): 55 | descr = self.desc_norm(self.layers(patch) + eps_l2_norm) 56 | descr = descr.view(descr.size(0), -1) 57 | return descr 58 | -------------------------------------------------------------------------------- /sosnet-weights/sosnet_32x32_hpatches_a.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruntian/SOSNet/7ae3730e76eaaac9331df10d28fc2d4a5b1f7688/sosnet-weights/sosnet_32x32_hpatches_a.pth -------------------------------------------------------------------------------- /sosnet-weights/sosnet_32x32_liberty.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruntian/SOSNet/7ae3730e76eaaac9331df10d28fc2d4a5b1f7688/sosnet-weights/sosnet_32x32_liberty.pth -------------------------------------------------------------------------------- /sosnet-weights/sosnet_32x32_notredame.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruntian/SOSNet/7ae3730e76eaaac9331df10d28fc2d4a5b1f7688/sosnet-weights/sosnet_32x32_notredame.pth -------------------------------------------------------------------------------- /sosnet-weights/sosnet_32x32_yosemite.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruntian/SOSNet/7ae3730e76eaaac9331df10d28fc2d4a5b1f7688/sosnet-weights/sosnet_32x32_yosemite.pth --------------------------------------------------------------------------------