fix: add PyTorch fix scripts and make torch import optional
- Add fix_pytorch.bat for Windows users to repair PyTorch installation - Add verify_vision.py to check and auto-fix vision dependencies - Make torch import optional in game_vision_ai.py to prevent crashes - Provides graceful fallback if PyTorch fails to load
This commit is contained in:
parent
92558d3e49
commit
b9ff965185
|
|
@ -0,0 +1,44 @@
|
||||||
|
@echo off
|
||||||
|
REM Fix PyTorch Installation for Lemontropia Suite
|
||||||
|
REM Run this as Administrator
|
||||||
|
|
||||||
|
echo ==========================================
|
||||||
|
echo Fixing PyTorch for Computer Vision
|
||||||
|
echo ==========================================
|
||||||
|
echo.
|
||||||
|
|
||||||
|
REM Step 1: Uninstall broken packages
|
||||||
|
echo [1/4] Uninstalling broken PyTorch packages...
|
||||||
|
pip uninstall -y torch torchvision torchaudio paddlepaddle-gpu paddlepaddle paddleocr 2>nul
|
||||||
|
|
||||||
|
REM Step 2: Clean pip cache
|
||||||
|
echo [2/4] Cleaning pip cache...
|
||||||
|
pip cache purge 2>nul
|
||||||
|
|
||||||
|
REM Step 3: Install CPU-only PyTorch (most stable on Windows Store Python)
|
||||||
|
echo [3/4] Installing CPU-only PyTorch (stable version)...
|
||||||
|
pip install torch==2.1.2 torchvision==0.16.2 --index-url https://download.pytorch.org/whl/cpu
|
||||||
|
|
||||||
|
REM Step 4: Install PaddleOCR (CPU version)
|
||||||
|
echo [4/4] Installing PaddleOCR...
|
||||||
|
pip install paddlepaddle==2.5.2
|
||||||
|
pip install paddleocr==2.7.0.3
|
||||||
|
|
||||||
|
REM Step 5: Verify installation
|
||||||
|
echo.
|
||||||
|
echo ==========================================
|
||||||
|
echo Verifying installation...
|
||||||
|
echo ==========================================
|
||||||
|
python -c "import torch; print(f'PyTorch: {torch.__version__}')"
|
||||||
|
python -c "import torch; print(f'CUDA available: {torch.cuda.is_available()}')"
|
||||||
|
python -c "from paddleocr import PaddleOCR; print('PaddleOCR: OK')"
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ==========================================
|
||||||
|
echo Installation Complete!
|
||||||
|
echo ==========================================
|
||||||
|
echo.
|
||||||
|
echo If you see errors above, try running:
|
||||||
|
echo pip install --upgrade pip setuptools wheel
|
||||||
|
@echo Then run this script again.
|
||||||
|
@pause
|
||||||
|
|
@ -7,7 +7,6 @@ Supports OCR (PaddleOCR) and icon detection for game UI analysis.
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import logging
|
import logging
|
||||||
import torch
|
|
||||||
import time
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
@ -18,6 +17,15 @@ import hashlib
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# Optional PyTorch import with fallback
|
||||||
|
try:
|
||||||
|
import torch
|
||||||
|
TORCH_AVAILABLE = True
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"PyTorch not available: {e}")
|
||||||
|
TORCH_AVAILABLE = False
|
||||||
|
torch = None
|
||||||
|
|
||||||
|
|
||||||
class GPUBackend(Enum):
|
class GPUBackend(Enum):
|
||||||
"""Supported GPU backends."""
|
"""Supported GPU backends."""
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
"""
|
||||||
|
Verify and fix Computer Vision dependencies
|
||||||
|
"""
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def check_torch():
|
||||||
|
"""Check PyTorch installation."""
|
||||||
|
try:
|
||||||
|
import torch
|
||||||
|
print(f"✅ PyTorch {torch.__version__} installed")
|
||||||
|
print(f" CUDA available: {torch.cuda.is_available()}")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ PyTorch error: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def check_paddle():
|
||||||
|
"""Check PaddlePaddle installation."""
|
||||||
|
try:
|
||||||
|
import paddle
|
||||||
|
print(f"✅ PaddlePaddle {paddle.__version__} installed")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ PaddlePaddle error: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def check_paddleocr():
|
||||||
|
"""Check PaddleOCR installation."""
|
||||||
|
try:
|
||||||
|
from paddleocr import PaddleOCR
|
||||||
|
print(f"✅ PaddleOCR installed")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ PaddleOCR error: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def check_opencv():
|
||||||
|
"""Check OpenCV installation."""
|
||||||
|
try:
|
||||||
|
import cv2
|
||||||
|
print(f"✅ OpenCV {cv2.__version__} installed")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ OpenCV error: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def install_fix():
|
||||||
|
"""Install working versions."""
|
||||||
|
print("\n🔧 Installing fixed versions...")
|
||||||
|
|
||||||
|
packages = [
|
||||||
|
"torch==2.1.2",
|
||||||
|
"torchvision==0.16.2",
|
||||||
|
"--index-url", "https://download.pytorch.org/whl/cpu"
|
||||||
|
]
|
||||||
|
|
||||||
|
print("Installing PyTorch CPU version...")
|
||||||
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "--force-reinstall"] + packages)
|
||||||
|
|
||||||
|
print("Installing PaddlePaddle...")
|
||||||
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "--force-reinstall", "paddlepaddle==2.5.2"])
|
||||||
|
|
||||||
|
print("Installing PaddleOCR...")
|
||||||
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "--force-reinstall", "paddleocr==2.7.0.3"])
|
||||||
|
|
||||||
|
print("\n✅ Installation complete!")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("=" * 50)
|
||||||
|
print("Computer Vision Dependency Check")
|
||||||
|
print("=" * 50)
|
||||||
|
print()
|
||||||
|
|
||||||
|
all_ok = True
|
||||||
|
all_ok &= check_torch()
|
||||||
|
all_ok &= check_paddle()
|
||||||
|
all_ok &= check_paddleocr()
|
||||||
|
all_ok &= check_opencv()
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("=" * 50)
|
||||||
|
|
||||||
|
if all_ok:
|
||||||
|
print("✅ All dependencies OK! Computer Vision should work.")
|
||||||
|
else:
|
||||||
|
print("❌ Some dependencies missing or broken.")
|
||||||
|
response = input("\nWould you like to auto-fix? (y/n): ")
|
||||||
|
if response.lower() == 'y':
|
||||||
|
install_fix()
|
||||||
|
print("\nPlease restart the app.")
|
||||||
|
else:
|
||||||
|
print("\nManual fix instructions:")
|
||||||
|
print("1. pip uninstall torch torchvision paddlepaddle paddleocr")
|
||||||
|
print("2. pip install torch==2.1.2 torchvision==0.16.2 --index-url https://download.pytorch.org/whl/cpu")
|
||||||
|
print("3. pip install paddlepaddle==2.5.2 paddleocr==2.7.0.3")
|
||||||
|
|
||||||
|
print()
|
||||||
|
input("Press Enter to exit...")
|
||||||
Loading…
Reference in New Issue