Download detectObjects.py from krishanwalia30/Extract_Objects_From_Images: direct link, hf CLI and curl.
- Browser
- Download file 389 Bytes
-
https://huggingface.co/krishanwalia30/Extract_Objects_From_Images/resolve/main/detectObjects.py
- Command line
-
hf download hf://krishanwalia30/Extract_Objects_From_Images/detectObjects.py
-
curl -L -o detectObjects.py https://huggingface.co/krishanwalia30/Extract_Objects_From_Images/resolve/main/detectObjects.py
389 Bytes
| import ultralytics | |
| from ultralytics import YOLO | |
| model = YOLO('yolov8n.pt') | |
| def detected_objects(filename:str): | |
| results = model.predict(source=filename, conf=0.25) | |
| categories = results[0].names | |
| dc = [] | |
| for i in range(len(results[0])): | |
| cat = results[0].boxes[i].cls | |
| dc.append(categories[int(cat)]) | |
| print(dc) | |
| return results, dc | |