ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.13k stars 16.43k forks source link

FileNotFoundError: [Errno 2] No such file or directory: '../data/labels/train.cache' #2788

Closed harrytrinh2 closed 3 years ago

harrytrinh2 commented 3 years ago

πŸ› Bug

I first run this command to train the model: ╰─❯ python train.py --img 640 --batch 8 --epoch 50 --data squareone_jusRol/squareone_jusRol.yaml --weight yolov5s.pt

How ever I cannot train model because FileNotFoundError: [Errno 2] No such file or directory: 'squareone_jusRol/data/labels/train.cache'


github: ⚠️ WARNING: code is out of date by 14 commits. Use 'git pull' to update or 'git clone https://github.com/ultralytics/yolov5' to download latest.
YOLOv5 πŸš€ v4.0-189-gc03d590 torch 1.8.1+cu102 CUDA:0 (GeForce RTX 2080 Ti, 11016.4375MB)
                                             CUDA:1 (GeForce RTX 2080 Ti, 11019.4375MB)

Namespace(adam=False, artifact_alias='latest', batch_size=8, bbox_interval=-1, bucket='', cache_images=False, cfg='', data='squareone_jusRol/squareone_jusRol.yaml', device='', entity=None, epochs=50, evolve=False, exist_ok=False, global_rank=-1, hyp='data/hyp.scratch.yaml', image_weights=False, img_size=[640, 640], label_smoothing=0.0, linear_lr=False, local_rank=-1, multi_scale=False, name='exp', noautoanchor=False, nosave=False, notest=False, project='runs/train', quad=False, rect=False, resume=False, save_dir='runs/train/exp', save_period=-1, single_cls=False, sync_bn=False, total_batch_size=8, upload_dataset=False, weights='yolov5s.pt', workers=8, world_size=1)
tensorboard: Start with 'tensorboard --logdir runs/train', view at http://localhost:6006/
hyperparameters: lr0=0.01, lrf=0.2, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0
wandb: Currently logged in as: phuccoi96 (use `wandb login --relogin` to force relogin)
wandb: Tracking run with wandb version 0.10.26
wandb: Syncing run exp
wandb: ⭐ View project at https://wandb.ai/phuccoi96/YOLOv5
wandb: πŸš€ View run at https://wandb.ai/phuccoi96/YOLOv5/runs/1wsy7a28
wandb: Run data is saved locally in /home/woody/LogoDetection/yolov5/wandb/run-20210414_163447-1wsy7a28
wandb: Run `wandb offline` to turn off syncing.

Overriding model.yaml nc=80 with nc=2

                 from  n    params  module                                  arguments                     
  0                -1  1      3520  models.common.Focus                     [3, 32, 3]                    
  1                -1  1     18560  models.common.Conv                      [32, 64, 3, 2]                
  2                -1  1     18816  models.common.C3                        [64, 64, 1]                   
  3                -1  1     73984  models.common.Conv                      [64, 128, 3, 2]               
  4                -1  1    156928  models.common.C3                        [128, 128, 3]                 
  5                -1  1    295424  models.common.Conv                      [128, 256, 3, 2]              
  6                -1  1    625152  models.common.C3                        [256, 256, 3]                 
  7                -1  1   1180672  models.common.Conv                      [256, 512, 3, 2]              
  8                -1  1    656896  models.common.SPP                       [512, 512, [5, 9, 13]]        
  9                -1  1   1182720  models.common.C3                        [512, 512, 1, False]          
 10                -1  1    131584  models.common.Conv                      [512, 256, 1, 1]              
 11                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 12           [-1, 6]  1         0  models.common.Concat                    [1]                           
 13                -1  1    361984  models.common.C3                        [512, 256, 1, False]          
 14                -1  1     33024  models.common.Conv                      [256, 128, 1, 1]              
 15                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 16           [-1, 4]  1         0  models.common.Concat                    [1]                           
 17                -1  1     90880  models.common.C3                        [256, 128, 1, False]          
 18                -1  1    147712  models.common.Conv                      [128, 128, 3, 2]              
 19          [-1, 14]  1         0  models.common.Concat                    [1]                           
 20                -1  1    296448  models.common.C3                        [256, 256, 1, False]          
 21                -1  1    590336  models.common.Conv                      [256, 256, 3, 2]              
 22          [-1, 10]  1         0  models.common.Concat                    [1]                           
 23                -1  1   1182720  models.common.C3                        [512, 512, 1, False]          
 24      [17, 20, 23]  1     18879  models.yolo.Detect                      [2, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]]
Model Summary: 283 layers, 7066239 parameters, 7066239 gradients, 16.4 GFLOPS

Transferred 356/362 items from yolov5s.pt
Scaled weight_decay = 0.0005
Optimizer groups: 62 .bias, 62 conv.weight, 59 other
train: Scanning 'squareone_jusRol/data/labels/train' images and labels... 0 found, 372 missing, 0 empty, 0 corrupted: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 372/372 [00:00<00:00, 16334.26it/s]
train: WARNING: No labels found in squareone_jusRol/data/labels/train.cache. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
Traceback (most recent call last):
  File "train.py", line 543, in <module>
    train(hyp, opt, device, tb_writer)
  File "train.py", line 189, in train
    dataloader, dataset = create_dataloader(train_path, imgsz, batch_size, gs, opt,
  File "/home/woody/LogoDetection/yolov5/utils/datasets.py", line 63, in create_dataloader
    dataset = LoadImagesAndLabels(path, imgsz, batch_size,
  File "/home/woody/LogoDetection/yolov5/utils/datasets.py", line 383, in __init__
    cache, exists = self.cache_labels(cache_path, prefix), False  # cache
  File "/home/woody/LogoDetection/yolov5/utils/datasets.py", line 501, in cache_labels
    torch.save(x, path)  # save for next time
  File "/home/woody/anaconda3/envs/yolov5/lib/python3.8/site-packages/torch/serialization.py", line 369, in save
    with _open_file_like(f, 'wb') as opened_file:
  File "/home/woody/anaconda3/envs/yolov5/lib/python3.8/site-packages/torch/serialization.py", line 230, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "/home/woody/anaconda3/envs/yolov5/lib/python3.8/site-packages/torch/serialization.py", line 211, in __init__
    super(_open_file, self).__init__(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: 'squareone_jusRol/data/labels/train.cache'

wandb: Waiting for W&B process to finish, PID 21833
wandb: Program failed with code 1.  Press ctrl-c to abort syncing.
wandb:                                                                                
wandb: Find user logs for this run at: /home/woody/LogoDetection/yolov5/wandb/run-20210414_163447-1wsy7a28/logs/debug.log
wandb: Find internal logs for this run at: /home/woody/LogoDetection/yolov5/wandb/run-20210414_163447-1wsy7a28/logs/debug-internal.log
wandb: Synced 5 W&B file(s), 0 media file(s), 0 artifact file(s) and 0 other file(s)
wandb: 
wandb: Synced exp: https://wandb.ai/phuccoi96/YOLOv5/runs/1wsy7a28

Expected behavior

I don't know why I cannot train the model with my custom dataset. Please help

github-actions[bot] commented 3 years ago

πŸ‘‹ Hello @TrinhDinhPhuc, thank you for your interest in πŸš€ YOLOv5! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a πŸ› Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:

$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

harrytrinh2 commented 3 years ago

I did follow the tutorial and clone a fresh yolov5 to train with my custom dataset. I got that error on the first run

glenn-jocher commented 3 years ago

@TrinhDinhPhuc your console output shows you are out of date by 14 commits so before you do anything else you should update your code with git pull or git clone again. Then once you do that I would follow the Train Custom Data tutorial closely to resolve your issue.

YOLOv5 Tutorials

harrytrinh2 commented 3 years ago

@glenn-jocher Thank you for your reply. I did use the latest yolov5 version but still got the error!

glenn-jocher commented 3 years ago

@TrinhDinhPhuc the error message says 'no labels found'. This means that YOLOv5 training did not find any labels for your dataset. Your data paths or data.yaml may be set up incorrectly. Make sure you follow the COCO128 example and organize your directories exactly as in the tutorial: https://docs.ultralytics.com/yolov5/tutorials/train_custom_data

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

VITEK-THE-BEST commented 2 years ago

I have the same problem

glenn-jocher commented 2 years ago

@VITEK-THE-BEST πŸ‘‹ 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:

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!

booooming commented 2 years ago

I have the same problem, so it can not be solved?

booooming commented 2 years ago

I have the same problem

Hi, bro. Have you solved this problem,thanks

booooming commented 2 years ago

Hi bro, have you solved this problem

glenn-jocher commented 2 years ago

πŸ‘‹ 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:

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!

zhitkoalina commented 1 year ago

I have the same problem

Hi, bro. Have you solved this problem,thanks

hello, have u solved it?

glenn-jocher commented 1 year ago

@zhitkoalina if you are encountering the error "No labels found" while training your custom dataset using YOLOv5, it means that the labels are not in the proper format or not properly configured in the data.yaml file.

To resolve this issue, you can follow the steps mentioned in the Train Custom Data page. Specifically, make sure your labels follow the YOLO format, and your data.yaml file is properly configured with the correct class names and label file paths.

If you still face issues, you can provide more details like the directory structure of your dataset, the contents of the data.yaml file, and the exact command used for training.

FanDe-chen commented 11 months ago

I use the following command to configure my dataset and training. python train.py --weights yolov5s.pt --cfg yolov5s.yaml --data "E:\ZZZ_Github\yolov5\My_Datasets\Footballs.v5i.yolov5pytorch\data.yaml" --epochs 100 --batch-size 8 --device 0 But it gave me the error for FileNotFoundError: [Errno 2] No such file or directory: 'E:\\ZZZ_Github\\yolov5\\Datasets\\Footballs.v5i.yolov5pytorch\\data.yaml'

glenn-jocher commented 11 months ago

@FanDe-chen it looks like there might be a discrepancy in the path to your data.yaml file. Please ensure that the path to your data.yaml file is correctly specified and matches the actual directory structure.

Based on the error message you provided, it seems that the path to the data.yaml file is incorrect. Double-check the path and ensure that it is pointing to the correct location of the data.yaml file on your system.

If you continue to encounter issues, make sure the data.yaml file is accessible at the specified location and that the file name and path are accurate.