马春杰杰 Exit Reader Mode

ValueError: tuple.index(x): x not in tuple

detectron2使用自定义数据集进行训练的时候,提示:

ValueError: tuple.index(x): x not in tuple

Traceback (most recent call last):
  File "projects/SparseRCNN/train_net.py", line 143, in <module>
    args=(args,),
  File "/home/ubuntu/bigdisk/part2/SparseR-CNN/detectron2/engine/launch.py", line 62, in launch
    main_func(*args)
  File "projects/SparseRCNN/train_net.py", line 129, in main
    trainer = Trainer(cfg)
  File "/home/ubuntu/bigdisk/part2/SparseR-CNN/detectron2/engine/defaults.py", line 284, in __init__
    data_loader = self.build_train_loader(cfg)
  File "projects/SparseRCNN/train_net.py", line 53, in build_train_loader
    return build_detection_train_loader(cfg, mapper=mapper)
  File "/home/ubuntu/bigdisk/part2/SparseR-CNN/detectron2/config/config.py", line 201, in wrapped
    explicit_args = _get_args_from_config(from_config, *args, **kwargs)
  File "/home/ubuntu/bigdisk/part2/SparseR-CNN/detectron2/config/config.py", line 236, in _get_args_from_config
    ret = from_config_func(*args, **kwargs)
  File "/home/ubuntu/bigdisk/part2/SparseR-CNN/detectron2/data/build.py", line 309, in _train_loader_from_config
    proposal_files=cfg.DATASETS.PROPOSAL_FILES_TRAIN if cfg.MODEL.LOAD_PROPOSALS else None,
  File "/home/ubuntu/bigdisk/part2/SparseR-CNN/detectron2/data/build.py", line 222, in get_detection_dataset_dicts
    dataset_dicts = [DatasetCatalog.get(dataset_name) for dataset_name in dataset_names]
  File "/home/ubuntu/bigdisk/part2/SparseR-CNN/detectron2/data/build.py", line 222, in <listcomp>
    dataset_dicts = [DatasetCatalog.get(dataset_name) for dataset_name in dataset_names]
  File "/home/ubuntu/bigdisk/part2/SparseR-CNN/detectron2/data/catalog.py", line 58, in get
    return f()
  File "/home/ubuntu/bigdisk/part2/SparseR-CNN/detectron2/data/datasets/pascal_voc.py", line 78, in <lambda>
    DatasetCatalog.register(name, lambda: load_voc_instances(dirname, split, class_names))
  File "/home/ubuntu/bigdisk/part2/SparseR-CNN/detectron2/data/datasets/pascal_voc.py", line 70, in load_voc_instances
    {"category_id": class_names.index(cls), "bbox": bbox, "bbox_mode": BoxMode.XYXY_ABS}
ValueError: tuple.index(x): x not in tuple

原因是数据类别不一致,修改:

/home/ubuntu/bigdisk/part2/SparseR-CNN/detectron2/data/datasets/pascal_voc.py

CLASS_NAMES改为正确的类别即可。

本文最后更新于2021年4月3日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!