def update_data(self): manager = LabelManager() build_params = self._label_build_params if self._data.workapp == WorkappType.IMAGE_SIESTA.value else None self._data = manager.update_label(label=self._data, info_build_params=build_params) if build_params is not None: self._init_label_build_info()
def test_get_labels_with_right_params(self, mock_response): id = uuid.uuid4() project_id = uuid.uuid4() response = mock_response.return_value response.status_code = 200 response.json.return_value = { 'data': { 'labels': { 'count': 100, 'edges': [{ 'id': id, 'projectId': project_id }] } } } manager = LabelManager() count, labels = manager.get_labels(project_id, page=0, page_size=10) self.assertEqual(count, 100) self.assertEqual(len(labels), 1) label = labels[0] self.assertEqual(label.id, id) self.assertEqual(label.project_id, project_id)
def test_get_labels_count(self, mock_response): response = mock_response.return_value response.status_code = 200 response.json.return_value = {'data': {'labels': {'count': 3}}} manager = LabelManager() count = manager.get_labels_count( project_id="29e6f25e-ac75-4882-9025-6ff73fd94cb1") self.assertEqual(count, 3)
def set_tags(self, tags: list = None): real_tags = [] if tags is not None and isinstance(tags, list): for tag in tags: real_tags.append(Tags(name=tag)) manager = LabelManager() self._data = manager.update_label_tags(label=self._data, tags=real_tags)
def test_get_label_detail_with_right_params(self, mock_response): response = mock_response.return_value response.status_code = 200 response.json.return_value = { "data": { "labels": { "count": 1, "edges": [{ "id": "29e6f25e-ac75-4882-9025-6ff73fd94cb1", "dataset": "dfdf", "dataKey": "Untitled.png", "tags": [{ "id": "2566992b-78a0-4ea0-9677-6811677d5e45", "name": "A" }], "result": { "objects": [{ "id": 1, "class": "person", "shape": { "box": { "x": 67.07317073170731, "y": 52.92682926829268, "width": 53.04878048780488, "height": 202.9268292682927 } }, "properties": [{ "name": "abc", "value": "a" }] }], "categorization": { "value": [] } }, "info_read_presigned_url": None, "info_write_presigned_url": None }] } } } label = Label(id=uuid.uuid4(), project_id=uuid.uuid4()) manager = LabelManager() manager.get_label(project_id=label.project_id, id=label.id)
def __init__(self, data, project): super().__init__() manager = LabelManager() if data.project_id is None or data.id is None: print('[ERROR] Data Handler cannot be initiated.') return self._data = data self._project = project self._created = time.time() if self._data.workapp == WorkappType.IMAGE_SIESTA.value: self._init_label_build_info()
def get_num_data(self, tags=[], **kwargs): if self._project is None: print('[WARNING] Project is not described') return None manager = LabelManager() tags = [{'name': tag} for tag in tags] option = {'project_id': self._project.id, 'tags': tags, **kwargs} num_data = manager.get_labels_count(**option) if num_data == 0: print('[WARNING] Data list is empty') return num_data
def test_get_0_labels_with_right_params(self, mock_response): response = mock_response.return_value response.status_code = 200 response.json.return_value = { 'data': { 'labels': { 'count': 0, 'edges': [] } } } manager = LabelManager() count, labels = manager.get_labels(project_id=uuid.uuid4(), page=0, page_size=10) self.assertEqual(count, 0) self.assertEqual(len(labels), 0)
def get_data_page(self, page_idx, page_size=10, num_data=None, tags=[], dataset=None, data_key=None, **kwargs): if num_data is None: num_data = self.get_num_data(tags=tags, **kwargs) num_pages = math.ceil(float(num_data) / page_size) if page_idx >= num_pages: print('[WARNING] Index out of bounds. Empty list returned') return [] workapp = self._project.workapp if workapp == 'video-siesta': # Video command = spb.Command(type='describe_videolabel') tags = [{'name': tag} for tag in tags] option = {'project_id': self._project.id, 'tags': tags, **kwargs} data_page, _ = spb.run(command=command, option=option, page=page_idx + 1, page_size=page_size) for data in data_page: yield VideoDataHandle(data, self._project) else: manager = LabelManager() tags = [{'name': tag} for tag in tags] option = { 'project_id': self._project.id, 'tags': tags, 'page': page_idx + 1, 'page_size': page_size, 'dataset': dataset, 'data_key': data_key, **kwargs } count, data_page = manager.get_labels(**option) for data in data_page: yield DataHandle(data, self._project)
def setUp(self): self.attrs = { 'id': uuid.uuid4(), 'project_id': uuid.uuid4(), 'tags': [Tags(name='TAG1'), Tags(name='TAG2')], 'status': '', 'stats': [Stats(name='STATS1', count=10)], 'data_id': uuid.uuid4(), 'dataset': 'TEST_DATASET_NAME', # [dataUrl] Init with property name -> To use response to model instance 'dataUrl': 'https://superb-ai.com', 'data': 'NOT YET IMPLEMENTED', 'result': { 'result': [] }, 'work_assignee': '*****@*****.**', 'label_type': '', 'related_label_method': '', 'consensus_status': '', 'consistency_score': 0.0 } self.label_manager = LabelManager()
def test_update_label(self, mock_response): response = mock_response.return_value response.status_code = 200 response.json.return_value = { "data": { "updateLabels": { "id": "29e6f25e-ac75-4882-9025-6ff73fd94cb1", "projectId": "b2a7205f-4f2a-4eb2-b845-3ed6af9a9fc5", "tags": [{ "id": "2566992b-78a0-4ea0-9677-6811677d5e45", "name": "A" }], "status": "SUBMITTED", "stats": [{ "name": "person", "count": 1 }], "workAssignee": "*****@*****.**", "labelType": "MAIN_LABEL", "relatedLabelMethod": "", "consensusStatus": "", "consistencyScore": 0, "dataId": "90722177-24f1-469f-9372-bb180f2a8c5e", "dataset": "dfdf", "dataKey": "Untitled.png", "dataUrl": "https://suite-asset.dev.superb-ai.com/apne2/tenants/pingu/assets/90722177-24f1-469f-9372-bb180f2a8c5e/image.png?Expires=1618384778&Signature=DEBpBduQI83HdfW6rouMxZiF73QvKp3teIpsvwcPvJGlSomN8GxiyOiTVE5R-5piJVhMCzbrAc~kbPFGgkciBceQEJOGMGxRnxlL4esAyMYzy28jETDwQpeXxHb5FYsYVe3YfRABaz8B2OOV1r2KElxW3NntEEc~6kcmbRPXKswZRFiXvYm1QPgAnUuaDHSzRBS8XKhB-jLhGFHfIzrrn47bazp1~aJIVfMRqgH8-7xhvVeEB65ijLuSmELQqg-S~pEmtfXQKeQ0z62Rlgn9IDkNiTo1gZf~r5kx0Wgf-yNyoyII2kiGvkRB8FqRuevU7hHsjk5B9fGj12sJRbm2lw__&Key-Pair-Id=APKAIBKPXKPWUNCICOBA", "result": { "objects": [{ "id": 1, "class": "person", "shape": { "box": { "x": 67.07317073170731, "y": 52.92682926829268, "width": 53.04878048780488, "height": 202.9268292682927 } }, "properties": [{ "name": "abc", "value": "a" }] }], "categorization": { "value": [] } }, "createdBy": "*****@*****.**", "createdAt": "2020-04-23T03:14:08.222649Z", "lastUpdatedBy": "*****@*****.**", "lastUpdatedAt": "2021-04-14T06:19:38.486464Z", "info_read_presigned_url": None, "info_write_presigned_url": None } } } manager = LabelManager() # update_label(self, project_id:uuid.UUID, id:uuid.UUID, result:dict, tags:list=[], **kwargs) label = Label(project_id="b2a7205f-4f2a-4eb2-b845-3ed6af9a9fc5", id="29e6f25e-ac75-4882-9025-6ff73fd94cb1", result={ "objects": [{ "id": 1, "class": "person", "shape": { "box": { "x": 67.07317073170731, "y": 52.92682926829268, "width": 53.04878048780488, "height": 202.9268292682927 } }, "properties": [{ "name": "abc", "value": "a" }] }], "categorization": { "value": [] } }, tags=[{ "name": "A" }]) manager.update_label(label=label)
def __init__(self): self.label_manager = LabelManager()