Spaces:
Running on Zero
Running on Zero
Fixed errors
Browse files- app.py +11 -5
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -6,15 +6,19 @@ import torch
|
|
| 6 |
import gradio as gr
|
| 7 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 8 |
from fastapi.responses import Response
|
| 9 |
-
from transformers import
|
|
|
|
| 10 |
|
| 11 |
# 1. Initialize FastAPI & Load Apple Depth Pro
|
| 12 |
fastapi_app = FastAPI(title="True Metric ToF Server")
|
| 13 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 14 |
|
|
|
|
|
|
|
| 15 |
print("Loading Apple Depth Pro components...")
|
| 16 |
-
image_processor =
|
| 17 |
model = DepthProForDepthEstimation.from_pretrained("apple/DepthPro-hf").to(device)
|
|
|
|
| 18 |
model.eval()
|
| 19 |
print(f"Model successfully loaded on target device: {device}")
|
| 20 |
|
|
@@ -74,9 +78,11 @@ def create_3d_point_cloud(input_pil_image):
|
|
| 74 |
outputs = model(**inputs)
|
| 75 |
|
| 76 |
post_processed = image_processor.post_process_depth_estimation(
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
| 80 |
|
| 81 |
# Step B: Pinhole camera math projection (u, v, depth) -> (X, Y, Z)
|
| 82 |
height, width = depth_matrix.shape
|
|
|
|
| 6 |
import gradio as gr
|
| 7 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 8 |
from fastapi.responses import Response
|
| 9 |
+
from transformers import DepthProImageProcessor, DepthProForDepthEstimation
|
| 10 |
+
|
| 11 |
|
| 12 |
# 1. Initialize FastAPI & Load Apple Depth Pro
|
| 13 |
fastapi_app = FastAPI(title="True Metric ToF Server")
|
| 14 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 15 |
|
| 16 |
+
# Updated to avoid the transformers deprecation crash
|
| 17 |
+
|
| 18 |
print("Loading Apple Depth Pro components...")
|
| 19 |
+
image_processor = DepthProImageProcessor.from_pretrained("apple/DepthPro-hf")
|
| 20 |
model = DepthProForDepthEstimation.from_pretrained("apple/DepthPro-hf").to(device)
|
| 21 |
+
|
| 22 |
model.eval()
|
| 23 |
print(f"Model successfully loaded on target device: {device}")
|
| 24 |
|
|
|
|
| 78 |
outputs = model(**inputs)
|
| 79 |
|
| 80 |
post_processed = image_processor.post_process_depth_estimation(
|
| 81 |
+
outputs, target_sizes=[(image.height, image.width)],
|
| 82 |
+
)
|
| 83 |
+
# Your list index fix: grabbing the first dictionary element out of the post-processed array
|
| 84 |
+
depth_matrix = post_processed[0]["predicted_depth"].detach().cpu().numpy().astype(np.float32)
|
| 85 |
+
|
| 86 |
|
| 87 |
# Step B: Pinhole camera math projection (u, v, depth) -> (X, Y, Z)
|
| 88 |
height, width = depth_matrix.shape
|
requirements.txt
CHANGED
|
@@ -2,6 +2,7 @@ fastapi
|
|
| 2 |
uvicorn[standard]
|
| 3 |
python-multipart
|
| 4 |
torch --index-url https://pytorch.org
|
|
|
|
| 5 |
transformers
|
| 6 |
accelerate
|
| 7 |
numpy
|
|
|
|
| 2 |
uvicorn[standard]
|
| 3 |
python-multipart
|
| 4 |
torch --index-url https://pytorch.org
|
| 5 |
+
torchvision --index-url https://pytorch.org
|
| 6 |
transformers
|
| 7 |
accelerate
|
| 8 |
numpy
|