From b987ecd4baa57ac9862b0eae14722cdd2ce0dcbb Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Wed, 31 May 2023 18:21:10 +0200 Subject: [PATCH] Fix possible bw issue in exportable code (#2212) * Fix backward compatibility of exportable code * Update exportable code reqs * Fix black --- .../exportable_code/demo/requirements.txt | 2 +- .../prediction_to_annotation_converter.py | 27 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) 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 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..c4a84a50335 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.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.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.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.