Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing multiprocessing memory leak in downbeats.py #505

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions madmom/features/downbeats.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,7 @@ def __init__(self, beats_per_bar, min_bpm=MIN_BPM, max_bpm=MAX_BPM,
'and `transition_lambda` must all have the same '
'length.')
# get num_threads from kwargs
num_threads = min(len(beats_per_bar), kwargs.get('num_threads', 1))
# init a pool of workers (if needed)
self.map = map
if num_threads != 1:
import multiprocessing as mp
self.map = mp.Pool(num_threads).map
self.num_threads = min(len(beats_per_bar), kwargs.get('num_threads', 1))
# convert timing information to construct a beat state space
min_interval = 60. * fps / max_bpm
max_interval = 60. * fps / min_bpm
Expand Down Expand Up @@ -277,8 +272,16 @@ def process(self, activations, **kwargs):
if not activations.any():
return np.empty((0, 2))
# (parallel) decoding of the activations with HMM
results = list(self.map(_process_dbn, zip(self.hmms,
it.repeat(activations))))
if self.num_threads == 1:
results = list(map(_process_dbn, zip(self.hmms,
it.repeat(activations))))
else:
# use a pool of workers (when needed)
import multiprocessing as mp
with mp.Pool(num_threads) as p:
results = list(p.map(_process_dbn, zip(self.hmms,
it.repeat(activations))))

# choose the best HMM (highest log probability)
best = np.argmax(list(r[1] for r in results))
# the best path through the state space
Expand Down