5050geometry | dict | Representation of the bounding box in the Box2DGeometry format.\n
5151metadata | dict | An arbitrary metadata blob for the annotation.\n
5252"""
53- __version__ = "0.1.0"
54-
5553import json
5654import logging
57- import warnings
5855import os
59- from typing import List , Union , Dict , Callable , Any , Optional
60-
61- import tqdm
62- import tqdm .notebook as tqdm_notebook
56+ import warnings
57+ from typing import Any , Callable , Dict , List , Optional , Union
6358
6459import grequests
60+ import pkg_resources
6561import requests
62+ import tqdm
63+ import tqdm .notebook as tqdm_notebook
6664from requests .adapters import HTTPAdapter
6765
6866# pylint: disable=E1101
6967# TODO: refactor to reduce this file to under 1000 lines.
7068# pylint: disable=C0302
7169from requests .packages .urllib3 .util .retry import Retry
7270
73- from .constants import REFERENCE_IDS_KEY , DATASET_ITEM_IDS_KEY , UPDATE_KEY
74- from .dataset import Dataset
75- from .dataset_item import DatasetItem
7671from .annotation import (
7772 BoxAnnotation ,
7873 PolygonAnnotation ,
79- SegmentationAnnotation ,
8074 Segment ,
81- )
82- from .prediction import (
83- BoxPrediction ,
84- PolygonPrediction ,
85- SegmentationPrediction ,
86- )
87- from .model_run import ModelRun
88- from .slice import Slice
89- from .upload_response import UploadResponse
90- from .payload_constructor import (
91- construct_append_payload ,
92- construct_annotation_payload ,
93- construct_model_creation_payload ,
94- construct_box_predictions_payload ,
95- construct_segmentation_payload ,
75+ SegmentationAnnotation ,
9676)
9777from .constants import (
98- NUCLEUS_ENDPOINT ,
78+ ANNOTATION_METADATA_SCHEMA_KEY ,
79+ ANNOTATIONS_IGNORED_KEY ,
80+ ANNOTATIONS_PROCESSED_KEY ,
81+ AUTOTAGS_KEY ,
82+ DATASET_ID_KEY ,
83+ DATASET_ITEM_IDS_KEY ,
9984 DEFAULT_NETWORK_TIMEOUT_SEC ,
100- ERRORS_KEY ,
85+ EMBEDDINGS_URL_KEY ,
10186 ERROR_ITEMS ,
10287 ERROR_PAYLOAD ,
103- ITEMS_KEY ,
104- ITEM_KEY ,
88+ ERRORS_KEY ,
10589 IMAGE_KEY ,
10690 IMAGE_URL_KEY ,
107- DATASET_ID_KEY ,
91+ ITEM_METADATA_SCHEMA_KEY ,
92+ ITEMS_KEY ,
10893 MODEL_RUN_ID_KEY ,
109- DATASET_ITEM_ID_KEY ,
110- SLICE_ID_KEY ,
111- ANNOTATIONS_PROCESSED_KEY ,
112- ANNOTATIONS_IGNORED_KEY ,
113- PREDICTIONS_PROCESSED_KEY ,
94+ NAME_KEY ,
95+ NUCLEUS_ENDPOINT ,
11496 PREDICTIONS_IGNORED_KEY ,
97+ PREDICTIONS_PROCESSED_KEY ,
98+ REFERENCE_IDS_KEY ,
99+ SLICE_ID_KEY ,
115100 STATUS_CODE_KEY ,
116- SUCCESS_STATUS_CODES ,
117- DATASET_NAME_KEY ,
118- DATASET_MODEL_RUNS_KEY ,
119- DATASET_SLICES_KEY ,
120- DATASET_LENGTH_KEY ,
121- NAME_KEY ,
122- ANNOTATIONS_KEY ,
123- AUTOTAGS_KEY ,
124- ANNOTATION_METADATA_SCHEMA_KEY ,
125- ITEM_METADATA_SCHEMA_KEY ,
126- EMBEDDINGS_URL_KEY ,
101+ UPDATE_KEY ,
127102)
128- from .model import Model
103+ from .dataset import Dataset
104+ from .dataset_item import DatasetItem
129105from .errors import (
106+ DatasetItemRetrievalError ,
130107 ModelCreationError ,
131108 ModelRunCreationError ,
132- DatasetItemRetrievalError ,
133109 NotFoundError ,
134110 NucleusAPIError ,
135111)
112+ from .model import Model
113+ from .model_run import ModelRun
114+ from .payload_constructor import (
115+ construct_annotation_payload ,
116+ construct_append_payload ,
117+ construct_box_predictions_payload ,
118+ construct_model_creation_payload ,
119+ construct_segmentation_payload ,
120+ )
121+ from .prediction import (
122+ BoxPrediction ,
123+ PolygonPrediction ,
124+ SegmentationPrediction ,
125+ )
126+ from .slice import Slice
127+ from .upload_response import UploadResponse
128+
129+ __version__ = pkg_resources .get_distribution ("scale-nucleus" ).version
136130
137131logger = logging .getLogger (__name__ )
138132logging .basicConfig ()
@@ -158,6 +152,8 @@ def __init__(
158152 self .endpoint = os .environ .get (
159153 "NUCLEUS_ENDPOINT" , NUCLEUS_ENDPOINT
160154 )
155+ else :
156+ self .endpoint = endpoint
161157 self ._use_notebook = use_notebook
162158 if use_notebook :
163159 self .tqdm_bar = tqdm_notebook .tqdm
@@ -230,13 +226,15 @@ def get_dataset(self, dataset_id: str) -> Dataset:
230226 """
231227 return Dataset (dataset_id , self )
232228
233- def get_model_run (self , model_run_id : str ) -> ModelRun :
229+ def get_model_run (self , model_run_id : str , dataset_id : str ) -> ModelRun :
234230 """
235231 Fetches a model_run for given id
236232 :param model_run_id: internally controlled model_run_id
233+ :param dataset_id: the dataset id which may determine the prediction schema
234+ for this model run if present on the dataset.
237235 :return: model_run
238236 """
239- return ModelRun (model_run_id , self )
237+ return ModelRun (model_run_id , dataset_id , self )
240238
241239 def delete_model_run (self , model_run_id : str ):
242240 """
@@ -674,7 +672,9 @@ def create_model_run(self, dataset_id: str, payload: dict) -> ModelRun:
674672 if response .get (STATUS_CODE_KEY , None ):
675673 raise ModelRunCreationError (response .get ("error" ))
676674
677- return ModelRun (response [MODEL_RUN_ID_KEY ], self )
675+ return ModelRun (
676+ response [MODEL_RUN_ID_KEY ], dataset_id = dataset_id , client = self
677+ )
678678
679679 def predict (
680680 self ,
0 commit comments