ExStella commited on
Commit
1de5900
·
1 Parent(s): ea973df

torch for gpu usage

Browse files
Files changed (2) hide show
  1. app.py +2 -1
  2. requirements.txt +2 -1
app.py CHANGED
@@ -5,13 +5,14 @@ from huggingface_hub import snapshot_download
5
  import os
6
  import cv2
7
  import tempfile
 
8
 
9
  # Function to load YOLO model from a Hugging Face repository
10
  def load_model(repo_id):
11
  download_dir = snapshot_download(repo_id)
12
  print(f"Model downloaded to: {download_dir}")
13
  model_path = os.path.join(download_dir, "best.pt") # Ensure best.pt is present in the repository
14
- detection_model = YOLO(model_path, device='cuda')
15
  return detection_model
16
 
17
  # Load models for traffic cones and license plates
 
5
  import os
6
  import cv2
7
  import tempfile
8
+ import torch
9
 
10
  # Function to load YOLO model from a Hugging Face repository
11
  def load_model(repo_id):
12
  download_dir = snapshot_download(repo_id)
13
  print(f"Model downloaded to: {download_dir}")
14
  model_path = os.path.join(download_dir, "best.pt") # Ensure best.pt is present in the repository
15
+ detection_model = YOLO(model_path).to('cuda' if torch.cuda.is_available() else 'cpu') # Move model to appropriate device
16
  return detection_model
17
 
18
  # Load models for traffic cones and license plates
requirements.txt CHANGED
@@ -2,4 +2,5 @@ ultralytics
2
  gradio
3
  huggingface_hub
4
  Pillow
5
- opencv-python
 
 
2
  gradio
3
  huggingface_hub
4
  Pillow
5
+ opencv-python
6
+ torch