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

It is supposed to be compatible for relative path in val2017.txt #33

Open
ckmessi opened this issue Aug 5, 2020 · 1 comment
Open

Comments

@ckmessi
Copy link

ckmessi commented Aug 5, 2020

Problem

When I run the basic demo script:

python test_half.py --data coco2017.data --cfg cfg/yolov4-pacsp.cfg --weights weights/yolov4-pacsp.pt --img 736 --iou-thr 0.7 --batch-size 8

It raised exception that the label files had not been found:

Traceback (most recent call last):
  File "test_half.py", line 257, in <module>
    opt.augment)
  File "test_half.py", line 64, in test
    dataset = LoadImagesAndLabels(path, img_size, batch_size, rect=True, single_cls=opt.single_cls)
  File "/path/to/PyTorch_YOLOv4/utils/datasets.py", line 382, in __init__
    assert nf > 0, 'No labels found in %s. See %s' % (os.path.dirname(file) + os.sep, help_url)
AssertionError: No labels found in ./labels/val2017/. See https://github.com/ultralytics/yolov3/wiki/Train-Custom-Data

By diving into the problem, I found it was caused by relative path.
For the coco2017 dataset, the zip file coco2017labels.zip download from data/get_coco2017.sh contains files:

- coco/
    - annotations/
    - images/
    - labels/
    - train2017.txt
    - val2017.txt
    - ...

The content of val2017.txt is like this:

./images/val2017/000000182611.jpg
./images/val2017/000000335177.jpg
./images/val2017/000000278705.jpg
./images/val2017/000000463618.jpg
./images/val2017/000000568981.jpg
...

Here, the paths of images are relative, so the script could not find the label file.

Solution

Refered to Yolov5 project, we can add two line in utils/database.py to support the relative path:

self.img_files = [x.replace('./', parent) if x.startswith('./') else x for x in self.img_files]

I have create a pull request #32

@FYM1209
Copy link

FYM1209 commented Sep 29, 2022

this two line add where

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

2 participants