rf-detr
rf-detr copied to clipboard
[Fix] issue of predictions overwrite regarding instance masks
Description
Please include a summary of the change and which issue is fixed or implemented. Please also include relevant motivation and context (e.g. links, docs, tickets etc.).
List any dependencies that are required for this change.
Type of change
Change in the prediction function to avoid an overwrite of predictions, which leads to len(predictions)==3 not being reached in mask inference mode.
In post process masks are move to cpu(), therefore keep needs to be moved for subsequent indexing as well.
With this change sv.MaskAnnotator().annotate() can be used for mask inference visualisation.
Please delete options that are not relevant.
- [x] Bug fix (non-breaking change which fixes an issue)
How has this change been tested, please provide a testcase or example of how you tested the change?
Via inference script visualisation that is based on predict script +
import io
import requests
import supervision as sv
from PIL import Image
from rfdetr import RFDETRSegPreview
from rfdetr.util.coco_classes import COCO_CLASSES
model = RFDETRSegPreview()
model.optimize_for_inference()
url = "https://media.roboflow.com/notebooks/examples/dog-2.jpeg"
image = Image.open(io.BytesIO(requests.get(url).content))
detections = model.predict(image, threshold=0.5)
labels = [
f"{COCO_CLASSES[class_id]} {confidence:.2f}"
for class_id, confidence
in zip(detections.class_id, detections.confidence)
]
annotated_image = image.copy()
annotated_image = sv.BoxAnnotator().annotate(annotated_image, detections)
annotated_image = sv.LabelAnnotator().annotate(annotated_image, detections, labels)
annotated_image = sv.MaskAnnotator().annotate(annotated_image, detections)
sv.plot_image(annotated_image)
Any specific deployment considerations
For example, documentation changes, usability, usage/costs, secrets, etc.