Skip to content

Commit

Permalink
Merge pull request #248 from roboflow/bugfix-trailing-slash
Browse files Browse the repository at this point in the history
BugFix: importing a yolo dataset with a trailing slash ignores annotations
  • Loading branch information
tonylampada committed Apr 26, 2024
2 parents 2a8917a + 3f1b6b3 commit 244938d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.debugpy",
"ms-python.black-formatter"
],
"settings": {
Expand Down
2 changes: 1 addition & 1 deletion roboflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from roboflow.models import CLIPModel, GazeModel # noqa: F401
from roboflow.util.general import write_line

__version__ = "1.1.27"
__version__ = "1.1.28"


def check_key(api_key, model, notebook, num_retries=0):
Expand Down
3 changes: 3 additions & 0 deletions roboflow/util/folderparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@


def parsefolder(folder):
folder = folder.strip()
if folder.endswith("/"):
folder = folder[:-1]
if not os.path.exists(folder):
raise Exception(f"folder does not exist. {folder}")
files = _list_files(folder)
Expand Down
21 changes: 12 additions & 9 deletions tests/util/test_folderparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ def test_parse_sharks_createml(self):
assert len(imgReference["annotations"]) == 5

def test_parse_sharks_yolov9(self):
sharksfolder = f"{thisdir}/../datasets/sharks-tiny-yolov9"
parsed = folderparser.parsefolder(sharksfolder)
testImagePath = "/train/images/sharks_mp4-20_jpg.rf.5359121123e86e016401ea2731e47949.jpg"
testImage = [i for i in parsed["images"] if i["file"] == testImagePath][0]
expectAnnotationFile = "/train/labels/sharks_mp4-20_jpg.rf.5359121123e86e016401ea2731e47949.txt"
assert testImage["annotationfile"]["file"] == expectAnnotationFile
assert testImage["annotationfile"]["labelmap"] == {0: "fish", 1: "primary", 2: "shark"}
def test(sharksfolder):
parsed = folderparser.parsefolder(sharksfolder)
testImagePath = "/train/images/sharks_mp4-20_jpg.rf.5359121123e86e016401ea2731e47949.jpg"
testImage = [i for i in parsed["images"] if i["file"] == testImagePath][0]
expectAnnotationFile = "/train/labels/sharks_mp4-20_jpg.rf.5359121123e86e016401ea2731e47949.txt"
assert testImage["annotationfile"]["file"] == expectAnnotationFile
assert testImage["annotationfile"]["labelmap"] == {0: "fish", 1: "primary", 2: "shark"}

test(f"{thisdir}/../datasets/sharks-tiny-yolov9")
test(f"{thisdir}/../datasets/sharks-tiny-yolov9/") # this was a bug once, can you believe it?

def test_parse_mosquitos_csv(self):
sharksfolder = f"{thisdir}/../datasets/mosquitos"
parsed = folderparser.parsefolder(sharksfolder)
folder = f"{thisdir}/../datasets/mosquitos"
parsed = folderparser.parsefolder(folder)
testImagePath = "/train_10308.jpeg"
testImage = [i for i in parsed["images"] if i["file"] == testImagePath][0]
assert testImage["annotationfile"]["name"] == "annotation.csv"
Expand Down

0 comments on commit 244938d

Please sign in to comment.