diff --git a/inference/core/workflows/core_steps/visualizations/background_color/v1.py b/inference/core/workflows/core_steps/visualizations/background_color/v1.py index 824cbfb6d6..753d3992f1 100644 --- a/inference/core/workflows/core_steps/visualizations/background_color/v1.py +++ b/inference/core/workflows/core_steps/visualizations/background_color/v1.py @@ -90,15 +90,7 @@ def getAnnotator( color: str, opacity: float, ) -> sv.annotators.base.BaseAnnotator: - key = "_".join( - map( - str, - [ - color, - opacity, - ], - ) - ) + key = (color, opacity) if key not in self.annotatorCache: background_color = str_to_color(color) diff --git a/inference/core/workflows/core_steps/visualizations/common/utils.py b/inference/core/workflows/core_steps/visualizations/common/utils.py index 812e2c8333..79207174a4 100644 --- a/inference/core/workflows/core_steps/visualizations/common/utils.py +++ b/inference/core/workflows/core_steps/visualizations/common/utils.py @@ -1,5 +1,7 @@ import supervision as sv +_COLOR_NAMES = {name for name in dir(sv.Color) if not name.startswith("_")} + def str_to_color(color: str) -> sv.Color: if color.startswith("#"): @@ -10,7 +12,7 @@ def str_to_color(color: str) -> sv.Color: elif color.startswith("bgr"): b, g, r = map(int, color[4:-1].split(",")) return sv.Color.from_bgr_tuple((b, g, r)) - elif hasattr(sv.Color, color.upper()): + elif color.upper() in _COLOR_NAMES: return getattr(sv.Color, color.upper()) else: raise ValueError(