Spaces:
Running
Running
''' | |
from transformers import pipeline | |
import cv2 | |
object_detector = pipeline("object-detection", model="facebook/detr-resnet-50") | |
def detect_objects(image_path): | |
image = cv2.imread(image_path) | |
results = object_detector(image) | |
return [r for r in results if r['score'] > 0.7] | |
''' | |
# services/detection_service.py | |
from transformers import pipeline | |
from PIL import Image | |
# β Load Hugging Face DETR pipeline properly | |
object_detector = pipeline("object-detection", model="facebook/detr-resnet-50") | |
def detect_objects(image_path): | |
""" | |
Detect objects using Hugging Face DETR pipeline. | |
- Accepts a file path to a local image. | |
- Converts image to PIL format. | |
- Feeds into Hugging Face detector. | |
- Returns list of high-confidence detections. | |
""" | |
# β Correct way: Open image properly | |
image = Image.open(image_path).convert("RGB") | |
# β Run inference | |
results = object_detector(image) | |
# β Return only high-confidence detections | |
return [r for r in results if r['score'] > 0.7] | |