class MyThread(threading.Thread): #继承父类threading.Thread
def init(self, data_set, dir_model):
threading.Thread.init(self)
self.data_set = data_set
self.dir_model = dir_model
def run(self): #把要执行的代码写到run函数里面 线程在创建后会直接运行run函数
s_time = time.time()
reid_feats, occ_feats = infer(self.data_set, self.dir_model)
print(time.time() - s_time)
for _ in range(8):
myThread = MyThread(data_set, dir_model)
myThread.run()
尹文宾 给我写的模板
多线程特征推断
本文介绍了一种使用多线程进行特征推断的方法,通过继承threading.Thread类实现线程,加速了reid_feats和occ_feats的计算过程。演示了如何在创建线程后直接运行run函数,执行代码并打印运行时间。
1346

被折叠的 条评论
为什么被折叠?



