[Bug] GUI Image Detection inference fails with IndexError when loading native YOLO .pt models

Open Beginner friendly
#693 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 6 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, pytorch, streamlit

Research direction

Start with gui/tasks/image_detection/sidebar.py to inspect the model-format selection and its default for .pt files, then read perceptionmetrics/models/utils/torchvision.py to locate the raw-tensor postprocessing path. Run streamlit run app.py and reproduce the error by loading yolov8n.pt in the Image Detection Model sidebar and running inference in Tab 2. Done means native YOLO models are auto-selected when appropriate, raw tensors are routed to YOLO postprocessing, and inference no longer raises the IndexError.

Written by the indexing model from the issue text.

Description

Problem Description

When loading a native YOLO model (such as yolov8n.pt) in the Streamlit GUI, running inference in Tab 2 fails with:

Failed to run inference: too many indices for tensor of dimension 2

Steps to reproduce:

  1. Run streamlit run app.py
  2. In sidebar → Image Detection Model: upload yolov8n.pt and valid ontology JSON.
  3. Leave Model Format as default (torchvision) and click Load Model.
  4. Tab 2 (Inference): upload any test image.

Root Cause:
In gui/tasks/image_detection/sidebar.py, the Model Format dropdown defaults to torchvision. Native YOLO models output a raw 2D tensor [84, 8400]. When passed to torchvision.postprocess_detection, executing output["scores"] on a 2D tensor raises IndexError.

Proposed Approach
  1. In gui/tasks/image_detection/sidebar.py: Auto-select YOLO in the dropdown if the model filename contains yolo or is a .pt file (while still allowing manual selection).
  2. In perceptionmetrics/models/utils/torchvision.py: Add a type check so if a raw tensor is passed, it routes to YOLO postprocessing rather than crashing with an unhandled exception.
Environment
  • OS: macOS (Apple Silicon M4)
  • Python: 3.11
  • Model: yolov8n.pt

I've reproduced and tested this locally. I would like to submit a PR for this if the approach looks good to the maintainers!

Dominant language
Python
Stars
117
Forks
121
Avg merge
1d 3h
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JdeRobot/PerceptionMetrics

All issues in JdeRobot/PerceptionMetrics

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.