Browse Source

Update yolov8.py (#5345)

results is empty when no objects are detected in frame so non iterable error fires. added itrable check on results
tags/20240410
dsplvd GitHub 2 years ago
parent
commit
3d8b7f8177
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 11 deletions
  1. +15
    -11
      python/ncnn/model_zoo/yolov8.py

+ 15
- 11
python/ncnn/model_zoo/yolov8.py View File

@@ -18,6 +18,7 @@ import ncnn
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 @@ class YoloV8s:
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



Loading…
Cancel
Save