From cd188dbde67890e49df7163af4b9316c164e9d4b Mon Sep 17 00:00:00 2001 From: WannaSeaU <1473628258@QQ.COM> Date: Fri, 22 Mar 2019 18:59:09 +0800 Subject: [PATCH] Empty label file may cause index error --- utils/datasets.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index 6ccefcc3..92b59f5b 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -141,13 +141,16 @@ class LoadImagesAndLabels(Dataset): # for training/testing with open(label_path, 'r') as file: lines = file.read().splitlines() labels0 = np.array([x.split() for x in lines], dtype=np.float32) - - # Normalized xywh to pixel xyxy format - labels = labels0.copy() - labels[:, 1] = ratio * w * (labels0[:, 1] - labels0[:, 3] / 2) + padw - labels[:, 2] = ratio * h * (labels0[:, 2] - labels0[:, 4] / 2) + padh - labels[:, 3] = ratio * w * (labels0[:, 1] + labels0[:, 3] / 2) + padw - labels[:, 4] = ratio * h * (labels0[:, 2] + labels0[:, 4] / 2) + padh + # If label file is empty + if labels0.size is 0: + labels = np.array([]) + else: + # Normalized xywh to pixel xyxy format + labels = labels0.copy() + labels[:, 1] = ratio * w * (labels0[:, 1] - labels0[:, 3] / 2) + padw + labels[:, 2] = ratio * h * (labels0[:, 2] - labels0[:, 4] / 2) + padh + labels[:, 3] = ratio * w * (labels0[:, 1] + labels0[:, 3] / 2) + padw + labels[:, 4] = ratio * h * (labels0[:, 2] + labels0[:, 4] / 2) + padh else: labels = np.array([])