initial commit
Browse files- README.md +4 -4
- app.py +92 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
-
title: RF
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.22.0
|
| 8 |
app_file: app.py
|
|
|
|
| 1 |
---
|
| 2 |
+
title: RF-DETR
|
| 3 |
+
emoji: 🔥
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.22.0
|
| 8 |
app_file: app.py
|
app.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
+
import supervision as sv
|
| 4 |
+
from rfdetr import RFDETRBase
|
| 5 |
+
from rfdetr.util.coco_classes import COCO_CLASSES
|
| 6 |
+
|
| 7 |
+
MARKDOWN = """
|
| 8 |
+
# RF-DETR 🔥
|
| 9 |
+
|
| 10 |
+
<div style="display: flex; align-items: center; gap: 8px;">
|
| 11 |
+
<a href="https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/how-to-finetune-rf-detr-on-detection-dataset.ipynb">
|
| 12 |
+
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="colab" />
|
| 13 |
+
</a>
|
| 14 |
+
<a href="https://blog.roboflow.com/rf-detr">
|
| 15 |
+
<img src="https://raw.githubusercontent.com/roboflow-ai/notebooks/main/assets/badges/roboflow-blogpost.svg" alt="roboflow" />
|
| 16 |
+
</a>
|
| 17 |
+
<a href="https://github.com/roboflow/rf-detr">
|
| 18 |
+
<img src="https://badges.aleen42.com/src/github.svg" alt="roboflow" />
|
| 19 |
+
</a>
|
| 20 |
+
</div>
|
| 21 |
+
|
| 22 |
+
RF-DETR is a real-time, transformer-based object detection model architecture developed
|
| 23 |
+
by [Roboflow](https://roboflow.com/) and released under the Apache 2.0 license.
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
COLOR = sv.ColorPalette.from_hex([
|
| 27 |
+
"#ffff00", "#ff9b00", "#ff8080", "#ff66b2", "#ff66ff", "#b266ff",
|
| 28 |
+
"#9999ff", "#3399ff", "#66ffff", "#33ff99", "#66ff66", "#99ff00"
|
| 29 |
+
])
|
| 30 |
+
|
| 31 |
+
MODEL = RFDETRBase()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@spaces.GPU()
|
| 35 |
+
def inference(image, confidence):
|
| 36 |
+
detections = MODEL.predict(image, threshold=confidence)
|
| 37 |
+
|
| 38 |
+
text_scale = sv.calculate_optimal_text_scale(resolution_wh=image.size)
|
| 39 |
+
thickness = sv.calculate_optimal_line_thickness(resolution_wh=image.size)
|
| 40 |
+
|
| 41 |
+
bbox_annotator = sv.BoxAnnotator(color=COLOR, thickness=thickness)
|
| 42 |
+
label_annotator = sv.LabelAnnotator(
|
| 43 |
+
color=COLOR,
|
| 44 |
+
text_color=sv.Color.BLACK,
|
| 45 |
+
text_scale=text_scale,
|
| 46 |
+
smart_position=True
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
labels = [
|
| 50 |
+
f"{COCO_CLASSES[class_id]} {confidence:.2f}"
|
| 51 |
+
for class_id, confidence
|
| 52 |
+
in zip(detections.class_id, detections.confidence)
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
+
annotated_image = image.copy()
|
| 56 |
+
annotated_image = bbox_annotator.annotate(annotated_image, detections)
|
| 57 |
+
annotated_image = label_annotator.annotate(annotated_image, detections, labels)
|
| 58 |
+
return annotated_image
|
| 59 |
+
|
| 60 |
+
with gr.Blocks() as demo:
|
| 61 |
+
gr.Markdown(MARKDOWN)
|
| 62 |
+
with gr.Row():
|
| 63 |
+
with gr.Column():
|
| 64 |
+
input_image = gr.Image(
|
| 65 |
+
label="Input Image",
|
| 66 |
+
image_mode='RGB',
|
| 67 |
+
type='pil',
|
| 68 |
+
height=600
|
| 69 |
+
)
|
| 70 |
+
confidence_slider = gr.Slider(
|
| 71 |
+
label="Confidence",
|
| 72 |
+
minimum=0.0,
|
| 73 |
+
maximum=1.0,
|
| 74 |
+
step=0.05,
|
| 75 |
+
value=0.5,
|
| 76 |
+
)
|
| 77 |
+
submit_button = gr.Button("Submit")
|
| 78 |
+
with gr.Column():
|
| 79 |
+
output_image = gr.Image(
|
| 80 |
+
label="Input Image",
|
| 81 |
+
image_mode='RGB',
|
| 82 |
+
type='pil',
|
| 83 |
+
height=600
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
submit_button.click(
|
| 87 |
+
inference,
|
| 88 |
+
inputs=[input_image, confidence_slider],
|
| 89 |
+
outputs=output_image
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
demo.launch(debug=False, show_error=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
spaces
|
| 3 |
+
rfdetr
|