CNN Model Body

This commit is contained in:
Steffen Illium
2020-02-16 21:00:07 +01:00
parent 1ce8d5993b
commit 2e60b19fa6
9 changed files with 412 additions and 318 deletions

23
lib/utils/parallel.py Normal file
View File

@ -0,0 +1,23 @@
import multiprocessing as mp
import time
def run_n_in_parallel(f, n, **kwargs):
output = mp.Queue()
kwargs.update(output=output)
# Setup a list of processes that we want to run
processes = [mp.Process(target=f, kwargs=kwargs) for _ in range(n)]
# Run processes
results = []
for p in processes:
p.start()
while len(results) != n:
time.sleep(1)
# Get process results from the output queue
results.extend([output.get() for _ in processes])
# Exit the completed processes
for p in processes:
p.join()
return results