问题描述
我想得到 2 个模型的推断。
第一个模型(以 20fps 运行,Pytorch),第二个是网络摄像头馈送上的较重模型(推理时间 1 秒,Tensorflow)。
第一个模型将在每一帧上运行,另一个模型不需要在每一帧上运行,大约每 50 帧中就有一个。
我尝试使用多处理,但我被困在如何返回函数的输出上。两个模型的输入是相同的。 第一个模型处理帧并返回处理后的帧,第二个模型处理并返回字符串。 字符串需要和处理后的帧一起显示,每50帧更新一次。
我在下面写了一段伪代码,.start() 函数不返回处理后的输出,需要替换它。
def first_model(frame):
#Process frame here
return processed_frame
def second_model(frame):
#Process frame here
return string_output
cap = cv2.VideoCapture(0)
i = 0
second_output = "Random text" #Output of second model is a string
while(True):
_,frame = cv2.read()
p = multiprocessing.pool(args=(frame,),target=first_model)
first_output = p.start() #This is not correct
if(i%50 == 0):
q = multiprocessing.pool(args=(frame,target=second_model)
second_output = q.start() #Again,This is not allowed
cv2.putText(first_output,second_output,region) #Put second output on every frame,on some predefined region
cv2.imshow(first_output)
i = i + 1
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)