Ignore blank lines in `*.txt` labels (#3366)
Browse filesFix for https://github.com/ultralytics/yolov5/issues/958#issuecomment-849512083
- utils/datasets.py +1 -1
utils/datasets.py
CHANGED
@@ -474,7 +474,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|
474 |
if os.path.isfile(lb_file):
|
475 |
nf += 1 # label found
|
476 |
with open(lb_file, 'r') as f:
|
477 |
-
l = [x.split() for x in f.read().strip().splitlines()]
|
478 |
if any([len(x) > 8 for x in l]): # is segment
|
479 |
classes = np.array([x[0] for x in l], dtype=np.float32)
|
480 |
segments = [np.array(x[1:], dtype=np.float32).reshape(-1, 2) for x in l] # (cls, xy1...)
|
|
|
474 |
if os.path.isfile(lb_file):
|
475 |
nf += 1 # label found
|
476 |
with open(lb_file, 'r') as f:
|
477 |
+
l = [x.split() for x in f.read().strip().splitlines() if len(x)]
|
478 |
if any([len(x) > 8 for x in l]): # is segment
|
479 |
classes = np.array([x[0] for x in l], dtype=np.float32)
|
480 |
segments = [np.array(x[1:], dtype=np.float32).reshape(-1, 2) for x in l] # (cls, xy1...)
|