工作中需要对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并行计算(持续更新)

 

相关文章:

  • 2021-09-22
  • 2022-12-23
  • 2022-02-09
  • 2022-02-23
  • 2021-12-28
  • 2021-12-05
  • 2022-12-23
  • 2022-01-27
猜你喜欢
  • 2021-08-09
  • 2021-05-21
  • 2021-10-01
  • 2022-02-09
  • 2021-10-22
  • 2021-09-10
  • 2021-09-09
相关资源
相似解决方案