Spaces:
Sleeping
Sleeping
Update yolov12/detector.py
Browse files- yolov12/detector.py +15 -8
yolov12/detector.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import subprocess
|
2 |
import os
|
|
|
3 |
|
4 |
def run_yolov12_inference(img_path):
|
5 |
project_dir = "static/uploaded"
|
@@ -16,14 +17,20 @@ def run_yolov12_inference(img_path):
|
|
16 |
"--name", "yolov12_output",
|
17 |
"--exist-ok"
|
18 |
]
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
try:
|
28 |
with open(label_file, "r") as f:
|
29 |
for line in f:
|
|
|
1 |
import subprocess
|
2 |
import os
|
3 |
+
from pathlib import Path
|
4 |
|
5 |
def run_yolov12_inference(img_path):
|
6 |
project_dir = "static/uploaded"
|
|
|
17 |
"--name", "yolov12_output",
|
18 |
"--exist-ok"
|
19 |
]
|
20 |
+
# TEMPORARY: simulate label output
|
21 |
+
filename = Path(args.source).name
|
22 |
+
label_path = Path(args.project) / args.name / "labels"
|
23 |
+
label_path.mkdir(parents=True, exist_ok=True)
|
24 |
+
|
25 |
+
with open(label_path / filename.replace(".jpg", ".txt"), "w") as f:
|
26 |
+
f.write("0 0.5 0.5 1 1 0.90\n") # fake class 0
|
27 |
+
subprocess.run(command, check=True)
|
28 |
+
|
29 |
+
# Try reading the prediction txt file
|
30 |
+
file_name = os.path.basename(img_path)
|
31 |
+
label_file = os.path.join(result_dir, "labels", file_name.replace(".jpg", ".txt"))
|
32 |
+
|
33 |
+
is_damaged = False
|
34 |
try:
|
35 |
with open(label_file, "r") as f:
|
36 |
for line in f:
|