def test_upload_dataset_with_label(self, accesskey, url, tmp_path): gas_client = GAS(access_key=accesskey, url=url) dataset_name = get_dataset_name() gas_client.create_dataset(dataset_name) dataset = Dataset(name=dataset_name) segment = dataset.create_segment("Segment1") # When uploading label, upload catalog first. dataset._catalog = Catalog.loads(CATALOG_CONTENTS) path = tmp_path / "sub" path.mkdir() local_path = path / "hello.txt" local_path.write_text("CONTENT") data = Data(local_path=str(local_path)) data.label = Label.loads(LABEL) segment.append(data) dataset_client = gas_client.upload_dataset(dataset) dataset_client.commit("upload dataset with label") dataset = Dataset(dataset_name, gas_client) assert dataset.catalog == Catalog.loads(CATALOG_CONTENTS) assert dataset[0][0].label == Label.loads(LABEL) statistics1 = dataset_client.get_label_statistics() assert statistics1 == Statistics(STATISTICS) total_size = dataset_client.get_total_size() assert total_size == TOTALSIZE gas_client.delete_dataset(dataset_name)
def test_get_label_statistics(self, mocker): params = self.dataset_client._status.get_status_info() response_data = { "labelStatistics": { "BOX2D": { "quantity": 10, "categories": [{ "name": "vehicles.bike", "quantity": 10, "attributes": [{ "name": "trafficLightColor", "enum": ["none", "red", "yellow"], "quantities": [5, 3, 2], }], }], } } } open_api_do = mocker.patch( f"{gas.__name__}.Client.open_api_do", return_value=mock_response(data=response_data), ) statistics1 = self.dataset_client.get_label_statistics() open_api_do.assert_called_once_with("GET", "labels/statistics", self.dataset_client.dataset_id, params=params) assert statistics1 == Statistics(response_data["labelStatistics"])
def get_label_statistics(self) -> Statistics: """Get label statistics of the search result. Returns: Required :class:`~tensorbay.client.dataset.Statistics`. """ params: Dict[str, Any] = {"commit": self.search_result_commit_id} return Statistics( self._client.open_api_do("GET", "labels/statistics", self.search_result_id, params=params).json()["labelStatistics"])
def get_label_statistics(self) -> Statistics: """Get label statistics of the dataset. Returns: Required :class:`~tensorbay.client.dataset.Statistics`. """ params: Dict[str, Any] = self._status.get_status_info() return Statistics( self._client.open_api_do("GET", "labels/statistics", self._dataset_id, params=params).json()["labelStatistics"])