|
3 | 3 | import logging |
4 | 4 | import os |
5 | 5 | import time |
6 | | -from typing import Any, Dict, List, BinaryIO |
7 | | -from tqdm import tqdm # type: ignore |
| 6 | +from typing import Any, BinaryIO, Dict, List |
8 | 7 |
|
9 | 8 | import backoff |
10 | 9 | import ndjson |
11 | 10 | import requests |
| 11 | +from tqdm import tqdm # type: ignore |
12 | 12 |
|
13 | 13 | import labelbox |
14 | 14 | from labelbox.orm import query |
15 | 15 | from labelbox.orm.db_object import DbObject |
16 | 16 | from labelbox.orm.model import Field, Relationship |
| 17 | +from labelbox.schema.annotation_import_validators import \ |
| 18 | + LabelsConfidencePresenceChecker |
17 | 19 | from labelbox.schema.enums import AnnotationImportState |
18 | 20 |
|
19 | 21 | NDJSON_MIME_TYPE = "application/x-ndjson" |
@@ -91,7 +93,7 @@ def wait_until_done(self, |
91 | 93 | """ |
92 | 94 | pbar = tqdm(total=100, |
93 | 95 | bar_format="{n}% |{bar}| [{elapsed}, {rate_fmt}{postfix}]" |
94 | | - ) if show_progress else None |
| 96 | + ) if show_progress else None |
95 | 97 | while self.state.value == AnnotationImportState.RUNNING.value: |
96 | 98 | logger.info(f"Sleeping for {sleep_time_seconds} seconds...") |
97 | 99 | time.sleep(sleep_time_seconds) |
@@ -451,6 +453,13 @@ def create_from_objects( |
451 | 453 | if not data_str: |
452 | 454 | raise ValueError('annotations cannot be empty') |
453 | 455 | data = data_str.encode('utf-8') |
| 456 | + |
| 457 | + has_confidence = LabelsConfidencePresenceChecker.check(predictions) |
| 458 | + if has_confidence: |
| 459 | + logger.warning(""" |
| 460 | + Confidence scores are not supported in MAL Prediction Import. |
| 461 | + Corresponding confidence score values will be ingored. |
| 462 | + """) |
454 | 463 | return cls._create_mal_import_from_bytes(client, project_id, name, data, |
455 | 464 | len(data)) |
456 | 465 |
|
@@ -603,6 +612,13 @@ def create_from_objects(cls, client: "labelbox.Client", project_id: str, |
603 | 612 | if not data_str: |
604 | 613 | raise ValueError('labels cannot be empty') |
605 | 614 | data = data_str.encode('utf-8') |
| 615 | + |
| 616 | + has_confidence = LabelsConfidencePresenceChecker.check(labels) |
| 617 | + if has_confidence: |
| 618 | + logger.warning(""" |
| 619 | + Confidence scores are not supported in Label Import. |
| 620 | + Corresponding confidence score values will be ignored. |
| 621 | + """) |
606 | 622 | return cls._create_label_import_from_bytes(client, project_id, name, |
607 | 623 | data, len(data)) |
608 | 624 |
|
@@ -661,7 +677,8 @@ def from_name(cls, |
661 | 677 | } |
662 | 678 | response = client.execute(query_str, params) |
663 | 679 | if response is None: |
664 | | - raise labelbox.exceptions.ResourceNotFoundError(LabelImport, params) |
| 680 | + raise labelbox.exceptions.ResourceNotFoundError( |
| 681 | + LabelImport, params) |
665 | 682 | response = response["labelImport"] |
666 | 683 | if as_json: |
667 | 684 | return response |
|
0 commit comments