Skip to content

Commit

Permalink
Cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
minhtuevo committed Jan 11, 2025
1 parent 21c0fb9 commit f9abb61
Showing 1 changed file with 36 additions and 45 deletions.
81 changes: 36 additions & 45 deletions fiftyone/utils/eval/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
| `voxel51.com <https://voxel51.com/>`_
|
"""
import contextlib
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from copy import deepcopy
import inspect
Expand Down Expand Up @@ -202,51 +201,43 @@ def evaluate_detections(
)

matches = []
with contextlib.ExitStack() as stack:
if use_masks:
stack.enter_context(
_samples.download_context(
media_fields=[gt_field, pred_field], progress=progress
)
# Create a pool of workers
executor_cls = (
ProcessPoolExecutor
if executor_type == "process"
else ThreadPoolExecutor
)
with executor_cls(max_workers=num_workers) as executor:
futures = []

# Submit batches of samples to the worker pool
for sample in _samples.iter_samples(
progress=progress, batch_size=batch_size, autosave=save
):
if processing_frames:
docs = sample.frames.values()
else:
docs = [sample]

future = executor.submit(
_process_sample,
docs,
eval_method,
eval_key,
processing_frames,
)

# Create a pool of workers
executor_cls = (
ProcessPoolExecutor
if executor_type == "process"
else ThreadPoolExecutor
)
with executor_cls(max_workers=num_workers) as executor:
futures = []

# Submit batches of samples to the worker pool
for batch in _samples.iter_samples(
progress=progress, batch_size=batch_size, autosave=save
):
if processing_frames:
docs = batch.frames.values()
else:
docs = [batch]

future = executor.submit(
_process_sample,
docs,
eval_method,
eval_key,
processing_frames,
)
futures.append((future, batch))

# Collect results
for future, sample in futures:
batch_matches, batch_stats = future.result()
matches.extend(batch_matches)

if save:
sample_tp, sample_fp, sample_fn = batch_stats
sample[f"{eval_key}_tp"] = sample_tp
sample[f"{eval_key}_fp"] = sample_fp
sample[f"{eval_key}_fn"] = sample_fn
futures.append((future, sample))

# Collect results
for future, sample in futures:
sample_matches, sample_stats = future.result()
matches.extend(sample_matches)

if save:
sample_tp, sample_fp, sample_fn = sample_stats
sample[f"{eval_key}_tp"] = sample_tp
sample[f"{eval_key}_fp"] = sample_fp
sample[f"{eval_key}_fn"] = sample_fn

# Generate and save final results
results = eval_method.generate_results(
Expand Down

0 comments on commit f9abb61

Please sign in to comment.