Skip to content

Commit

Permalink
Issue #51: Implement documentation suggestion
Browse files Browse the repository at this point in the history
issue #62: correct multiple import ruff error
  • Loading branch information
Maxence Guindon committed Apr 8, 2024
1 parent 03065a4 commit 2f65a37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
13 changes: 7 additions & 6 deletions model_inference/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
async def process_inference_results(data: dict, imageDims: list[int, int], area_ratio: float = 0.5, seed: int = 3) -> dict:
"""
Process the inference results by performing various operations on the data.
Indicate if there are overlapping boxes and calculate the label
occurrence. The overlapping is determined if the common area of two boxes
is greater than the area_ratio (default = 0.5) of the area of each box.
Indicate if there are overlapping boxes and calculates the label
occurrence. Boxes can overlap if their common area is greater than the
area_ratio (default = 0.5) of the area of each box.
Args:
data (dict): The inference results data.
data (dict): The inference result data.
imageDims (tuple): The dimensions of the image.
area_ratio (float): The area ratio of a box to consider the overlapping
area_ratio (float): The area ratio of a box to consider in the box
overlap claculation.
seed (int): The seed for the random number generator.
Returns:
dict: The processed inference results data.
dict: The processed inference result data.
Raises:
ProcessInferenceResultError: If there is an error processing the
Expand Down
23 changes: 12 additions & 11 deletions tests/test_overlapping_in_inference.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import unittest
import model_inference.inference as inference, random

import asyncio
import random

from model_inference.inference import process_inference_results, ProcessInferenceResultError


class TestInferenceProcessFunction(unittest.TestCase):
Expand All @@ -28,7 +29,7 @@ def test_process_inference_overlap_results(self):
"boxes": boxes,
"totalBoxes": 2
}
result = asyncio.run(inference.process_inference_results(data=[data], imageDims=[100, 100]))
result = asyncio.run(process_inference_results(data=[data], imageDims=[100, 100]))


self.assertFalse(result[0]["boxes"][0]["overlapping"])
Expand All @@ -43,7 +44,7 @@ def test_process_inference_overlap_score_results(self):
"boxes": boxes,
"totalBoxes": 2
}
result = asyncio.run(inference.process_inference_results(data=[data], imageDims=[100, 100]))
result = asyncio.run(process_inference_results(data=[data], imageDims=[100, 100]))


self.assertFalse(result[0]["boxes"][0]["overlapping"])
Expand Down Expand Up @@ -75,7 +76,7 @@ def test_generate_color(self):
test_result.append(label_occurences[box["label"]])
colors = []

result = asyncio.run(inference.process_inference_results(data=[data], imageDims=[100, 100], seed=3))
result = asyncio.run(process_inference_results(data=[data], imageDims=[100, 100], seed=3))

for box in result[0]["boxes"]:
colors.append(box["color"])
Expand All @@ -92,21 +93,21 @@ def test_process_inference_error(self):
"totalBoxes": 2
}

with self.assertRaises(inference.ProcessInferenceResultError):
asyncio.run(inference.process_inference_results(data=[data], imageDims=[100, 100]))
with self.assertRaises(ProcessInferenceResultError):
asyncio.run(process_inference_results(data=[data], imageDims=[100, 100]))

data ={
"boxes": boxes,
"totalBoxes": 2
}

with self.assertRaises(inference.ProcessInferenceResultError):
asyncio.run(inference.process_inference_results(data=[data], imageDims=100))
with self.assertRaises(ProcessInferenceResultError):
asyncio.run(process_inference_results(data=[data], imageDims=100))

data ={
"boxes": None,
"totalBoxes": 2
}

with self.assertRaises(inference.ProcessInferenceResultError):
asyncio.run(inference.process_inference_results(data=[data], imageDims=[100, 100]))
with self.assertRaises(ProcessInferenceResultError):
asyncio.run(process_inference_results(data=[data], imageDims=[100, 100]))

0 comments on commit 2f65a37

Please sign in to comment.