Skip to content

Commit f630f37

Browse files
authored
Merge pull request #339 from Labelbox/tpeharda/DIAG-904-import-prediction-progress
[DIAG-904] Show Annotation Import progress
2 parents b814162 + 8d0487d commit f630f37

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

labelbox/data/annotation_types/classification/classification.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class ClassificationAnswer(FeatureSchema):
2525
- Because it inherits from FeatureSchema
2626
the option can be represented with either the name or feature_schema_id
2727
28-
- The key frame arg only applies to video classifications.
29-
Each answer can have a key frame indepdent of the others.
28+
- The keyframe arg only applies to video classifications.
29+
Each answer can have a keyframe independent of the others.
3030
So unlike object annotations, classification annotations
31-
track key frames at a classification answer level.
31+
track keyframes at a classification answer level.
3232
"""
3333
extra: Dict[str, Any] = {}
3434
keyframe: Optional[bool] = None

labelbox/schema/annotation_import.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import time
66
from typing import Any, Dict, List, BinaryIO
7+
from tqdm import tqdm # type: ignore
78

89
import backoff
910
import ndjson
@@ -25,6 +26,7 @@ class AnnotationImport(DbObject):
2526
input_file_url = Field.String("input_file_url")
2627
error_file_url = Field.String("error_file_url")
2728
status_file_url = Field.String("status_file_url")
29+
progress = Field.String("progress")
2830

2931
created_by = Relationship.ToOne("User", False, "created_by")
3032

@@ -76,18 +78,30 @@ def statuses(self) -> List[Dict[str, Any]]:
7678
self.wait_until_done()
7779
return self._fetch_remote_ndjson(self.status_file_url)
7880

79-
def wait_until_done(self, sleep_time_seconds: int = 10) -> None:
81+
def wait_until_done(self,
82+
sleep_time_seconds: int = 10,
83+
show_progress: bool = False) -> None:
8084
"""Blocks import job until certain conditions are met.
8185
Blocks until the AnnotationImport.state changes either to
8286
`AnnotationImportState.FINISHED` or `AnnotationImportState.FAILED`,
8387
periodically refreshing object's state.
8488
Args:
85-
sleep_time_seconds (str): a time to block between subsequent API calls
89+
sleep_time_seconds (int): a time to block between subsequent API calls
90+
show_progress (bool): should show progress bar
8691
"""
92+
pbar = tqdm(total=100,
93+
bar_format="{n}% |{bar}| [{elapsed}, {rate_fmt}{postfix}]"
94+
) if show_progress else None
8795
while self.state.value == AnnotationImportState.RUNNING.value:
8896
logger.info(f"Sleeping for {sleep_time_seconds} seconds...")
8997
time.sleep(sleep_time_seconds)
9098
self.__backoff_refresh()
99+
if self.progress and self.progress and pbar:
100+
pbar.update(int(self.progress.replace("%", "")) - pbar.n)
101+
102+
if pbar:
103+
pbar.update(100 - pbar.n)
104+
pbar.close()
91105

92106
@backoff.on_exception(
93107
backoff.expo,
@@ -499,7 +513,7 @@ def create_from_objects(cls, client: "labelbox.Client", project_id: str,
499513
client: Labelbox Client for executing queries
500514
project_id: Project to import labels into
501515
name: Name of the import job. Can be used to reference the task later
502-
labels: List of labels
516+
labels: List of labels
503517
Returns:
504518
LabelImport
505519
"""

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
"requests>=2.22.0",
2828
"google-api-core>=1.22.1",
2929
"pydantic>=1.8,<2.0",
30+
"tqdm",
3031
],
3132
extras_require={
3233
'data': [
3334
"shapely", "geojson", "numpy", "rasterio", "PILLOW",
34-
"opencv-python", "typeguard", "tqdm", "imagesize"
35+
"opencv-python", "typeguard", "imagesize"
3536
],
3637
},
3738
classifiers=[

0 commit comments

Comments
 (0)