[go: nahoru, domu]

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

Ignore Empty Newlines in Yolo Label File #584

Merged
merged 8 commits into from
Nov 15, 2023

Conversation

SummitStudiosDev
Copy link
Contributor

Description

I had an empty newline after the label in one of my yolo label files, it started broke the entire program, failing to load the dataset.

  File "C:\Users\codys\Desktop\project\labelled datasets\visualizelabel - toFile.py", line 19, in <module>
    dataset = sv.DetectionDataset.from_yolo(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\codys\AppData\Local\Programs\Python\Python311\Lib\site-packages\supervision\dataset\core.py", line 313, in from_yolo
    classes, images, annotations = load_yolo_annotations(
                                   ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\codys\AppData\Local\Programs\Python\Python311\Lib\site-packages\supervision\dataset\formats\yolo.py", line 161, in load_yolo_annotations
    annotation = yolo_annotations_to_detections(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\codys\AppData\Local\Programs\Python\Python311\Lib\site-packages\supervision\dataset\formats\yolo.py", line 85, in yolo_annotations_to_detections
    class_id.append(int(values[0]))
                        ~~~~~~^^^
IndexError: list index out of range

I went to yolo.py and I added a line printing out values, and it gave me [] as causing the problem, which makes sense.
I then went and added a line printing print(lines) (because values = line.split() and for line in lines:), and I got

['1 0.35195 0.51250 0.16016 0.11112', '']
['1 0.35195 0.51250 0.16016 0.11112', '']

preceding the error message which led me to conclude that there must be an extra newline.

Adding a check to see if values is length 0, and if it is just run a continue statement solves the problem and the library simply ignores the empty line instead of throwing an error.

if(len(values)==0):
            continue

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How has this change been tested, please provide a testcase or example of how you tested the change?

My program now runs, and I didn't have to modify my label txts at all.

Any specific deployment considerations

This would be a rather harmless ease-of-convivence fix, as all it does is ignore empty Newlines in a yolo label file, which otherwise would crash the entire program.

This is my first pull request so sorry if it's confusing!

@CLAassistant
Copy link
CLAassistant commented Nov 10, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor
@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello there, thank you for opening an PR ! 🙏🏻 The team was notified and they will get back to you asap.

SkalskiP and others added 2 commits November 10, 2023 10:15
Refactored import paths for test utility methods across multiple test files to align with a recent package restructure. Enriched 'read_txt_file' functionality in 'file.py' allowing to optionally skip empty lines, enhancing flexibility for various use-cases. Added tests for the new 'read_txt_file' behavior in a new 'test_file.py'. Renamed 'utils.py' in test package to 'test_utils.py' for better differentiation from the util package in the source code.
SkalskiP and others added 2 commits November 10, 2023 10:25
Added linting rule exceptions for 'test/utils/test_file.py' in 'pyproject.toml'. Specifically, the 'W291' error which checks for trailing whitespace is ignored for this test file. This is necessary to test whether 'read_txt_file' function in 'test_utils.py' correctly ignores trailing whitespaces in varies test scenarios.
@SkalskiP
Copy link
Collaborator

Hi, @SummitStudiosDev! 👋🏻 Thanks a lot for your interest in our project. I moved the solution into read_txt_file to make it more reusable.

@onuralpszr I tried to exclude test/utils/test_file.py from W291. What am I doing wrong?

Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
@onuralpszr
Copy link
Collaborator

Hi, @SummitStudiosDev! 👋🏻 Thanks a lot for your interest in our project. I moved the solution into read_txt_file to make it more reusable.

@onuralpszr I tried to exclude test/utils/test_file.py from W291. What am I doing wrong?

Hi, @SummitStudiosDev! 👋🏻 Thanks a lot for your interest in our project. I moved the solution into read_txt_file to make it more reusable.

@onuralpszr I tried to exclude test/utils/test_file.py from W291. What am I doing wrong?

exclude not needed and fixed.

Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
@SkalskiP
Copy link
Collaborator
SkalskiP commented Nov 15, 2023

@onuralpszr, we still need to fix the test. The test was broken by auto-format. All you did was change the expected result to match the test broken by auto format.

@SkalskiP
Copy link
Collaborator

Thanks a lot for your help, @SummitStudiosDev 🙏🏻 Let's merge this. I will solve test problems on my own.

@SkalskiP SkalskiP merged commit 109d048 into roboflow:develop Nov 15, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Current Release: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants