Skip to content

Commit

Permalink
fix: round floats to 2 dp
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBlenny committed Jun 9, 2022
1 parent 4a7547a commit d73068f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
10 changes: 5 additions & 5 deletions nuclio_lighting_flash/nuclio_detection_labels_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ def transform(self, sample: Dict[str, Any]) -> List[Dict[str, Any]]:
# the actual image size, "self.image_width", " self.image_height".
# This is why we "/ width * self.image_width" etc
box = [
bbox["xmin"] / width * self.image_width,
bbox["ymin"] / height * self.image_height,
(bbox["xmin"] + bbox["width"]) / width * self.image_width,
(bbox["ymin"] + bbox["height"]) / height * self.image_height,
round(bbox["xmin"] / width * self.image_width, 2),
round(bbox["ymin"] / height * self.image_height, 2),
round((bbox["xmin"] + bbox["width"]) / width * self.image_width, 2),
round((bbox["ymin"] + bbox["height"]) / height * self.image_height, 2),
]

label = label.item()
Expand All @@ -74,7 +74,7 @@ def transform(self, sample: Dict[str, Any]) -> List[Dict[str, Any]]:

detections.append(
{
"confidence": confidence,
"confidence": round(confidence, 2),
"label": label,
"points": box,
"type": "rectangle",
Expand Down
18 changes: 4 additions & 14 deletions nuclio_lighting_flash/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,15 @@ def test_main():
assert response.body == json.dumps(
[
{
"confidence": 0.9171872138977051,
"confidence": 0.92,
"label": "giraffe",
"points": [
372.63145446777344,
114.83981323242188,
601.5438079833984,
315.83863592147827,
],
"points": [372.63, 114.84, 601.54, 315.84],
"type": "rectangle",
},
{
"confidence": 0.8744097352027893,
"confidence": 0.87,
"label": "giraffe",
"points": [
52.77256488800049,
305.4035350084305,
185.64495086669922,
349.67146718502045,
],
"points": [52.77, 305.4, 185.64, 349.67],
"type": "rectangle",
},
]
Expand Down

0 comments on commit d73068f

Please sign in to comment.