@@ -56,6 +56,14 @@ def format_prediction_response(
56
56
]
57
57
],
58
58
]:
59
+ """Helper function to convert JSON response from endpoints to python objects
60
+
61
+ Args:
62
+ response: JSON dictionary response from REST endpoint.
63
+ Returns:
64
+ annotation_response: Dictionary containing a list of annotations for each type,
65
+ keyed by the type name.
66
+ """
59
67
annotation_payload = response .get (ANNOTATIONS_KEY , None )
60
68
if not annotation_payload :
61
69
# An error occurred
@@ -86,43 +94,15 @@ def format_prediction_response(
86
94
return annotation_response
87
95
88
96
89
- def _get_all_field_values (metadata_list : List [dict ], key : str ):
90
- return {metadata [key ] for metadata in metadata_list if key in metadata }
91
-
92
-
93
- def suggest_metadata_schema (
94
- data : Union [
95
- List [DatasetItem ],
96
- List [BoxPrediction ],
97
- List [PolygonPrediction ],
98
- List [CuboidPrediction ],
99
- ]
100
- ):
101
- metadata_list : List [dict ] = [
102
- d .metadata for d in data if d .metadata is not None
103
- ]
104
- schema = {}
105
- all_keys = {k for metadata in metadata_list for k in metadata .keys ()}
106
-
107
- all_key_values : Dict [str , set ] = {
108
- k : _get_all_field_values (metadata_list , k ) for k in all_keys
109
- }
110
-
111
- for key , values in all_key_values .items ():
112
- entry : dict = {}
113
- if all (isinstance (x , (float , int )) for x in values ):
114
- entry ["type" ] = "number"
115
- elif len (values ) <= 50 :
116
- entry ["type" ] = "category"
117
- entry ["choices" ] = list (values )
118
- else :
119
- entry ["type" ] = "text"
120
- schema [key ] = entry
121
- return schema
122
-
123
-
124
97
def format_dataset_item_response (response : dict ) -> dict :
125
- """Format the raw client response into api objects."""
98
+ """Format the raw client response into api objects.
99
+
100
+ Args:
101
+ response: JSON dictionary response from REST endpoint
102
+ Returns:
103
+ item_dict: A dictionary with two entries, one for the dataset item, and annother
104
+ for all of the associated annotations.
105
+ """
126
106
if ANNOTATIONS_KEY not in response :
127
107
raise ValueError (
128
108
f"Server response was missing the annotation key: { response } "
@@ -148,6 +128,15 @@ def format_dataset_item_response(response: dict) -> dict:
148
128
149
129
150
130
def convert_export_payload (api_payload ):
131
+ """Helper function to convert raw JSON to API objects
132
+
133
+ Args:
134
+ api_payload: JSON dictionary response from REST endpoint
135
+ Returns:
136
+ return_payload: A list of dictionaries for each dataset item. Each dictionary
137
+ is in the same format as format_dataset_item_response: one key for the
138
+ dataset item, another for the annotations.
139
+ """
151
140
return_payload = []
152
141
for row in api_payload :
153
142
return_payload_row = {}
@@ -225,6 +214,7 @@ def serialize_and_write_to_presigned_url(
225
214
dataset_id : str ,
226
215
client ,
227
216
):
217
+ """This helper function can be used to serialize a list of API objects to NDJSON."""
228
218
request_id = uuid .uuid4 ().hex
229
219
response = client .make_request (
230
220
payload = {},
0 commit comments