roboflow / roboflow/roboflow-python

`model.predict` fails when running segmentation model on numpy images

Open
#346 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
629
Forks
140
Avg merge
2d 2h
Merged PRs (30d)
5

Description

import cv2

version = rf.workspace("model-examples").project("car-parts-instance-segmentation").version(3)
dataset = version.download("yolov8")
seg_model = version.model

first_image_path = os.listdir(f"{dataset.location}/train/images")[0]
first_image_path = f"{dataset.location}/train/images/{first_image_path}"
seg_image = cv2.imread(first_image_path)
assert seg_image is not None
# Path
result = seg_model.predict(first_image_path).json()
detections = sv.Detections.from_inference(result)
assert len(detections) > 0
# Succeeds

# Np img
result = seg_model.predict(seg_image).json()
detections = sv.Detections.from_inference(result)
assert len(detections) > 0
# Fails!

# Empty np img
result = seg_model.predict(black_image).json()
detections = sv.Detections.from_inference(result)
assert len(detections) == 0
# Fails!

Contributor guide

Open the contributing guide

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.

Research direction

Start by reproducing the examples in the issue and trace the model.predict entry point for path inputs versus NumPy images. Verify the behavior for the segmentation image and the empty black image; done means both return results that can be converted with sv.Detections.from_inference, with zero detections for the empty image.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, opencv, python
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.