Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
mischeiwiller
commited on
Commit
•
b368542
1
Parent(s):
bc3919a
Update app.py
Browse files
app.py
CHANGED
@@ -6,26 +6,30 @@ import kornia.feature as KF
|
|
6 |
import torch
|
7 |
import numpy as np
|
8 |
|
9 |
-
def
|
10 |
-
# Convert numpy
|
11 |
-
|
12 |
-
|
13 |
|
14 |
-
# Ensure 3D
|
15 |
-
if
|
16 |
-
|
17 |
-
if img_2.ndim == 2:
|
18 |
-
img_2 = img_2.unsqueeze(0)
|
19 |
|
20 |
-
# Ensure 3 channel
|
21 |
-
if
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
|
26 |
# Add batch dimension
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
IS = ImageStitcher(KF.LoFTR(pretrained='outdoor'), estimator='ransac')
|
31 |
with torch.no_grad():
|
|
|
6 |
import torch
|
7 |
import numpy as np
|
8 |
|
9 |
+
def preprocess_image(img):
|
10 |
+
# Convert numpy array to Tensor and ensure correct shape
|
11 |
+
if isinstance(img, np.ndarray):
|
12 |
+
img = K.image_to_tensor(img, keepdim=False).float() / 255.0
|
13 |
|
14 |
+
# Ensure 3D tensor (C, H, W)
|
15 |
+
if img.ndim == 2:
|
16 |
+
img = img.unsqueeze(0)
|
|
|
|
|
17 |
|
18 |
+
# Ensure 3 channel image
|
19 |
+
if img.shape[0] == 1:
|
20 |
+
img = img.repeat(3, 1, 1)
|
21 |
+
elif img.shape[0] > 3:
|
22 |
+
img = img[:3] # Take only the first 3 channels if more than 3
|
23 |
|
24 |
# Add batch dimension
|
25 |
+
img = img.unsqueeze(0)
|
26 |
+
|
27 |
+
return img
|
28 |
+
|
29 |
+
def inference(img_1, img_2):
|
30 |
+
# Preprocess images
|
31 |
+
img_1 = preprocess_image(img_1)
|
32 |
+
img_2 = preprocess_image(img_2)
|
33 |
|
34 |
IS = ImageStitcher(KF.LoFTR(pretrained='outdoor'), estimator='ransac')
|
35 |
with torch.no_grad():
|