Files
operating-room-monitor-server/backend/app/algorithm_runner/infer_util.py
Kevin 1af442481e 重组为 backend/clients/docs 三层结构,并清理 git 污染。
将后端迁入 backend/,完善根目录 .gitignore,删除误提交的 .mypy_cache 缓存文件。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-21 16:02:25 +08:00

29 lines
829 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Torch 设备选择、类名归一化(子进程与 actionformer_gated 共用)。"""
from __future__ import annotations
import sys
def norm_product_name(name: str) -> str:
s = (name or "").strip()
if s == "一次性医用垫单":
return "一次性使用手术单(一次性医用垫单)"
return s
def resolve_inference_device(explicit: str) -> str | None:
configured = (explicit or "").strip()
if configured:
return configured
try:
import torch
except Exception:
return None
# 有 NVIDIA 时始终优先 CUDA含 Linux / 少数非 Mac 环境Mac 无可用 CUDA 时再试 MPS。
if torch.cuda.is_available():
return "cuda:0"
if sys.platform == "darwin" and torch.backends.mps.is_available():
return "mps"
return None