Skip to content

Commit c1d9d02

Browse files
Merge pull request #1725 from roboflow/fix/supervision-ensure_cv2_image_for_annotation-replaced-by-ensure_cv2_image_for_class_method
Handle Supervision 0.27.0
2 parents 5d4bc04 + db027ba commit c1d9d02

File tree

9 files changed

+68
-29
lines changed

9 files changed

+68
-29
lines changed

docs/workflows/create_workflow_block.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,7 @@ the method signatures.
15331533

15341534
import supervision as sv
15351535
1536+
from inference.core.utils.drawing import create_tiles
15361537
from inference.core.workflows.execution_engine.entities.base import (
15371538
Batch,
15381539
OutputDefinition,
@@ -1593,7 +1594,7 @@ the method signatures.
15931594
prediction,
15941595
)
15951596
visualisations.append(annotated_image)
1596-
tile = sv.create_tiles(visualisations)
1597+
tile = create_tiles(visualisations)
15971598
return {"visualisations": tile}
15981599
```
15991600

@@ -1827,6 +1828,7 @@ the method signatures.
18271828

18281829
import supervision as sv
18291830
1831+
from inference.core.utils.drawing import create_tiles
18301832
from inference.core.workflows.execution_engine.entities.base import (
18311833
Batch,
18321834
OutputDefinition,
@@ -1887,7 +1889,7 @@ the method signatures.
18871889
prediction,
18881890
)
18891891
visualisations_batch_element.append(annotated_image)
1890-
tile = sv.create_tiles(visualisations_batch_element)
1892+
tile = create_tiles(visualisations_batch_element)
18911893
visualisations.append({"visualisations": tile})
18921894
return visualisations
18931895
```

docs/workflows/execution_engine_changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ change will only affect new workflows created to utilise new functionalities.
163163

164164
import supervision as sv
165165

166+
from inference.core.utils.drawing import create_tiles
166167
from inference.core.workflows.execution_engine.entities.base import (
167168
Batch,
168169
OutputDefinition,
@@ -224,7 +225,7 @@ change will only affect new workflows created to utilise new functionalities.
224225
prediction,
225226
)
226227
visualisations.append(annotated_image)
227-
tile = sv.create_tiles(visualisations)
228+
tile = create_tiles(visualisations)
228229
return {"visualisations": tile}
229230
```
230231

inference/core/workflows/core_steps/visualizations/common/annotators/halo.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
from supervision.annotators.base import BaseAnnotator, ImageType
77
from supervision.annotators.utils import ColorLookup, resolve_color
88
from supervision.draw.color import ColorPalette
9-
from supervision.utils.conversion import ensure_cv2_image_for_annotation
9+
10+
try:
11+
from supervision.utils.conversion import ensure_cv2_image_for_annotation
12+
except ImportError:
13+
from supervision.utils.conversion import (
14+
ensure_cv2_image_for_class_method as ensure_cv2_image_for_annotation,
15+
)
1016

1117

1218
class HaloAnnotator(BaseAnnotator):

inference/core/workflows/core_steps/visualizations/common/annotators/polygon.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
from supervision.detection.utils.converters import mask_to_polygons
99
from supervision.draw.color import ColorPalette
1010
from supervision.draw.utils import draw_polygon
11-
from supervision.utils.conversion import ensure_cv2_image_for_annotation
11+
12+
try:
13+
from supervision.utils.conversion import ensure_cv2_image_for_annotation
14+
except ImportError:
15+
from supervision.utils.conversion import (
16+
ensure_cv2_image_for_class_method as ensure_cv2_image_for_annotation,
17+
)
1218

1319

1420
class PolygonAnnotator(BaseAnnotator):

tests/workflows/integration_tests/execution/stub_plugins/dimensionality_manipulation_plugin/tile_detections_batch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import supervision as sv
88
from pydantic import ConfigDict, Field
99

10+
from inference.core.utils.drawing import create_tiles
1011
from inference.core.workflows.execution_engine.entities.base import (
1112
Batch,
1213
OutputDefinition,
@@ -92,6 +93,6 @@ def run(
9293
prediction,
9394
)
9495
visualisations_batch_element.append(annotated_image)
95-
tile = sv.create_tiles(visualisations_batch_element)
96+
tile = create_tiles(visualisations_batch_element)
9697
visualisations.append({"visualisations": tile})
9798
return visualisations

tests/workflows/integration_tests/execution/stub_plugins/dimensionality_manipulation_plugin/tile_detections_non_batch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import supervision as sv
88
from pydantic import ConfigDict, Field
99

10+
from inference.core.utils.drawing import create_tiles
1011
from inference.core.workflows.execution_engine.entities.base import (
1112
Batch,
1213
OutputDefinition,
@@ -86,5 +87,5 @@ def run(
8687
prediction,
8788
)
8889
visualisations.append(annotated_image)
89-
tile = sv.create_tiles(visualisations)
90+
tile = create_tiles(visualisations)
9091
return {"visualisations": tile}

tests/workflows/integration_tests/execution/test_workflow_with_custom_python_block.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,12 @@ def test_workflow_with_custom_python_block_when_custom_python_execution_forbidde
504504

505505
FUNCTION_TO_MERGE_CROPS_INTO_TILES = """
506506
def run(self, crops: Optional[Batch[Optional[WorkflowImageData]]]) -> BlockResult:
507+
from inference.core.utils.drawing import create_tiles
507508
if crops is None:
508509
return {"tiles": None}
509510
black_image = np.zeros((192, 168, 3), dtype=np.uint8)
510511
images = [crop.numpy_image if crop is not None else black_image for crop in crops]
511-
return {"tiles": sv.create_tiles(images)}
512+
return {"tiles": create_tiles(images)}
512513
"""
513514

514515

tests/workflows/integration_tests/execution/test_workflow_with_dimensionality_change.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,13 +650,13 @@ def test_workflow_with_detections_tiling_in_batch_variant(
650650
"visualisation",
651651
}, "Expected all declared outputs to be delivered"
652652
assert result[0]["visualisation"].shape == (
653-
416,
654-
362,
653+
426,
654+
377,
655655
3,
656656
), "Expected visualisation to be image of shape (416, 362, 3)"
657657
assert result[1]["visualisation"].shape == (
658658
296,
659-
522,
659+
527,
660660
3,
661661
), "Expected visualisation to be image of shape (296, 522, 3)"
662662

@@ -767,12 +767,12 @@ def test_workflow_with_detections_tiling_in_non_batch_variant(
767767
"visualisation",
768768
}, "Expected all declared outputs to be delivered"
769769
assert result[0]["visualisation"].shape == (
770-
416,
771-
362,
770+
426,
771+
377,
772772
3,
773773
), "Expected visualisation to be image of shape (416, 362, 3)"
774774
assert result[1]["visualisation"].shape == (
775775
296,
776-
522,
776+
527,
777777
3,
778778
), "Expected visualisation to be image of shape (296, 522, 3)"

tests/workflows/integration_tests/execution/test_workflow_with_sahi.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,22 @@ def slicer_callback(image_slice: np.ndarray):
508508
detections = sv.Detections.from_inference(predictions)
509509
return detections
510510

511-
slicer = sv.InferenceSlicer(
512-
callback=slicer_callback,
513-
slice_wh=(640, 640),
514-
overlap_ratio_wh=(0.2, 0.2),
515-
overlap_filter=sv.OverlapFilter.NON_MAX_SUPPRESSION,
516-
iou_threshold=0.3,
517-
)
511+
try:
512+
slicer = sv.InferenceSlicer(
513+
callback=slicer_callback,
514+
slice_wh=(640, 640),
515+
overlap_wh=(0.2, 0.2),
516+
overlap_filter=sv.OverlapFilter.NON_MAX_SUPPRESSION,
517+
iou_threshold=0.3,
518+
)
519+
except ValueError:
520+
slicer = sv.InferenceSlicer(
521+
callback=slicer_callback,
522+
slice_wh=(640, 640),
523+
overlap_ratio_wh=(0.2, 0.2),
524+
overlap_filter=sv.OverlapFilter.NON_MAX_SUPPRESSION,
525+
iou_threshold=0.3,
526+
)
518527

519528
# when
520529
detections_obtained_directly = slicer(crowd_image)
@@ -525,20 +534,32 @@ def slicer_callback(image_slice: np.ndarray):
525534
}
526535
)
527536

537+
detections_obtained_directly_xyxy = detections_obtained_directly.xyxy.copy()
538+
detections_obtained_directly_xyxy.sort(axis=0)
539+
workflow_result_xyxy = workflow_result[0]["predictions"].xyxy.copy()
540+
workflow_result_xyxy.sort(axis=0)
528541
# then
529542
assert np.allclose(
530-
detections_obtained_directly.xyxy,
531-
workflow_result[0]["predictions"].xyxy,
532-
atol=1e-1,
543+
detections_obtained_directly_xyxy,
544+
workflow_result_xyxy,
545+
atol=2,
533546
), "Expected bounding boxes to be the same for workflow SAHI and direct SAHI"
547+
detections_obtained_directly_confidence = detections_obtained_directly.confidence.copy()
548+
detections_obtained_directly_confidence.sort()
549+
workflow_result_confidence = workflow_result[0]["predictions"].confidence.copy()
550+
workflow_result_confidence.sort()
534551
assert np.allclose(
535-
detections_obtained_directly.confidence,
536-
workflow_result[0]["predictions"].confidence,
537-
atol=1e-4,
552+
detections_obtained_directly_confidence,
553+
workflow_result_confidence,
554+
atol=1e-1,
538555
), "Expected confidences to be the same for workflow SAHI and direct SAHI"
556+
detections_obtained_directly_class_id = detections_obtained_directly.class_id.copy()
557+
detections_obtained_directly_class_id.sort(axis=0)
558+
workflow_result_class_id = workflow_result[0]["predictions"].class_id.copy()
559+
workflow_result_class_id.sort(axis=0)
539560
assert np.all(
540-
detections_obtained_directly.class_id
541-
== workflow_result[0]["predictions"].class_id
561+
detections_obtained_directly_class_id
562+
== workflow_result_class_id
542563
), "Expected class ids to be the same for workflow SAHI and direct SAHI"
543564

544565

0 commit comments

Comments
 (0)