Skip to content

Commit

Permalink
rle enconding
Browse files Browse the repository at this point in the history
  • Loading branch information
Dayof committed Sep 30, 2024
1 parent 13e415d commit d661cd3
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions vision_agent/tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def owl_v2_image(
)
data = data_obj.model_dump(by_alias=True)
detections = send_inference_request(data, "tools", v2=False)
# get the first frame detections
# get the first frame
detection = detections[0]
bboxes_formatted = [
ODResponseData(
Expand Down Expand Up @@ -429,17 +429,18 @@ def florence2_sam2_image(
)
req_data = req_data_obj.model_dump(by_alias=True)
detections_ft = send_inference_request(req_data, "tools", v2=False)
# get the first frame detections
# get the first frame
detection = detections_ft[0]
return_data = []
all_masks = np.array(detection["masks"])
for i in range(len(detection["bboxes"])):
return_data.append(
{
"score": 1.0,
"label": detection["labels"][i],
"bbox": detection["bboxes"][i],
"mask": all_masks[i, :, :].astype(np.uint8),
"bbox": normalize_bbox(
detection["bboxes"][i], detection["masks"][i]["size"]
),
"mask": rle_decode_array(detection["masks"][i]),
}
)
return return_data
Expand All @@ -453,6 +454,7 @@ def florence2_sam2_image(
detections: Dict[str, Any] = send_inference_request(
payload, "florence2-sam2", files=files, v2=True
)

return_data = []
for _, data_i in detections["0"].items():
mask = rle_decode_array(data_i["mask"])
Expand Down Expand Up @@ -1189,7 +1191,7 @@ def florence2_phrase_grounding(
v2=False,
metadata_payload={"function_name": "florence2_phrase_grounding"},
)
# get the first frame detections
# get the first frame
detection = detections[0]
else:
data = {
Expand Down Expand Up @@ -1607,7 +1609,7 @@ def extract_frames_and_timestamps(
"""

def reformat(
frames_and_timestamps: List[Tuple[np.ndarray, float]]
frames_and_timestamps: List[Tuple[np.ndarray, float]],
) -> List[Dict[str, Union[np.ndarray, float]]]:
return [
{"frame": frame, "timestamp": timestamp}
Expand Down

0 comments on commit d661cd3

Please sign in to comment.