From f7bc7fcae34caa69637245e6e2ae3e8572db435e Mon Sep 17 00:00:00 2001 From: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com> Date: Wed, 11 Feb 2026 23:47:02 +0530 Subject: [PATCH] fix: use model device instead of hardcoded device detection in preprocessing --- depth_anything_v2/dpt.py | 3 +-- metric_depth/depth_anything_v2/dpt.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/depth_anything_v2/dpt.py b/depth_anything_v2/dpt.py index 18d3e6f..c44b535 100644 --- a/depth_anything_v2/dpt.py +++ b/depth_anything_v2/dpt.py @@ -215,7 +215,6 @@ def image2tensor(self, raw_image, input_size=518): image = transform({'image': image})['image'] image = torch.from_numpy(image).unsqueeze(0) - DEVICE = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu' - image = image.to(DEVICE) + image = image.to(next(self.parameters()).device) return image, (h, w) diff --git a/metric_depth/depth_anything_v2/dpt.py b/metric_depth/depth_anything_v2/dpt.py index 6541304..9918b93 100644 --- a/metric_depth/depth_anything_v2/dpt.py +++ b/metric_depth/depth_anything_v2/dpt.py @@ -216,7 +216,6 @@ def image2tensor(self, raw_image, input_size=518): image = transform({'image': image})['image'] image = torch.from_numpy(image).unsqueeze(0) - DEVICE = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu' - image = image.to(DEVICE) + image = image.to(next(self.parameters()).device) return image, (h, w)