工作中需要對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)