Spaces:
Sleeping
Sleeping
Update yolov12/yolo.py
Browse files- yolov12/yolo.py +9 -14
yolov12/yolo.py
CHANGED
@@ -1,37 +1,32 @@
|
|
1 |
-
import subprocess
|
2 |
import os
|
|
|
3 |
|
4 |
def run_yolov12_inference(img_path):
|
5 |
project_dir = "static/uploaded"
|
6 |
result_dir = os.path.join(project_dir, "yolov12_output")
|
|
|
7 |
|
8 |
command = [
|
9 |
-
"
|
10 |
-
"--weights", "../runs/detect/train7/weights/best.pt",
|
11 |
"--source", img_path,
|
12 |
-
"--conf", "0.25",
|
13 |
-
"--save-txt",
|
14 |
-
"--save-conf",
|
15 |
"--project", project_dir,
|
16 |
"--name", "yolov12_output",
|
17 |
-
"--exist-ok"
|
18 |
]
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
label_file = os.path.join(result_dir, "labels", file_name.replace(".jpg", ".txt"))
|
25 |
|
26 |
is_damaged = False
|
27 |
try:
|
28 |
with open(label_file, "r") as f:
|
29 |
for line in f:
|
30 |
class_id = int(line.split()[0])
|
31 |
-
if class_id == 0:
|
32 |
is_damaged = True
|
33 |
break
|
34 |
except FileNotFoundError:
|
35 |
-
|
36 |
|
37 |
return is_damaged
|
|
|
|
|
1 |
import os
|
2 |
+
import subprocess
|
3 |
|
4 |
def run_yolov12_inference(img_path):
|
5 |
project_dir = "static/uploaded"
|
6 |
result_dir = os.path.join(project_dir, "yolov12_output")
|
7 |
+
label_file = os.path.join(result_dir, "labels", os.path.basename(img_path).replace(".jpg", ".txt"))
|
8 |
|
9 |
command = [
|
10 |
+
"python3", "yolov12/detector.py", # Simulated CLI
|
|
|
11 |
"--source", img_path,
|
|
|
|
|
|
|
12 |
"--project", project_dir,
|
13 |
"--name", "yolov12_output",
|
|
|
14 |
]
|
15 |
|
16 |
+
try:
|
17 |
+
subprocess.run(command, check=True)
|
18 |
+
except Exception as e:
|
19 |
+
print("❌ Subprocess failed:", e)
|
|
|
20 |
|
21 |
is_damaged = False
|
22 |
try:
|
23 |
with open(label_file, "r") as f:
|
24 |
for line in f:
|
25 |
class_id = int(line.split()[0])
|
26 |
+
if class_id == 0:
|
27 |
is_damaged = True
|
28 |
break
|
29 |
except FileNotFoundError:
|
30 |
+
print("⚠️ No label file found:", label_file)
|
31 |
|
32 |
return is_damaged
|