Files
CodexandClaude Opus 4.5 a19fa35a0f chore: 整理 tools/ 47 个脚本按功能分组
- diagnostics/ 11 个:环境/配置/依赖诊断
- logs/ 7 个:日志分析与查看
- coords/ 6 个:坐标拾取与区域选择
- cleanup/ 3 个:代码清理工具
- adb/ 2 个:ADB / 输入法相关
- windows/ 4 个:Windows 系统修复(备份)
- dev/ 9 个:开发辅助 / 运行时探测

并更新 tools/README.md 描述新结构。
删除 3 个明显的临时调试脚本 (_dump_lines.py / tmp_*.py)。

tools/ 不被业务代码 import,分组仅为人工浏览方便。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-05-20 23:25:28 +08:00

209 lines
6.7 KiB
Python
Raw Permalink 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.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
检查GPU是否可用的脚本
"""
import sys
# 修复Windows控制台编码问题
if sys.platform == "win32":
try:
reconfigure_func = getattr(sys.stdout, 'reconfigure', None)
if reconfigure_func:
reconfigure_func(encoding="utf-8")
except Exception:
pass
def check_torch_cuda():
"""检查PyTorch是否支持CUDA"""
try:
try:
import torch # type: ignore # pylint: disable=import-error
except ImportError:
print("[GPU检测] PyTorch未安装")
return False
if torch.cuda.is_available():
print(f"[GPU检测] PyTorch CUDA可用")
print(f" CUDA版本: {torch.version.cuda}")
print(f" GPU数量: {torch.cuda.device_count()}")
for i in range(torch.cuda.device_count()):
print(f" GPU {i}: {torch.cuda.get_device_name(i)}")
return True
else:
print("[GPU检测] PyTorch CUDA不可用")
return False
except Exception as e:
print(f"[GPU检测] PyTorch CUDA检测失败: {e}")
return False
def check_easyocr_gpu():
"""检查EasyOCR是否可以使用GPU"""
try:
try:
import easyocr # type: ignore # pylint: disable=import-error
except ImportError:
print("[GPU检测] EasyOCR未安装")
return False
print("[GPU检测] EasyOCR已安装")
# EasyOCR使用PyTorch,所以需要PyTorch支持CUDA
try:
import torch # type: ignore
if torch.cuda.is_available():
print("[GPU检测] EasyOCR可以使用GPU(通过PyTorch CUDA)")
return True
else:
print("[GPU检测] EasyOCR无法使用GPU(PyTorch CUDA不可用)")
return False
except ImportError:
print("[GPU检测] EasyOCR需要PyTorch才能使用GPU")
return False
except ImportError:
print("[GPU检测] EasyOCR未安装")
return False
except Exception as e:
print(f"[GPU检测] EasyOCR GPU检测失败: {e}")
return False
def check_paddleocr_gpu():
"""检查PaddleOCR是否可以使用GPU"""
try:
print("[GPU检测] PaddleOCR已安装")
# PaddleOCR需要paddlepaddle-gpu版本
try:
try:
import paddle # type: ignore # pylint: disable=import-error
except ImportError:
print("[GPU检测] PaddleOCR未安装(paddle不可用)")
return False
if paddle.device.is_compiled_with_cuda():
print("[GPU检测] PaddleOCR可以使用GPU(paddlepaddle-gpu已安装)")
if paddle.device.get_device():
print(f" Paddle设备: {paddle.device.get_device()}")
return True
else:
print("[GPU检测] PaddleOCR无法使用GPU(需要安装paddlepaddle-gpu)")
return False
except ImportError:
print("[GPU检测] PaddleOCR需要paddlepaddle才能使用GPU")
return False
except ImportError:
print("[GPU检测] PaddleOCR未安装")
return False
except Exception as e:
print(f"[GPU检测] PaddleOCR GPU检测失败: {e}")
return False
def check_integrated_graphics():
"""检查是否是集成显卡(核显)"""
try:
try:
import torch # type: ignore # pylint: disable=import-error
except ImportError:
return False
if torch.cuda.is_available():
for i in range(torch.cuda.device_count()):
gpu_name = torch.cuda.get_device_name(i).lower()
# 常见的核显标识
integrated_keywords = [
"intel",
"iris",
"uhd",
"hd graphics",
"amd",
"radeon vega",
"radeon graphics",
]
is_integrated = any(
keyword in gpu_name for keyword in integrated_keywords
)
if is_integrated:
print(
f"[GPU检测] 检测到可能是集成显卡: {torch.cuda.get_device_name(i)}"
)
print("[GPU检测] 警告:集成显卡的GPU加速效果可能不明显")
return True
except Exception:
pass
return False
def main():
"""主函数"""
print("=" * 60)
print("GPU可用性检测")
print("=" * 60)
print()
# 检查PyTorch CUDA
print("[1] 检查PyTorch CUDA支持")
torch_cuda_available = check_torch_cuda()
print()
# 检查是否是核显
is_integrated = False # 初始化,避免未绑定错误
if torch_cuda_available:
print("[2] 检查显卡类型")
is_integrated = check_integrated_graphics()
print()
# 检查EasyOCR GPU支持
print("[3] 检查EasyOCR GPU支持")
easyocr_gpu_available = check_easyocr_gpu()
print()
# 检查PaddleOCR GPU支持
print("[4] 检查PaddleOCR GPU支持")
paddleocr_gpu_available = check_paddleocr_gpu()
print()
# 总结
print("=" * 60)
print("检测结果总结")
print("=" * 60)
if torch_cuda_available:
print("[OK] PyTorch CUDA可用")
if is_integrated:
print("[WARN] 检测到集成显卡,GPU加速效果可能有限")
else:
print("[OK] 检测到独立显卡,GPU加速效果较好")
else:
print("[NO] PyTorch CUDA不可用(将使用CPU模式)")
if easyocr_gpu_available:
print("[OK] EasyOCR可以使用GPU")
else:
print("[NO] EasyOCR无法使用GPU(将使用CPU模式)")
if paddleocr_gpu_available:
print("[OK] PaddleOCR可以使用GPU")
else:
print("[NO] PaddleOCR无法使用GPU(将使用CPU模式)")
print()
print("建议:")
if not torch_cuda_available:
print(" - 如果使用NVIDIA独立显卡,请安装CUDA和PyTorch GPU版本")
print(" - 如果使用集成显卡,GPU加速效果可能不明显,建议继续使用CPU模式")
elif is_integrated:
print(" - 集成显卡的GPU加速效果可能不明显")
print(" - 可以尝试启用GPU,但性能提升可能有限")
print(" - 如果遇到问题,建议继续使用CPU模式")
else:
print(" - 可以启用GPU加速以提升OCR性能")
print(" - 修改 Underlying_Operations.py 中的 gpu=False 为 gpu=True")
if __name__ == "__main__":
main()