PaddlePaddle / PaddleDetection

Object Detection toolkit based on PaddlePaddle. It supports object detection, instance segmentation, multiple object tracking and real-time multi-person keypoint detection.
Apache License 2.0
12.8k stars 2.89k forks source link

训练时遇到无法正常加载自定义数据集的错误 #8574

Open joe1558 opened 1 year ago

joe1558 commented 1 year ago

问题确认 Search before asking

请提出你的问题 Please ask your question

训练时使用如下命令python train.py -c configs/arsl_fcos_r50_fpn_coco_full.yml --eval出现以下错误,按照错误的描述是没能加载出json文件,查看配置文件内容也没有什么问题,metric设置的是coco,数据集路径也没有问题,json文件也可以正常打开和解析,不知道应该还要检查哪里去更改错误。

loading annotations into memory...
Done (t=0.04s)
creating index...
index created!
[08/25 17:04:13] ppdet.data.source.coco INFO: Load [1002 samples valid, 0 samples invalid] in file /home/ltsyl308/qyj/asml/dataset/coco/annotations/instances_train2017.json.
[08/25 17:04:13] ppdet.data.source.coco INFO: Use 1002 sup_samples data as LABELED
loading annotations into memory...
Traceback (most recent call last):
  File "train.py", line 211, in <module>
    main()
  File "train.py", line 207, in main
    run(FLAGS, cfg)
  File "train.py", line 136, in run
    trainer = Trainer_ARSL(cfg, mode='train')
  File "/home/ltsyl308/anaconda3/envs/py36/lib/python3.7/site-packages/paddledet-0.0.0-py3.7.egg/ppdet/engine/trainer_ssod.py", line 491, in __init__
    self.dataset, self.dataset_unlabel, cfg.worker_num)
  File "/home/ltsyl308/anaconda3/envs/py36/lib/python3.7/site-packages/paddledet-0.0.0-py3.7.egg/ppdet/data/reader.py", line 536, in __call__
    self.dataset_unlabel.parse_dataset()
  File "/home/ltsyl308/anaconda3/envs/py36/lib/python3.7/site-packages/paddledet-0.0.0-py3.7.egg/ppdet/data/source/coco.py", line 402, in parse_dataset
    coco = COCO(anno_path)
  File "/home/ltsyl308/anaconda3/envs/py36/lib/python3.7/site-packages/pycocotools/coco.py", line 82, in __init__
    dataset = json.load(f)
  File "/home/ltsyl308/anaconda3/envs/py36/lib/python3.7/json/__init__.py", line 296, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "/home/ltsyl308/anaconda3/envs/py36/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/home/ltsyl308/anaconda3/envs/py36/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/home/ltsyl308/anaconda3/envs/py36/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)``
joe1558 commented 1 year ago

尝试使用traceback在此处寻找到错误的原因

File "/home/ltsyl308/anaconda3/envs/py36/lib/python3.7/site-packages/pycocotools/coco.py", line 82, in __init__
    dataset = json.load(f)

将原本coco文件中82行的代码

 with open(annotation_file, 'r') as f:
                    dataset = json.load(f)

改为

   try:
                with open(annotation_file, 'r') as f:
                    dataset = json.load(f)
            except Exception as e:
                traceback.print_exc()

出现错误

File "/home/ltsyl308/anaconda3/envs/py36/lib/python3.7/site-packages/paddledet-0.0.0-py3.7.egg/ppdet/engine/trainer_ssod.py", line 491, in __init__
    self.dataset, self.dataset_unlabel, cfg.worker_num)
  File "/home/ltsyl308/anaconda3/envs/py36/lib/python3.7/site-packages/paddledet-0.0.0-py3.7.egg/ppdet/data/reader.py", line 536, in __call__
    self.dataset_unlabel.parse_dataset()
  File "/home/ltsyl308/anaconda3/envs/py36/lib/python3.7/site-packages/paddledet-0.0.0-py3.7.egg/ppdet/data/source/coco.py", line 402, in parse_dataset
    coco = COCO(anno_path)
  File "/home/ltsyl308/anaconda3/envs/py36/lib/python3.7/site-packages/pycocotools/coco.py", line 89, in __init__
    assert type(dataset)==dict, 'annotation file format {} not supported'.format(type(dataset))
UnboundLocalError: local variable 'dataset' referenced before assignment
creativesalam commented 1 year ago

share your annotations .json file

LokeZhou commented 8 months ago

这个应该是json文件的格式有问题