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

Mistaken path change from "images" to "labels" #3719

Closed
tetelevm opened this issue Jun 21, 2021 · 3 comments · Fixed by #3720
Closed

Mistaken path change from "images" to "labels" #3719

tetelevm opened this issue Jun 21, 2021 · 3 comments · Fixed by #3720
Labels
question Further information is requested

Comments

@tetelevm
Copy link

Hello! I create dir /images/train/ on my GoogleDrive and put the train images into /images/train/images/ and labels into /images/train/labels/. I expect the script to look for labels in /images/train/labels, but it looks at the /labels/to_train/images/ (replaces the first word "images" instead of the last word). Isn't this a bug?

@tetelevm tetelevm added the question Further information is requested label Jun 21, 2021
@glenn-jocher
Copy link
Member

@tetelevm yes I see the same result in master. Code to reproduce:

import os
from utils.datasets import img2label_paths

img2label_paths(['dataset/images/images/img1.jpg'])

# output ['dataset/labels/images/img1.txt']

@glenn-jocher
Copy link
Member

glenn-jocher commented Jun 21, 2021

Possible fix:

import os

def img2label_paths(img_paths):
    # Define label paths as a function of image paths
    sa, sb = os.sep + 'images' + os.sep, os.sep + 'labels' + os.sep  # /images/, /labels/ substrings
    return ['txt'.join(x.replace(sa, sb, 1).rsplit(x.split('.')[-1], 1)) for x in img_paths]


def img2label_paths_fix(img_paths):
    # Define label paths as a function of image paths
    sa, sb = os.sep + 'images' + os.sep, os.sep + 'labels' + os.sep  # /images/, /labels/ substrings
    return ['txt'.join(sb.join(x.rsplit(sa, 1)).rsplit(x.split('.')[-1], 1)) for x in img_paths]


def img2label_paths_fix2(img_paths):
    # Define label paths as a function of image paths
    sa, sb = os.sep + 'images' + os.sep, os.sep + 'labels' + os.sep  # /images/, /labels/ substrings
    return [sb.join(x.rsplit(sa, 1)).rsplit('.', 1)[0] + '.txt' for x in img_paths]

images = ['dataset/images/images/img1.jpg'] * 100

print(img2label_paths(images[0:1]))
print(img2label_paths_fix(images[0:1]))
print(img2label_paths_fix2(images[0:1]))

%timeit img2label_paths(images)
%timeit img2label_paths_fix(images)
%timeit img2label_paths_fix2(images)

## OUTPUT
['dataset/labels/images/img1.txt']
['dataset/images/labels/img1.txt']
['dataset/images/labels/img1.txt']

55.2 µs ± 519 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
70.7 µs ± 2.09 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
51.8 µs ± 336 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)

It looks like we have a winner.

@glenn-jocher glenn-jocher linked a pull request Jun 21, 2021 that will close this issue
@glenn-jocher
Copy link
Member

@tetelevm good news 😃! Your original issue may now be fixed ✅ in PR #3720. To receive this update:

  • Gitgit pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload with model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle
  • Dockersudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀!

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

Successfully merging a pull request may close this issue.

2 participants