Repository navigation
wandbutils.py line 161 AttributeError: 'NoneType' object has no attribute 'startswith'Â #2674
Description
Activity
ð Hello @markgicharu, 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.txtEnvironments
YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
- Google Colab and Kaggle notebooks with free GPU:
- Google Cloud Deep Learning VM. See GCP Quickstart Guide
- Amazon Deep Learning AMI. See AWS Quickstart Guide
- Docker Image. See Docker Quickstart Guide
Status
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.
@markgicharu hi sorry about that. This may be related to a recent update we did with W&B and @AyushExel.
If you believe you have a reproducible issue, we suggest you close this issue and raise a new one using the ð Bug Report template, providing screenshots and a minimum reproducible example to help us better understand and diagnose your problem. Thank you!
Looking. It should be a typo. I'll push a fix
@markgicharu Can you share the data.yaml file that you're passing with --data argument? I think either the train or val path is empty that's why data_ditc['val or train'] results as NoneType.
@glenn-jocher what should be the behaviour here, should we allow users to train without having a val set?
@glenn-jocher @markgicharu Okay I reproduced this issue with coco128 dataset. If I comment out the the val path like this:
train: ../coco128/images/train2017/ # 128 images
#val: ../coco128/images/train2017/ # 128 images
But even on disabling wandb, it throws an error:
Traceback (most recent call last):
File "train.py", line 541, in <module>
train(hyp, opt, device, tb_writer)
File "train.py", line 99, in train
test_path = data_dict['val']
KeyError: 'val'
I think the desired behavior is to not allow users to only pass the train set without passing val set. What should I do here? Even on pushing a fix for this, wandb_utils won't throw an error but the above error will still be there
@AyushExel training requires a val set. I think normally this error would be caught in the dataloader in either L368, L371, L373 and the message explains the cause well. If the error is caused earlier now then I suppose a similar assert statement might be reasonable to explain to the user the problem (as often the error message is hard for the user to connect to the cause of the error).
Lines 355 to 374 in b8b8629
| f = [] # image files | |
| for p in path if isinstance(path, list) else [path]: | |
| p = Path(p) # os-agnostic | |
| if p.is_dir(): # dir | |
| f += glob.glob(str(p / '**' / '*.*'), recursive=True) | |
| # f = list(p.rglob('**/*.*')) # pathlib | |
| elif p.is_file(): # file | |
| with open(p, 'r') as t: | |
| t = t.read().strip().splitlines() | |
| parent = str(p.parent) + os.sep | |
| f += [x.replace('./', parent) if x.startswith('./') else x for x in t] # local to global path | |
| # f += [p.parent / x.lstrip(os.sep) for x in t] # local to global path (pathlib) | |
| else: | |
| raise Exception(f'{prefix}{p} does not exist') | |
| self.img_files = sorted([x.replace('/', os.sep) for x in f if x.split('.')[-1].lower() in img_formats]) | |
| # self.img_files = sorted([x for x in f if x.suffix[1:].lower() in img_formats]) # pathlib | |
| assert self.img_files, f'{prefix}No images found' | |
| except Exception as e: | |
| raise Exception(f'{prefix}Error loading data from {path}: {e}\nSee {help_url}') | |
@markgicharu you need to fully populate the train and val fields in your dataset.yaml as the Train Custom Data Tutorial shows. Please see this tutorial to get started. If you have no val set you can re-use your training set to validate on (as the COCO128 training does), though this is usually only used for sanity checks and is not best practices.
YOLOv5 Tutorials
- Train Custom Data ð RECOMMENDED
- Tips for Best Training Results âïļ RECOMMENDED
- Weights & Biases Logging ð NEW
- Supervisely Ecosystem ð NEW
- Multi-GPU Training
- PyTorch Hub â NEW
- ONNX and TorchScript Export
- Test-Time Augmentation (TTA)
- Model Ensembling
- Model Pruning/Sparsity
- Hyperparameter Evolution
- Transfer Learning with Frozen Layers â NEW
- TensorRT Deployment
This should address the problem #2683
@markgicharu Can you share the data.yaml file that you're passing with
--dataargument? I think either the train or val path is empty that's whydata_ditc['val or train']results as NoneType.@glenn-jocher what should be the behaviour here, should we allow users to train without having a val set?
Hello @AyushExel
Am sharing the data.yaml below:
I tried checking the paths to see if there is any issue. Maybe you can advise best from the file below.
I have split my dataset in train, validate and test in a 70-20-10 split.
data.yaml.zip
@markgicharu hi sorry about that. This may be related to a recent update we did with W&B and @AyushExel.
If you believe you have a reproducible issue, we suggest you close this issue and raise a new one using the ð Bug Report template, providing screenshots and a minimum reproducible example to help us better understand and diagnose your problem. Thank you!
@glenn-jocher Many thanks for the prompt response
I will push it to a bug as suggested
Apologies for the late response. Been up and down during Easter. AM back settled now.
Thanks again
@markgicharu this problem may have been fixed recently in PR #2683. Can you please git pull or reclone and try again to see if the issue is resolved? Thank you!
@glenn-jocher This matter is resolved
When i pass the absolute path for the train and test in the data.yaml the system works well.
Many thanks for the prompt response.
@markgicharu great! Happy trainings.
while executing
%cd /content/yolov5/
!python test.py --data '../data.yaml' --img 416 --conf 0.40 --weights 'path to weights'
In Colab. I am facing issue:
/content/yolov5
Namespace(weights=['path to weights'], data='../data.yaml', batch_size=32, img_size=416, conf_thres=0.4, iou_thres=0.6, task='val', device='', single_cls=False, augment=False, verbose=False, save_txt=False, save_hybrid=False, save_conf=False, save_json=False, project='runs/test', name='exp', exist_ok=False)
YOLOv5 ð v7.0-185-g2334aa7 torch 2.0.1+cu118 CUDA:0 (Tesla T4, 15101.8125MB)
Traceback (most recent call last):
File "/content/yolov5/test.py", line 316, in
test(opt.data,
File "/content/yolov5/test.py", line 54, in test
(save_dir / 'labels' if save_txt else save_dir).mkdir(parents=True, exist_ok=True) # make dir
AttributeError: 'NoneType' object has no attribute 'mkdir'
@anupkumar08 it looks like the issue you are facing might be related to the way you are specifying the weights path or data path. The current error message suggests that there might be a problem related to saving directories.
Make sure that you have provided the correct path to the weights file and the data.yaml file. Also, ensure that the data.yaml file is correctly formatted with the paths to your dataset, and the weights path is pointing to a valid location.
If the issue persists, please consider opening a new issue on the YOLOv5 GitHub repository, providing a detailed description of the problem along with the command you used, and any relevant code or configuration files. This will allow the community to better understand and assist with your specific situation.
âQuestion Whenever i try to run my model i run into this error AttributeError: 'NoneType' object has no attribute 'startswith' from wandbutils.py line 161 I wonder why ? Any workaround or fix
Additional context
Traceback (most recent call last):
File "train.py", line 541, in
train(hyp, opt, device, tb_writer)
File "train.py", line 72, in train
wandb_logger = WandbLogger(opt, Path(opt.save_dir).stem, run_id, data_dict)
File "C:\Users\markg\venv\yolov5\utils\wandb_logging\wandb_utils.py", line 109, in init
self.data_dict = self.setup_training(opt, data_dict)
File "C:\Users\markg\venv\yolov5\utils\wandb_logging\wandb_utils.py", line 140, in setup_training
self.train_artifact_path, self.train_artifact = self.download_dataset_artifact(data_dict.get('train'),
File "C:\Users\markg\venv\yolov5\utils\wandb_logging\wandb_utils.py", line 161, in download_dataset_artifact
if path.startswith(WANDB_ARTIFACT_PREFIX):
AttributeError: 'NoneType' object has no attribute 'startswith'