Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions rfdetr/datasets/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,29 @@ def build_roboflow(image_set, args, resolution):
root = Path(args.dataset_dir)
assert root.exists(), f'provided Roboflow path {root} does not exist'
mode = 'instances'

# Adaptively detect val/valid folder name
val_folder = None
if (root / "valid").exists():
val_folder = "valid"
elif (root / "val").exists():
val_folder = "val"
else:
raise FileNotFoundError(f"Neither 'val' nor 'valid' folder found in {root}")

# Build path mapping, optimizing test dataset handling
PATHS = {
"train": (root / "train", root / "train" / "_annotations.coco.json"),
"val": (root / "valid", root / "valid" / "_annotations.coco.json"),
"test": (root / "test", root / "test" / "_annotations.coco.json"),
"val": (root / val_folder, root / val_folder / "_annotations.coco.json"),
}

# Handle test dataset: if test doesn't exist, use val dataset instead
if (root / "test").exists() and (root / "test" / "_annotations.coco.json").exists():
PATHS["test"] = (root / "test", root / "test" / "_annotations.coco.json")
else:
print(f"Warning: test dataset not found, using {val_folder} dataset for testing")
PATHS["test"] = (root / val_folder, root / val_folder / "_annotations.coco.json")

img_folder, ann_file = PATHS[image_set.split("_")[0]]

try:
Expand Down