Skip to content

Commit 3d8b7f8

Browse files
authored
Update yolov8.py (#5345)
results is empty when no objects are detected in frame so non iterable error fires. added itrable check on results
1 parent ddd17dd commit 3d8b7f8

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

python/ncnn/model_zoo/yolov8.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from .model_store import get_model_file
1919
from ..utils.objects import Detect_Object
2020
from ..utils.functional import *
21+
from typing import Iterable
2122

2223
class YoloV8s:
2324
def __init__(
@@ -204,17 +205,20 @@ def __call__(self, img):
204205
pred, self.prob_threshold, self.nms_threshold
205206
)[0]
206207

207-
objects = [
208-
Detect_Object(
209-
obj[5],
210-
obj[4],
211-
(obj[0] - (wpad / 2)) / scale,
212-
(obj[1] - (hpad / 2)) / scale,
213-
(obj[2] - obj[0]) / scale,
214-
(obj[3] - obj[1]) / scale,
215-
)
216-
for obj in result
217-
]
208+
if isinstance(result, Iterable):
209+
objects = [
210+
Detect_Object(
211+
obj[5],
212+
obj[4],
213+
(obj[0] - (wpad / 2)) / scale,
214+
(obj[1] - (hpad / 2)) / scale,
215+
(obj[2] - obj[0]) / scale,
216+
(obj[3] - obj[1]) / scale,
217+
)
218+
for obj in result
219+
]
220+
else:
221+
objects = []
218222

219223
return objects
220224

0 commit comments

Comments
 (0)