From b46cfa48527c2e16794c1356cd69a2554716b22e Mon Sep 17 00:00:00 2001 From: dsplvd Date: Fri, 23 Feb 2024 10:56:41 -0300 Subject: [PATCH] Update yolov8.py results is empty when no objects are detected in frame so non iterable error fires. added itrable check on results --- python/ncnn/model_zoo/yolov8.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/python/ncnn/model_zoo/yolov8.py b/python/ncnn/model_zoo/yolov8.py index 6a512809a9ad..0debb9365100 100644 --- a/python/ncnn/model_zoo/yolov8.py +++ b/python/ncnn/model_zoo/yolov8.py @@ -18,6 +18,7 @@ from .model_store import get_model_file from ..utils.objects import Detect_Object from ..utils.functional import * +from typing import Iterable class YoloV8s: def __init__( @@ -204,17 +205,20 @@ def __call__(self, img): pred, self.prob_threshold, self.nms_threshold )[0] - objects = [ - Detect_Object( - obj[5], - obj[4], - (obj[0] - (wpad / 2)) / scale, - (obj[1] - (hpad / 2)) / scale, - (obj[2] - obj[0]) / scale, - (obj[3] - obj[1]) / scale, - ) - for obj in result - ] + if isinstance(result, Iterable): + objects = [ + Detect_Object( + obj[5], + obj[4], + (obj[0] - (wpad / 2)) / scale, + (obj[1] - (hpad / 2)) / scale, + (obj[2] - obj[0]) / scale, + (obj[3] - obj[1]) / scale, + ) + for obj in result + ] + else: + objects = [] return objects