From 3743a92784f6c2c0e5a4a0a836d4ec7696451b9c Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Thu, 1 Jun 2023 05:16:45 +0900 Subject: [PATCH 1/3] Fix backward compatibility of exportable code --- .../prediction_to_annotation_converter.py | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/otx/api/usecases/exportable_code/prediction_to_annotation_converter.py b/otx/api/usecases/exportable_code/prediction_to_annotation_converter.py index 277512818a0..dc8d73864f0 100644 --- a/otx/api/usecases/exportable_code/prediction_to_annotation_converter.py +++ b/otx/api/usecases/exportable_code/prediction_to_annotation_converter.py @@ -61,8 +61,13 @@ class DetectionToAnnotationConverter(IPredictionToAnnotationConverter): def __init__(self, labels: Union[LabelSchemaEntity, List], configuration: Optional[Dict[str, Any]] = None): self.labels = labels.get_labels(include_empty=False) if isinstance(labels, LabelSchemaEntity) else labels self.label_map = dict(enumerate(self.labels)) - self.use_ellipse_shapes = configuration["use_ellipse_shapes"] - self.confidence_threshold = configuration["confidence_threshold"] + self.use_ellipse_shapes = False + self.confidence_threshold = 0. + if configuration is not None: + if "use_ellipse_shapes" in configuration: + self.use_ellipse_shapes = configuration["use_ellipse_shapes"] + if "confidence_threshold" in configuration: + self.confidence_threshold = configuration["confidence_threshold"] def convert_to_annotation( self, predictions: np.ndarray, metadata: Optional[Dict[str, np.ndarray]] = None @@ -424,8 +429,13 @@ class MaskToAnnotationConverter(IPredictionToAnnotationConverter): def __init__(self, labels: LabelSchemaEntity, configuration: Optional[Dict[str, Any]] = None): self.labels = labels.get_labels(include_empty=False) - self.use_ellipse_shapes = configuration["use_ellipse_shapes"] - self.confidence_threshold = configuration["confidence_threshold"] + self.use_ellipse_shapes = False + self.confidence_threshold = 0. + if configuration is not None: + if "use_ellipse_shapes" in configuration: + self.use_ellipse_shapes = configuration["use_ellipse_shapes"] + if "confidence_threshold" in configuration: + self.confidence_threshold = configuration["confidence_threshold"] def convert_to_annotation(self, predictions: tuple, metadata: Dict[str, Any]) -> AnnotationSceneEntity: """Convert predictions to OTX Annotation Scene using the metadata. @@ -492,8 +502,13 @@ class RotatedRectToAnnotationConverter(IPredictionToAnnotationConverter): def __init__(self, labels: LabelSchemaEntity, configuration: Optional[Dict[str, Any]] = None): self.labels = labels.get_labels(include_empty=False) - self.use_ellipse_shapes = configuration["use_ellipse_shapes"] - self.confidence_threshold = configuration["confidence_threshold"] + self.use_ellipse_shapes = False + self.confidence_threshold = 0. + if configuration is not None: + if "use_ellipse_shapes" in configuration: + self.use_ellipse_shapes = configuration["use_ellipse_shapes"] + if "confidence_threshold" in configuration: + self.confidence_threshold = configuration["confidence_threshold"] def convert_to_annotation(self, predictions: tuple, metadata: Dict[str, Any]) -> AnnotationSceneEntity: """Convert predictions to OTX Annotation Scene using the metadata. From 45f05871cd1775b55d11010f2326793fa60745b3 Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Thu, 1 Jun 2023 05:19:11 +0900 Subject: [PATCH 2/3] Update exportable code reqs --- otx/api/usecases/exportable_code/demo/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/otx/api/usecases/exportable_code/demo/requirements.txt b/otx/api/usecases/exportable_code/demo/requirements.txt index 2f0e203eedf..1835b57ad05 100644 --- a/otx/api/usecases/exportable_code/demo/requirements.txt +++ b/otx/api/usecases/exportable_code/demo/requirements.txt @@ -1,4 +1,4 @@ openvino==2022.3.0 openmodelzoo-modelapi==2022.3.0 -otx==1.2.3 +otx @ git+https://github.com/openvinotoolkit/training_extensions/@3743a92784f6c2c0e5a4a0a836d4ec7696451b9c#egg=otx numpy>=1.21.0,<=1.23.5 # np.bool was removed in 1.24.0 which was used in openvino runtime From 5612c8799ad71661252b70e06bded5fa97f825f5 Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Thu, 1 Jun 2023 06:14:41 +0900 Subject: [PATCH 3/3] Fix black --- .../exportable_code/prediction_to_annotation_converter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/otx/api/usecases/exportable_code/prediction_to_annotation_converter.py b/otx/api/usecases/exportable_code/prediction_to_annotation_converter.py index dc8d73864f0..c4a84a50335 100644 --- a/otx/api/usecases/exportable_code/prediction_to_annotation_converter.py +++ b/otx/api/usecases/exportable_code/prediction_to_annotation_converter.py @@ -62,7 +62,7 @@ def __init__(self, labels: Union[LabelSchemaEntity, List], configuration: Option self.labels = labels.get_labels(include_empty=False) if isinstance(labels, LabelSchemaEntity) else labels self.label_map = dict(enumerate(self.labels)) self.use_ellipse_shapes = False - self.confidence_threshold = 0. + self.confidence_threshold = 0.0 if configuration is not None: if "use_ellipse_shapes" in configuration: self.use_ellipse_shapes = configuration["use_ellipse_shapes"] @@ -430,7 +430,7 @@ class MaskToAnnotationConverter(IPredictionToAnnotationConverter): def __init__(self, labels: LabelSchemaEntity, configuration: Optional[Dict[str, Any]] = None): self.labels = labels.get_labels(include_empty=False) self.use_ellipse_shapes = False - self.confidence_threshold = 0. + self.confidence_threshold = 0.0 if configuration is not None: if "use_ellipse_shapes" in configuration: self.use_ellipse_shapes = configuration["use_ellipse_shapes"] @@ -503,7 +503,7 @@ class RotatedRectToAnnotationConverter(IPredictionToAnnotationConverter): def __init__(self, labels: LabelSchemaEntity, configuration: Optional[Dict[str, Any]] = None): self.labels = labels.get_labels(include_empty=False) self.use_ellipse_shapes = False - self.confidence_threshold = 0. + self.confidence_threshold = 0.0 if configuration is not None: if "use_ellipse_shapes" in configuration: self.use_ellipse_shapes = configuration["use_ellipse_shapes"]