Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
mischeiwiller
commited on
Commit
•
bc3919a
1
Parent(s):
307c14f
Update app.py
Browse files
app.py
CHANGED
@@ -7,11 +7,25 @@ import torch
|
|
7 |
import numpy as np
|
8 |
|
9 |
def inference(img_1, img_2):
|
10 |
-
# Convert numpy arrays to Tensors
|
11 |
img_1: Tensor = K.image_to_tensor(img_1, keepdim=False).float() / 255.0
|
12 |
-
img_1 = img_1.unsqueeze(0) # Add batch dimension
|
13 |
img_2: Tensor = K.image_to_tensor(img_2, keepdim=False).float() / 255.0
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
IS = ImageStitcher(KF.LoFTR(pretrained='outdoor'), estimator='ransac')
|
17 |
with torch.no_grad():
|
|
|
7 |
import numpy as np
|
8 |
|
9 |
def inference(img_1, img_2):
|
10 |
+
# Convert numpy arrays to Tensors and ensure correct shape
|
11 |
img_1: Tensor = K.image_to_tensor(img_1, keepdim=False).float() / 255.0
|
|
|
12 |
img_2: Tensor = K.image_to_tensor(img_2, keepdim=False).float() / 255.0
|
13 |
+
|
14 |
+
# Ensure 3D tensors (C, H, W)
|
15 |
+
if img_1.ndim == 2:
|
16 |
+
img_1 = img_1.unsqueeze(0)
|
17 |
+
if img_2.ndim == 2:
|
18 |
+
img_2 = img_2.unsqueeze(0)
|
19 |
+
|
20 |
+
# Ensure 3 channel images
|
21 |
+
if img_1.shape[0] == 1:
|
22 |
+
img_1 = img_1.repeat(3, 1, 1)
|
23 |
+
if img_2.shape[0] == 1:
|
24 |
+
img_2 = img_2.repeat(3, 1, 1)
|
25 |
+
|
26 |
+
# Add batch dimension
|
27 |
+
img_1 = img_1.unsqueeze(0)
|
28 |
+
img_2 = img_2.unsqueeze(0)
|
29 |
|
30 |
IS = ImageStitcher(KF.LoFTR(pretrained='outdoor'), estimator='ransac')
|
31 |
with torch.no_grad():
|