Merge pull request #151 from WannaSeaU/patch-1
Empty label file may cause index error
This commit is contained in:
commit
eafa2740db
|
@ -137,17 +137,20 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|||
|
||||
# Load labels
|
||||
if os.path.isfile(label_path):
|
||||
# labels0 = np.loadtxt(label_path, dtype=np.float32).reshape(-1, 5) # SLOWER
|
||||
with open(label_path, 'r') as file:
|
||||
lines = file.read().splitlines()
|
||||
labels0 = np.array([x.split() for x in lines], dtype=np.float32)
|
||||
|
||||
x = np.array([x.split() for x in lines], dtype=np.float32)
|
||||
if x.size is 0:
|
||||
# Empty labels file
|
||||
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
|
||||
labels = x.copy()
|
||||
labels[:, 1] = ratio * w * (x[:, 1] - x[:, 3] / 2) + padw
|
||||
labels[:, 2] = ratio * h * (x[:, 2] - x[:, 4] / 2) + padh
|
||||
labels[:, 3] = ratio * w * (x[:, 1] + x[:, 3] / 2) + padw
|
||||
labels[:, 4] = ratio * h * (x[:, 2] + x[:, 4] / 2) + padh
|
||||
else:
|
||||
labels = np.array([])
|
||||
|
||||
|
|
Loading…
Reference in New Issue