rf-detr
rf-detr copied to clipboard
Fail to run the predict example from the README.md
Search before asking
- [x] I have searched the RF-DETR issues and found no similar bug report.
Bug
Hi! Thanks for providing rfdetr!
I tried to run the predict example from the README.md. But it fails with the following error:
RuntimeError: Only tensors, lists, tuples of tensors, or dictionary of tensors can be output from traced functions
What can I do to fix this?
Erik
Environment
pip install rfdetr
Minimal Reproducible Example
import io
import requests
import supervision as sv
from PIL import Image
from rfdetr import RFDETRBase
from rfdetr.util.coco_classes import COCO_CLASSES
# https://github.com/roboflow/rf-detr
model = RFDETRBase()
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)
sv.plot_image(annotated_image)
Additional
No response
Are you willing to submit a PR?
- [ ] Yes, I'd like to help by submitting a PR!