diff --git a/tensorbay/client/segment.py b/tensorbay/client/segment.py index 63e526bd5..ddb8b9dd0 100644 --- a/tensorbay/client/segment.py +++ b/tensorbay/client/segment.py @@ -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. @@ -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.