Spaces:
Build error
Build error
temp
Browse files
app.py
CHANGED
@@ -6,11 +6,10 @@ from how.networks import how_net
|
|
6 |
|
7 |
import fire_network
|
8 |
|
|
|
9 |
|
10 |
# Possible Scales for multiscale inference
|
11 |
-
|
12 |
-
infer_opts = {"scales": scales, "features_num": 1000}
|
13 |
-
|
14 |
|
15 |
# Load net
|
16 |
state = torch.load('fire.pth', map_location='cpu')
|
@@ -18,28 +17,42 @@ state['net_params']['pretrained'] = None # no need for imagenet pretrained model
|
|
18 |
net = fire_network.init_network(**state['net_params']).to(device)
|
19 |
net.load_state_dict(state['state_dict'])
|
20 |
|
21 |
-
|
22 |
transforms.Resize(1024),
|
23 |
transforms.ToTensor(),
|
24 |
transforms.Normalize(**dict(zip(["mean", "std"], net.runtime['mean_std'])))
|
25 |
])
|
26 |
|
27 |
|
28 |
-
#
|
|
|
|
|
|
|
|
|
|
|
29 |
def generate_matching_superfeatures(im1, im2, scale=6):
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
output1 = net.get_superfeatures(im1.to(device), scales=scales)
|
34 |
-
feats1 = output1[0]
|
35 |
-
attns1 = output1[1]
|
36 |
-
strenghts1 = output1[2]
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
attns2 = output2[1]
|
41 |
-
strenghts2 = output2[2]
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
|
45 |
|
|
|
6 |
|
7 |
import fire_network
|
8 |
|
9 |
+
import cv2
|
10 |
|
11 |
# Possible Scales for multiscale inference
|
12 |
+
scales = [2.0, 1.414, 1.0, 0.707, 0.5, 0.353, 0.25]
|
|
|
|
|
13 |
|
14 |
# Load net
|
15 |
state = torch.load('fire.pth', map_location='cpu')
|
|
|
17 |
net = fire_network.init_network(**state['net_params']).to(device)
|
18 |
net.load_state_dict(state['state_dict'])
|
19 |
|
20 |
+
transform = transforms.Compose([
|
21 |
transforms.Resize(1024),
|
22 |
transforms.ToTensor(),
|
23 |
transforms.Normalize(**dict(zip(["mean", "std"], net.runtime['mean_std'])))
|
24 |
])
|
25 |
|
26 |
|
27 |
+
# which sf
|
28 |
+
sf_idx_ = [55, 14, 5, 4, 52, 57, 40, 9]
|
29 |
+
|
30 |
+
|
31 |
+
col = plt.get_cmap('tab10')
|
32 |
+
|
33 |
def generate_matching_superfeatures(im1, im2, scale=6):
|
34 |
|
35 |
+
im1_tensor = transform(im1)
|
36 |
+
im2_tensor = transform(im2)
|
|
|
|
|
|
|
|
|
37 |
|
38 |
+
im1_cv = cv2.imread(im1)
|
39 |
+
im2_cv = cv2.imread(im2)
|
|
|
|
|
40 |
|
41 |
+
# extract features
|
42 |
+
with torch.no_grad():
|
43 |
+
output1 = net.get_superfeatures(im1.to(device), scales=scales)
|
44 |
+
feats1 = output1[0]
|
45 |
+
attns1 = output1[1]
|
46 |
+
strenghts1 = output1[2]
|
47 |
+
|
48 |
+
output2 = net.get_superfeatures(im2.to(device), scales=scales)
|
49 |
+
feats2 = output2[0]
|
50 |
+
attns2 = output2[1]
|
51 |
+
strenghts2 = output2[2]
|
52 |
+
|
53 |
+
print(feats1.shape)
|
54 |
+
print(attns1.shape)
|
55 |
+
print(strenghts1.shape)
|
56 |
|
57 |
|
58 |
|