Skip to content

Commit 67e026b

Browse files
author
Ubuntu
committed
Add docstrings
1 parent ffb2c08 commit 67e026b

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

nucleus/dataset.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import requests
44

55
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+
)
713
from nucleus.url_utils import sanitize_string_args
814
from nucleus.utils import (
915
convert_export_payload,
@@ -527,6 +533,7 @@ def get_scene(self, reference_id) -> Scene:
527533
)
528534

529535
def export_predictions(self, model):
536+
"""Exports all predications from a model run"""
530537
json_response = self._client.make_request(
531538
payload=None,
532539
route=f"dataset/{self.id}/model/{model.id}/export",
@@ -563,8 +570,32 @@ def calculate_evaluation_metrics(self, model, options=None):
563570
)
564571

565572
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,
567585
):
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+
"""
568599
if asynchronous:
569600
check_all_mask_paths_remote(predictions)
570601

@@ -586,6 +617,13 @@ def upload_predictions(
586617
)
587618

588619
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+
"""
589627
return format_prediction_response(
590628
self._client.make_request(
591629
payload=None,
@@ -595,6 +633,12 @@ def predictions_iloc(self, model, index):
595633
)
596634

597635
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+
"""
598642
return format_prediction_response(
599643
self._client.make_request(
600644
payload=None,
@@ -604,6 +648,13 @@ def predictions_refloc(self, model, reference_id):
604648
)
605649

606650
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+
"""
607658
return from_json(
608659
self._client.make_request(
609660
payload=None,

0 commit comments

Comments
 (0)