工作中需要对tensorflow 的一个predict结果加速,利用python中的线程池

def getPPLs(tester,datas):

  for line in datas:
tester(line)

tester = run_epoch.rescore(session, test_lm, data, test_data, eval_op=None, test=True)
listDatas=splitList(test_data,16)#16 是线程的数量
threadsPool=[]
for sub_test_data in listDatas:
threadsPool.append(Thread(target=getPPLs, args=(tester, sub_test_data)))

for thread in threadsPool:
thread.start()

for thread in threadsPool:
thread.join()
tmd2=time()
print("tmd2-tmd1 ",tmd2-tmd1)

python并行计算(持续更新)-LMLPHP

04-30 04:19