tools/infer.py fails without the COCO dataset: ImageFolder._load_images always opens instances_val2017.json
问题确认 Search before asking
Bug组件 Bug Component
Inference
Bug描述 Describe the Bug
1. Inference requires the COCO annotation file. Single-image inference as shown in
docs/tutorials/GETTING_STARTED.md, here with a PicoDet model, without the COCO dataset downloaded:
python tools/infer.py -c configs/picodet/picodet_s_320_coco_lcnet.yml \
-o use_gpu=False weights=https://paddledet.bj.bcebos.com/models/picodet_s_320_coco_lcnet.pdparams \
--infer_img=demo/000000014439.jpg --output_dir=output
fails with
File "ppdet/engine/trainer.py", line 1161, in predict
File "ppdet/data/source/dataset.py", line 252, in set_images
File "ppdet/data/source/dataset.py", line 222, in _load_images
FileNotFoundError: [Errno 2] No such file or directory: 'dataset/coco/annotations/instances_val2017.json'
ImageFolder._load_images builds COCO(anno_file) unconditionally, but only uses it when do_eval is true. Loading
it only under do_eval makes the command above succeed (7 detections on the demo image) with no other change.
2. The font is cached in a literal ./~ directory. ppdet/utils/visualizer.py line 112 calls
get_path(font_url, "~/.cache/paddle/"). The tilde is never expanded, so simfang.ttf is downloaded into
./~/.cache/paddle/ under the current working directory instead of the home directory. Wrapping the path in
os.path.expanduser fixes it.
复现环境 Environment
- OS: Linux (Ubuntu 24.04)
- PaddlePaddle: 2.6.2 (CPU)
- PaddleDetection: release/2.9 (commit b25522a)
- Python: 3.10
- CUDA: none (CPU only)
Bug描述确认 Bug description confirmation
- [x] 我确认已经提供了Bug复现步骤、代码改动说明、以及环境信息,确认问题是可以复现的。I confirm that the bug replication steps, code change instructions, and environment information have been provided, and the problem can be reproduced.
是否愿意提交PR? Are you willing to submit a PR?
- [ ] 我愿意提交PR!I'd like to help by submitting a PR!
I will work on this. I will cover annotation-free inference, preserve COCO image IDs for evaluation, and check the font cache path, with regression tests and the reported CPU PicoDet command.
The annotation failure is reproduced and fixed locally; evaluation IDs still pass regression checks. I found that the separate font-path problem is already covered by open PRs #9489 and #9490, so I will keep this PR focused on the annotation-loading failure and reference, rather than close, this two-part issue.