1

I faced an error while running YOLOv5 on Google Colab. I think the issue is with the content of the data.yaml file (attached below), and despite trying various concepts, it's still not working. How can I resolve this?

!python /content/yolov5/train.py --batch 70 --epochs 30 --data "/content/elec_meter_yaml/data.yaml" --cfg /content/yolov5/models/yolov5x.yaml  --weights yolov5x.pt --name runs

Error

Traceback (most recent call last):
  File "/content/yolov5/train.py", line 640, in <module>
    main(opt)
  File "/content/yolov5/train.py", line 529, in main
    train(opt.hyp, opt, device, callbacks)
  File "/content/yolov5/train.py", line 112, in train
    data_dict = data_dict or check_dataset(data)  # check if None
  File "/content/yolov5/utils/general.py", line 518, in check_dataset
    data = yaml_load(data)  # dictionary
  File "/content/yolov5/utils/general.py", line 603, in yaml_load
    return yaml.safe_load(f)
  File "/usr/local/lib/python3.8/dist-packages/yaml/__init__.py", line 125, in safe_load
    return load(stream, SafeLoader)
  File "/usr/local/lib/python3.8/dist-packages/yaml/__init__.py", line 81, in load
    return loader.get_single_data()
  File "/usr/local/lib/python3.8/dist-packages/yaml/constructor.py", line 49, in get_single_data
    node = self.get_single_node()
  File "/usr/local/lib/python3.8/dist-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/usr/local/lib/python3.8/dist-packages/yaml/composer.py", line 58, in compose_document
    self.get_event()
  File "/usr/local/lib/python3.8/dist-packages/yaml/parser.py", line 118, in get_event
    self.current_event = self.state()
  File "/usr/local/lib/python3.8/dist-packages/yaml/parser.py", line 193, in parse_document_end
    token = self.peek_token()
  File "/usr/local/lib/python3.8/dist-packages/yaml/scanner.py", line 129, in peek_token
    self.fetch_more_tokens()
  File "/usr/local/lib/python3.8/dist-packages/yaml/scanner.py", line 223, in fetch_more_tokens
    return self.fetch_value()
  File "/usr/local/lib/python3.8/dist-packages/yaml/scanner.py", line 577, in fetch_value
    raise ScannerError(None, None,
yaml.scanner.ScannerError: mapping values are not allowed here
  in "/content/elec_meter_yaml/data.yaml", line 6, column 6

data.yaml

train = '/content/elec_meter_yaml/train.txt'
val = '/content/elec_meter_yaml/val.txt'
test = '/content/elec_meter_yaml/test.txt'
nc = 12

names:
  0: one
  1: two
  2: three
  3: four
  4: five
  5: six
  6: seven
  7: eight
  8: nine
  9: zero
  10: meter
  11: dot
Anthon
  • 69,918
  • 32
  • 186
  • 246
박경덕
  • 13
  • 5

1 Answers1

0

You get the message because the YAML document is invalid.

It starts with a multi-line scalar without quotes. The first line is the whole of

train = '/content/elec_meter_yaml/train.txt'

(you can have quotes in the middle of non-quoted scalar).

That scalar ends after 12, and up until then the YAML document is ok, because at the root of a document you can have a mapping, a sequence, or a scalar.

Within a unquoted scalar you cannot have a value indicator (that is usually a colon followed by a space/newline), and that is what you have with names:.

So if you want everything to be one single scalar, and you have a : in the string, you must quote it:

"train = '/content/elec_meter_yaml/train.txt'
val = '/content/elec_meter_yaml/val.txt'
test = '/content/elec_meter_yaml/test.txt'
nc = 12

names:
  0: one
  1: two
  2: three
  3: four
  4: five
  5: six
  6: seven
  7: eight
  8: nine
  9: zero
  10: meter
  11: dot"

On the other hand you might just be mixing Python dictionary intialisation with YAML key-value pairs and want a root level mapping. In that case change the equal signs in the first four lines:

train: '/content/elec_meter_yaml/train.txt'
val: '/content/elec_meter_yaml/val.txt'
test: '/content/elec_meter_yaml/test.txt'
nc: 12

names:
  0: one
  1: two
  2: three
  3: four
  4: five
  5: six
  6: seven
  7: eight
  8: nine
  9: zero
  10: meter
  11: dot

That also is valid YAML, but of course it will load differently from the other document.

Anthon
  • 69,918
  • 32
  • 186
  • 246