Simon9's picture
Upload inference.py with huggingface_hub
6ebf14b verified
"""
Football Field Detection Model - Roboflow Inference Wrapper
"""
from inference import get_model
import os
class FootballFieldDetector:
"""Wrapper for Roboflow football field keypoint detection model"""
def __init__(self, api_key: str):
"""
Initialize the field detection model
Args:
api_key: Your Roboflow API key
"""
self.model_id = "football-field-detection-f07vi/14"
self.model = get_model(model_id=self.model_id, api_key=api_key)
def predict(self, image, confidence: float = 0.3):
"""
Detect field keypoints
Args:
image: Image as numpy array or path to image
confidence: Confidence threshold (0.0-1.0)
Returns:
Keypoint detection results
"""
result = self.model.infer(image, confidence=confidence)[0]
return result
# Example usage:
if __name__ == "__main__":
import os
# Set your API key
api_key = os.getenv("ROBOFLOW_API_KEY")
# Initialize detector
detector = FootballFieldDetector(api_key=api_key)
# Run inference
results = detector.predict("path/to/image.jpg", confidence=0.3)
print(f"Detected keypoints: {results}")