ayousanz Claude commited on
Commit
88317fd
·
1 Parent(s): 805cd4d

Fix: auto-detect device for GPU/CPU fallback

Browse files

Use torch.cuda.is_available() to auto-detect device.
Falls back to CPU when GPU is not available.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -29,10 +29,13 @@ def detect(image, face_score_threshold, landmark_score_threshold):
29
  """Detect anime faces and landmarks in the image."""
30
  global detector
31
 
32
- # Lazy initialization on GPU
33
  if detector is None:
34
  from anime_face_detector import create_detector
35
- detector = create_detector('yolov3', device='cuda:0')
 
 
 
36
 
37
  # Convert RGB to BGR for OpenCV
38
  image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
 
29
  """Detect anime faces and landmarks in the image."""
30
  global detector
31
 
32
+ # Lazy initialization with auto device detection
33
  if detector is None:
34
  from anime_face_detector import create_detector
35
+ # Auto-detect device: use GPU if available, otherwise CPU
36
+ device = 'cuda:0' if torch.cuda.is_available() else 'cpu'
37
+ print(f'Using device: {device}')
38
+ detector = create_detector('yolov3', device=device)
39
 
40
  # Convert RGB to BGR for OpenCV
41
  image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)