Update app.py
Browse files
app.py
CHANGED
@@ -26,26 +26,21 @@ async def analyze_path(file: UploadFile = File(...)):
|
|
26 |
image_bytes = await file.read()
|
27 |
image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
|
28 |
|
29 |
-
# 🟢 Chuyển ảnh sang NumPy để lật đúng chiều
|
30 |
-
image_np = np.array(image)
|
31 |
-
|
32 |
# 🟢 Lật ảnh trước khi tính toán Depth Map
|
|
|
33 |
flipped_image = cv2.flip(image_np, -1)
|
34 |
-
|
35 |
-
# 🟢 Chuyển đổi lại thành ảnh PIL để đưa vào MiDaS
|
36 |
-
flipped_image_pil = Image.fromarray(flipped_image)
|
37 |
|
38 |
# 🟢 Chuyển đổi ảnh thành tensor phù hợp với MiDaS
|
39 |
-
|
40 |
|
41 |
# 🟢 Bắt đầu đo thời gian dự đoán Depth Map
|
42 |
start_time = time.time()
|
43 |
|
44 |
# 🟢 Dự đoán Depth Map với MiDaS
|
45 |
with torch.no_grad():
|
46 |
-
depth_map = model(
|
47 |
depth_map = torch.nn.functional.interpolate(
|
48 |
-
depth_map.unsqueeze(1), size=
|
49 |
).squeeze().cpu().numpy()
|
50 |
|
51 |
end_time = time.time()
|
|
|
26 |
image_bytes = await file.read()
|
27 |
image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
|
28 |
|
|
|
|
|
|
|
29 |
# 🟢 Lật ảnh trước khi tính toán Depth Map
|
30 |
+
image_np = np.array(image)
|
31 |
flipped_image = cv2.flip(image_np, -1)
|
|
|
|
|
|
|
32 |
|
33 |
# 🟢 Chuyển đổi ảnh thành tensor phù hợp với MiDaS
|
34 |
+
flipped_image_tensor = transform(flipped_image).to(device)
|
35 |
|
36 |
# 🟢 Bắt đầu đo thời gian dự đoán Depth Map
|
37 |
start_time = time.time()
|
38 |
|
39 |
# 🟢 Dự đoán Depth Map với MiDaS
|
40 |
with torch.no_grad():
|
41 |
+
depth_map = model(flipped_image_tensor)
|
42 |
depth_map = torch.nn.functional.interpolate(
|
43 |
+
depth_map.unsqueeze(1), size=(image_np.shape[0], image_np.shape[1]), mode="bicubic", align_corners=False
|
44 |
).squeeze().cpu().numpy()
|
45 |
|
46 |
end_time = time.time()
|