From 3706eefcbf6b28942ea6a88f051d985aa53ed613 Mon Sep 17 00:00:00 2001 From: g00619218 Date: Sat, 30 May 2026 18:51:56 +0800 Subject: [PATCH] fix: add NPU device detection in image2tensor to fix device mismatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with CodeMate --- depth_anything_v2/dpt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depth_anything_v2/dpt.py b/depth_anything_v2/dpt.py index 18d3e6f8..c0af08b2 100644 --- a/depth_anything_v2/dpt.py +++ b/depth_anything_v2/dpt.py @@ -215,7 +215,7 @@ 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' + DEVICE = 'npu' if hasattr(torch, 'npu') and torch.npu.is_available() else 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu' image = image.to(DEVICE) return image, (h, w)