Martin Tomov commited on
Commit
386f67c
1 Parent(s): e1ab1fa

cv2.rectangle() method v2

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -25,6 +25,7 @@ class BoundingBox:
25
  @property
26
  def xyxy(self) -> List[float]:
27
  return [self.xmin, self.ymin, self.xmax, self.ymax]
 
28
  @dataclass
29
  class DetectionResult:
30
  score: float
@@ -112,7 +113,7 @@ def refine_masks(masks: torch.BoolTensor, polygon_refinement: bool = False) -> L
112
  return list(masks)
113
 
114
  @spaces.GPU
115
- def detect(image: Image.Image, labels: List[str], threshold: float = 0.3, detector_id: Optional[str] = None) -> List<Dict[str, Any]]:
116
  detector_id = detector_id if detector_id else "IDEA-Research/grounding-dino-base"
117
  object_detector = pipeline(model=detector_id, task="zero-shot-object-detection", device="cuda")
118
  labels = [label if label.endswith(".") else label+"." for label in labels]
@@ -165,7 +166,7 @@ def create_yellow_background_with_insects(image: np.ndarray, detections: List[De
165
  yellow_background = cv2.cvtColor(yellow_background, cv2.COLOR_BGR2RGB)
166
  return yellow_background
167
 
168
- def run_length_encoding(mask):
169
  pixels = mask.flatten()
170
  rle = []
171
  last_val = 0
@@ -182,7 +183,7 @@ def run_length_encoding(mask):
182
  rle.append(count)
183
  return rle
184
 
185
- def detections_to_json(detections):
186
  detections_list = []
187
  for detection in detections:
188
  detection_dict = {
 
25
  @property
26
  def xyxy(self) -> List[float]:
27
  return [self.xmin, self.ymin, self.xmax, self.ymax]
28
+
29
  @dataclass
30
  class DetectionResult:
31
  score: float
 
113
  return list(masks)
114
 
115
  @spaces.GPU
116
+ def detect(image: Image.Image, labels: List[str], threshold: float = 0.3, detector_id: Optional[str] = None) -> List[DetectionResult]:
117
  detector_id = detector_id if detector_id else "IDEA-Research/grounding-dino-base"
118
  object_detector = pipeline(model=detector_id, task="zero-shot-object-detection", device="cuda")
119
  labels = [label if label.endswith(".") else label+"." for label in labels]
 
166
  yellow_background = cv2.cvtColor(yellow_background, cv2.COLOR_BGR2RGB)
167
  return yellow_background
168
 
169
+ def run_length_encoding(mask: np.ndarray) -> List[int]:
170
  pixels = mask.flatten()
171
  rle = []
172
  last_val = 0
 
183
  rle.append(count)
184
  return rle
185
 
186
+ def detections_to_json(detections: List[DetectionResult]) -> List[Dict[str, Any]]:
187
  detections_list = []
188
  for detection in detections:
189
  detection_dict = {