jiuface commited on
Commit
5197257
1 Parent(s): 6aa2176

sort mask from left to right

Browse files
app.py CHANGED
@@ -107,7 +107,8 @@ def process_image(image_input, image_url, task_prompt, text_prompt=None, dilate=
107
  (image_width, image_height) = image_input.size
108
  bboxes = detections.xyxy
109
  merge_mask_image = np.zeros((image_height, image_width), dtype=np.uint8)
110
-
 
111
  for bbox in bboxes:
112
  x1, y1, x2, y2 = map(int, bbox)
113
  cv2.rectangle(merge_mask_image, (x1, y1), (x2, y2), 255, thickness=cv2.FILLED)
 
107
  (image_width, image_height) = image_input.size
108
  bboxes = detections.xyxy
109
  merge_mask_image = np.zeros((image_height, image_width), dtype=np.uint8)
110
+ # sort from left to right
111
+ bboxes = sorted(bboxes, key=lambda bbox: bbox[0])
112
  for bbox in bboxes:
113
  x1, y1, x2, y2 = map(int, bbox)
114
  cv2.rectangle(merge_mask_image, (x1, y1), (x2, y2), 255, thickness=cv2.FILLED)
utils/__pycache__/florence.cpython-310.pyc CHANGED
Binary files a/utils/__pycache__/florence.cpython-310.pyc and b/utils/__pycache__/florence.cpython-310.pyc differ
 
utils/__pycache__/sam.cpython-310.pyc CHANGED
Binary files a/utils/__pycache__/sam.cpython-310.pyc and b/utils/__pycache__/sam.cpython-310.pyc differ
 
utils/florence.py CHANGED
@@ -49,6 +49,7 @@ def run_florence_inference(
49
  else:
50
  prompt = task
51
  inputs = processor(text=prompt, images=image, return_tensors="pt").to(device)
 
52
  generated_ids = model.generate(
53
  input_ids=inputs["input_ids"],
54
  pixel_values=inputs["pixel_values"],
 
49
  else:
50
  prompt = task
51
  inputs = processor(text=prompt, images=image, return_tensors="pt").to(device)
52
+ print(inputs)
53
  generated_ids = model.generate(
54
  input_ids=inputs["input_ids"],
55
  pixel_values=inputs["pixel_values"],
utils/sam.py CHANGED
@@ -37,7 +37,10 @@ def run_sam_inference(
37
  ) -> sv.Detections:
38
  image = np.array(image.convert("RGB"))
39
  model.set_image(image)
40
- mask, score, _ = model.predict(box=detections.xyxy, multimask_output=False)
 
 
 
41
 
42
  # dirty fix; remove this later
43
  if len(mask.shape) == 4:
 
37
  ) -> sv.Detections:
38
  image = np.array(image.convert("RGB"))
39
  model.set_image(image)
40
+ # from left to right
41
+ bboxes = detections.xyxy
42
+ bboxes = sorted(bboxes, key=lambda bbox: bbox[0])
43
+ mask, score, _ = model.predict(box=bboxes, multimask_output=False)
44
 
45
  # dirty fix; remove this later
46
  if len(mask.shape) == 4: