Skip to content

Commit fcd7819

Browse files
ihaoheclaude
andcommitted
Improve dataset handling with adaptive folder detection and better test dataset fallback
- Add adaptive val/valid folder detection to support both YOLO (val) and COCO (valid) dataset structures - Implement fallback mechanism for test dataset since most datasets don't include test split - Reduce the need for manual dataset modification by automatically handling different folder naming conventions - Add proper error handling with FileNotFoundError for missing validation folders - Convert Chinese comments to English for better internationalization 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 24ce179 commit fcd7819

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

rfdetr/datasets/coco.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,29 @@ def build_roboflow(image_set, args, resolution):
238238
root = Path(args.dataset_dir)
239239
assert root.exists(), f'provided Roboflow path {root} does not exist'
240240
mode = 'instances'
241+
242+
# Adaptively detect val/valid folder name
243+
val_folder = None
244+
if (root / "valid").exists():
245+
val_folder = "valid"
246+
elif (root / "val").exists():
247+
val_folder = "val"
248+
else:
249+
raise FileNotFoundError(f"Neither 'val' nor 'valid' folder found in {root}")
250+
251+
# Build path mapping, optimizing test dataset handling
241252
PATHS = {
242253
"train": (root / "train", root / "train" / "_annotations.coco.json"),
243-
"val": (root / "valid", root / "valid" / "_annotations.coco.json"),
244-
"test": (root / "test", root / "test" / "_annotations.coco.json"),
254+
"val": (root / val_folder, root / val_folder / "_annotations.coco.json"),
245255
}
246256

257+
# Handle test dataset: if test doesn't exist, use val dataset instead
258+
if (root / "test").exists() and (root / "test" / "_annotations.coco.json").exists():
259+
PATHS["test"] = (root / "test", root / "test" / "_annotations.coco.json")
260+
else:
261+
print(f"Warning: test dataset not found, using {val_folder} dataset for testing")
262+
PATHS["test"] = (root / val_folder, root / val_folder / "_annotations.coco.json")
263+
247264
img_folder, ann_file = PATHS[image_set.split("_")[0]]
248265

249266
try:

0 commit comments

Comments
 (0)