Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification of obb behaviour with InferenceSlicer #1394

Closed
1 task done
robmarkcole opened this issue Jul 22, 2024 · 8 comments
Closed
1 task done

Clarification of obb behaviour with InferenceSlicer #1394

robmarkcole opened this issue Jul 22, 2024 · 8 comments
Labels
question Further information is requested

Comments

@robmarkcole
Copy link

Search before asking

  • I have searched the Supervision issues and found no similar feature requests.

Question

Based on reviewing source code, I understand that with an obb model, the regular box enclosing the obb box is used with SAHI. As a result, merged regular boxes, and not obb boxes are returned. I wanted to confirm this, and suggest a note is added in the docs.

I also want to know if this could be responsible for the odd predictions below - perhaps the enclosing boxes are not merged correctly:

image

Additional

No response

@robmarkcole robmarkcole added the question Further information is requested label Jul 22, 2024
@SkalskiP
Copy link
Collaborator

Hi, @robmarkcole 👋🏻 Lots to unpack here.

  • OBB support in InferenceSlicer has not been officially released yet, but we're working on it. (We should perhaps explicitly state that only object detection and instance segmentation are currently supported.)
  • A test version of OBB in InferenceSlicer is available in the develop branch. You can read more about it here and here. To use it, you would need to install supervision like this: pip install git+https://github.com/roboflow/supervision.git.
  • If you want to plot OBB, use OrientedBoxAnnotator instead of BoundingBoxAnnotator (deprecated) or BoxAnnotator.
  • Regarding the quality of the result you received, it might be related to the second issue you opened - incorrect channel order. What slice_wh value are you using? The default is (320, 320), I'd try to increase it to (640, 640).

@robmarkcole
Copy link
Author

Thanks @SkalskiP these results are much better!

image
image_path = "my.png"
image = np.array(Image.open(image_path))

def callback(image_slice: np.ndarray) -> sv.Detections:
    result = model(image_slice)[0]
    return sv.Detections.from_ultralytics(result)

slicer = sv.InferenceSlicer(callback = callback, slice_wh=(768, 768))
detections = slicer(image)
detections = detections[detections.class_id == 1] # ships id in DOTA

oriented_box_annotator = sv.OrientedBoxAnnotator()
label_annotator = sv.LabelAnnotator()

annotated_image = oriented_box_annotator.annotate(scene=image, detections=detections)
annotated_image = label_annotator.annotate(scene=annotated_image, detections=detections)

@SkalskiP
Copy link
Collaborator

@robmarkcole that is true; this looks a lot better! There is still room for improvement. Especially where it comes to post-processing and merging double detections. We don't have that component yet for OBB.

Can I close the issue?

@050603
Copy link

050603 commented Jul 30, 2024

image
`import cv2
import numpy as np
import supervision as sv
from ultralytics import YOLO
from PIL import Image

model = YOLO("/root/autodl-tmp/code/ultralytics/runs/obb/train/weights/best.pt")

image_path = "/root/autodl-tmp/DOTA/images/test/P1068.png"
image = np.array(Image.open(image_path))

def callback(image_slice: np.ndarray) -> sv.Detections:
result = model(image_slice)[0]
return sv.Detections.from_ultralytics(result)

slicer = sv.InferenceSlicer(callback = callback)
detections = slicer(image)

oriented_box_annotator = sv.OrientedBoxAnnotator()
label_annotator = sv.LabelAnnotator()

annotated_image = oriented_box_annotator.annotate(scene=image, detections=detections)
annotated_image = label_annotator.annotate(scene=annotated_image, detections=detections)

annotated_pil_image = Image.fromarray(annotated_image)
annotated_pil_image.show()`

@SkalskiP Why doesn't the target box display at the correct scale when drawing with OrientedBoxAnnotator?

@LinasKo
Copy link
Contributor

LinasKo commented Jul 30, 2024

I believe we have a fix in the develop branch.

Did you try this?
pip install git+https://github.com/roboflow/supervision.git@develop

@050603
Copy link

050603 commented Jul 31, 2024

I believe we have a fix in the develop branch.

Did you try this? pip install git+https://github.com/roboflow/supervision.git@develop

@LinasKo Yes, that's how I do it.

@050603
Copy link

050603 commented Aug 2, 2024

@LinasKo I checked the saved CSV file and found that the coordinates were all relative to the pixel position of the slice (up to 640), without considering the position of the slice itself.
image

@SkalskiP
Copy link
Collaborator

SkalskiP commented Aug 6, 2024

Hi @050603 👋🏻 is there any chance you could provide us with your model and image?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants