Skip to content
Advertisement

Predicting in parallel using concurrent.futures of tensorflow.keras models

I am trying to implement some parallel jobs using concurrent.futures. Each worker requires a copy of a TensorFlow model and some data. I implemented it in the following way (MWE)

JavaScript

simple_model() creates the model. clone_model clones a TensorFlow model. work represents an MWE of possible work. worker assigns the work in parallel.

This is not working, it just stuck and does not produce any output. However, the above code works if I replace ProcessPoolExecutor with ThreadPoolExecutor. But does not provide any speedup(it could be that it’s not running the workers in parallel).

From my understanding, the error lies in the argument model of future_to_samples = {executor.submit(work, model, seq): seq for model, seq in zip(model_list, seqences)}.

Advertisement

Answer

I modified the code such that it sends the path of the model than the model itself to the child processes. And it works.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement