Simon9 commited on
Commit
6ebf14b
·
verified ·
1 Parent(s): 0901d81

Upload inference.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. inference.py +47 -0
inference.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Football Field Detection Model - Roboflow Inference Wrapper
3
+ """
4
+
5
+ from inference import get_model
6
+ import os
7
+
8
+ class FootballFieldDetector:
9
+ """Wrapper for Roboflow football field keypoint detection model"""
10
+
11
+ def __init__(self, api_key: str):
12
+ """
13
+ Initialize the field detection model
14
+
15
+ Args:
16
+ api_key: Your Roboflow API key
17
+ """
18
+ self.model_id = "football-field-detection-f07vi/14"
19
+ self.model = get_model(model_id=self.model_id, api_key=api_key)
20
+
21
+ def predict(self, image, confidence: float = 0.3):
22
+ """
23
+ Detect field keypoints
24
+
25
+ Args:
26
+ image: Image as numpy array or path to image
27
+ confidence: Confidence threshold (0.0-1.0)
28
+
29
+ Returns:
30
+ Keypoint detection results
31
+ """
32
+ result = self.model.infer(image, confidence=confidence)[0]
33
+ return result
34
+
35
+ # Example usage:
36
+ if __name__ == "__main__":
37
+ import os
38
+
39
+ # Set your API key
40
+ api_key = os.getenv("ROBOFLOW_API_KEY")
41
+
42
+ # Initialize detector
43
+ detector = FootballFieldDetector(api_key=api_key)
44
+
45
+ # Run inference
46
+ results = detector.predict("path/to/image.jpg", confidence=0.3)
47
+ print(f"Detected keypoints: {results}")