Skip to content

Commit fdf2936

Browse files
committed
report progress of delegated operations
1 parent d458e19 commit fdf2936

12 files changed

+125
-9
lines changed

plugins/annotation/__init__.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
|
77
"""
88
import contextlib
9+
import inspect
910
import json
1011
import threading
1112

@@ -893,8 +894,17 @@ def execute(self, ctx):
893894

894895
_inject_annotation_secrets(ctx)
895896

897+
kwargs = {}
898+
899+
if ctx.delegated:
900+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
901+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
902+
896903
ctx.dataset.load_annotations(
897-
anno_key, unexpected=unexpected, cleanup=cleanup
904+
anno_key,
905+
unexpected=unexpected,
906+
cleanup=cleanup,
907+
**kwargs,
898908
)
899909

900910
if not ctx.delegated:

plugins/annotation/fiftyone.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "@voxel51/annotation"
22
description: Utilities for integrating FiftyOne with annotation tools
33
version: 1.0.1
44
fiftyone:
5-
version: ">=0.22"
5+
version: ">=0.23.3"
66
url: https://github.com/voxel51/fiftyone-plugins/tree/main/plugins/annotation
77
license: Apache 2.0
88
operators:

plugins/brain/__init__.py

+36
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import base64
99
from collections import defaultdict
1010
from datetime import datetime
11+
import inspect
1112
import json
1213

1314
from bson import json_util
@@ -72,6 +73,13 @@ def execute(self, ctx):
7273
num_workers = 0
7374

7475
target_view = _get_target_view(ctx, target)
76+
77+
kwargs = {}
78+
79+
if ctx.delegated:
80+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
81+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
82+
7583
fob.compute_visualization(
7684
target_view,
7785
patches_field=patches_field,
@@ -82,6 +90,7 @@ def execute(self, ctx):
8290
batch_size=batch_size,
8391
num_workers=num_workers,
8492
skip_failures=skip_failures,
93+
**kwargs,
8594
)
8695

8796

@@ -176,6 +185,11 @@ def execute(self, ctx):
176185
num_workers = 0
177186

178187
target_view = _get_target_view(ctx, target)
188+
189+
if ctx.delegated:
190+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
191+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
192+
179193
fob.compute_similarity(
180194
target_view,
181195
patches_field=patches_field,
@@ -1057,6 +1071,13 @@ def execute(self, ctx):
10571071
num_workers = 0
10581072

10591073
target_view = _get_target_view(ctx, target)
1074+
1075+
kwargs = {}
1076+
1077+
if ctx.delegated:
1078+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
1079+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
1080+
10601081
fob.compute_uniqueness(
10611082
target_view,
10621083
uniqueness_field=uniqueness_field,
@@ -1066,6 +1087,7 @@ def execute(self, ctx):
10661087
batch_size=batch_size,
10671088
num_workers=num_workers,
10681089
skip_failures=skip_failures,
1090+
**kwargs,
10691091
)
10701092

10711093
if not ctx.delegated:
@@ -1142,6 +1164,11 @@ def execute(self, ctx):
11421164
mistakenness_field = kwargs.pop("mistakenness_field")
11431165

11441166
target_view = _get_target_view(ctx, target)
1167+
1168+
if ctx.delegated:
1169+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
1170+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
1171+
11451172
fob.compute_mistakenness(
11461173
target_view,
11471174
pred_field,
@@ -1320,12 +1347,21 @@ def execute(self, ctx):
13201347
target = ctx.params.get("target", None)
13211348
label_field = ctx.params.get("label_field")
13221349
hardness_field = ctx.params.get("hardness_field")
1350+
delegate = ctx.params.get("delegate", False)
13231351

13241352
target_view = _get_target_view(ctx, target)
1353+
1354+
kwargs = {}
1355+
1356+
if ctx.delegated:
1357+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
1358+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
1359+
13251360
fob.compute_hardness(
13261361
target_view,
13271362
label_field,
13281363
hardness_field=hardness_field,
1364+
**kwargs,
13291365
)
13301366

13311367
if not ctx.delegated:

plugins/brain/fiftyone.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "@voxel51/brain"
22
description: Utilities for working with the FiftyOne Brain
33
version: 1.1.1
44
fiftyone:
5-
version: ">=0.22"
5+
version: ">=0.23.3"
66
url: https://github.com/voxel51/fiftyone-plugins/tree/main/plugins/brain
77
license: Apache 2.0
88
operators:

plugins/evaluation/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
| `voxel51.com <https://voxel51.com/>`_
66
|
77
"""
8+
import inspect
89
import json
910

1011
from bson import json_util
@@ -61,6 +62,10 @@ def execute(self, ctx):
6162
elif eval_type == "segmentation":
6263
eval_fcn = target_view.evaluate_segmentations
6364

65+
if ctx.delegated:
66+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
67+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
68+
6469
eval_fcn(
6570
pred_field,
6671
gt_field=gt_field,

plugins/evaluation/fiftyone.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "@voxel51/evaluation"
22
description: Utilities for evaluating models with FiftyOne
33
version: 1.0.1
44
fiftyone:
5-
version: ">=0.22"
5+
version: ">=0.23.3"
66
url: https://github.com/voxel51/fiftyone-plugins/tree/main/plugins/evaluation
77
license: Apache 2.0
88
operators:

plugins/io/__init__.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88
import base64
99
import contextlib
10+
import inspect
1011
import multiprocessing.dummy
1112
import os
1213

@@ -820,8 +821,13 @@ def _import_media_only(ctx):
820821
make_sample = lambda f: fo.Sample(filepath=f, tags=tags)
821822

822823
if ctx.delegated:
824+
kwargs = {}
825+
826+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
827+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
828+
823829
samples = map(make_sample, filepaths)
824-
ctx.dataset.add_samples(samples, num_samples=len(filepaths))
830+
ctx.dataset.add_samples(samples, num_samples=len(filepaths), **kwargs)
825831
return
826832

827833
batcher = fou.DynamicBatcher(
@@ -859,6 +865,10 @@ def _import_media_and_labels(ctx):
859865
if label_types is not None:
860866
kwargs["label_types"] = label_types
861867

868+
if ctx.delegated:
869+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
870+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
871+
862872
ctx.dataset.add_dir(
863873
dataset_dir=dataset_dir,
864874
dataset_type=dataset_type,
@@ -899,6 +909,10 @@ def _import_labels_only(ctx):
899909
if label_types is not None:
900910
kwargs["label_types"] = label_types
901911

912+
if ctx.delegated:
913+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
914+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
915+
902916
with contextlib.ExitStack() as exit_context:
903917
if labels_file is not None:
904918
tmp_dir = exit_context.enter_context(fos.TempDir())
@@ -2062,6 +2076,10 @@ def _export_samples(ctx):
20622076
if "abs_paths" not in kwargs:
20632077
kwargs["abs_paths"] = abs_paths
20642078

2079+
if ctx.delegated:
2080+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
2081+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
2082+
20652083
target_view.export(
20662084
export_dir=export_dir,
20672085
dataset_type=dataset_type,
@@ -2534,10 +2552,17 @@ def execute(self, ctx):
25342552

25352553
target_view = _get_target_view(ctx, target)
25362554

2555+
kwargs = {}
2556+
2557+
if ctx.delegated:
2558+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
2559+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
2560+
25372561
target_view.draw_labels(
25382562
output_dir,
25392563
label_fields=label_fields,
25402564
overwrite=overwrite,
2565+
**kwargs,
25412566
)
25422567

25432568

plugins/io/fiftyone.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "@voxel51/io"
22
description: A collection of import/export utilities
33
version: 1.0.1
44
fiftyone:
5-
version: ">=0.22.2"
5+
version: ">=0.23.3"
66
url: https://github.com/voxel51/fiftyone-plugins/tree/main/plugins/io
77
license: Apache 2.0
88
operators:

plugins/utils/__init__.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
|
77
"""
88
import contextlib
9+
import inspect
910
import json
1011
import multiprocessing.dummy
1112

@@ -1479,7 +1480,14 @@ def execute(self, ctx):
14791480
view = _get_target_view(ctx, target)
14801481

14811482
if ctx.delegated:
1482-
view.compute_metadata(overwrite=overwrite, num_workers=num_workers)
1483+
kwargs = {}
1484+
1485+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
1486+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
1487+
1488+
view.compute_metadata(
1489+
overwrite=overwrite, num_workers=num_workers, **kwargs
1490+
)
14831491
else:
14841492
for update in _compute_metadata_generator(
14851493
ctx, view, overwrite=overwrite, num_workers=num_workers
@@ -1785,13 +1793,20 @@ def execute(self, ctx):
17851793
if not ctx.delegated:
17861794
num_workers = 0
17871795

1796+
kwargs = {}
1797+
1798+
if ctx.delegated:
1799+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
1800+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
1801+
17881802
foui.transform_images(
17891803
view,
17901804
size=size,
17911805
output_field=thumbnail_path,
17921806
output_dir=output_dir,
17931807
num_workers=num_workers,
17941808
skip_failures=True,
1809+
**kwargs,
17951810
)
17961811

17971812
if thumbnail_path not in ctx.dataset.app_config.media_fields:
@@ -2118,6 +2133,17 @@ def execute(self, ctx):
21182133
args = ctx.params["args"]
21192134
kwargs = ctx.params["kwargs"]
21202135

2136+
# Special handling if we find a `progress` kwarg that is float/int
2137+
progress = kwargs.get("progress", None)
2138+
if isinstance(progress, float):
2139+
# Report progress every `progress` seconds
2140+
set_progress = lambda pb: ctx.set_progress(progress=pb.progress)
2141+
kwargs["progress"] = fo.report_progress(set_progress, dt=progress)
2142+
elif isinstance(progress, int):
2143+
# Report progress every in `progress` equally-spaced increments
2144+
set_progress = lambda pb: ctx.set_progress(progress=pb.progress)
2145+
kwargs["progress"] = fo.report_progress(set_progress, n=progress)
2146+
21212147
if has_view:
21222148
sample_collection = ctx.view
21232149
elif has_dataset:

plugins/utils/fiftyone.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "@voxel51/utils"
22
description: A collection of utility operators
33
version: 1.1.1
44
fiftyone:
5-
version: ">=0.22"
5+
version: ">=0.23.3"
66
url: https://github.com/voxel51/fiftyone-plugins/tree/main/plugins/utils
77
license: Apache 2.0
88
operators:

plugins/zoo/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
|
77
"""
88
from collections import defaultdict
9+
import inspect
910

1011
import fiftyone as fo
1112
import fiftyone.operators as foo
@@ -48,6 +49,10 @@ def execute(self, ctx):
4849

4950
dataset_name = _get_zoo_dataset_name(ctx)
5051

52+
if ctx.delegated:
53+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
54+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
55+
5156
dataset = foz.load_zoo_dataset(
5257
name,
5358
splits=splits,
@@ -547,6 +552,12 @@ def execute(self, ctx):
547552
if not ctx.delegated:
548553
num_workers = 0
549554

555+
kwargs = {}
556+
557+
if ctx.delegated:
558+
progress = lambda pb: ctx.set_progress(progress=pb.progress)
559+
kwargs["progress"] = fo.report_progress(progress, dt=5.0)
560+
550561
if embeddings and patches_field is not None:
551562
target_view.compute_patch_embeddings(
552563
model,
@@ -555,6 +566,7 @@ def execute(self, ctx):
555566
batch_size=batch_size,
556567
num_workers=num_workers,
557568
skip_failures=skip_failures,
569+
**kwargs,
558570
)
559571
elif embeddings:
560572
target_view.compute_embeddings(
@@ -563,6 +575,7 @@ def execute(self, ctx):
563575
batch_size=batch_size,
564576
num_workers=num_workers,
565577
skip_failures=skip_failures,
578+
**kwargs,
566579
)
567580
else:
568581
target_view.apply_model(
@@ -575,6 +588,7 @@ def execute(self, ctx):
575588
skip_failures=skip_failures,
576589
output_dir=output_dir,
577590
rel_dir=rel_dir,
591+
**kwargs,
578592
)
579593

580594
if not ctx.delegated:

plugins/zoo/fiftyone.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "@voxel51/zoo"
22
description: A collection of FiftyOne Zoo utilities
33
version: 1.1.1
44
fiftyone:
5-
version: ">=0.22"
5+
version: ">=0.23.3"
66
url: https://github.com/voxel51/fiftyone-plugins/tree/main/plugins/zoo
77
license: Apache 2.0
88
operators:

0 commit comments

Comments
 (0)