Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScannerError when import ultralytics #13995

Open
1 of 2 tasks
lolawang22 opened this issue Jun 25, 2024 · 2 comments
Open
1 of 2 tasks

ScannerError when import ultralytics #13995

lolawang22 opened this issue Jun 25, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@lolawang22
Copy link

lolawang22 commented Jun 25, 2024

Search before asking

  • I have searched the YOLOv8 issues and found no similar bug report.

YOLOv8 Component

Install

Bug

I was able to train and test yolov8 before. But last Friday I suddenly got this Scanner Error and wasn't able to import ultralytics. I was accessing a linux system through vscode remote control with venv. I used the exact same venv on my local computer and was able to run.

`

ScannerError Traceback (most recent call last)
Cell In[3], line 1
----> 1 import ultralytics
2 ultralytics.checks()

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/ultralytics/init.py:10
7 # Set ENV Variables (place before imports)
8 os.environ["OMP_NUM_THREADS"] = "1" # reduce CPU utilization during training
---> 10 from ultralytics.data.explorer.explorer import Explorer
11 from ultralytics.models import NAS, RTDETR, SAM, YOLO, FastSAM, YOLOWorld
12 from ultralytics.utils import ASSETS, SETTINGS

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/ultralytics/data/init.py:3
1 # Ultralytics YOLO 🚀, AGPL-3.0 license
----> 3 from .base import BaseDataset
4 from .build import build_dataloader, build_grounding, build_yolo_dataset, load_inference_source
5 from .dataset import (
6 ClassificationDataset,
7 GroundingDataset,
(...)
11 YOLOMultiModalDataset,
12 )

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/ultralytics/data/base.py:17
14 import psutil
15 from torch.utils.data import Dataset
---> 17 from ultralytics.data.utils import FORMATS_HELP_MSG, HELP_URL, IMG_FORMATS
18 from ultralytics.utils import DEFAULT_CFG, LOCAL_RANK, LOGGER, NUM_THREADS, TQDM
21 class BaseDataset(Dataset):

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/ultralytics/data/utils.py:19
16 import numpy as np
17 from PIL import Image, ImageOps
---> 19 from ultralytics.nn.autobackend import check_class_names
20 from ultralytics.utils import (
21 DATASETS_DIR,
22 LOGGER,
(...)
32 yaml_save,
33 )
34 from ultralytics.utils.checks import check_file, check_font, is_ascii

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/ultralytics/nn/init.py:3
1 # Ultralytics YOLO 🚀, AGPL-3.0 license
----> 3 from .tasks import (
4 BaseModel,
5 ClassificationModel,
6 DetectionModel,
7 SegmentationModel,
8 attempt_load_one_weight,
9 attempt_load_weights,
10 guess_model_scale,
11 guess_model_task,
12 parse_model,
13 torch_safe_load,
14 yaml_model_load,
15 )
17 all = (
18 "attempt_load_one_weight",
19 "attempt_load_weights",
(...)
28 "BaseModel",
29 )

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/ultralytics/nn/tasks.py:10
7 import torch
8 import torch.nn as nn
---> 10 from ultralytics.nn.modules import (
11 AIFI,
12 C1,
13 C2,
14 C3,
15 C3TR,
16 ELAN1,
17 OBB,
18 PSA,
19 SPP,
20 SPPELAN,
21 SPPF,
22 AConv,
23 ADown,
24 Bottleneck,
25 BottleneckCSP,
26 C2f,
27 C2fAttn,
28 C2fCIB,
29 C3Ghost,
30 C3x,
31 CBFuse,
32 CBLinear,
33 Classify,
34 Concat,
35 Conv,
36 Conv2,
37 ConvTranspose,
38 Detect,
39 DWConv,
40 DWConvTranspose2d,
41 Focus,
42 GhostBottleneck,
43 GhostConv,
44 HGBlock,
45 HGStem,
46 ImagePoolingAttn,
47 Pose,
48 RepC3,
49 RepConv,
50 RepNCSPELAN4,
51 RepVGGDW,
52 ResNetLayer,
53 RTDETRDecoder,
54 SCDown,
55 Segment,
56 WorldDetect,
57 v10Detect,
58 )
59 from ultralytics.utils import DEFAULT_CFG_DICT, DEFAULT_CFG_KEYS, LOGGER, colorstr, emojis, yaml_load
60 from ultralytics.utils.checks import check_requirements, check_suffix, check_yaml

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/ultralytics/nn/modules/init.py:72
20 from .block import (
21 C1,
22 C2,
(...)
55 SCDown,
56 )
57 from .conv import (
58 CBAM,
59 ChannelAttention,
(...)
70 SpatialAttention,
71 )
---> 72 from .head import OBB, Classify, Detect, Pose, RTDETRDecoder, Segment, WorldDetect, v10Detect
73 from .transformer import (
74 AIFI,
75 MLP,
(...)
83 TransformerLayer,
84 )
86 all = (
87 "Conv",
88 "Conv2",
(...)
152 "SCDown",
153 )

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/ultralytics/nn/modules/head.py:11
8 import torch.nn as nn
9 from torch.nn.init import constant_, xavier_uniform_
---> 11 from ultralytics.utils.tal import TORCH_1_10, dist2bbox, dist2rbox, make_anchors
13 from .block import DFL, BNContrastiveHead, ContrastiveHead, Proto
14 from .conv import Conv

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/ultralytics/utils/init.py:1054
1050 # Run below code on utils init ------------------------------------------------------------------------------------
1051
1052 # Check first-install steps
1053 PREFIX = colorstr("Ultralytics: ")
-> 1054 SETTINGS = SettingsManager() # initialize settings
1055 DATASETS_DIR = Path(SETTINGS["datasets_dir"]) # global datasets directory
1056 WEIGHTS_DIR = Path(SETTINGS["weights_dir"]) # global weights directory

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/ultralytics/utils/init.py:986, in SettingsManager.init(self, file, version)
983 if not self.file.exists():
984 self.save()
--> 986 self.load()
987 correct_keys = self.keys() == self.defaults.keys()
988 correct_types = all(type(a) is type(b) for a, b in zip(self.values(), self.defaults.values()))

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/ultralytics/utils/init.py:1011, in SettingsManager.load(self)
1009 def load(self):
1010 """Loads settings from the YAML file."""
-> 1011 super().update(yaml_load(self.file))

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/ultralytics/utils/init.py:381, in yaml_load(file, append_filename)
378 s = re.sub(r"[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD\U00010000-\U0010ffff]+", "", s)
380 # Add YAML filename to dict and return
--> 381 data = yaml.safe_load(s) or {} # always return a dict (yaml.safe_load() may return None for empty files)
382 if append_filename:
383 data["yaml_file"] = str(file)

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/yaml/init.py:125, in safe_load(stream)
117 def safe_load(stream):
118 """
119 Parse the first YAML document in a stream
120 and produce the corresponding Python object.
(...)
123 to be safe for untrusted input.
124 """
--> 125 return load(stream, SafeLoader)

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/yaml/init.py:81, in load(stream, Loader)
79 loader = Loader(stream)
80 try:
---> 81 return loader.get_single_data()
82 finally:
83 loader.dispose()

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/yaml/constructor.py:49, in BaseConstructor.get_single_data(self)
47 def get_single_data(self):
48 # Ensure that the stream contains a single document and construct it.
---> 49 node = self.get_single_node()
50 if node is not None:
51 return self.construct_document(node)

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/yaml/composer.py:36, in Composer.get_single_node(self)
34 document = None
35 if not self.check_event(StreamEndEvent):
---> 36 document = self.compose_document()
38 # Ensure that the stream contains no more documents.
39 if not self.check_event(StreamEndEvent):

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/yaml/composer.py:55, in Composer.compose_document(self)
52 self.get_event()
54 # Compose the root node.
---> 55 node = self.compose_node(None, None)
57 # Drop the DOCUMENT-END event.
58 self.get_event()

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/yaml/composer.py:84, in Composer.compose_node(self, parent, index)
82 node = self.compose_sequence_node(anchor)
83 elif self.check_event(MappingStartEvent):
---> 84 node = self.compose_mapping_node(anchor)
85 self.ascend_resolver()
86 return node

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/yaml/composer.py:127, in Composer.compose_mapping_node(self, anchor)
125 if anchor is not None:
126 self.anchors[anchor] = node
--> 127 while not self.check_event(MappingEndEvent):
128 #key_event = self.peek_event()
129 item_key = self.compose_node(node, None)
130 #if item_key in node.value:
131 # raise ComposerError("while composing a mapping", start_event.start_mark,
132 # "found duplicate key", key_event.start_mark)

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/yaml/parser.py:98, in Parser.check_event(self, *choices)
96 if self.current_event is None:
97 if self.state:
---> 98 self.current_event = self.state()
99 if self.current_event is not None:
100 if not choices:

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/yaml/parser.py:428, in Parser.parse_block_mapping_key(self)
427 def parse_block_mapping_key(self):
--> 428 if self.check_token(KeyToken):
429 token = self.get_token()
430 if not self.check_token(KeyToken, ValueToken, BlockEndToken):

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/yaml/scanner.py:115, in Scanner.check_token(self, *choices)
113 def check_token(self, *choices):
114 # Check if the next token is one of the given types.
--> 115 while self.need_more_tokens():
116 self.fetch_more_tokens()
117 if self.tokens:

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/yaml/scanner.py:152, in Scanner.need_more_tokens(self)
149 return True
150 # The current token may be a potential simple key, so we
151 # need to look further.
--> 152 self.stale_possible_simple_keys()
153 if self.next_possible_simple_key() == self.tokens_taken:
154 return True

File /local/home/lola/envs/leaflet/lib/python3.12/site-packages/yaml/scanner.py:291, in Scanner.stale_possible_simple_keys(self)
288 if key.line != self.line
289 or self.index-key.index > 1024:
290 if key.required:
--> 291 raise ScannerError("while scanning a simple key", key.mark,
292 "could not find expected ':'", self.get_mark())
293 del self.possible_simple_keys[level]

ScannerError: while scanning a simple key
in "", line 3, column 1:
s
^
could not find expected ':'
in "", line 4, column 1:
weights_dir: weights
^
`

Environment

OS Name Microsoft Windows 10 Enterprise
Version 10.0.19045 Build 19045
VSCode 1.90.2
ultralytics Version: 8.2.42

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@lolawang22 lolawang22 added the bug Something isn't working label Jun 25, 2024
Copy link

👋 Hello @lolawang22, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the 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.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

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

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
Copy link
Member

@lolawang22 hi there,

Thank you for reporting this issue. The ScannerError you're encountering typically indicates a problem with parsing a YAML file, which is often due to formatting issues.

To help us diagnose and resolve this issue more effectively, could you please provide a minimal reproducible example? This will allow us to replicate the problem on our end. You can find guidelines on how to create a minimal reproducible example here.

Additionally, please ensure that you are using the latest versions of all relevant packages, including ultralytics, PyYAML, and any other dependencies. Sometimes, updating to the latest version can resolve such issues.

Here's a quick checklist to help you troubleshoot:

  1. Check YAML Files: Ensure that all YAML files you are using are correctly formatted. YAML is sensitive to indentation and special characters.
  2. Update Packages: Run pip install --upgrade ultralytics pyyaml to make sure you have the latest versions.
  3. Recreate Virtual Environment: Sometimes, issues can arise from the virtual environment itself. Consider recreating your virtual environment and reinstalling the packages.

If the issue persists after these steps, please share the specific YAML file or the relevant portion of it that might be causing the error. This will help us pinpoint the problem more accurately.

Thank you for your cooperation, and we look forward to resolving this issue for you! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants