1313logger = logging .getLogger (__name__ )
1414
1515
16+ def _convert_classification_prediction (
17+ labels : Sequence [Label ], prediction : ClassificationResult
18+ ) -> list [DatasetItemAnnotation ]:
19+ predicted_labels : list [LabelReference ] = []
20+ predicted_confidences : list [float ] = []
21+ for predicted_label in prediction .top_labels :
22+ label_name = predicted_label .name
23+ label = next ((label for label in labels if label .name == label_name ), None )
24+ if not label :
25+ logger .warning ("Prediction label %s cannot be found in the project" , label_name )
26+ continue
27+ confidence = predicted_label .confidence
28+ if confidence is None :
29+ logger .warning ("The predicted label %s does not have a confidence score; assuming 1.0" , label_name )
30+ confidence = 1.0
31+ predicted_labels .append (LabelReference (id = label .id ))
32+ predicted_confidences .append (confidence )
33+ return [DatasetItemAnnotation (labels = predicted_labels , shape = FullImage (), confidences = predicted_confidences )]
34+
35+
1636def _convert_detection_prediction (labels : Sequence [Label ], prediction : DetectionResult ) -> list [DatasetItemAnnotation ]:
1737 result = []
38+ prediction_scores_list = prediction .scores .tolist ()
1839 for idx , box in enumerate (prediction .bboxes ):
1940 label_name = prediction .label_names [idx ]
20- confidence = prediction . scores . tolist () [idx ]
41+ bbox_confidence = prediction_scores_list [idx ]
2142 label = next ((label for label in labels if label .name == label_name ), None )
2243 if not label :
2344 logger .warning ("Prediction label %s cannot be found in the project" , label_name )
@@ -26,38 +47,23 @@ def _convert_detection_prediction(labels: Sequence[Label], prediction: Detection
2647 annotation = DatasetItemAnnotation (
2748 labels = [LabelReference (id = label .id )],
2849 shape = Rectangle (x = x1 , y = y1 , width = (x2 - x1 ), height = (y2 - y1 )),
29- confidence = confidence ,
50+ confidences = [ bbox_confidence ] ,
3051 )
3152 result .append (annotation )
3253 return result
3354
3455
35- def _convert_classification_prediction (
36- labels : Sequence [Label ], prediction : ClassificationResult
37- ) -> list [DatasetItemAnnotation ]:
38- annotation_labels : list [LabelReference ] = []
39- confidence = 0
40- for predicted_label in prediction .top_labels :
41- label_name = predicted_label .name
42- confidence = predicted_label .confidence
43- label = next ((label for label in labels if label .name == label_name ), None )
44- if not label :
45- logger .warning ("Prediction label %s cannot be found in the project" , label_name )
46- continue
47- annotation_labels .append (LabelReference (id = label .id ))
48- return [DatasetItemAnnotation (labels = annotation_labels , shape = FullImage (), confidence = confidence )]
49-
50-
5156def _convert_segmentation_prediction (
5257 labels : Sequence [Label ],
5358 frame_data : np .ndarray ,
5459 prediction : InstanceSegmentationResult ,
5560) -> list [DatasetItemAnnotation ]:
5661 height , width , _ = frame_data .shape
5762 result = []
63+ prediction_scores_list = prediction .scores .tolist ()
5864 for idx , box in enumerate (prediction .bboxes ):
5965 label_name = prediction .label_names [idx ]
60- confidence = prediction . scores . tolist () [idx ]
66+ polygon_confidence = prediction_scores_list [idx ]
6167 label = next ((label for label in labels if label .name == label_name ), None )
6268 if not label :
6369 logger .warning ("Prediction label %s cannot be found in the project" , label_name )
@@ -73,7 +79,7 @@ def _convert_segmentation_prediction(
7379 continue
7480 polygon = Polygon (points = [Point (x = point [0 ][0 ], y = point [0 ][1 ]) for point in list (contour )])
7581 annotation = DatasetItemAnnotation (
76- labels = [LabelReference (id = label .id )], shape = polygon , confidence = confidence
82+ labels = [LabelReference (id = label .id )], shape = polygon , confidences = [ polygon_confidence ]
7783 )
7884 result .append (annotation )
7985 return result
0 commit comments