Skip to content

Commit

Permalink
Remove parallelism in face detection example (#7141)
Browse files Browse the repository at this point in the history
This is a temporary hotfix while [1] is being investigated.
Naturally, it has a similar performance compared to the single-threaded
Dask solution.

[1] #7140
  • Loading branch information
lagru committed Sep 21, 2023
1 parent 3c2111f commit b8c7f85
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import numpy as np
import matplotlib.pyplot as plt

from dask import delayed

from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score
Expand All @@ -48,7 +46,6 @@
# integral image within this ROI is computed. Finally, the integral image is
# used to extract the features.

@delayed
def extract_feature_image(img, feature_type, feature_coord=None):
"""Extract the haar feature for the current image"""
ii = integral_image(img)
Expand All @@ -67,12 +64,10 @@ def extract_feature_image(img, feature_type, feature_coord=None):
# To speed up the example, extract the two types of features only
feature_types = ['type-2-x', 'type-2-y']

# Build a computation graph using Dask. This allows the use of multiple
# CPU cores later during the actual computation
X = delayed(extract_feature_image(img, feature_types) for img in images)
# Compute the result
t_start = time()
X = np.array(X.compute(scheduler='single-threaded'))
X = [extract_feature_image(img, feature_types) for img in images]
X = np.stack(X)
time_full_feature_comp = time() - t_start

# Label images (100 faces and 100 non-faces)
Expand Down Expand Up @@ -139,12 +134,13 @@ def extract_feature_image(img, feature_type, feature_coord=None):
# but we would like to emphasize the usage of `feature_coord` and `feature_type`
# to recompute a subset of desired features.

# Build the computational graph using Dask
X = delayed(extract_feature_image(img, feature_type_sel, feature_coord_sel)
for img in images)
# Compute the result
t_start = time()
X = np.array(X.compute(scheduler='single-threaded'))
X = [
extract_feature_image(img, feature_type_sel, feature_coord_sel)
for img in images
]
X = np.stack(X)
time_subs_feature_comp = time() - t_start

y = np.array([1] * 100 + [0] * 100)
Expand Down

0 comments on commit b8c7f85

Please sign in to comment.