Commit ·
cf76678
1
Parent(s): 74b2a48
added all necessary files for application
Browse files- .gitattributes +3 -0
- app.py +56 -0
- example1.jpg +3 -0
- example2.jpg +3 -0
- example3.jpg +3 -0
- gc10-det.pth +3 -0
- neu-det.pth +3 -0
- requirements.txt +2 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
.pth filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
.jpg filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import supervision as sv
|
| 3 |
+
from rfdetr import RFDETRBase
|
| 4 |
+
|
| 5 |
+
models = {
|
| 6 |
+
"GC10-DET": "src/models/gc10-det.pth",
|
| 7 |
+
"NEU-DET": "src/models/neu-det.pth"
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
def predict(model_name, img, conf, iou):
|
| 11 |
+
model_path = models[model_name]
|
| 12 |
+
model = RFDETRBase(pretrain_weights=model_path)
|
| 13 |
+
model.optimize_for_inference()
|
| 14 |
+
|
| 15 |
+
results = model.predict(img, threshold=conf)
|
| 16 |
+
results = results.with_nmm(threshold=iou)
|
| 17 |
+
|
| 18 |
+
labels = [f"defect {confidence:.2f}" for confidence in results.confidence]
|
| 19 |
+
|
| 20 |
+
annotated_image = img.copy()
|
| 21 |
+
annotated_image = sv.BoxAnnotator().annotate(annotated_image, results)
|
| 22 |
+
annotated_image = sv.LabelAnnotator().annotate(annotated_image, results, labels)
|
| 23 |
+
|
| 24 |
+
return annotated_image
|
| 25 |
+
|
| 26 |
+
base_conf, base_iou = 0.25, 0.5
|
| 27 |
+
title = "Detection with RF-DETR trained on NEU-DET and GC10-DET"
|
| 28 |
+
des = """
|
| 29 |
+
**Instructions:**
|
| 30 |
+
1. Choose a model:
|
| 31 |
+
\- **GC10-DET** - for images from the GC10 dataset (10 defect types, steel surface images)
|
| 32 |
+
\- **NEU-DET** - for images from the NEU dataset (6 defect types, steel strip images)
|
| 33 |
+
2. Upload Image.
|
| 34 |
+
3. Adjust thresholds
|
| 35 |
+
4. Click the **Submit** button. Wait while predictions are generated.
|
| 36 |
+
"""
|
| 37 |
+
interface = gr.Interface(
|
| 38 |
+
fn=predict,
|
| 39 |
+
inputs=[
|
| 40 |
+
gr.Dropdown(list(models.keys()), label="Select Model"),
|
| 41 |
+
'image',
|
| 42 |
+
gr.Slider(maximum=1, minimum=0, value=base_conf, label="Confidence Threshold"),
|
| 43 |
+
gr.Slider(maximum=1, minimum=0, value=base_iou, label="NMM IoU Threshold")
|
| 44 |
+
],
|
| 45 |
+
outputs=["image"],
|
| 46 |
+
title=title,
|
| 47 |
+
description=des,
|
| 48 |
+
examples=[
|
| 49 |
+
["GC10-DET", "example1.jpg", base_conf, base_iou],
|
| 50 |
+
["GC10-DET", "example2.jpg", base_conf, base_iou],
|
| 51 |
+
["NEU-DET", "example3.jpg", base_conf, base_iou]
|
| 52 |
+
]
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
interface.launch()
|
| 56 |
+
|
example1.jpg
ADDED
|
Git LFS Details
|
example2.jpg
ADDED
|
Git LFS Details
|
example3.jpg
ADDED
|
Git LFS Details
|
gc10-det.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a234a044908796b7d6f065d845c7368461c08ec3b4b86ee9c175ad911df7bb26
|
| 3 |
+
size 127619710
|
neu-det.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0f78db58695d4d66bfb2437c17710cc21e8f616b8136de6de158e616b1155805
|
| 3 |
+
size 127619710
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
git+https://github.com/roboflow/rf-detr.git
|