From 7fc0a006f804a5d36c7eb0a7e923b3ef186f818a Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 27 May 2021 14:27:16 +0200 Subject: [PATCH] Ignore blank lines in `*.txt` labels Fix for https://github.com/ultralytics/yolov5/issues/958#issuecomment-849512083 --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index 36416b14e138..1ac689397f12 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -470,7 +470,7 @@ def cache_labels(self, path=Path('./labels.cache'), prefix=''): if os.path.isfile(lb_file): nf += 1 # label found with open(lb_file, 'r') as f: - l = [x.split() for x in f.read().strip().splitlines()] + l = [x.split() for x in f.read().strip().splitlines() if len(x)] if any([len(x) > 8 for x in l]): # is segment classes = np.array([x[0] for x in l], dtype=np.float32) segments = [np.array(x[1:], dtype=np.float32).reshape(-1, 2) for x in l] # (cls, xy1...)