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

使用tools/infer.py报错 #9194

Open
1 task done
LittleCool-Man opened this issue Oct 25, 2024 · 6 comments
Open
1 task done

使用tools/infer.py报错 #9194

LittleCool-Man opened this issue Oct 25, 2024 · 6 comments
Assignees

Comments

@LittleCool-Man
Copy link

问题确认 Search before asking

  • 我已经搜索过问题,但是没有找到解答。I have searched the question and found no related answer.

请提出你的问题 Please ask your question

执行命令

python PaddleDetection/tools/infer.py -c PaddleDetection/configs/picodet/picodet_m_416_coco_lcnet.yml --infer_dir pic/

提示

Traceback (most recent call last):
  File "/home/aistudio/PaddleDetection/tools/infer.py", line 273, in <module>
    main()
  File "/home/aistudio/PaddleDetection/tools/infer.py", line 269, in main
    run(FLAGS, cfg)
  File "/home/aistudio/PaddleDetection/tools/infer.py", line 218, in run
    trainer.predict(
  File "/home/aistudio/PaddleDetection/ppdet/engine/trainer.py", line 994, in predict
    self.dataset.set_images(images, do_eval=do_eval)
  File "/home/aistudio/PaddleDetection/ppdet/data/source/dataset.py", line 240, in set_images
    self.roidbs = self._load_images(do_eval=do_eval)
  File "/home/aistudio/PaddleDetection/ppdet/data/source/dataset.py", line 210, in _load_images
    coco = COCO(anno_file)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/pycocotools/coco.py", line 82, in __init__
    dataset = json.load(f)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/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)

picodet_m_416_coco_lcnet.yml配置如下:

_BASE_: [
  '../datasets/voc.yml',
  '../runtime.yml',
  '_base_/picodet_v2.yml',
  '_base_/optimizer_300e.yml',
  '_base_/picodet_416_reader.yml',
]

pretrain_weights: weights/picodet_m_416_coco_lcnet.pdparams
# weights: output/picodet_s_416_coco_lcnet/119
weights: output/best_model
find_unused_parameters: True
use_ema: true
epoch: 300
snapshot_epoch: 10

LCNet:
  scale: 0.75
  feature_maps: [3, 4, 5]

LCPAN:
  out_channels: 96

PicoHeadV2:
  conv_feat:
    name: PicoFeat
    feat_in: 96
    feat_out: 96
    num_convs: 2
    num_fpn_stride: 4
    norm_type: bn
    share_cls_reg: True
    use_se: True
  feat_in_chan: 96

TrainReader:
  sample_transforms:
  - Decode: {}
  - Mosaic:
      prob: 0.6
      input_dim: [640, 640]
      degrees: [-10, 10]
      scale: [0.1, 2.0]
      shear: [-2, 2]
      translate: [-0.1, 0.1]
      enable_mixup: True
  - AugmentHSV: {is_bgr: False, hgain: 5, sgain: 30, vgain: 30}
  - RandomCrop: {}
  - RandomFlip: {prob: 0.5}
  - RandomDistort: {}
  batch_transforms:
  - BatchRandomResize: {target_size: [352, 384, 416, 448, 480], random_size: True, random_interp: True, keep_ratio: False}
  - NormalizeImage: {is_scale: true, mean: [0.485,0.456,0.406], std: [0.229, 0.224,0.225]}
  - Permute: {}
  - PadGT: {}
  batch_size: 72
  shuffle: true
  drop_last: false

LearningRate:
  base_lr: 0.06
  schedulers:
  - !CosineDecay
    max_epochs: 300
  - !LinearWarmup
    start_factor: 0.1
    steps: 300

voc.yml配置如下:

metric: VOC
map_type: 11point
num_classes: 3

TrainDataset:
  name: VOCDataSet
  dataset_dir: dataset/voc
  anno_path: train.txt
  label_list: label.txt
  data_fields: ['image', 'gt_bbox', 'gt_class', 'difficult']

EvalDataset:
  name: VOCDataSet
  dataset_dir: dataset/voc
  anno_path: valid.txt
  label_list: label.txt
  data_fields: ['image', 'gt_bbox', 'gt_class', 'difficult']

TestDataset:
  name: ImageFolder
  anno_path: dataset/voc/label.txt

数据集目录:

image

运行环境:

AIstudio-GPU
python3.10.10
paddlepaddle2.6.2
paddledetection2.7

使用voc数据集训练时一切正常,voc数据集都是xml文件,为什么在调用infer.py推理时要去验证json文件呢,是哪个配置没修改吗?

@lunaticsst
Copy link
Contributor

lunaticsst commented Oct 25, 2024

您好,我看到picodet_m_416_coco_lcnet.yml原文件中所使用的数据集是coco格式的,您提供的报错信息中显示调用了COCO数据集对应的class,因此可能这个算法和voc格式数据集不适配,建议您将数据保存副本后将数据集转换为COCO格式即可。我们在PaddleX中提供了目标检测数据集VOC格式转换为COCO格式的功能,您可以安装PaddleX并参考https://github.com/PaddlePaddle/PaddleX/blob/5029b5053d82b9acfd4b0b6e57c3a58773224504/docs/module_usage/tutorials/cv_modules/object_detection.md 中4.1.3部分对应的命令进行转换。

@LittleCool-Man
Copy link
Author

LittleCool-Man commented Oct 25, 2024

您好,我看到picodet_m_416_coco_lcnet.yml原文件中所使用的数据集是coco格式的,您提供的报错信息中显示调用了COCO数据集对应的class,因此可能这个算法和voc格式数据集不适配,建议您将数据保存副本后将数据集转换为COCO格式即可。我们在PaddleX中提供了目标检测数据集VOC格式转换为COCO格式的功能,您可以安装PaddleX并参考https://github.com/PaddlePaddle/PaddleX/blob/5029b5053d82b9acfd4b0b6e57c3a58773224504/docs/module_usage/tutorials/cv_modules/object_detection.md 中4.1.3部分对应的命令进行转换。

感谢您的回复,我稍后会将数据集格式修改为coco同时修改相应配置文件尝试一下。
此外我还是想了解一下,同样的配置训练时调用train,py没有报错,正常完成训练,应该说明这个是支持voc数据集的,picodet_m_416_coco_lcnet.yml、voc.yml都做了修改将数据集格式指向voc,为什么在调用infer.py是会将数据集指向coco格式呢。是因为picodet_m_416_coco_lcnet.pdparams这个预训练模型推理时只支持coco格式吗,还是因为存在其他配置文件需要修改呢?

@EvW1998
Copy link

EvW1998 commented Oct 25, 2024

#9192 我发现运行快速体验中的infer命令也会报如上的错误。 请问为什么推理单张图片时会调用数据集呢? @lunaticsst

@TingquanGao TingquanGao self-assigned this Oct 25, 2024
@TingquanGao
Copy link
Collaborator

该问题需要排查,猜测是在推理单张图时,需要class id和label的映射表,该信息默认是从coco数据集的json文件中读取的。
建议尝试PaddleX进行单图推理,相关目标检测模型目标检测产线

@EvW1998
Copy link

EvW1998 commented Oct 28, 2024

该问题需要排查,猜测是在推理单张图时,需要class id和label的映射表,该信息默认是从coco数据集的json文件中读取的。 建议尝试PaddleX进行单图推理,相关目标检测模型目标检测产线

经过我的排查,问题应该是无论数据集格式为VOC或COCO,infer.py都尝试通过抽取COCO的json文件中的标签。并没有在数据集格式为VOC时,改为读取label_list.txt。

@TingquanGao
Copy link
Collaborator

感谢反馈!我记录下该问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants