David Ko commited on
Commit
44253a0
ยท
1 Parent(s): e821ec3

Fix: YOLOv8 model download permission issues using temp directory

Browse files
Files changed (1) hide show
  1. api.py +26 -5
api.py CHANGED
@@ -23,14 +23,35 @@ try:
23
  import os
24
  from ultralytics import YOLO
25
 
26
- # ๋ชจ๋ธ ํŒŒ์ผ ๊ฒฝ๋กœ
27
- model_path = "yolov8n.pt"
 
 
28
 
29
  # ๋ชจ๋ธ ํŒŒ์ผ์ด ์—†์œผ๋ฉด ์ง์ ‘ ๋‹ค์šด๋กœ๋“œ
30
  if not os.path.exists(model_path):
31
- print("Downloading YOLOv8 model...")
32
- os.system("wget -q https://ultralytics.com/assets/yolov8n.pt -O yolov8n.pt")
33
- print("YOLOv8 model downloaded successfully")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  yolo_model = YOLO(model_path) # Using the nano model for faster inference
36
  print("YOLOv8 model loaded successfully")
 
23
  import os
24
  from ultralytics import YOLO
25
 
26
+ # ๋ชจ๋ธ ํŒŒ์ผ ๊ฒฝ๋กœ - ์ž„์‹œ ๋””๋ ‰ํ† ๋ฆฌ ์‚ฌ์šฉ
27
+ import tempfile
28
+ temp_dir = tempfile.gettempdir()
29
+ model_path = os.path.join(temp_dir, "yolov8n.pt")
30
 
31
  # ๋ชจ๋ธ ํŒŒ์ผ์ด ์—†์œผ๋ฉด ์ง์ ‘ ๋‹ค์šด๋กœ๋“œ
32
  if not os.path.exists(model_path):
33
+ print(f"Downloading YOLOv8 model to {model_path}...")
34
+ try:
35
+ os.system(f"wget -q https://ultralytics.com/assets/yolov8n.pt -O {model_path}")
36
+ print("YOLOv8 model downloaded successfully")
37
+ except Exception as e:
38
+ print(f"Error downloading YOLOv8 model: {e}")
39
+ # ๋‹ค์šด๋กœ๋“œ ์‹คํŒจ ์‹œ ๋Œ€์ฒด URL ์‹œ๋„
40
+ try:
41
+ os.system(f"wget -q https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt -O {model_path}")
42
+ print("YOLOv8 model downloaded from alternative source")
43
+ except Exception as e2:
44
+ print(f"Error downloading from alternative source: {e2}")
45
+ # ๋งˆ์ง€๋ง‰ ๋Œ€์•ˆ์œผ๋กœ ์ง์ ‘ ๋ชจ๋ธ URL ์‚ฌ์šฉ
46
+ try:
47
+ os.system(f"curl -L https://ultralytics.com/assets/yolov8n.pt --output {model_path}")
48
+ print("YOLOv8 model downloaded using curl")
49
+ except Exception as e3:
50
+ print(f"All download attempts failed: {e3}")
51
+
52
+ # ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์„ค์ • - ์„ค์ • ํŒŒ์ผ ๊ฒฝ๋กœ ์ง€์ •
53
+ os.environ["YOLO_CONFIG_DIR"] = temp_dir
54
+ os.environ["MPLCONFIGDIR"] = temp_dir
55
 
56
  yolo_model = YOLO(model_path) # Using the nano model for faster inference
57
  print("YOLOv8 model loaded successfully")