Skip to content

wandbutils.py line 161 AttributeError: 'NoneType' object has no attribute 'startswith' #2674

Description

@markgicharu

❔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'

Activity

github-actions commented on Mar 31, 2021

@github-actions
Contributor

👋 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.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.

glenn-jocher commented on Apr 1, 2021

@glenn-jocher
Member

@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!

AyushExel commented on Apr 1, 2021

@AyushExel
Contributor

Looking. It should be a typo. I'll push a fix

AyushExel commented on Apr 1, 2021

@AyushExel
Contributor

@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?

AyushExel commented on Apr 1, 2021

@AyushExel
Contributor

@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

glenn-jocher commented on Apr 1, 2021

@glenn-jocher
Member

@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).

yolov5/utils/datasets.py

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

AyushExel commented on Apr 1, 2021

@AyushExel
Contributor

This should address the problem #2683

markgicharu commented on Apr 3, 2021

@markgicharu
Author

@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?

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 commented on Apr 3, 2021

@markgicharu
Author

@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

glenn-jocher commented on Apr 5, 2021

@glenn-jocher
Member

@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!

markgicharu commented on Apr 5, 2021

@markgicharu
Author

@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.

glenn-jocher commented on Apr 5, 2021

@glenn-jocher
Member

@markgicharu great! Happy trainings.

added a commit that references this issue on May 12, 2021
45a98db
added a commit that references this issue on May 17, 2021
9402cd1
added a commit that references this issue on Jul 20, 2021
0e92d5f
added a commit that references this issue on Oct 12, 2021
71759fc
added a commit that references this issue on Aug 26, 2022
f82e613

anupkumar08 commented on Jun 19, 2023

@anupkumar08

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'

glenn-jocher commented on Nov 15, 2023

@glenn-jocher
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions