Empty label file may cause index error
This commit is contained in:
parent
476724be2d
commit
cd188dbde6
|
@ -141,13 +141,16 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
||||||
with open(label_path, 'r') as file:
|
with open(label_path, 'r') as file:
|
||||||
lines = file.read().splitlines()
|
lines = file.read().splitlines()
|
||||||
labels0 = np.array([x.split() for x in lines], dtype=np.float32)
|
labels0 = np.array([x.split() for x in lines], dtype=np.float32)
|
||||||
|
# If label file is empty
|
||||||
# Normalized xywh to pixel xyxy format
|
if labels0.size is 0:
|
||||||
labels = labels0.copy()
|
labels = np.array([])
|
||||||
labels[:, 1] = ratio * w * (labels0[:, 1] - labels0[:, 3] / 2) + padw
|
else:
|
||||||
labels[:, 2] = ratio * h * (labels0[:, 2] - labels0[:, 4] / 2) + padh
|
# Normalized xywh to pixel xyxy format
|
||||||
labels[:, 3] = ratio * w * (labels0[:, 1] + labels0[:, 3] / 2) + padw
|
labels = labels0.copy()
|
||||||
labels[:, 4] = ratio * h * (labels0[:, 2] + labels0[:, 4] / 2) + padh
|
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:
|
else:
|
||||||
labels = np.array([])
|
labels = np.array([])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue