3
3
import requests
4
4
5
5
from nucleus .job import AsyncJob
6
- from nucleus .prediction import from_json
6
+ from nucleus .prediction import (
7
+ BoxPrediction ,
8
+ CuboidPrediction ,
9
+ PolygonPrediction ,
10
+ SegmentationPrediction ,
11
+ from_json ,
12
+ )
7
13
from nucleus .url_utils import sanitize_string_args
8
14
from nucleus .utils import (
9
15
convert_export_payload ,
@@ -527,6 +533,7 @@ def get_scene(self, reference_id) -> Scene:
527
533
)
528
534
529
535
def export_predictions (self , model ):
536
+ """Exports all predications from a model run"""
530
537
json_response = self ._client .make_request (
531
538
payload = None ,
532
539
route = f"dataset/{ self .id } /model/{ model .id } /export" ,
@@ -563,8 +570,32 @@ def calculate_evaluation_metrics(self, model, options=None):
563
570
)
564
571
565
572
def upload_predictions (
566
- self , model , predictions , update = False , asynchronous = False
573
+ self ,
574
+ model ,
575
+ predictions : List [
576
+ Union [
577
+ BoxPrediction ,
578
+ PolygonPrediction ,
579
+ CuboidPrediction ,
580
+ SegmentationPrediction ,
581
+ ]
582
+ ],
583
+ update = False ,
584
+ asynchronous = False ,
567
585
):
586
+ """
587
+ Uploads model outputs as predictions for a model_run. Returns info about the upload.
588
+ :param predictions: List of prediction objects to ingest
589
+ :param update: Whether to update (if true) or ignore (if false) on conflicting reference_id/annotation_id
590
+ :param asynchronous: If true, return launch and then return a reference to an asynchronous job object. This is recommended for large ingests.
591
+ :return:
592
+ If synchronoius
593
+ {
594
+ "model_run_id": str,
595
+ "predictions_processed": int,
596
+ "predictions_ignored": int,
597
+ }
598
+ """
568
599
if asynchronous :
569
600
check_all_mask_paths_remote (predictions )
570
601
@@ -586,6 +617,13 @@ def upload_predictions(
586
617
)
587
618
588
619
def predictions_iloc (self , model , index ):
620
+ """
621
+ Returns predictions For Dataset Item by index.
622
+ :param model: model object to get predictions from.
623
+ :param index: absolute number of Dataset Item for a dataset corresponding to the model run.
624
+ :return: List[Union[BoxPrediction, PolygonPrediction, CuboidPrediction, SegmentationPrediction]],
625
+ }
626
+ """
589
627
return format_prediction_response (
590
628
self ._client .make_request (
591
629
payload = None ,
@@ -595,6 +633,12 @@ def predictions_iloc(self, model, index):
595
633
)
596
634
597
635
def predictions_refloc (self , model , reference_id ):
636
+ """
637
+ Returns predictions for dataset Item by its reference_id.
638
+ :param model: model object to get predictions from.
639
+ :param reference_id: reference_id of a dataset item.
640
+ :return: List[Union[BoxPrediction, PolygonPrediction, CuboidPrediction, SegmentationPrediction]],
641
+ """
598
642
return format_prediction_response (
599
643
self ._client .make_request (
600
644
payload = None ,
@@ -604,6 +648,13 @@ def predictions_refloc(self, model, reference_id):
604
648
)
605
649
606
650
def prediction_loc (self , model , reference_id , annotation_id ):
651
+ """
652
+ Returns info for single Prediction by its reference id and annotation id. Not supported for segmentation predictions yet.
653
+ :param reference_id: the user specified id for the image
654
+ :param annotation_id: the user specified id for the prediction, or if one was not provided, the Scale internally generated id for the prediction
655
+ :return:
656
+ BoxPrediction | PolygonPrediction | CuboidPrediction
657
+ """
607
658
return from_json (
608
659
self ._client .make_request (
609
660
payload = None ,
0 commit comments