def forward(self, x): gx = self.gx(F.pad(x, (1, 1, 0, 0), 'replicate')) gy = self.gy(F.pad(x, (0, 0, 1, 1), 'replicate')) mag = torch.sqrt(gx * gx + gy * gy + 1e-10) ori = torch.atan2(gy, gx + 1e-8) if x.is_cuda: self.gk = self.gk.cuda() else: self.gk = self.gk.cpu() mag = mag * self.gk.expand_as(mag) o_big = (ori + 2.0 * math.pi) / (2.0 * math.pi) * float( self.num_ang_bins) bo0_big = torch.floor(o_big) wo1_big = o_big - bo0_big bo0_big = bo0_big % self.num_ang_bins bo1_big = (bo0_big + 1) % self.num_ang_bins wo0_big = (1.0 - wo1_big) * mag wo1_big = wo1_big * mag ang_bins = [] for i in range(0, self.num_ang_bins): ang_bins.append( self.pk((bo0_big == i).float() * wo0_big + (bo1_big == i).float() * wo1_big)) ang_bins = torch.cat(ang_bins, 1) ang_bins = ang_bins.view(ang_bins.size(0), -1) ang_bins = L2Norm()(ang_bins) ang_bins = torch.clamp(ang_bins, 0., float(self.clipval)) ang_bins = L2Norm()(ang_bins) return ang_bins
def forward(self, input): x_features = self.features(self.input_norm(input)) scale = self.scale(x_features).view(x_features.size(0), -1) desc = L2Norm()(self.descriptor(x_features).view(x_features.size(0), -1)) #print( x_features.shape) #sys.exit(0) return scale,desc
def forward(self, input): flat = input.view(input.size(0), -1) mp = torch.sum(flat, dim=1) / (32. * 32.) sp = torch.std(flat, dim=1) + 1e-7 x_features = self.features( (input - mp.unsqueeze(-1).unsqueeze(-1).expand_as(input)) / sp.unsqueeze(-1).unsqueeze(1).expand_as(input)) x = x_features.view(x_features.size(0), -1) return L2Norm()(x)
def forward(self, input): # print(input.size()) x_features = self.features(input_norm(input)) y = self.features1(x_features.view(x_features.size(0), -1)) y = self.features2(y) y = y*20 x = y.view(y.size(0), -1) return L2Norm()(x)
def forward(self, input): flat = input.view(input.size(0), -1) #mp = args.mean-image#torch.sum(flat, dim=1) / (32. * 32.) #sp = args.std-image#torch.std(flat, dim=1) + 1e-7 #x_features = self.features( #(input - mp.unsqueeze(-1).unsqueeze(-1).expand_as(input)) / sp.unsqueeze(-1).unsqueeze(1).expand_as(input)) x_features = self.features(input) x = x_features.view(x_features.size(0), -1) return L2Norm()(x)
def forward(self, input): x_features_1 = self.features_1(self.input_norm(input)) x_features_2 = self.features_2(x_features_1) x_features_3 = self.features_3(x_features_2) x_f_1_down = self.pooling4(x_features_1) x_f_2_down = self.pooling2(x_features_2) fuse = torch.cat((x_f_1_down, x_f_2_down, x_features_3), 1) result = self.result(fuse) x = result.view(result.size(0), -1) return L2Norm()(x)
def forward(self, x): x = self.input_norm(x) int1 = self.bn1(self.conv1(x)) x = F.relu(int1) x = F.relu(self.bn2(self.conv2(x))) x = F.relu(self.bn3(self.conv3(x))) x = F.relu(self.bn4(self.conv4(x))) x = F.relu(self.bn5(self.conv5(x))) x = F.relu(self.bn6(self.conv6(x))) x = self.bn7(self.conv7(x)) int2 = x.view(x.size(0), -1) return L2Norm()(int2)
def forward(self, input): # print(input.size()) y = self.features(input_norm(input)) x = y.view(y.size(0), y.size(1), -1) torch.zeros([y.size(0), y.size(1), self.k]) for i in range(x.size(0)): tmpx = x[i, :, :].view(y.size(1), -1) U, S, VT = tmpx.svd() # print(tmpx.size(),U.size(),S.size(),VT.size()) new_U = U[:tmpx.size(0), :self.k] new_VT = VT[:self.k, :(tmpx.size(-1))] SD = Variable(torch.eye(self.k)).cuda() * S[:self.k] # print("SD.size is",SD.size()) # print("new_VT.size is", new_VT.size()) b = torch.mm(SD, new_VT) newData = torch.mm(new_U, b) # print("newData size is:", newData.size()) return L2Norm()(newData)
def forward(self, input): x_features = self.features(self.input_norm(input)) x = x_features.view(x_features.size(0), -1) return L2Norm()(x)
def forward(self, x): x = self.features(x) x = x.view(x.size(0), -1) x = self.classifier(x) return L2Norm()(x) return x
descriptor = descriptor.cuda() model_weights = 'HardNet++.pth' hncheckpoint = torch.load(model_weights) descriptor.load_state_dict(hncheckpoint['state_dict']) descriptor.train() elif args.descriptor == 'TFeat': descriptor = HardTFeatNet(sm=SIFTNet(patch_size=32)) if not args.no_cuda: descriptor = descriptor.cuda() model_weights = 'HardTFeat.pth' hncheckpoint = torch.load(model_weights) descriptor.load_state_dict(hncheckpoint['state_dict']) descriptor.train() else: descriptor = lambda x: L2Norm()(x.view(x.size(0), -1) - x.view( x.size(0), -1).mean(dim=1, keepdim=True).expand( x.size(0), x.size(1) * x.size(2) * x.size(3)).detach()) suffix = args.expname + "_" + args.arch + '_6Brown_' + args.descriptor + '_' + str( args.lr) + '_' + str(args.n_pairs) + "_" + str(args.loss) ##########################################3 def create_loaders(): kwargs = { 'num_workers': args.num_workers, 'pin_memory': args.pin_memory } if args.cuda else {} transform = transforms.Compose( [transforms.Lambda(np_reshape),
def forward(self, input): x = self.features(self.input_norm(input)) x = x.view(x.size(0), -1) x = self.classifier(x) return L2Norm()(x)