Skip to content

Added manual file path selection option for coco#511

Open
shardulmahamulkar wants to merge 2 commits intoJdeRobot:masterfrom
shardulmahamulkar:feat/manual-path-selection-coco-clean
Open

Added manual file path selection option for coco#511
shardulmahamulkar wants to merge 2 commits intoJdeRobot:masterfrom
shardulmahamulkar:feat/manual-path-selection-coco-clean

Conversation

@shardulmahamulkar
Copy link
Copy Markdown

@shardulmahamulkar shardulmahamulkar commented Mar 26, 2026

Closes #465

Summary

The Streamlit app auto-detects image directories and annotation files based on a fixed COCO folder convention (images/{split}/ + annotations/instances_{split}.json). When users have datasets organised differently, the app failed silently with a generic error and no guidance.

This PR adds an optional "Use manual paths" checkbox in the sidebar (COCO mode only) that lets users override auto-detection by specifying the image directory and annotation file directly.

Changes

perceptionmetrics/utils/gui.py
Added
browse_file(filetypes=None)
A cross-platform native file-picker dialog (Windows / WSL / macOS / Linux via zenity or kdialog), analogous to the existing
browse_folder()
.
app.py
Imports
browse_file
alongside
browse_folder

.

Dataset Viewer (tabs/dataset_viewer.py)

  • Added session state keys:
    • manual_img_dir
    • manual_ann_file
    • manual_paths_enabled
  • Introduced a "Use manual paths" checkbox for COCO datasets.
    • When enabled:
      • Displays inputs for Image Directory and Annotation File (.json), each with a browse option.
      • Overrides automatic dataset path detection.
    • When disabled:
      • Clears manual path state to ensure default auto-detection is used.
  • Moved manual path handling logic to the beginning of dataset_viewer_tab():
    • Allows bypassing dataset_path validation when valid manual paths are provided.
  • Updated cache key logic:
    • Uses manual_{img_dir}_{ann_file}_{split} when manual paths are active to prevent stale cache usage.
  • Improved error handling:
    • Displays actual exception messages (FileNotFoundError and generic exceptions).
    • Includes expected COCO directory structure in a formatted code block for clarity.

Evaluator (tabs/evaluator.py)

  • Added the same manual path handling logic as in the dataset viewer.
  • Hoisted manual path checks to ensure consistent behavior.
  • Updated cache key logic to match dataset viewer implementation.
  • Relaxed dataset loading condition:
    • Now allows loading when either:
      • manual paths are provided, OR
      • a valid dataset_path directory exists
        .
        Error messages updated with expected structure hints.

Expected COCO Structure (auto-detection)

dataset_root/
├── images/
│   ├── train/       # or train2017, train2, etc.
│   ├── val/
│   └── test/
└── annotations/
    ├── instances_train.json
    ├── instances_val.json
    └── instances_test.json

Testing

  • Default behaviour unchanged : leave checkbox unticked, point to a standard COCO dataset → loads correctly in Dataset Viewer and Evaluator.
  • Checkbox reveals inputs : tick "Use manual paths" → Image Directory and Annotation File fields + Browse buttons appear.
  • Browse buttons work : folder picker opens for Image Directory;
    .json
  • File picker opens for Annotation File.
  • Manual override works : fill in non-standard paths → dataset loads correctly.
  • Uncheck clears override :untick checkbox → manual path fields disappear and auto-detection resumes on next load.
  • Helpful errors : with bad paths, error shows the actual exception + expected folder structure.
  • No dataset_path required : manual paths work even if the Dataset Folder field is left empty.
  • Existing tests pass : pytest tests/

Update: YOLO Manual Path Selection

The YOLO mode currently does not correctly detect datasets when using manual path selection. Additionally, Streamlit caching is causing inconsistent behavior in some cases.

I am actively working on resolving these issues.

In the meantime, please feel free to review the current changes and let me know if there are any suggestions or improvements.

@shardulmahamulkar
Copy link
Copy Markdown
Author

Updated: YOLO manual path selection is now implemented in the latest commit (4c96108). Both COCO and YOLO manual paths are working. Ready for review.

@shardulmahamulkar shardulmahamulkar marked this pull request as ready for review March 28, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow manual selection of image directory and annotation file in Streamlit GUI

1 participant