Spaces:
Sleeping
Sleeping
Download yolo_detect.py from shkumar156/Backend-Object-Detection: direct link, hf CLI and curl.
- Browser
- Download file 620 Bytes
-
https://huggingface.co/spaces/shkumar156/Backend-Object-Detection/resolve/main/yolo_detect.py
- Command line
-
hf download hf://spaces/shkumar156/Backend-Object-Detection/yolo_detect.py
-
curl -L -o yolo_detect.py https://huggingface.co/spaces/shkumar156/Backend-Object-Detection/resolve/main/yolo_detect.py
620 Bytes
| import sys | |
| from ultralytics import YOLO | |
| from pathlib import Path | |
| if len(sys.argv) < 3: | |
| print("Usage: python yolo_detect.py <weights_path> <image_path>") | |
| sys.exit(1) | |
| weights_path = sys.argv[1] | |
| image_path = sys.argv[2] | |
| print("Using weights file:", weights_path) | |
| model = YOLO(weights_path) | |
| # Use /data/runs/detect as the project directory (writable in Hugging Face Spaces) | |
| results = model(image_path, save=True, project='/data/runs/detect', exist_ok=True) | |
| # Print the path to the saved image | |
| for r in results: | |
| for path in Path(r.save_dir).glob("*"): | |
| if path.is_file(): | |
| print(str(path)) |