File size: 712 Bytes
111eec1
 
 
 
 
 
 
 
 
 
 
 
92f9a27
 
 
 
7767f20
 
 
 
92f9a27
7767f20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# scripts/download_yolov8_model.py
from ultralytics import YOLO
import os

# Directory to save the model
MODEL_DIR = "models"
os.makedirs(MODEL_DIR, exist_ok=True)

# Path to save the model
MODEL_PATH = os.path.join(MODEL_DIR, "yolov8_model.pt")

# Download pre-trained YOLOv8 nano model
try:
    model = YOLO("yolov8n.pt")  # Automatically downloads from Ultralytics
    model.save(MODEL_PATH)
    print(f"Model saved to {MODEL_PATH}")
    # Verify file integrity
    import torch
    checkpoint = torch.load(MODEL_PATH, map_location='cpu', weights_only=False)
    print(f"Model file verified as valid PyTorch checkpoint")
except Exception as e:
    print(f"Failed to download, save, or verify model: {str(e)}")