Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
#1
by
hysts
HF staff
- opened
app.py
CHANGED
@@ -12,8 +12,11 @@ import os
|
|
12 |
# Run the script to get pretrained models
|
13 |
subprocess.run(["bash", "get_pretrained_models.sh"])
|
14 |
|
|
|
|
|
15 |
# Load model and preprocessing transform
|
16 |
model, transform = depth_pro.create_model_and_transforms()
|
|
|
17 |
model.eval()
|
18 |
|
19 |
def resize_image(image_path, max_size=1024):
|
@@ -30,7 +33,7 @@ def resize_image(image_path, max_size=1024):
|
|
30 |
img.save(temp_file, format="PNG")
|
31 |
return temp_file.name
|
32 |
|
33 |
-
@spaces.GPU(duration=
|
34 |
def predict_depth(input_image):
|
35 |
temp_file = None
|
36 |
try:
|
@@ -42,6 +45,7 @@ def predict_depth(input_image):
|
|
42 |
image = result[0]
|
43 |
f_px = result[-1] # Assuming f_px is the last item in the returned tuple
|
44 |
image = transform(image)
|
|
|
45 |
|
46 |
# Run inference
|
47 |
prediction = model.infer(image, f_px=f_px)
|
|
|
12 |
# Run the script to get pretrained models
|
13 |
subprocess.run(["bash", "get_pretrained_models.sh"])
|
14 |
|
15 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
16 |
+
|
17 |
# Load model and preprocessing transform
|
18 |
model, transform = depth_pro.create_model_and_transforms()
|
19 |
+
model = model.to(device)
|
20 |
model.eval()
|
21 |
|
22 |
def resize_image(image_path, max_size=1024):
|
|
|
33 |
img.save(temp_file, format="PNG")
|
34 |
return temp_file.name
|
35 |
|
36 |
+
@spaces.GPU(duration=20)
|
37 |
def predict_depth(input_image):
|
38 |
temp_file = None
|
39 |
try:
|
|
|
45 |
image = result[0]
|
46 |
f_px = result[-1] # Assuming f_px is the last item in the returned tuple
|
47 |
image = transform(image)
|
48 |
+
image = image.to(device)
|
49 |
|
50 |
# Run inference
|
51 |
prediction = model.infer(image, f_px=f_px)
|