Yolov5: TypeError: float() argument must be a string or a number, not 'tuple'

Created on 20 Sep 2020  路  12Comments  路  Source: ultralytics/yolov5

When I start to train my own custom data(Python 3.8, Pytorch1.6), I encounter this bug:
QQ鍥剧墖20200920164809

I can ensure clone the the latest repo and do not do any edits.
Thanks.

bug

All 12 comments

Hello @LXY34, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook Open In Colab, Docker Image, and Google Cloud Quickstart Guide for example environments.

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 model or data training question, please note Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:

  • Cloud-based AI systems operating on hundreds of HD video streams in realtime.
  • Edge AI integrated into custom iOS and Android apps for realtime 30 FPS video inference.
  • Custom data training, hyperparameter evolution, and model exportation to any destination.

For more information please visit https://www.ultralytics.com.

@glenn-jocher @LXY34 I have been getting the same error. I have my custom data just as the https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data says.

The repo was downloaded on 23rd Sept, 2020.
My images are in ../highway/images/train/, ../highway/images/val/ and ../highway/images/test/
My labels are in ../highway/labels/train/ and ../highway/labels/val/

`
Optimizer groups: 62 .bias, 70 conv.weight, 59 other
Scanning images: 4% 355/8944 [00:00<00:14, 583.20it/s]WARNING: ../highway/images/train/000516.jpg: setting an array element with a sequence.
Scanning images: 6% 575/8944 [00:01<00:15, 525.14it/s]WARNING: ../highway/images/train/000823.jpg: setting an array element with a sequence.
Scanning images: 7% 631/8944 [00:01<00:15, 534.04it/s]WARNING: ../highway/images/train/000881.jpg: setting an array element with a sequence.
Scanning images: 8% 749/8944 [00:01<00:14, 560.11it/s]WARNING: ../highway/images/train/001010.jpg: setting an array element with a sequence.
WARNING: ../highway/images/train/001033.jpg: setting an array element with a sequence.
WARNING: ../highway/images/train/001043.jpg: setting an array element with a sequence.
Scanning images: 17% 1528/8944 [00:02<00:14, 527.95it/s]WARNING: ../highway/images/train/002089.jpg: setting an array element with a sequence.
Scanning images: 100% 8944/8944 [00:15<00:00, 565.60it/s]
TypeError: float() argument must be a string or a number, not 'tuple'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "train.py", line 456, in
train(hyp, opt, device, tb_writer)
File "train.py", line 169, in train
rank=rank, world_size=opt.world_size, workers=opt.workers)
File "/gdrive/My Drive/Traffic/yolov5/utils/datasets.py", line 61, in create_dataloader
rank=rank)
File "/gdrive/My Drive/Traffic/yolov5/utils/datasets.py", line 380, in __init__
self.shapes = np.array(shapes, dtype=np.float64)
ValueError: setting an array element with a sequence.`

PS. I remove the cache file saved in image directory and restart runtime in my Colab everytime i attempt training.
I had no problem like a couple of weeks ago.

@bipulneupane error checks when loading your dataset are indicating issues with the images or labelled mentioned.

@bipulneupane did you manage to resolve this issue? If not, please reproduce in our Colab notebook and link us to it so we can try to debug!
https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb

@bipulneupane did you manage to resolve this issue? If not, please reproduce in our Colab notebook and link us to it so we can try to debug!
https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb

Thanks for reaching out @glenn-jocher . As you said, the problem was few missing images/labels.

@bipulneupane I see, thanks for the feedback. Do you think there's anything we could do to help diagnose these issues more easily, or improvements to prevents these errors?

@bipulneupane I see, thanks for the feedback. Do you think there's anything we could do to help diagnose these issues more easily, or improvements to prevents these errors?

I really like that Yolov5 is in Pytorch, which makes it easier to install and use atleast for me. But this particular issue i reported could be improved TypeError: float() argument must be a string or a number, not tuple.

It showed a warning at 4% of the scan as Scanning images: 4% 355/8944 [00:00<00:14, 583.20it/s]WARNING: ../highway/images/train/000516.jpg: setting an array element with a sequence. but still continued scanning the images till 100%, which took about 30 mins for my dataset. If there was supposed to be an error later, maybe the process could have been able to skip the particular label or stopped right then at 4% ?

Just a suggestion @glenn-jocher . Other than that, i have already used Yolo5 for few applications, and asked my colleagues to do replace the older Yolo models because of the speed, performance and easy implementation. I really love this repo. Thanks.

@bipulneupane hmm ok. When YOLOv5 first encounters a new dataset, it will scan all of the images and labels, performing checks for corruption and issues in each image-label pair, and then save the labels in a data.cache file for faster loading in the future.

Datasets are recached only upon change detection, i.e. if an image, label or directory is moved, modified, added or removed.

Maybe we can implement improvements into this scanning and caching region of the code. Correct operation will always require correct images and labels, but maybe there's room for error reporting to allow users to correct their dataset more easily, or even to automatically ignore incorrect image-label pairs, at the risk of silent errors going unnoticed or ignored by users, possibly leading to additional confusion down the road (i.e. "why were my images not used during training?")

Did you discover the origin of the problem in your image /highway/images/train/000516.jpg or did you just delete this image-label pair? How did you resolve the issue?

@bipulneupane most importantly, how can we reproduce this error message?

@bipulneupane also FYI your warning message originates on L499 here during the scanning and caching process.
https://github.com/ultralytics/yolov5/blob/0fda95aaf4e74db6505a343b8d2162782f4ab444/utils/datasets.py#L479-L504

Commit https://github.com/ultralytics/yolov5/commit/d61930e017c287c63f509fc6abb481c0c87e4265 should help to fix this. This update automatically ignores corrupted images or labels in the dataset, and presents a more explicit warning to inform of the corrupted and ignored images.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

linhaoqi027 picture linhaoqi027  路  4Comments

hktxt picture hktxt  路  3Comments

krishnam3065 picture krishnam3065  路  4Comments

lisa676 picture lisa676  路  3Comments

KangHoyong picture KangHoyong  路  3Comments