这是我的实时目标检测代码的一部分
for i in range (classes.size): # here is my classes id is retrieved
if(classes[0][i] == 2 and scores[0][i]>0.5):
print("e waste detected")
我的输出是:
e waste detected
e waste detected
e waste detected
e waste detected..
.....
.... and so on.
我只想把这份声明打印一次。我能做什么?请帮帮我
如果触发了条件,可以使用break statement退出for循环。你知道吗
编辑:在没有数据文件的情况下,很难使用github上的代码来实现这一点,但这里有一个与您的用例类似的玩具示例:
除去中断符,您将看到现在看到的行为—但是请注意缩进,它应该在if语句中。你知道吗
尝试此操作(添加的代码用#NEW comment标记)
双大括号表示生成器理解,它在
any
找到第一个真值时停止。你知道吗相关问题 更多 >
编程相关推荐