From becdb2b965c4523097ea7ee0538df1c8a087b272 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 19 Jul 2024 16:39:51 -0700 Subject: [PATCH 1/4] add backgroundcolor block --- inference/core/workflows/core_steps/loader.py | 4 + .../visualizations/background_color.py | 114 ++++++++++++++++++ inference/usage_tracking/collector.py | 15 ++- 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 inference/core/workflows/core_steps/visualizations/background_color.py diff --git a/inference/core/workflows/core_steps/loader.py b/inference/core/workflows/core_steps/loader.py index 58d49e175e..fbbfe1a181 100644 --- a/inference/core/workflows/core_steps/loader.py +++ b/inference/core/workflows/core_steps/loader.py @@ -84,6 +84,9 @@ from inference.core.workflows.core_steps.visualizations.blur import ( BlurVisualizationBlock, ) +from inference.core.workflows.core_steps.visualizations.background_color import ( + BackgroundColorVisualizationBlock, +) from inference.core.workflows.core_steps.visualizations.bounding_box import ( BoundingBoxVisualizationBlock, ) @@ -207,6 +210,7 @@ def load_blocks() -> List[ PropertyDefinitionBlock, DimensionCollapseBlock, FirstNonEmptyOrDefaultBlock, + BackgroundColorVisualizationBlock, BlurVisualizationBlock, BoundingBoxVisualizationBlock, CircleVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/background_color.py b/inference/core/workflows/core_steps/visualizations/background_color.py new file mode 100644 index 0000000000..26773b4a99 --- /dev/null +++ b/inference/core/workflows/core_steps/visualizations/background_color.py @@ -0,0 +1,114 @@ +from typing import List, Literal, Optional, Type, Union + +import supervision as sv +from pydantic import ConfigDict, Field + +from inference.core.workflows.core_steps.visualizations.base import ( + OUTPUT_IMAGE_KEY, + VisualizationBlock, + VisualizationManifest, +) +from inference.core.workflows.core_steps.visualizations.utils import str_to_color + +from inference.core.workflows.entities.base import WorkflowImageData +from inference.core.workflows.entities.types import ( + BATCH_OF_INSTANCE_SEGMENTATION_PREDICTION_KIND, + STRING_KIND, + FLOAT_ZERO_TO_ONE_KIND, + FloatZeroToOne, + StepOutputSelector, + WorkflowParameterSelector, +) +from inference.core.workflows.prototypes.block import BlockResult, WorkflowBlockManifest + +TYPE: str = "BackgroundColorVisualization" +SHORT_DESCRIPTION = "Paints a mask over all areas outside of detected regions in an image." +LONG_DESCRIPTION = """ +The `BackgroundColorVisualization` block draws all areas +outside of detected regions in an image with a specified +color. +""" + + +class BackgroundColorManifest(VisualizationManifest): + type: Literal[f"{TYPE}"] + model_config = ConfigDict( + json_schema_extra={ + "short_description": SHORT_DESCRIPTION, + "long_description": LONG_DESCRIPTION, + "license": "Apache-2.0", + "block_type": "visualization", + } + ) + + color: Union[str, WorkflowParameterSelector(kind=[STRING_KIND])] = Field( # type: ignore + description="Color of the background.", + default="BLACK", + examples=["WHITE", "#FFFFFF", "rgb(255, 255, 255)" "$inputs.background_color"], + ) + + opacity: Union[FloatZeroToOne, WorkflowParameterSelector(kind=[FLOAT_ZERO_TO_ONE_KIND])] = Field( # type: ignore + description="Transparency of the Mask overlay.", + default=0.5, + examples=[0.5, "$inputs.opacity"], + ) + + +class BackgroundColorVisualizationBlock(VisualizationBlock): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.annotatorCache = {} + + @classmethod + def get_manifest(cls) -> Type[WorkflowBlockManifest]: + return BackgroundColorManifest + + def getAnnotator( + self, + color: str, + opacity: float, + ) -> sv.annotators.base.BaseAnnotator: + key = "_".join( + map( + str, + [ + color, + opacity, + ], + ) + ) + + if key not in self.annotatorCache: + background_color = str_to_color(color) + self.annotatorCache[key] = sv.BackgroundColorAnnotator( + color=background_color, + opacity=opacity, + ) + + return self.annotatorCache[key] + + async def run( + self, + image: WorkflowImageData, + predictions: sv.Detections, + copy_image: bool, + color: str, + opacity: Optional[float], + ) -> BlockResult: + annotator = self.getAnnotator( + color, + opacity + ) + + annotated_image = annotator.annotate( + scene=image.numpy_image.copy() if copy_image else image.numpy_image, + detections=predictions, + ) + + output = WorkflowImageData( + parent_metadata=image.parent_metadata, + workflow_root_ancestor_metadata=image.workflow_root_ancestor_metadata, + numpy_image=annotated_image, + ) + + return {OUTPUT_IMAGE_KEY: output} diff --git a/inference/usage_tracking/collector.py b/inference/usage_tracking/collector.py index 1a73f1fe5b..9d857a2d78 100644 --- a/inference/usage_tracking/collector.py +++ b/inference/usage_tracking/collector.py @@ -298,7 +298,20 @@ def system_info( if ip_address: ip_address_hash_hex = UsageCollector._hash(ip_address) else: - ip_address: str = socket.gethostbyname(socket.gethostname()) + try: + ip_address: str = socket.gethostbyname(socket.gethostname()) + except: + s = None + try: + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.connect(("8.8.8.8", 80)) + ip_address = s.getsockname()[0] + except: + ip_address: str = socket.gethostbyname("localhost") + + if s: + s.close() + ip_address_hash_hex = UsageCollector._hash(ip_address) if not time_ns: From 5034fed60a1181e17891fa1bec00ae862326b40f Mon Sep 17 00:00:00 2001 From: James Date: Fri, 19 Jul 2024 16:49:52 -0700 Subject: [PATCH 2/4] add backgroundcolor code --- .../visualizations/annotators/__init__.py | 0 .../annotators/background_color.py | 71 +++++++++++++++++++ .../visualizations/background_color.py | 3 +- 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 inference/core/workflows/core_steps/visualizations/annotators/__init__.py create mode 100644 inference/core/workflows/core_steps/visualizations/annotators/background_color.py diff --git a/inference/core/workflows/core_steps/visualizations/annotators/__init__.py b/inference/core/workflows/core_steps/visualizations/annotators/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/inference/core/workflows/core_steps/visualizations/annotators/background_color.py b/inference/core/workflows/core_steps/visualizations/annotators/background_color.py new file mode 100644 index 0000000000..8bfe57fb36 --- /dev/null +++ b/inference/core/workflows/core_steps/visualizations/annotators/background_color.py @@ -0,0 +1,71 @@ +import cv2 +from supervision.annotators.base import BaseAnnotator, ImageType +from supervision.draw.color import Color +from supervision.detection.core import Detections +from supervision.utils.conversion import ensure_cv2_image_for_annotation +import numpy as np + +class BackgroundColorAnnotator(BaseAnnotator): + """ + A class for drawing background colors outside of detected box or mask regions. + !!! warning + This annotator uses `sv.Detections.mask`. + """ + + def __init__( + self, + color: Color = Color.BLACK, + opacity: float = 0.5, + force_box: bool = False, + ): + """ + Args: + color (Color): The color to use for annotating detections. + opacity (float): Opacity of the overlay mask. Must be between `0` and `1`. + """ + self.color: Color = color + self.opacity = opacity + self.force_box = force_box + + @ensure_cv2_image_for_annotation + def annotate(self, scene: ImageType, detections: Detections) -> ImageType: + """ + Annotates the given scene with masks based on the provided detections. + Args: + scene (ImageType): The image where masks will be drawn. + `ImageType` is a flexible type, accepting either `numpy.ndarray` + or `PIL.Image.Image`. + detections (Detections): Object detections to annotate. + Returns: + The annotated image, matching the type of `scene` (`numpy.ndarray` + or `PIL.Image.Image`) + Example: + ```python + import supervision as sv + image = ... + detections = sv.Detections(...) + background_color_annotator = sv.BackgroundColorAnnotator() + annotated_frame = background_color_annotator.annotate( + scene=image.copy(), + detections=detections + ) + ``` + ![background-color-annotator-example](https://media.roboflow.com/ + supervision-annotator-examples/background-color-annotator-example-purple.png) + """ + + colored_mask = np.full_like(scene, self.color.as_bgr(), dtype=np.uint8) + + cv2.addWeighted( + scene, 1 - self.opacity, colored_mask, self.opacity, 0, dst=colored_mask + ) + + if detections.mask is None or self.force_box: + for detection_idx in range(len(detections)): + x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int) + colored_mask[y1:y2, x1:x2] = scene[y1:y2, x1:x2] + else: + for mask in detections.mask: + colored_mask[mask] = scene[mask] + + return colored_mask \ No newline at end of file diff --git a/inference/core/workflows/core_steps/visualizations/background_color.py b/inference/core/workflows/core_steps/visualizations/background_color.py index 26773b4a99..5bba301df9 100644 --- a/inference/core/workflows/core_steps/visualizations/background_color.py +++ b/inference/core/workflows/core_steps/visualizations/background_color.py @@ -1,6 +1,7 @@ from typing import List, Literal, Optional, Type, Union import supervision as sv +from inference.core.workflows.core_steps.visualizations.annotators.background_color import BackgroundColorAnnotator from pydantic import ConfigDict, Field from inference.core.workflows.core_steps.visualizations.base import ( @@ -80,7 +81,7 @@ def getAnnotator( if key not in self.annotatorCache: background_color = str_to_color(color) - self.annotatorCache[key] = sv.BackgroundColorAnnotator( + self.annotatorCache[key] = BackgroundColorAnnotator( color=background_color, opacity=opacity, ) From 05c3408b41fed091f9d37e42c0e741a652f8d3a6 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 19 Jul 2024 16:53:06 -0700 Subject: [PATCH 3/4] run isort --- .../core/interfaces/camera/video_source.py | 2 +- inference/core/interfaces/http/orjson_utils.py | 2 +- inference/core/interfaces/stream/sinks.py | 4 ++-- inference/core/interfaces/stream/stream.py | 2 +- inference/core/interfaces/stream/watchdog.py | 1 - inference/core/interfaces/udp/udp_stream.py | 2 +- .../operations/detections/base.py | 4 ++-- .../workflows/core_steps/common/serializers.py | 2 +- .../core/workflows/core_steps/common/utils.py | 4 ++-- .../fusion/detections_classes_replacement.py | 4 ++-- .../core_steps/fusion/detections_consensus.py | 2 +- inference/core/workflows/core_steps/loader.py | 6 +++--- .../models/third_party/barcode_detection.py | 4 ++-- .../models/third_party/qr_code_detection.py | 4 ++-- .../sinks/roboflow/roboflow_dataset_upload.py | 2 +- .../transformations/detection_offset.py | 2 +- .../transformations/detections_filter.py | 2 +- .../detections_transformation.py | 2 +- .../core_steps/transformations/dynamic_crop.py | 2 +- .../transformations/dynamic_zones.py | 2 +- .../transformations/perspective_correction.py | 2 +- .../annotators/background_color.py | 8 +++++--- .../visualizations/background_color.py | 18 +++++++++--------- .../core_steps/visualizations/base.py | 2 +- .../visualizations/base_colorable.py | 2 +- .../core_steps/visualizations/blur.py | 2 +- .../core_steps/visualizations/bounding_box.py | 2 +- .../core_steps/visualizations/circle.py | 2 +- .../core_steps/visualizations/color.py | 2 +- .../core_steps/visualizations/corner.py | 2 +- .../core_steps/visualizations/crop.py | 2 +- .../workflows/core_steps/visualizations/dot.py | 2 +- .../core_steps/visualizations/ellipse.py | 2 +- .../core_steps/visualizations/halo.py | 2 +- .../core_steps/visualizations/label.py | 2 +- .../core_steps/visualizations/mask.py | 2 +- .../core_steps/visualizations/pixelate.py | 2 +- .../core_steps/visualizations/polygon.py | 2 +- .../core_steps/visualizations/triangle.py | 2 +- .../executor/output_constructor.py | 2 +- inference/usage_tracking/collector.py | 2 +- 41 files changed, 60 insertions(+), 59 deletions(-) diff --git a/inference/core/interfaces/camera/video_source.py b/inference/core/interfaces/camera/video_source.py index 81f4e90a74..9683a46614 100644 --- a/inference/core/interfaces/camera/video_source.py +++ b/inference/core/interfaces/camera/video_source.py @@ -7,9 +7,9 @@ from typing import Any, Callable, Dict, List, Optional, Protocol, Tuple, Union import cv2 -import supervision as sv from numpy import ndarray +import supervision as sv from inference.core import logger from inference.core.env import ( DEFAULT_ADAPTIVE_MODE_READER_PACE_TOLERANCE, diff --git a/inference/core/interfaces/http/orjson_utils.py b/inference/core/interfaces/http/orjson_utils.py index ffe4b47eec..c96c810cd6 100644 --- a/inference/core/interfaces/http/orjson_utils.py +++ b/inference/core/interfaces/http/orjson_utils.py @@ -2,10 +2,10 @@ from typing import Any, Dict, List, Optional, Union import orjson -import supervision as sv from fastapi.responses import ORJSONResponse from pydantic import BaseModel +import supervision as sv from inference.core.entities.responses.inference import InferenceResponse from inference.core.utils.function import deprecated from inference.core.utils.image_utils import ImageType diff --git a/inference/core/interfaces/stream/sinks.py b/inference/core/interfaces/stream/sinks.py index 3e9affbef8..468c8e2913 100644 --- a/inference/core/interfaces/stream/sinks.py +++ b/inference/core/interfaces/stream/sinks.py @@ -6,9 +6,8 @@ import cv2 import numpy as np -import supervision as sv -from supervision.annotators.base import BaseAnnotator +import supervision as sv from inference.core import logger from inference.core.active_learning.middlewares import ActiveLearningMiddleware from inference.core.interfaces.camera.entities import VideoFrame @@ -16,6 +15,7 @@ from inference.core.interfaces.stream.utils import wrap_in_list from inference.core.utils.drawing import create_tiles from inference.core.utils.preprocess import letterbox_image +from supervision.annotators.base import BaseAnnotator DEFAULT_BBOX_ANNOTATOR = sv.BoundingBoxAnnotator() DEFAULT_LABEL_ANNOTATOR = sv.LabelAnnotator() diff --git a/inference/core/interfaces/stream/stream.py b/inference/core/interfaces/stream/stream.py index 019383fd4b..df60c05452 100644 --- a/inference/core/interfaces/stream/stream.py +++ b/inference/core/interfaces/stream/stream.py @@ -6,10 +6,10 @@ import cv2 import numpy as np -import supervision as sv from PIL import Image import inference.core.entities.requests.inference +import supervision as sv from inference.core.active_learning.middlewares import ( NullActiveLearningMiddleware, ThreadingActiveLearningMiddleware, diff --git a/inference/core/interfaces/stream/watchdog.py b/inference/core/interfaces/stream/watchdog.py index c9701efad0..d6f6fe846e 100644 --- a/inference/core/interfaces/stream/watchdog.py +++ b/inference/core/interfaces/stream/watchdog.py @@ -9,7 +9,6 @@ from typing import Any, Deque, Dict, Iterable, List, Optional, TypeVar import supervision as sv - from inference.core.interfaces.camera.entities import ( StatusUpdate, UpdateSeverity, diff --git a/inference/core/interfaces/udp/udp_stream.py b/inference/core/interfaces/udp/udp_stream.py index 418c97343f..c806c595a8 100644 --- a/inference/core/interfaces/udp/udp_stream.py +++ b/inference/core/interfaces/udp/udp_stream.py @@ -7,10 +7,10 @@ import cv2 import numpy as np -import supervision as sv from PIL import Image import inference.core.entities.requests.inference +import supervision as sv from inference.core.active_learning.middlewares import ( NullActiveLearningMiddleware, ThreadingActiveLearningMiddleware, diff --git a/inference/core/workflows/core_steps/common/query_language/operations/detections/base.py b/inference/core/workflows/core_steps/common/query_language/operations/detections/base.py index c7e424c408..cc46a9f29c 100644 --- a/inference/core/workflows/core_steps/common/query_language/operations/detections/base.py +++ b/inference/core/workflows/core_steps/common/query_language/operations/detections/base.py @@ -2,9 +2,8 @@ from typing import Any, Callable, Dict, List import numpy as np -import supervision as sv -from supervision import Position +import supervision as sv from inference.core.workflows.core_steps.common.query_language.entities.enums import ( DetectionsProperty, DetectionsSelectionMode, @@ -19,6 +18,7 @@ from inference.core.workflows.core_steps.common.query_language.operations.utils import ( safe_stringify, ) +from supervision import Position PROPERTIES_EXTRACTORS = { DetectionsProperty.CONFIDENCE: lambda detections: detections.confidence.tolist(), diff --git a/inference/core/workflows/core_steps/common/serializers.py b/inference/core/workflows/core_steps/common/serializers.py index 732c26fcb8..3c8a540526 100644 --- a/inference/core/workflows/core_steps/common/serializers.py +++ b/inference/core/workflows/core_steps/common/serializers.py @@ -1,8 +1,8 @@ from typing import Any, Dict, List import numpy as np -import supervision as sv +import supervision as sv from inference.core.workflows.constants import ( CLASS_ID_KEY, CLASS_NAME_KEY, diff --git a/inference/core/workflows/core_steps/common/utils.py b/inference/core/workflows/core_steps/common/utils.py index 51608802c1..b976a6f3ba 100644 --- a/inference/core/workflows/core_steps/common/utils.py +++ b/inference/core/workflows/core_steps/common/utils.py @@ -4,9 +4,8 @@ from typing import Any, Dict, Iterable, List, Optional, Union import numpy as np -import supervision as sv -from supervision.config import CLASS_NAME_DATA_FIELD +import supervision as sv from inference.core.entities.requests.clip import ClipCompareRequest from inference.core.entities.requests.cogvlm import CogVLMInferenceRequest from inference.core.entities.requests.doctr import DoctrOCRInferenceRequest @@ -43,6 +42,7 @@ OriginCoordinatesSystem, WorkflowImageData, ) +from supervision.config import CLASS_NAME_DATA_FIELD def load_core_model( diff --git a/inference/core/workflows/core_steps/fusion/detections_classes_replacement.py b/inference/core/workflows/core_steps/fusion/detections_classes_replacement.py index 675084ef73..cf3f0d8d6f 100644 --- a/inference/core/workflows/core_steps/fusion/detections_classes_replacement.py +++ b/inference/core/workflows/core_steps/fusion/detections_classes_replacement.py @@ -2,10 +2,9 @@ from uuid import uuid4 import numpy as np -import supervision as sv from pydantic import ConfigDict, Field -from supervision.config import CLASS_NAME_DATA_FIELD +import supervision as sv from inference.core.workflows.constants import DETECTION_ID_KEY, PARENT_ID_KEY from inference.core.workflows.entities.base import Batch, OutputDefinition from inference.core.workflows.entities.types import ( @@ -20,6 +19,7 @@ WorkflowBlock, WorkflowBlockManifest, ) +from supervision.config import CLASS_NAME_DATA_FIELD LONG_DESCRIPTION = """ Combine results of detection model with classification results performed separately for diff --git a/inference/core/workflows/core_steps/fusion/detections_consensus.py b/inference/core/workflows/core_steps/fusion/detections_consensus.py index 945f6b0da6..4fb4dfccc8 100644 --- a/inference/core/workflows/core_steps/fusion/detections_consensus.py +++ b/inference/core/workflows/core_steps/fusion/detections_consensus.py @@ -17,9 +17,9 @@ from uuid import uuid4 import numpy as np -import supervision as sv from pydantic import AliasChoices, ConfigDict, Field, PositiveInt +import supervision as sv from inference.core.workflows.constants import ( DETECTION_ID_KEY, IMAGE_DIMENSIONS_KEY, diff --git a/inference/core/workflows/core_steps/loader.py b/inference/core/workflows/core_steps/loader.py index fbbfe1a181..0fa6d5c2b9 100644 --- a/inference/core/workflows/core_steps/loader.py +++ b/inference/core/workflows/core_steps/loader.py @@ -79,14 +79,14 @@ from inference.core.workflows.core_steps.transformations.relative_static_crop import ( RelativeStaticCropBlock, ) +from inference.core.workflows.core_steps.visualizations.background_color import ( + BackgroundColorVisualizationBlock, +) # Visualizers from inference.core.workflows.core_steps.visualizations.blur import ( BlurVisualizationBlock, ) -from inference.core.workflows.core_steps.visualizations.background_color import ( - BackgroundColorVisualizationBlock, -) from inference.core.workflows.core_steps.visualizations.bounding_box import ( BoundingBoxVisualizationBlock, ) diff --git a/inference/core/workflows/core_steps/models/third_party/barcode_detection.py b/inference/core/workflows/core_steps/models/third_party/barcode_detection.py index 086dca1db9..5b1615678a 100644 --- a/inference/core/workflows/core_steps/models/third_party/barcode_detection.py +++ b/inference/core/workflows/core_steps/models/third_party/barcode_detection.py @@ -2,11 +2,10 @@ from uuid import uuid4 import numpy as np -import supervision as sv import zxingcpp from pydantic import ConfigDict -from supervision.config import CLASS_NAME_DATA_FIELD +import supervision as sv from inference.core.workflows.constants import ( DETECTED_CODE_KEY, DETECTION_ID_KEY, @@ -32,6 +31,7 @@ WorkflowBlock, WorkflowBlockManifest, ) +from supervision.config import CLASS_NAME_DATA_FIELD LONG_DESCRIPTION = """ Detect the location of barcodes in an image. diff --git a/inference/core/workflows/core_steps/models/third_party/qr_code_detection.py b/inference/core/workflows/core_steps/models/third_party/qr_code_detection.py index ff260e83ad..cb6100381a 100644 --- a/inference/core/workflows/core_steps/models/third_party/qr_code_detection.py +++ b/inference/core/workflows/core_steps/models/third_party/qr_code_detection.py @@ -3,10 +3,9 @@ import cv2 import numpy as np -import supervision as sv from pydantic import AliasChoices, ConfigDict, Field -from supervision.config import CLASS_NAME_DATA_FIELD +import supervision as sv from inference.core.workflows.constants import ( DETECTED_CODE_KEY, DETECTION_ID_KEY, @@ -32,6 +31,7 @@ WorkflowBlock, WorkflowBlockManifest, ) +from supervision.config import CLASS_NAME_DATA_FIELD LONG_DESCRIPTION = """ Detect the location of a QR code. diff --git a/inference/core/workflows/core_steps/sinks/roboflow/roboflow_dataset_upload.py b/inference/core/workflows/core_steps/sinks/roboflow/roboflow_dataset_upload.py index ac41518314..c611bdbd65 100644 --- a/inference/core/workflows/core_steps/sinks/roboflow/roboflow_dataset_upload.py +++ b/inference/core/workflows/core_steps/sinks/roboflow/roboflow_dataset_upload.py @@ -7,10 +7,10 @@ from typing import Any, Dict, List, Literal, Optional, Tuple, Type, Union from uuid import uuid4 -import supervision as sv from fastapi import BackgroundTasks from pydantic import ConfigDict, Field +import supervision as sv from inference.core.active_learning.cache_operations import ( return_strategy_credit, use_credit_of_matching_strategy, diff --git a/inference/core/workflows/core_steps/transformations/detection_offset.py b/inference/core/workflows/core_steps/transformations/detection_offset.py index 579cbb6d14..3f793ceec3 100644 --- a/inference/core/workflows/core_steps/transformations/detection_offset.py +++ b/inference/core/workflows/core_steps/transformations/detection_offset.py @@ -3,9 +3,9 @@ from typing import Dict, List, Literal, Optional, Type, Union import numpy as np -import supervision as sv from pydantic import AliasChoices, ConfigDict, Field, PositiveInt +import supervision as sv from inference.core.workflows.constants import DETECTION_ID_KEY, PARENT_ID_KEY from inference.core.workflows.entities.base import Batch, OutputDefinition from inference.core.workflows.entities.types import ( diff --git a/inference/core/workflows/core_steps/transformations/detections_filter.py b/inference/core/workflows/core_steps/transformations/detections_filter.py index 5c58ffae18..cd5801b71e 100644 --- a/inference/core/workflows/core_steps/transformations/detections_filter.py +++ b/inference/core/workflows/core_steps/transformations/detections_filter.py @@ -1,8 +1,8 @@ from typing import Any, Dict, List, Literal, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.common.query_language.entities.operations import ( AllOperationsType, OperationDefinition, diff --git a/inference/core/workflows/core_steps/transformations/detections_transformation.py b/inference/core/workflows/core_steps/transformations/detections_transformation.py index 9fd3b01577..41d6b5c17c 100644 --- a/inference/core/workflows/core_steps/transformations/detections_transformation.py +++ b/inference/core/workflows/core_steps/transformations/detections_transformation.py @@ -1,9 +1,9 @@ from copy import copy from typing import Any, Dict, List, Literal, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.common.query_language.entities.operations import ( DEFAULT_OPERAND_NAME, AllOperationsType, diff --git a/inference/core/workflows/core_steps/transformations/dynamic_crop.py b/inference/core/workflows/core_steps/transformations/dynamic_crop.py index b6c3eb7d62..4da4a0bf60 100644 --- a/inference/core/workflows/core_steps/transformations/dynamic_crop.py +++ b/inference/core/workflows/core_steps/transformations/dynamic_crop.py @@ -1,9 +1,9 @@ from dataclasses import replace from typing import Dict, List, Literal, Optional, Type, Union -import supervision as sv from pydantic import AliasChoices, ConfigDict, Field +import supervision as sv from inference.core.workflows.constants import DETECTION_ID_KEY from inference.core.workflows.entities.base import ( Batch, diff --git a/inference/core/workflows/core_steps/transformations/dynamic_zones.py b/inference/core/workflows/core_steps/transformations/dynamic_zones.py index dc0a9c5233..1c6a84ced2 100644 --- a/inference/core/workflows/core_steps/transformations/dynamic_zones.py +++ b/inference/core/workflows/core_steps/transformations/dynamic_zones.py @@ -2,9 +2,9 @@ import cv2 as cv import numpy as np -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.entities.base import Batch, OutputDefinition from inference.core.workflows.entities.types import ( BATCH_OF_INSTANCE_SEGMENTATION_PREDICTION_KIND, diff --git a/inference/core/workflows/core_steps/transformations/perspective_correction.py b/inference/core/workflows/core_steps/transformations/perspective_correction.py index 1edd5706ae..b838f532c6 100644 --- a/inference/core/workflows/core_steps/transformations/perspective_correction.py +++ b/inference/core/workflows/core_steps/transformations/perspective_correction.py @@ -3,9 +3,9 @@ import cv2 as cv import numpy as np -import supervision as sv from pydantic import AliasChoices, ConfigDict, Field +import supervision as sv from inference.core.logger import logger from inference.core.workflows.constants import KEYPOINTS_XY_KEY_IN_SV_DETECTIONS from inference.core.workflows.entities.base import ( diff --git a/inference/core/workflows/core_steps/visualizations/annotators/background_color.py b/inference/core/workflows/core_steps/visualizations/annotators/background_color.py index 8bfe57fb36..accd9f9dcf 100644 --- a/inference/core/workflows/core_steps/visualizations/annotators/background_color.py +++ b/inference/core/workflows/core_steps/visualizations/annotators/background_color.py @@ -1,9 +1,11 @@ import cv2 +import numpy as np + from supervision.annotators.base import BaseAnnotator, ImageType -from supervision.draw.color import Color from supervision.detection.core import Detections +from supervision.draw.color import Color from supervision.utils.conversion import ensure_cv2_image_for_annotation -import numpy as np + class BackgroundColorAnnotator(BaseAnnotator): """ @@ -68,4 +70,4 @@ def annotate(self, scene: ImageType, detections: Detections) -> ImageType: for mask in detections.mask: colored_mask[mask] = scene[mask] - return colored_mask \ No newline at end of file + return colored_mask diff --git a/inference/core/workflows/core_steps/visualizations/background_color.py b/inference/core/workflows/core_steps/visualizations/background_color.py index 5bba301df9..0c624141f1 100644 --- a/inference/core/workflows/core_steps/visualizations/background_color.py +++ b/inference/core/workflows/core_steps/visualizations/background_color.py @@ -1,21 +1,22 @@ from typing import List, Literal, Optional, Type, Union -import supervision as sv -from inference.core.workflows.core_steps.visualizations.annotators.background_color import BackgroundColorAnnotator from pydantic import ConfigDict, Field +import supervision as sv +from inference.core.workflows.core_steps.visualizations.annotators.background_color import ( + BackgroundColorAnnotator, +) from inference.core.workflows.core_steps.visualizations.base import ( OUTPUT_IMAGE_KEY, VisualizationBlock, VisualizationManifest, ) from inference.core.workflows.core_steps.visualizations.utils import str_to_color - from inference.core.workflows.entities.base import WorkflowImageData from inference.core.workflows.entities.types import ( BATCH_OF_INSTANCE_SEGMENTATION_PREDICTION_KIND, - STRING_KIND, FLOAT_ZERO_TO_ONE_KIND, + STRING_KIND, FloatZeroToOne, StepOutputSelector, WorkflowParameterSelector, @@ -23,7 +24,9 @@ from inference.core.workflows.prototypes.block import BlockResult, WorkflowBlockManifest TYPE: str = "BackgroundColorVisualization" -SHORT_DESCRIPTION = "Paints a mask over all areas outside of detected regions in an image." +SHORT_DESCRIPTION = ( + "Paints a mask over all areas outside of detected regions in an image." +) LONG_DESCRIPTION = """ The `BackgroundColorVisualization` block draws all areas outside of detected regions in an image with a specified @@ -96,10 +99,7 @@ async def run( color: str, opacity: Optional[float], ) -> BlockResult: - annotator = self.getAnnotator( - color, - opacity - ) + annotator = self.getAnnotator(color, opacity) annotated_image = annotator.annotate( scene=image.numpy_image.copy() if copy_image else image.numpy_image, diff --git a/inference/core/workflows/core_steps/visualizations/base.py b/inference/core/workflows/core_steps/visualizations/base.py index 8dadaaa7a6..e4abfa8cbc 100644 --- a/inference/core/workflows/core_steps/visualizations/base.py +++ b/inference/core/workflows/core_steps/visualizations/base.py @@ -1,9 +1,9 @@ from abc import ABC, abstractmethod from typing import List, Literal, Optional, Type, Union -import supervision as sv from pydantic import AliasChoices, ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.utils import str_to_color from inference.core.workflows.entities.base import OutputDefinition, WorkflowImageData from inference.core.workflows.entities.types import ( diff --git a/inference/core/workflows/core_steps/visualizations/base_colorable.py b/inference/core/workflows/core_steps/visualizations/base_colorable.py index bc1a438cbe..9e41ce52b3 100644 --- a/inference/core/workflows/core_steps/visualizations/base_colorable.py +++ b/inference/core/workflows/core_steps/visualizations/base_colorable.py @@ -1,9 +1,9 @@ from abc import ABC, abstractmethod from typing import List, Literal, Optional, Union -import supervision as sv from pydantic import Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import ( VisualizationBlock, VisualizationManifest, diff --git a/inference/core/workflows/core_steps/visualizations/blur.py b/inference/core/workflows/core_steps/visualizations/blur.py index d64568accf..892bf2a4f9 100644 --- a/inference/core/workflows/core_steps/visualizations/blur.py +++ b/inference/core/workflows/core_steps/visualizations/blur.py @@ -1,8 +1,8 @@ from typing import Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import ( OUTPUT_IMAGE_KEY, VisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/bounding_box.py b/inference/core/workflows/core_steps/visualizations/bounding_box.py index 375d5f5b95..46608d497c 100644 --- a/inference/core/workflows/core_steps/visualizations/bounding_box.py +++ b/inference/core/workflows/core_steps/visualizations/bounding_box.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/circle.py b/inference/core/workflows/core_steps/visualizations/circle.py index ede5e38755..bcc87bd2c0 100644 --- a/inference/core/workflows/core_steps/visualizations/circle.py +++ b/inference/core/workflows/core_steps/visualizations/circle.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/color.py b/inference/core/workflows/core_steps/visualizations/color.py index 2e247544cf..6fddc84286 100644 --- a/inference/core/workflows/core_steps/visualizations/color.py +++ b/inference/core/workflows/core_steps/visualizations/color.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/corner.py b/inference/core/workflows/core_steps/visualizations/corner.py index aee47eadc3..6135a38cf1 100644 --- a/inference/core/workflows/core_steps/visualizations/corner.py +++ b/inference/core/workflows/core_steps/visualizations/corner.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/crop.py b/inference/core/workflows/core_steps/visualizations/crop.py index 7dd2c6ddf8..74055515a4 100644 --- a/inference/core/workflows/core_steps/visualizations/crop.py +++ b/inference/core/workflows/core_steps/visualizations/crop.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/dot.py b/inference/core/workflows/core_steps/visualizations/dot.py index 565400fea1..6b1ed886fb 100644 --- a/inference/core/workflows/core_steps/visualizations/dot.py +++ b/inference/core/workflows/core_steps/visualizations/dot.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/ellipse.py b/inference/core/workflows/core_steps/visualizations/ellipse.py index 1692b548b0..329b05707b 100644 --- a/inference/core/workflows/core_steps/visualizations/ellipse.py +++ b/inference/core/workflows/core_steps/visualizations/ellipse.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/halo.py b/inference/core/workflows/core_steps/visualizations/halo.py index f58b3d119e..5cffc276a8 100644 --- a/inference/core/workflows/core_steps/visualizations/halo.py +++ b/inference/core/workflows/core_steps/visualizations/halo.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/label.py b/inference/core/workflows/core_steps/visualizations/label.py index 9d3ffe2052..a49e143539 100644 --- a/inference/core/workflows/core_steps/visualizations/label.py +++ b/inference/core/workflows/core_steps/visualizations/label.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/mask.py b/inference/core/workflows/core_steps/visualizations/mask.py index 40571f63c3..7f36557395 100644 --- a/inference/core/workflows/core_steps/visualizations/mask.py +++ b/inference/core/workflows/core_steps/visualizations/mask.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/pixelate.py b/inference/core/workflows/core_steps/visualizations/pixelate.py index 5a6a1a6e50..280b4640c2 100644 --- a/inference/core/workflows/core_steps/visualizations/pixelate.py +++ b/inference/core/workflows/core_steps/visualizations/pixelate.py @@ -1,8 +1,8 @@ from typing import Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import ( OUTPUT_IMAGE_KEY, VisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/polygon.py b/inference/core/workflows/core_steps/visualizations/polygon.py index 826e9bfa80..d68efe3eae 100644 --- a/inference/core/workflows/core_steps/visualizations/polygon.py +++ b/inference/core/workflows/core_steps/visualizations/polygon.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/triangle.py b/inference/core/workflows/core_steps/visualizations/triangle.py index 760944b675..53db5aff1f 100644 --- a/inference/core/workflows/core_steps/visualizations/triangle.py +++ b/inference/core/workflows/core_steps/visualizations/triangle.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union -import supervision as sv from pydantic import ConfigDict, Field +import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/execution_engine/executor/output_constructor.py b/inference/core/workflows/execution_engine/executor/output_constructor.py index 236273f334..fd65d06083 100644 --- a/inference/core/workflows/execution_engine/executor/output_constructor.py +++ b/inference/core/workflows/execution_engine/executor/output_constructor.py @@ -1,9 +1,9 @@ from typing import Any, Dict, List, Optional import numpy as np -import supervision as sv from networkx import DiGraph +import supervision as sv from inference.core.workflows.constants import WORKFLOW_INPUT_BATCH_LINEAGE_ID from inference.core.workflows.core_steps.common.utils import ( sv_detections_to_root_coordinates, diff --git a/inference/usage_tracking/collector.py b/inference/usage_tracking/collector.py index 9d857a2d78..df12c3d956 100644 --- a/inference/usage_tracking/collector.py +++ b/inference/usage_tracking/collector.py @@ -311,7 +311,7 @@ def system_info( if s: s.close() - + ip_address_hash_hex = UsageCollector._hash(ip_address) if not time_ns: From 7b48ed9faf004dab2b8292c9786081c6ae0e69da Mon Sep 17 00:00:00 2001 From: Peter Robicheaux Date: Fri, 19 Jul 2024 23:55:16 +0000 Subject: [PATCH 4/4] Style --- inference/core/interfaces/camera/video_source.py | 2 +- inference/core/interfaces/http/orjson_utils.py | 2 +- inference/core/interfaces/stream/sinks.py | 4 ++-- inference/core/interfaces/stream/stream.py | 2 +- inference/core/interfaces/stream/watchdog.py | 1 + inference/core/interfaces/udp/udp_stream.py | 2 +- .../common/query_language/operations/detections/base.py | 4 ++-- inference/core/workflows/core_steps/common/serializers.py | 2 +- inference/core/workflows/core_steps/common/utils.py | 4 ++-- .../core_steps/fusion/detections_classes_replacement.py | 4 ++-- .../core/workflows/core_steps/fusion/detections_consensus.py | 2 +- .../core_steps/models/third_party/barcode_detection.py | 4 ++-- .../core_steps/models/third_party/qr_code_detection.py | 4 ++-- .../core_steps/sinks/roboflow/roboflow_dataset_upload.py | 2 +- .../workflows/core_steps/transformations/detection_offset.py | 2 +- .../workflows/core_steps/transformations/detections_filter.py | 2 +- .../core_steps/transformations/detections_transformation.py | 2 +- .../core/workflows/core_steps/transformations/dynamic_crop.py | 2 +- .../workflows/core_steps/transformations/dynamic_zones.py | 2 +- .../core_steps/transformations/perspective_correction.py | 2 +- .../core_steps/visualizations/annotators/background_color.py | 1 - .../workflows/core_steps/visualizations/background_color.py | 2 +- inference/core/workflows/core_steps/visualizations/base.py | 2 +- .../workflows/core_steps/visualizations/base_colorable.py | 2 +- inference/core/workflows/core_steps/visualizations/blur.py | 2 +- .../core/workflows/core_steps/visualizations/bounding_box.py | 2 +- inference/core/workflows/core_steps/visualizations/circle.py | 2 +- inference/core/workflows/core_steps/visualizations/color.py | 2 +- inference/core/workflows/core_steps/visualizations/corner.py | 2 +- inference/core/workflows/core_steps/visualizations/crop.py | 2 +- inference/core/workflows/core_steps/visualizations/dot.py | 2 +- inference/core/workflows/core_steps/visualizations/ellipse.py | 2 +- inference/core/workflows/core_steps/visualizations/halo.py | 2 +- inference/core/workflows/core_steps/visualizations/label.py | 2 +- inference/core/workflows/core_steps/visualizations/mask.py | 2 +- .../core/workflows/core_steps/visualizations/pixelate.py | 2 +- inference/core/workflows/core_steps/visualizations/polygon.py | 2 +- .../core/workflows/core_steps/visualizations/triangle.py | 2 +- .../workflows/execution_engine/executor/output_constructor.py | 2 +- 39 files changed, 44 insertions(+), 44 deletions(-) diff --git a/inference/core/interfaces/camera/video_source.py b/inference/core/interfaces/camera/video_source.py index 9683a46614..81f4e90a74 100644 --- a/inference/core/interfaces/camera/video_source.py +++ b/inference/core/interfaces/camera/video_source.py @@ -7,9 +7,9 @@ from typing import Any, Callable, Dict, List, Optional, Protocol, Tuple, Union import cv2 +import supervision as sv from numpy import ndarray -import supervision as sv from inference.core import logger from inference.core.env import ( DEFAULT_ADAPTIVE_MODE_READER_PACE_TOLERANCE, diff --git a/inference/core/interfaces/http/orjson_utils.py b/inference/core/interfaces/http/orjson_utils.py index c96c810cd6..ffe4b47eec 100644 --- a/inference/core/interfaces/http/orjson_utils.py +++ b/inference/core/interfaces/http/orjson_utils.py @@ -2,10 +2,10 @@ from typing import Any, Dict, List, Optional, Union import orjson +import supervision as sv from fastapi.responses import ORJSONResponse from pydantic import BaseModel -import supervision as sv from inference.core.entities.responses.inference import InferenceResponse from inference.core.utils.function import deprecated from inference.core.utils.image_utils import ImageType diff --git a/inference/core/interfaces/stream/sinks.py b/inference/core/interfaces/stream/sinks.py index 468c8e2913..3e9affbef8 100644 --- a/inference/core/interfaces/stream/sinks.py +++ b/inference/core/interfaces/stream/sinks.py @@ -6,8 +6,9 @@ import cv2 import numpy as np - import supervision as sv +from supervision.annotators.base import BaseAnnotator + from inference.core import logger from inference.core.active_learning.middlewares import ActiveLearningMiddleware from inference.core.interfaces.camera.entities import VideoFrame @@ -15,7 +16,6 @@ from inference.core.interfaces.stream.utils import wrap_in_list from inference.core.utils.drawing import create_tiles from inference.core.utils.preprocess import letterbox_image -from supervision.annotators.base import BaseAnnotator DEFAULT_BBOX_ANNOTATOR = sv.BoundingBoxAnnotator() DEFAULT_LABEL_ANNOTATOR = sv.LabelAnnotator() diff --git a/inference/core/interfaces/stream/stream.py b/inference/core/interfaces/stream/stream.py index df60c05452..019383fd4b 100644 --- a/inference/core/interfaces/stream/stream.py +++ b/inference/core/interfaces/stream/stream.py @@ -6,10 +6,10 @@ import cv2 import numpy as np +import supervision as sv from PIL import Image import inference.core.entities.requests.inference -import supervision as sv from inference.core.active_learning.middlewares import ( NullActiveLearningMiddleware, ThreadingActiveLearningMiddleware, diff --git a/inference/core/interfaces/stream/watchdog.py b/inference/core/interfaces/stream/watchdog.py index d6f6fe846e..c9701efad0 100644 --- a/inference/core/interfaces/stream/watchdog.py +++ b/inference/core/interfaces/stream/watchdog.py @@ -9,6 +9,7 @@ from typing import Any, Deque, Dict, Iterable, List, Optional, TypeVar import supervision as sv + from inference.core.interfaces.camera.entities import ( StatusUpdate, UpdateSeverity, diff --git a/inference/core/interfaces/udp/udp_stream.py b/inference/core/interfaces/udp/udp_stream.py index c806c595a8..418c97343f 100644 --- a/inference/core/interfaces/udp/udp_stream.py +++ b/inference/core/interfaces/udp/udp_stream.py @@ -7,10 +7,10 @@ import cv2 import numpy as np +import supervision as sv from PIL import Image import inference.core.entities.requests.inference -import supervision as sv from inference.core.active_learning.middlewares import ( NullActiveLearningMiddleware, ThreadingActiveLearningMiddleware, diff --git a/inference/core/workflows/core_steps/common/query_language/operations/detections/base.py b/inference/core/workflows/core_steps/common/query_language/operations/detections/base.py index cc46a9f29c..c7e424c408 100644 --- a/inference/core/workflows/core_steps/common/query_language/operations/detections/base.py +++ b/inference/core/workflows/core_steps/common/query_language/operations/detections/base.py @@ -2,8 +2,9 @@ from typing import Any, Callable, Dict, List import numpy as np - import supervision as sv +from supervision import Position + from inference.core.workflows.core_steps.common.query_language.entities.enums import ( DetectionsProperty, DetectionsSelectionMode, @@ -18,7 +19,6 @@ from inference.core.workflows.core_steps.common.query_language.operations.utils import ( safe_stringify, ) -from supervision import Position PROPERTIES_EXTRACTORS = { DetectionsProperty.CONFIDENCE: lambda detections: detections.confidence.tolist(), diff --git a/inference/core/workflows/core_steps/common/serializers.py b/inference/core/workflows/core_steps/common/serializers.py index 3c8a540526..732c26fcb8 100644 --- a/inference/core/workflows/core_steps/common/serializers.py +++ b/inference/core/workflows/core_steps/common/serializers.py @@ -1,8 +1,8 @@ from typing import Any, Dict, List import numpy as np - import supervision as sv + from inference.core.workflows.constants import ( CLASS_ID_KEY, CLASS_NAME_KEY, diff --git a/inference/core/workflows/core_steps/common/utils.py b/inference/core/workflows/core_steps/common/utils.py index b976a6f3ba..51608802c1 100644 --- a/inference/core/workflows/core_steps/common/utils.py +++ b/inference/core/workflows/core_steps/common/utils.py @@ -4,8 +4,9 @@ from typing import Any, Dict, Iterable, List, Optional, Union import numpy as np - import supervision as sv +from supervision.config import CLASS_NAME_DATA_FIELD + from inference.core.entities.requests.clip import ClipCompareRequest from inference.core.entities.requests.cogvlm import CogVLMInferenceRequest from inference.core.entities.requests.doctr import DoctrOCRInferenceRequest @@ -42,7 +43,6 @@ OriginCoordinatesSystem, WorkflowImageData, ) -from supervision.config import CLASS_NAME_DATA_FIELD def load_core_model( diff --git a/inference/core/workflows/core_steps/fusion/detections_classes_replacement.py b/inference/core/workflows/core_steps/fusion/detections_classes_replacement.py index cf3f0d8d6f..675084ef73 100644 --- a/inference/core/workflows/core_steps/fusion/detections_classes_replacement.py +++ b/inference/core/workflows/core_steps/fusion/detections_classes_replacement.py @@ -2,9 +2,10 @@ from uuid import uuid4 import numpy as np +import supervision as sv from pydantic import ConfigDict, Field +from supervision.config import CLASS_NAME_DATA_FIELD -import supervision as sv from inference.core.workflows.constants import DETECTION_ID_KEY, PARENT_ID_KEY from inference.core.workflows.entities.base import Batch, OutputDefinition from inference.core.workflows.entities.types import ( @@ -19,7 +20,6 @@ WorkflowBlock, WorkflowBlockManifest, ) -from supervision.config import CLASS_NAME_DATA_FIELD LONG_DESCRIPTION = """ Combine results of detection model with classification results performed separately for diff --git a/inference/core/workflows/core_steps/fusion/detections_consensus.py b/inference/core/workflows/core_steps/fusion/detections_consensus.py index 4fb4dfccc8..945f6b0da6 100644 --- a/inference/core/workflows/core_steps/fusion/detections_consensus.py +++ b/inference/core/workflows/core_steps/fusion/detections_consensus.py @@ -17,9 +17,9 @@ from uuid import uuid4 import numpy as np +import supervision as sv from pydantic import AliasChoices, ConfigDict, Field, PositiveInt -import supervision as sv from inference.core.workflows.constants import ( DETECTION_ID_KEY, IMAGE_DIMENSIONS_KEY, diff --git a/inference/core/workflows/core_steps/models/third_party/barcode_detection.py b/inference/core/workflows/core_steps/models/third_party/barcode_detection.py index 5b1615678a..086dca1db9 100644 --- a/inference/core/workflows/core_steps/models/third_party/barcode_detection.py +++ b/inference/core/workflows/core_steps/models/third_party/barcode_detection.py @@ -2,10 +2,11 @@ from uuid import uuid4 import numpy as np +import supervision as sv import zxingcpp from pydantic import ConfigDict +from supervision.config import CLASS_NAME_DATA_FIELD -import supervision as sv from inference.core.workflows.constants import ( DETECTED_CODE_KEY, DETECTION_ID_KEY, @@ -31,7 +32,6 @@ WorkflowBlock, WorkflowBlockManifest, ) -from supervision.config import CLASS_NAME_DATA_FIELD LONG_DESCRIPTION = """ Detect the location of barcodes in an image. diff --git a/inference/core/workflows/core_steps/models/third_party/qr_code_detection.py b/inference/core/workflows/core_steps/models/third_party/qr_code_detection.py index cb6100381a..ff260e83ad 100644 --- a/inference/core/workflows/core_steps/models/third_party/qr_code_detection.py +++ b/inference/core/workflows/core_steps/models/third_party/qr_code_detection.py @@ -3,9 +3,10 @@ import cv2 import numpy as np +import supervision as sv from pydantic import AliasChoices, ConfigDict, Field +from supervision.config import CLASS_NAME_DATA_FIELD -import supervision as sv from inference.core.workflows.constants import ( DETECTED_CODE_KEY, DETECTION_ID_KEY, @@ -31,7 +32,6 @@ WorkflowBlock, WorkflowBlockManifest, ) -from supervision.config import CLASS_NAME_DATA_FIELD LONG_DESCRIPTION = """ Detect the location of a QR code. diff --git a/inference/core/workflows/core_steps/sinks/roboflow/roboflow_dataset_upload.py b/inference/core/workflows/core_steps/sinks/roboflow/roboflow_dataset_upload.py index c611bdbd65..ac41518314 100644 --- a/inference/core/workflows/core_steps/sinks/roboflow/roboflow_dataset_upload.py +++ b/inference/core/workflows/core_steps/sinks/roboflow/roboflow_dataset_upload.py @@ -7,10 +7,10 @@ from typing import Any, Dict, List, Literal, Optional, Tuple, Type, Union from uuid import uuid4 +import supervision as sv from fastapi import BackgroundTasks from pydantic import ConfigDict, Field -import supervision as sv from inference.core.active_learning.cache_operations import ( return_strategy_credit, use_credit_of_matching_strategy, diff --git a/inference/core/workflows/core_steps/transformations/detection_offset.py b/inference/core/workflows/core_steps/transformations/detection_offset.py index 3f793ceec3..579cbb6d14 100644 --- a/inference/core/workflows/core_steps/transformations/detection_offset.py +++ b/inference/core/workflows/core_steps/transformations/detection_offset.py @@ -3,9 +3,9 @@ from typing import Dict, List, Literal, Optional, Type, Union import numpy as np +import supervision as sv from pydantic import AliasChoices, ConfigDict, Field, PositiveInt -import supervision as sv from inference.core.workflows.constants import DETECTION_ID_KEY, PARENT_ID_KEY from inference.core.workflows.entities.base import Batch, OutputDefinition from inference.core.workflows.entities.types import ( diff --git a/inference/core/workflows/core_steps/transformations/detections_filter.py b/inference/core/workflows/core_steps/transformations/detections_filter.py index cd5801b71e..5c58ffae18 100644 --- a/inference/core/workflows/core_steps/transformations/detections_filter.py +++ b/inference/core/workflows/core_steps/transformations/detections_filter.py @@ -1,8 +1,8 @@ from typing import Any, Dict, List, Literal, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.common.query_language.entities.operations import ( AllOperationsType, OperationDefinition, diff --git a/inference/core/workflows/core_steps/transformations/detections_transformation.py b/inference/core/workflows/core_steps/transformations/detections_transformation.py index 41d6b5c17c..9fd3b01577 100644 --- a/inference/core/workflows/core_steps/transformations/detections_transformation.py +++ b/inference/core/workflows/core_steps/transformations/detections_transformation.py @@ -1,9 +1,9 @@ from copy import copy from typing import Any, Dict, List, Literal, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.common.query_language.entities.operations import ( DEFAULT_OPERAND_NAME, AllOperationsType, diff --git a/inference/core/workflows/core_steps/transformations/dynamic_crop.py b/inference/core/workflows/core_steps/transformations/dynamic_crop.py index 4da4a0bf60..b6c3eb7d62 100644 --- a/inference/core/workflows/core_steps/transformations/dynamic_crop.py +++ b/inference/core/workflows/core_steps/transformations/dynamic_crop.py @@ -1,9 +1,9 @@ from dataclasses import replace from typing import Dict, List, Literal, Optional, Type, Union +import supervision as sv from pydantic import AliasChoices, ConfigDict, Field -import supervision as sv from inference.core.workflows.constants import DETECTION_ID_KEY from inference.core.workflows.entities.base import ( Batch, diff --git a/inference/core/workflows/core_steps/transformations/dynamic_zones.py b/inference/core/workflows/core_steps/transformations/dynamic_zones.py index 1c6a84ced2..dc0a9c5233 100644 --- a/inference/core/workflows/core_steps/transformations/dynamic_zones.py +++ b/inference/core/workflows/core_steps/transformations/dynamic_zones.py @@ -2,9 +2,9 @@ import cv2 as cv import numpy as np +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.entities.base import Batch, OutputDefinition from inference.core.workflows.entities.types import ( BATCH_OF_INSTANCE_SEGMENTATION_PREDICTION_KIND, diff --git a/inference/core/workflows/core_steps/transformations/perspective_correction.py b/inference/core/workflows/core_steps/transformations/perspective_correction.py index b838f532c6..1edd5706ae 100644 --- a/inference/core/workflows/core_steps/transformations/perspective_correction.py +++ b/inference/core/workflows/core_steps/transformations/perspective_correction.py @@ -3,9 +3,9 @@ import cv2 as cv import numpy as np +import supervision as sv from pydantic import AliasChoices, ConfigDict, Field -import supervision as sv from inference.core.logger import logger from inference.core.workflows.constants import KEYPOINTS_XY_KEY_IN_SV_DETECTIONS from inference.core.workflows.entities.base import ( diff --git a/inference/core/workflows/core_steps/visualizations/annotators/background_color.py b/inference/core/workflows/core_steps/visualizations/annotators/background_color.py index accd9f9dcf..3af4391605 100644 --- a/inference/core/workflows/core_steps/visualizations/annotators/background_color.py +++ b/inference/core/workflows/core_steps/visualizations/annotators/background_color.py @@ -1,6 +1,5 @@ import cv2 import numpy as np - from supervision.annotators.base import BaseAnnotator, ImageType from supervision.detection.core import Detections from supervision.draw.color import Color diff --git a/inference/core/workflows/core_steps/visualizations/background_color.py b/inference/core/workflows/core_steps/visualizations/background_color.py index 0c624141f1..83bd2aabc6 100644 --- a/inference/core/workflows/core_steps/visualizations/background_color.py +++ b/inference/core/workflows/core_steps/visualizations/background_color.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.annotators.background_color import ( BackgroundColorAnnotator, ) diff --git a/inference/core/workflows/core_steps/visualizations/base.py b/inference/core/workflows/core_steps/visualizations/base.py index e4abfa8cbc..8dadaaa7a6 100644 --- a/inference/core/workflows/core_steps/visualizations/base.py +++ b/inference/core/workflows/core_steps/visualizations/base.py @@ -1,9 +1,9 @@ from abc import ABC, abstractmethod from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import AliasChoices, ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.utils import str_to_color from inference.core.workflows.entities.base import OutputDefinition, WorkflowImageData from inference.core.workflows.entities.types import ( diff --git a/inference/core/workflows/core_steps/visualizations/base_colorable.py b/inference/core/workflows/core_steps/visualizations/base_colorable.py index 9e41ce52b3..bc1a438cbe 100644 --- a/inference/core/workflows/core_steps/visualizations/base_colorable.py +++ b/inference/core/workflows/core_steps/visualizations/base_colorable.py @@ -1,9 +1,9 @@ from abc import ABC, abstractmethod from typing import List, Literal, Optional, Union +import supervision as sv from pydantic import Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import ( VisualizationBlock, VisualizationManifest, diff --git a/inference/core/workflows/core_steps/visualizations/blur.py b/inference/core/workflows/core_steps/visualizations/blur.py index 892bf2a4f9..d64568accf 100644 --- a/inference/core/workflows/core_steps/visualizations/blur.py +++ b/inference/core/workflows/core_steps/visualizations/blur.py @@ -1,8 +1,8 @@ from typing import Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import ( OUTPUT_IMAGE_KEY, VisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/bounding_box.py b/inference/core/workflows/core_steps/visualizations/bounding_box.py index 46608d497c..375d5f5b95 100644 --- a/inference/core/workflows/core_steps/visualizations/bounding_box.py +++ b/inference/core/workflows/core_steps/visualizations/bounding_box.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/circle.py b/inference/core/workflows/core_steps/visualizations/circle.py index bcc87bd2c0..ede5e38755 100644 --- a/inference/core/workflows/core_steps/visualizations/circle.py +++ b/inference/core/workflows/core_steps/visualizations/circle.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/color.py b/inference/core/workflows/core_steps/visualizations/color.py index 6fddc84286..2e247544cf 100644 --- a/inference/core/workflows/core_steps/visualizations/color.py +++ b/inference/core/workflows/core_steps/visualizations/color.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/corner.py b/inference/core/workflows/core_steps/visualizations/corner.py index 6135a38cf1..aee47eadc3 100644 --- a/inference/core/workflows/core_steps/visualizations/corner.py +++ b/inference/core/workflows/core_steps/visualizations/corner.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/crop.py b/inference/core/workflows/core_steps/visualizations/crop.py index 74055515a4..7dd2c6ddf8 100644 --- a/inference/core/workflows/core_steps/visualizations/crop.py +++ b/inference/core/workflows/core_steps/visualizations/crop.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/dot.py b/inference/core/workflows/core_steps/visualizations/dot.py index 6b1ed886fb..565400fea1 100644 --- a/inference/core/workflows/core_steps/visualizations/dot.py +++ b/inference/core/workflows/core_steps/visualizations/dot.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/ellipse.py b/inference/core/workflows/core_steps/visualizations/ellipse.py index 329b05707b..1692b548b0 100644 --- a/inference/core/workflows/core_steps/visualizations/ellipse.py +++ b/inference/core/workflows/core_steps/visualizations/ellipse.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/halo.py b/inference/core/workflows/core_steps/visualizations/halo.py index 5cffc276a8..f58b3d119e 100644 --- a/inference/core/workflows/core_steps/visualizations/halo.py +++ b/inference/core/workflows/core_steps/visualizations/halo.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/label.py b/inference/core/workflows/core_steps/visualizations/label.py index a49e143539..9d3ffe2052 100644 --- a/inference/core/workflows/core_steps/visualizations/label.py +++ b/inference/core/workflows/core_steps/visualizations/label.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/mask.py b/inference/core/workflows/core_steps/visualizations/mask.py index 7f36557395..40571f63c3 100644 --- a/inference/core/workflows/core_steps/visualizations/mask.py +++ b/inference/core/workflows/core_steps/visualizations/mask.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/pixelate.py b/inference/core/workflows/core_steps/visualizations/pixelate.py index 280b4640c2..5a6a1a6e50 100644 --- a/inference/core/workflows/core_steps/visualizations/pixelate.py +++ b/inference/core/workflows/core_steps/visualizations/pixelate.py @@ -1,8 +1,8 @@ from typing import Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import ( OUTPUT_IMAGE_KEY, VisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/polygon.py b/inference/core/workflows/core_steps/visualizations/polygon.py index d68efe3eae..826e9bfa80 100644 --- a/inference/core/workflows/core_steps/visualizations/polygon.py +++ b/inference/core/workflows/core_steps/visualizations/polygon.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/core_steps/visualizations/triangle.py b/inference/core/workflows/core_steps/visualizations/triangle.py index 53db5aff1f..760944b675 100644 --- a/inference/core/workflows/core_steps/visualizations/triangle.py +++ b/inference/core/workflows/core_steps/visualizations/triangle.py @@ -1,8 +1,8 @@ from typing import List, Literal, Optional, Type, Union +import supervision as sv from pydantic import ConfigDict, Field -import supervision as sv from inference.core.workflows.core_steps.visualizations.base import OUTPUT_IMAGE_KEY from inference.core.workflows.core_steps.visualizations.base_colorable import ( ColorableVisualizationBlock, diff --git a/inference/core/workflows/execution_engine/executor/output_constructor.py b/inference/core/workflows/execution_engine/executor/output_constructor.py index fd65d06083..236273f334 100644 --- a/inference/core/workflows/execution_engine/executor/output_constructor.py +++ b/inference/core/workflows/execution_engine/executor/output_constructor.py @@ -1,9 +1,9 @@ from typing import Any, Dict, List, Optional import numpy as np +import supervision as sv from networkx import DiGraph -import supervision as sv from inference.core.workflows.constants import WORKFLOW_INPUT_BATCH_LINEAGE_ID from inference.core.workflows.core_steps.common.utils import ( sv_detections_to_root_coordinates,