Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'No labels found' after 'Caching labels' #1024

Closed
emmbertelen opened this issue Apr 8, 2020 · 35 comments
Closed

'No labels found' after 'Caching labels' #1024

emmbertelen opened this issue Apr 8, 2020 · 35 comments
Labels
bug Something isn't working

Comments

@emmbertelen
Copy link

🐛 Bug

I work in JupyterLab. I am trying to train with custom data. I have the exact same copy of my directory structure that Train Custom Data showed with Coco. The training stops with 'No labels found' after 'Caching labels'.

kép

Any idea on this?
Thanks.

@emmbertelen emmbertelen added the bug Something isn't working label Apr 8, 2020
@mdhasanai
Copy link

I also got the same error.

@mdhasanai
Copy link

I resolved it.
Image path should be

./coco/images/train100.jgp'
not 
../coco/images/train100.jgp'

remove one '.' from class files.

@emmbertelen
Copy link
Author

but you put the coco folder outside of yolo folder, right?

@mdhasanai
Copy link

but you put the coco folder outside of yolo folder, right?

Inside the yolo folder where train.py exists.

@glenn-jocher
Copy link
Member

all paths are relative to the yolov3 folder. In the tutorials the coco folder is alongside the yolov3 folder, not inside it.

@emmbertelen
Copy link
Author

@glenn-jocher I also tried with coco. I left everything as it is in the tutorial. I tried with the image set of data/coco1cls.txt, and coco alongside with yolo. Only created a coco1.names file with one class in it, and a coco1cls.data file:
kép

And the training died just like before:

kép

@glenn-jocher
Copy link
Member

@emmbertelen I updated the error message to show you exactly where it is looking in f54d28b

If you git pull and try again it will show you the search folder.

You should use the directory structure established in the tutorial and go from there.

@glenn-jocher
Copy link
Member

glenn-jocher commented Apr 8, 2020

For example, if I rename my coco folder and try to train, I see this. This path is relative to the yolov3 folder.

Namespace(accumulate=4, adam=False, batch_size=16, bucket='', cache_images=False, cfg='cfg/yolov3-spp.cfg', data='data/coco16.data', device='', epochs=300, evolve=False, img_size=[416], multi_scale=False, name='', nosave=False, notest=False, rect=False, resume=False, single_cls=False, weights='weights/yolov3-spp-ultralytics.pt')
Using CPU

Run 'tensorboard --logdir=runs' to view tensorboard at http://localhost:6006/
Model Summary: 225 layers, 6.29987e+07 parameters, 6.29987e+07 gradients
Caching labels: 100%|██████████| 16/16 [00:00<00:00, 86928.58it/s]
Traceback (most recent call last):
  File "/Users/glennjocher/PycharmProjects/yolov3/train.py", line 425, in <module>
    train()  # train normally
  File "/Users/glennjocher/PycharmProjects/yolov3/train.py", line 178, in train
    single_cls=opt.single_cls)
  File "/Users/glennjocher/PycharmProjects/yolov3/utils/datasets.py", line 382, in __init__
    assert nf > 0, 'No labels found in %s. See %s' % (os.path.dirname(file) + os.sep, help_url)
AssertionError: No labels found in ../coco/labels/train2017/. See https://docs.ultralytics.com/yolov5/tutorials/train_custom_data

@emmbertelen
Copy link
Author

@glenn-jocher Thank you very much for your help, it made me identify the problem. My "parent" directory, where I stored my custom images and labels was: 'tower_images'. And look at this: datasets.py replaced every "images" in the path. Im not sure if it is a bug, but this is one of the most hilarious thing that was blocking me for 2 days... Btw Im very thankful for your work and for this yolo implenetation, it really inspires me.
kép
So after all, I renamed my dataset's directory, and now it trains.

@glenn-jocher
Copy link
Member

glenn-jocher commented Apr 9, 2020

@emmbertelen ah great! No this is not a bug, it searches for /labels/ next to an /images/ folder.

@Nishaghoul
Copy link

Hey, I did use the correct path and still an error pops up.
The error that pops up is here,
Screenshot (110)

please have a look at my file directory and let me know where am I going wrong?
Screenshot (109)

@Nishaghoul
Copy link

please ignore the imagesfake and labelsfake folders

@glenn-jocher
Copy link
Member

glenn-jocher commented Apr 12, 2021

@Nishaghoul follow the YOLOv5 Train Custom Data Tutorial to get started. You can use COCO128 as an example of the proper dataset structure.

YOLOv5 Tutorials

@HarshSh24
Copy link

I was facing the same issue. I found that my labelling was not in right format. For example my label corresponding to image.jpg should be image.txt but my labeling was image.jpg.txt.
Hope this helps!!

@pavi2707
Copy link

pavi2707 commented Oct 27, 2021

I am having the same "No labels found error" . Please help!

Traceback (most recent call last):
File "/content/yolov5/train.py", line 627, in
main(opt)
File "/content/yolov5/train.py", line 524, in main
train(opt.hyp, opt, device, callbacks)
File "/content/yolov5/train.py", line 217, in train
prefix=colorstr('train: '))
File "/content/yolov5/utils/datasets.py", line 108, in create_dataloader
prefix=prefix)
File "/content/yolov5/utils/datasets.py", line 431, in init
assert nf > 0 or not augment, f'{prefix}No labels in {cache_path}. Can not train without labels. See {HELP_URL}'
AssertionError: train: No labels in ../content/yolov5/d/labels/train.cache. Can not train without labels. See https://docs.ultralytics.com/yolov5/tutorials/train_custom_data

@glenn-jocher
Copy link
Member

glenn-jocher commented Oct 27, 2021

@pavi2707 if not labels are found then you have set up your dataset incorrectly. See https://docs.ultralytics.com/yolov5/tutorials/train_custom_data for directions of dataset creation.

1.1 Create dataset.yaml

COCO128 is an example small tutorial dataset composed of the first 128 images in COCO train2017. These same 128 images are used for both training and validation to verify our training pipeline is capable of overfitting. data/coco128.yaml, shown below, is the dataset config file that defines 1) the dataset root directory path and relative paths to train / val / test image directories (or *.txt files with image paths), 2) the number of classes nc and 3) a list of class names:

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../datasets/coco128  # dataset root dir
train: images/train2017  # train images (relative to 'path') 128 images
val: images/train2017  # val images (relative to 'path') 128 images
test:  # test images (optional)

# Classes
nc: 80  # number of classes
names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
         'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
         'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
         'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
         'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
         'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
         'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
         'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
         'hair drier', 'toothbrush' ]  # class names

1.2 Create Labels

After using a tool like Roboflow Annotate to label your images, export your labels to YOLO format, with one *.txt file per image (if no objects in image, no *.txt file is required). The *.txt file specifications are:

  • One row per object
  • Each row is class x_center y_center width height format.
  • Box coordinates must be in normalized xywh format (from 0 - 1). If your boxes are in pixels, divide x_center and width by image width, and y_center and height by image height.
  • Class numbers are zero-indexed (start from 0).

Image Labels

The label file corresponding to the above image contains 2 persons (class 0) and a tie (class 27):

1.3 Organize Directories

Organize your train and val images and labels according to the example below. YOLOv5 assumes /coco128 is inside a /datasets directory next to the /yolov5 directory. YOLOv5 locates labels automatically for each image by replacing the last instance of /images/ in each image path with /labels/. For example:

../datasets/coco128/images/im0.jpg  # image
../datasets/coco128/labels/im0.txt  # label

@RAravindDS
Copy link

I am also facing the same error

@glenn-jocher
Copy link
Member

glenn-jocher commented Apr 21, 2022

@RAravindDS 👋 Hello! Thanks for asking about YOLOv5 🚀 dataset formatting. To train correctly your data must be in YOLOv5 format. Please see our Train Custom Data tutorial for full documentation on dataset setup and all steps required to start training your first model. A few excerpts from the tutorial:

1.1 Create dataset.yaml

COCO128 is an example small tutorial dataset composed of the first 128 images in COCO train2017. These same 128 images are used for both training and validation to verify our training pipeline is capable of overfitting. data/coco128.yaml, shown below, is the dataset config file that defines 1) the dataset root directory path and relative paths to train / val / test image directories (or *.txt files with image paths), 2) the number of classes nc and 3) a list of class names:

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../datasets/coco128  # dataset root dir
train: images/train2017  # train images (relative to 'path') 128 images
val: images/train2017  # val images (relative to 'path') 128 images
test:  # test images (optional)

# Classes
nc: 80  # number of classes
names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
         'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
         'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
         'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
         'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
         'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
         'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
         'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
         'hair drier', 'toothbrush' ]  # class names

1.2 Create Labels

After using a tool like Roboflow Annotate to label your images, export your labels to YOLO format, with one *.txt file per image (if no objects in image, no *.txt file is required). The *.txt file specifications are:

  • One row per object
  • Each row is class x_center y_center width height format.
  • Box coordinates must be in normalized xywh format (from 0 - 1). If your boxes are in pixels, divide x_center and width by image width, and y_center and height by image height.
  • Class numbers are zero-indexed (start from 0).

Image Labels

The label file corresponding to the above image contains 2 persons (class 0) and a tie (class 27):

1.3 Organize Directories

Organize your train and val images and labels according to the example below. YOLOv5 assumes /coco128 is inside a /datasets directory next to the /yolov5 directory. YOLOv5 locates labels automatically for each image by replacing the last instance of /images/ in each image path with /labels/. For example:

../datasets/coco128/images/im0.jpg  # image
../datasets/coco128/labels/im0.txt  # label

Good luck 🍀 and let us know if you have any other questions!

@Bergschaf
Copy link

Bergschaf commented Apr 21, 2022

I'm facing the same error, but the strange thing is, that it works for my training data, but it dosen't find any labels in the test data. Both have the same data structure.
Bild_2022-04-21_092137676
Bild_2022-04-21_092158507
Bild_2022-04-21_092628089

@RAravindDS
Copy link

RAravindDS commented Oct 11, 2022 via email

@gitDawn
Copy link

gitDawn commented Nov 30, 2022

It is not clear what is the difference between the annotations/ folder to the labels/ folder, and why do you need labels/ if the annotations/ includes exactly that.

@glenn-jocher
Copy link
Member

glenn-jocher commented Nov 30, 2022

👋 Hello! Thanks for asking about YOLOv5 🚀 dataset formatting. To train correctly your data must be in YOLOv5 format. Please see our Train Custom Data tutorial for full documentation on dataset setup and all steps required to start training your first model. A few excerpts from the tutorial:

1.1 Create dataset.yaml

COCO128 is an example small tutorial dataset composed of the first 128 images in COCO train2017. These same 128 images are used for both training and validation to verify our training pipeline is capable of overfitting. data/coco128.yaml, shown below, is the dataset config file that defines 1) the dataset root directory path and relative paths to train / val / test image directories (or *.txt files with image paths) and 2) a class names dictionary:

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../datasets/coco128  # dataset root dir
train: images/train2017  # train images (relative to 'path') 128 images
val: images/train2017  # val images (relative to 'path') 128 images
test:  # test images (optional)

# Classes (80 COCO classes)
names:
  0: person
  1: bicycle
  2: car
  ...
  77: teddy bear
  78: hair drier
  79: toothbrush

1.2 Create Labels

After using a tool like Roboflow Annotate to label your images, export your labels to YOLO format, with one *.txt file per image (if no objects in image, no *.txt file is required). The *.txt file specifications are:

  • One row per object
  • Each row is class x_center y_center width height format.
  • Box coordinates must be in normalized xywh format (from 0 - 1). If your boxes are in pixels, divide x_center and width by image width, and y_center and height by image height.
  • Class numbers are zero-indexed (start from 0).

The label file corresponding to the above image contains 2 persons (class 0) and a tie (class 27):

1.3 Organize Directories

Organize your train and val images and labels according to the example below. YOLOv5 assumes /coco128 is inside a /datasets directory next to the /yolov5 directory. YOLOv5 locates labels automatically for each image by replacing the last instance of /images/ in each image path with /labels/. For example:

../datasets/coco128/images/im0.jpg  # image
../datasets/coco128/labels/im0.txt  # label

Good luck 🍀 and let us know if you have any other questions!

@Sricharan01
Copy link

Sricharan01 commented Dec 26, 2022

@Nishaghoul , @glenn-jocher Hey I'm getting same error for YOLO v7 model. Can you help to solve this error......

image

@FraCamp
Copy link

FraCamp commented Mar 9, 2023

Is it possible to test using a pretreined model, on a custom dataset?
I have a custom dataset with COCO annotations, and I managed to get labels (in the same folder of the images with .txt extension) for every images, so I dont need to download them from COCO, but when I try test.py --options......... these errors:

test: Scanning 'dataset/test/testdevmob.cache' images and labels... 0 found, 0 missing, 0 empty, 126170 corrupted: 100%|███████████████████████████████| 126170/126170 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "test.py", line 319, in <module>
    test(opt.data,
  File "test.py", line 90, in test
    dataloader = create_dataloader(data[task], imgsz, batch_size, gs, opt, pad=0.5, rect=True,
  File "/workspace/utils/datasets.py", line 69, in create_dataloader
    dataset = LoadImagesAndLabels(path, imgsz, batch_size,
  File "/workspace/utils/datasets.py", line 408, in __init__
    labels, shapes, self.segments = zip(*cache.values())
ValueError: not enough values to unpack (expected 3, got 0)

Is there any solution?

@zhitkoalina
Copy link

@Nishaghoul , @glenn-jocher Hey I'm getting same error for YOLO v7 model. Can you help to solve this error......

image

same error here, did you find a solution?

@zhitkoalina
Copy link

!chmod +w /content/gdrive/My\ Drive/{your path here}/data/labels
solved it for me

@glenn-jocher
Copy link
Member

@songfy825 hello,

Thank you for sharing your solution to the YOLOv3 issue. It is great to hear that the chmod +w command worked for you. This command changes the permissions of the specified directory to allow write access for all users. It is important to be careful when executing such commands as it can potentially leave your system vulnerable.

If you have any further questions or require additional support, please do not hesitate to ask.

Best,

@songfy825
Copy link

thank you for your reply

@glenn-jocher
Copy link
Member

@songfy825 hello,

You're welcome. If you have any more questions or run into any issues, please don't hesitate to ask. We are here to help.

Best,

@Miarviolin
Copy link

I uploaded labels file in my drive .rar then extracted on google drive this solved the problem of no labels , as Idiscovered when upload file in google drive it changes it's format but if you extracted it in your drive it will keep the same format thank you

@glenn-jocher
Copy link
Member

@rigvedrs thank you for sharing your solution to the issue. It's great to hear that extracting the labels file directly in your Google Drive helped resolve the problem of missing labels. It seems that uploading the file to Google Drive might change its format, whereas extracting it in your own drive preserves the original format. We appreciate you sharing this insight with the community. If you have any more questions or need further assistance, please feel free to ask.

@rigvedrs
Copy link

rigvedrs commented Jul 2, 2023

@glenn-jocher I am experiencing a similar issue while using YOLO V8 and have added it as an issue here ultralytics/ultralytics#3485 (comment) . Can you check that out please whenever you have time.
Thanks!

@glenn-jocher
Copy link
Member

@rigvedrs hi there,

Thank you for reaching out and letting us know about the issue you're experiencing with YOLOv8. I understand that you have already added it as an issue on the Ultralytics GitHub repository.

As a reminder, please keep in mind that I am the author and maintainer of the Ultralytics YOLOv3 repository, and not the YOLOv8 repository. However, I will do my best to assist you and provide guidance.

To ensure your issue receives proper attention, I recommend providing as much detail as possible in your GitHub issue, such as the specific error message, steps to reproduce the issue, and any relevant code snippets. This will help the Ultralytics team and the community understand the problem you are facing and provide effective solutions.

Thank you for your understanding, and I hope your issue gets resolved soon.

Kind regards,

@pderrenger
Copy link
Member

Ensure your labels directory is correctly structured. Each image should have a corresponding .txt file in the /labels/ directory, with paths matching the /images/ directory. Double-check your dataset configuration and paths. If the issue persists, verify with the latest version of the repository.

@pderrenger
Copy link
Member

@RAravindDS ensure your labels are in the correct directory structure. Each image should have a corresponding .txt file in the /labels/ folder. Verify the paths in your dataset configuration file are correct. If the issue persists, check the format of your label files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests