XciD HF Staff commited on
Commit
7c12218
·
unverified ·
1 Parent(s): 03fed12

fix: cast inputs to float16 to match model dtype

Browse files
Files changed (1) hide show
  1. app.py +2 -2
app.py CHANGED
@@ -40,7 +40,7 @@ def predict(image):
40
 
41
  # Segmentation
42
  seg_inputs = seg_processor(images=image_resized, task_inputs=["semantic"], return_tensors="pt")
43
- seg_inputs = {k: v.to(device) for k, v in seg_inputs.items()}
44
 
45
  seg_outputs = seg_model(**seg_inputs)
46
  seg_result = seg_processor.post_process_semantic_segmentation(
@@ -56,7 +56,7 @@ def predict(image):
56
 
57
  # Depth estimation
58
  depth_inputs = depth_processor(images=image_resized, return_tensors="pt")
59
- depth_inputs = {k: v.to(device) for k, v in depth_inputs.items()}
60
 
61
  depth_outputs = depth_model(**depth_inputs)
62
  depth_map = depth_outputs.predicted_depth.squeeze().cpu().numpy()
 
40
 
41
  # Segmentation
42
  seg_inputs = seg_processor(images=image_resized, task_inputs=["semantic"], return_tensors="pt")
43
+ seg_inputs = {k: v.to(device, dtype=torch.float16) if v.is_floating_point() else v.to(device) for k, v in seg_inputs.items()}
44
 
45
  seg_outputs = seg_model(**seg_inputs)
46
  seg_result = seg_processor.post_process_semantic_segmentation(
 
56
 
57
  # Depth estimation
58
  depth_inputs = depth_processor(images=image_resized, return_tensors="pt")
59
+ depth_inputs = {k: v.to(device, dtype=torch.float16) if v.is_floating_point() else v.to(device) for k, v in depth_inputs.items()}
60
 
61
  depth_outputs = depth_model(**depth_inputs)
62
  depth_map = depth_outputs.predicted_depth.squeeze().cpu().numpy()