Skip to content

Commit

Permalink
feat(client): adapt OpenAPI uploadMultiLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
zhen.chen committed Mar 7, 2022
1 parent 3a04358 commit 5b26087
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions tensorbay/client/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,43 @@ def _upload_label(self, data: Union[AuthData, Data]) -> None:

self._client.open_api_do("PUT", "labels", self._dataset_id, json=post_data)

def _upload_multi_label(self, data: Iterable[Union[AuthData, Data, RemoteData]]) -> None:
post_data: Dict[str, Any] = {
"segmentName": self.name,
"labels": [],
}
for single_data in data:
label = single_data.label.dumps()
if not label:
continue

remote_path = (
single_data.path
if isinstance(single_data, RemoteData)
else single_data.target_remote_path
)
post_data["label"].append({"remotePath": remote_path, "label": label})
post_data.update(self._status.get_status_info())

self._client.open_api_do("PUT", "multi/data/labels", self._dataset_id, json=post_data)

def upload_label(self, data: Union[Data, Iterable[Data]]) -> None:
"""Upload label with Data object to the draft.
Arguments:
data: The data object which represents the local file to upload.
"""
self._status.check_authority_for_draft()

if isinstance(data, Data):
data = [data]

for chunked_data in chunked(data, 128):
self._upload_multi_label(chunked_data)
for single_data in chunked_data:
self._upload_mask_files(single_data.label)

@property
def name(self) -> str:
"""Return the segment name.
Expand Down Expand Up @@ -458,18 +495,6 @@ def upload_file(self, local_path: str, target_remote_path: str = "") -> None:

self._synchronize_upload_info((data.get_callback_body(),))

def upload_label(self, data: Data) -> None:
"""Upload label with Data object to the draft.
Arguments:
data: The data object which represents the local file to upload.
"""
self._status.check_authority_for_draft()

self._upload_mask_files(data.label)
self._upload_label(data)

def upload_data(self, data: Data) -> None:
"""Upload Data object to the draft.
Expand Down

0 comments on commit 5b26087

Please sign in to comment.