Skip to content

Commit

Permalink
Fix count result parsing (#105)
Browse files Browse the repository at this point in the history
The format of roi response is a bit different than what was expected.

---------

Co-authored-by: Auto-format Bot <[email protected]>
  • Loading branch information
CoreyEWood and Auto-format Bot authored Oct 8, 2024
1 parent a86f207 commit af20f53
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 35 deletions.
6 changes: 3 additions & 3 deletions app/core/edge_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def parse_inference_response(response: dict) -> dict:
text: str | None = None
# Attempt to extract rois / text
if secondary_predictions is not None:
roi_predictions: list[list[dict]] | None = secondary_predictions.get("roi_predictions", None)
roi_predictions: dict[str, list[list[dict]]] | None = secondary_predictions.get("roi_predictions", None)
text_predictions: list[str] | None = secondary_predictions.get("text_predictions", None)
if roi_predictions is not None:
rois = roi_predictions[0]
rois = roi_predictions["rois"][0]
for i, roi in enumerate(rois):
geometry = rois[i]["geometry"]
geometry = roi["geometry"]
# TODO add validation to calculate x and y automatically
x = 0.5 * (geometry["left"] + geometry["right"])
y = 0.5 * (geometry["top"] + geometry["bottom"])
Expand Down
72 changes: 40 additions & 32 deletions test/edge_inference/test_parse_inference_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ def mock_count_response():
},
"predictions": None,
"secondary_predictions": {
"roi_predictions": [[{
"label": "bird",
"geometry": {"left": 0.1, "top": 0.2, "right": 0.3, "bottom": 0.4, "version": "2.0"},
"score": 0.9,
"version": "2.0",
}]],
"roi_predictions": {
"rois": [[{
"label": "bird",
"geometry": {"left": 0.1, "top": 0.2, "right": 0.3, "bottom": 0.4, "version": "2.0"},
"score": 0.9,
"version": "2.0",
}]]
},
"text_predictions": ["This is a bird."],
},
}
Expand All @@ -39,20 +41,22 @@ def mock_binary_with_rois_response():
"multi_predictions": None,
"predictions": {"confidences": [0.54], "labels": [0], "probabilities": [0.45], "scores": [-2.94]},
"secondary_predictions": {
"roi_predictions": [[
{
"label": "cat",
"geometry": {"left": 0.1, "top": 0.2, "right": 0.3, "bottom": 0.4, "version": "2.0"},
"score": 0.8,
"version": "2.0",
},
{
"label": "cat",
"geometry": {"left": 0.6, "top": 0.7, "right": 0.8, "bottom": 0.9, "version": "2.0"},
"score": 0.7,
"version": "2.0",
},
]],
"roi_predictions": {
"rois": [[
{
"label": "cat",
"geometry": {"left": 0.1, "top": 0.2, "right": 0.3, "bottom": 0.4, "version": "2.0"},
"score": 0.8,
"version": "2.0",
},
{
"label": "cat",
"geometry": {"left": 0.6, "top": 0.7, "right": 0.8, "bottom": 0.9, "version": "2.0"},
"score": 0.7,
"version": "2.0",
},
]]
},
"text_predictions": None,
},
}
Expand All @@ -79,12 +83,14 @@ def mock_invalid_predictions_response():
},
"predictions": {"confidences": [0.54], "labels": [0], "probabilities": [0.45], "scores": [-2.94]},
"secondary_predictions": {
"roi_predictions": [[{
"label": "bird",
"geometry": {"left": 0.1, "top": 0.2, "right": 0.3, "bottom": 0.4, "version": "2.0"},
"score": 0.9,
"version": "2.0",
}]],
"roi_predictions": {
"rois": [[{
"label": "bird",
"geometry": {"left": 0.1, "top": 0.2, "right": 0.3, "bottom": 0.4, "version": "2.0"},
"score": 0.9,
"version": "2.0",
}]]
},
"text_predictions": None,
},
}
Expand All @@ -96,12 +102,14 @@ def mock_invalid_predictions_missing_response():
"multi_predictions": None,
"predictions": None,
"secondary_predictions": {
"roi_predictions": [[{
"label": "bird",
"geometry": {"left": 0.1, "top": 0.2, "right": 0.3, "bottom": 0.4, "version": "2.0"},
"score": 0.9,
"version": "2.0",
}]],
"roi_predictions": {
"rois": [[{
"label": "bird",
"geometry": {"left": 0.1, "top": 0.2, "right": 0.3, "bottom": 0.4, "version": "2.0"},
"score": 0.9,
"version": "2.0",
}]]
},
"text_predictions": None,
},
}
Expand Down

0 comments on commit af20f53

Please sign in to comment.