ultralytics / ultralytics

Ultralytics YOLO11 ๐Ÿš€
https://docs.ultralytics.com
GNU Affero General Public License v3.0
31.85k stars 6.1k forks source link

RuntimeError: Dataset 'data.yaml' error mapping values are not allowed here #2539

Closed pigking0126 closed 1 year ago

pigking0126 commented 1 year ago

Search before asking

Question

I have use train yolov8 model for few times, but this issue came out from nowhere today, I don't know whether it's a yolov8 issue or other python lib issue cause this problem:

(yolov8) C:\Users\user\Downloads\arrow.v2i.yolov8>yolo task=detect mode=train model=yolov8m.pt data=data.yaml epochs=200 batch=32 imgsz=640 workers=8 save=True patience=20 Ultralytics YOLOv8.0.98 Python-3.9.16 torch-2.0.0+cu118 CUDA:0 (NVIDIA GeForce RTX 3060, 12287MiB) yolo\engine\trainer: task=detect, mode=train, model=yolov8m.pt, data=data.yaml, epochs=200, patience=20, batch=32, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=None, exist_ok=False, pretrained=False, optimizer=SGD, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=0, resume=False, amp=True, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, show=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, vid_stride=1, line_width=None, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, boxes=True, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=None, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, label_smoothing=0.0, nbs=64, 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, copy_paste=0.0, cfg=None, v5loader=False, tracker=botsort.yaml, save_dir=runs\detect\train2 Traceback (most recent call last): File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\ultralytics\yolo\engine\trainer.py", line 122, in init self.data = check_det_dataset(self.args.data) File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\ultralytics\yolo\data\utils.py", line 206, in check_det_dataset data = yaml_load(data, append_filename=True) # dictionary File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\ultralytics\yolo\utils__init.py", line 290, in yaml_load return {**yaml.safe_load(s), 'yaml_file': str(file)} if append_filename else yaml.safe_load(s) File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\yaml__init__.py", line 125, in safe_load return load(stream, SafeLoader) File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\yaml\init__.py", line 81, in load return loader.get_single_data() File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\yaml\constructor.py", line 49, in get_single_data node = self.get_single_node() File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\yaml\composer.py", line 36, in get_single_node document = self.compose_document() File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\yaml\composer.py", line 58, in compose_document self.get_event() File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\yaml\parser.py", line 118, in get_event self.current_event = self.state() File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\yaml\parser.py", line 193, in parse_document_end token = self.peek_token() File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\yaml\scanner.py", line 129, in peek_token self.fetch_more_tokens() File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\yaml\scanner.py", line 223, in fetch_more_tokens return self.fetch_value() File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\yaml\scanner.py", line 577, in fetch_value raise ScannerError(None, None, yaml.scanner.ScannerError: mapping values are not allowed here in "", line 5, column 3: nc: 1 ^

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

Traceback (most recent call last): File "C:\Users\user\anaconda3\envs\yolov8\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\user\anaconda3\envs\yolov8\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\user\anaconda3\envs\yolov8\Scripts\yolo.exe__main.py", line 7, in File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\ultralytics\yolo\cfg\init.py", line 394, in entrypoint getattr(model, mode)(**overrides) # default args from model File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\ultralytics\yolo\engine\model.py", line 365, in train self.trainer = TASK_MAP[self.task][1](overrides=overrides, _callbacks=self.callbacks) File "C:\Users\user\anaconda3\envs\yolov8\lib\site-packages\ultralytics\yolo\engine\trainer.py", line 126, in init__ raise RuntimeError(emojis(f"Dataset '{clean_url(self.args.data)}' error โŒ {e}")) from e RuntimeError: Dataset 'data.yaml' error mapping values are not allowed here in "", line 5, column 3: nc: 1 ^

this is mt data.yaml:

train:C:\Users\user\Downloads\arrow.v2i.yolov8\train\images val:C:\Users\user\Downloads\arrow.v2i.yolov8\valid\images test:C:\Users\user\Downloads\arrow.v2i.yolov8\test\images

nc: 1 names: ['arrow']

Additional

No response

github-actions[bot] commented 1 year ago

๐Ÿ‘‹ Hello @pigking0126, thank you for your interest in YOLOv8 ๐Ÿš€! We recommend a visit to the YOLOv8 Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a ๐Ÿ› Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training โ“ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Install

Pip install the ultralytics package including all requirements in a Python>=3.7 environment with PyTorch>=1.7.

pip install ultralytics

Environments

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

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 1 year ago

@pigking0126 hello,

Based on the error message you shared, it seems that there is an error with the data.yaml file you provided. The error message indicates that "mapping values are not allowed here", and points to line 5, column 3. Please review this line and ensure that the YAML syntax is correct and that there are no unexpected characters or formatting issues.

If you need further assistance, please provide more details about your configuration and the steps you have taken so far to troubleshoot the issue.

Best regards.

github-actions[bot] commented 1 year ago

๐Ÿ‘‹ Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

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 YOLO ๐Ÿš€ and Vision AI โญ

enterprise6868 commented 10 months ago

I have met the same question like you.Have you ever fixed it? Thanks

glenn-jocher commented 10 months ago

@enterprise6868 hello,

It appears the error is typically related to a syntax issue in your data.yaml file. Ensure correct indentation and no misformatted characters are present. YAML is sensitive to spaces and requires consistent indentation. If the issue persists, verify the structure against the YOLOv8 documentation for data.yaml files.

Best regards.

jin2089 commented 6 months ago

I encountered the same problem, the reason for my error is to put the yaml file in the train and val address does not correspond to the template coco2017.yaml in the corresponding, against the change can be normal training!

jin2089 commented 6 months ago

I encountered the same problem, the reason for my error is to put the yaml file in the train and val address does not correspond to the template coco2017.yaml in the corresponding, against the change can be normal training!

enterprise6868 commented 6 months ago

Thanks! But I had already fixed my problem 3 months ago.The reason why there is error is that we need to strictly follow yaml file standards, especially the space. I forget to type space button to rewrite the yaml file. Above all ,thank a lot to your reply and sharing. 

Enterprise @.***

 

------------------ ๅŽŸๅง‹้‚ฎไปถ ------------------ ๅ‘ไปถไบบ: "ultralytics/ultralytics" @.>; ๅ‘้€ๆ—ถ้—ด: 2024ๅนด4ๆœˆ6ๆ—ฅ(ๆ˜ŸๆœŸๅ…ญ) ๆ™šไธŠ9:33 @.>; @.**@.>; ไธป้ข˜: Re: [ultralytics/ultralytics] RuntimeError: Dataset 'data.yaml' error mapping values are not allowed here (Issue #2539)

I encountered the same problem, the reason for my error is to put the yaml file in the train and val address does not correspond to the template coco2017.yaml in the corresponding, against the change can be normal training!

โ€” Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

glenn-jocher commented 6 months ago

@enterprise6868 Hi there! ๐Ÿ‘‹

Great to hear you've resolved the issue with your data.yaml file! It's a common pitfall, and as you pointed out, the details really do matter, especially with spaces in YAML files. It's a valuable tip for anyone working with YOLOv8 or similar configurations -- always double-check your formatting!

Thanks for your patience and for sharing your solution with the community. If you have any more insights or run into other challenges, feel free to share. Happy coding! ๐Ÿ˜Š