ultralytics / yolov5

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

Data Loader Error - ValueError #7943

Closed ryanfont80 closed 2 years ago

ryanfont80 commented 2 years ago

I am having an issue with a data set - it is all images. I can confirm they all work, are not blank or missing, and all have the proper label files associated. Yet EVERY time I try to load the data set I get this:

Transferred 955/963 items from yolov5x6.pt Scaled weight_decay = 0.0005 optimizer: SGD with parameter groups 159 weight (no decay), 163 weight, 163 bias train: Scanning '/home/citadel/yolov5/data/datasets/24gmodel/train/labels.cache' images and labels... 43 train: Caching images (9.7GB ram): 18%|ā–ˆā–Š | 7866/43498 [00:04<00:19, 1826.71it/s]
Traceback (most recent call last): File "/home/citadel/yolov5/train.py", line 670, in main(opt) File "/home/citadel/yolov5/train.py", line 565, in main train(opt.hyp, opt, device, callbacks) File "/home/citadel/yolov5/train.py", line 221, in train train_loader, dataset = create_dataloader(train_path, File "/home/citadel/yolov5/utils/dataloaders.py", line 114, in create_dataloader dataset = LoadImagesAndLabels( File "/home/citadel/yolov5/utils/dataloaders.py", line 524, in init for i, x in pbar: File "/usr/local/lib/python3.10/dist-packages/tqdm/std.py", line 1195, in iter for obj in iterable: File "/usr/lib/python3.10/multiprocessing/pool.py", line 870, in next raise value File "/usr/lib/python3.10/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, *kwds)) File "/home/citadel/yolov5/utils/dataloaders.py", line 659, in load_image im = np.load(fn, allow_pickle=True) File "/home/citadel/.local/lib/python3.10/site-packages/numpy/lib/npyio.py", line 430, in load return format.read_array(fid, allow_pickle=allow_pickle, File "/home/citadel/.local/lib/python3.10/site-packages/numpy/lib/format.py", line 786, in read_array array.shape = shape ValueError: cannot reshape array of size 0 into shape (640,640,3) Traceback (most recent call last): File "/home/citadel/yolov5/train.py", line 670, in main(opt) File "/home/citadel/yolov5/train.py", line 565, in main train(opt.hyp, opt, device, callbacks) File "/home/citadel/yolov5/train.py", line 221, in train train_loader, dataset = create_dataloader(train_path, File "/home/citadel/yolov5/utils/dataloaders.py", line 114, in create_dataloader dataset = LoadImagesAndLabels( File "/home/citadel/yolov5/utils/dataloaders.py", line 524, in init for i, x in pbar: File "/usr/local/lib/python3.10/dist-packages/tqdm/std.py", line 1195, in iter for obj in iterable: File "/usr/lib/python3.10/multiprocessing/pool.py", line 870, in next raise value File "/usr/lib/python3.10/multiprocessing/pool.py", line 125, in worker result = (True, func(args, **kwds)) File "/home/citadel/yolov5/utils/dataloaders.py", line 659, in load_image im = np.load(fn, allow_pickle=True) File "/home/citadel/.local/lib/python3.10/site-packages/numpy/lib/npyio.py", line 430, in load return format.read_array(fid, allow_pickle=allow_pickle, File "/home/citadel/.local/lib/python3.10/site-packages/numpy/lib/format.py", line 786, in read_array array.shape = shape ValueError: cannot reshape array of size 0 into shape (640,640,3)

Any ideas?

github-actions[bot] commented 2 years ago

šŸ‘‹ Hello @ryanfont80, 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://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

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), validation (val.py), inference (detect.py) and export (export.py) on macOS, Windows, and Ubuntu every 24 hours and on every commit.

ryanfont80 commented 2 years ago

The error is happening in the exact same spot every time.. even deleted the image that was at item #7866 in case there was some weird corruption.

glenn-jocher commented 2 years ago

@ryanfont80 not sure why one would express surprise at deterministic behavior. Follow dataset guidelines below.

šŸ‘‹ 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!

github-actions[bot] commented 2 years ago

šŸ‘‹ Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 šŸš€ resources:

Access additional Ultralytics āš” resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 šŸš€ and Vision AI ā­!