Tejeshwar commited on
Commit
0715ea0
Β·
verified Β·
1 Parent(s): d3d97d9

Update yolov12/yolo.py

Browse files
Files changed (1) hide show
  1. yolov12/yolo.py +26 -8
yolov12/yolo.py CHANGED
@@ -6,27 +6,45 @@ def run_yolov12_inference(img_path):
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
 
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
+ print(f"πŸ“Έ Running YOLOv12 on image: {img_path}")
10
+ print(f"πŸ“‚ Expected label file: {label_file}")
11
+
12
  command = [
13
+ "python3", "yolov12/detector.py",
14
  "--source", img_path,
15
  "--project", project_dir,
16
  "--name", "yolov12_output",
17
+ "--conf", "0.1", # ⬅️ Lowered for test
18
+ "--save-txt",
19
+ "--save-conf"
20
  ]
21
 
22
  try:
23
  subprocess.run(command, check=True)
24
+ print("βœ… Subprocess finished successfully.")
25
  except Exception as e:
26
  print("❌ Subprocess failed:", e)
27
+ return False
28
 
29
  is_damaged = False
30
+
31
+ if os.path.exists(label_file):
32
+ print(f"βœ… Found label file: {label_file}")
33
  with open(label_file, "r") as f:
34
+ lines = f.readlines()
35
+ print(f"πŸ“„ Label file contents:\n{lines}")
36
+ for line in lines:
37
+ try:
38
+ class_id = int(line.split()[0])
39
+ print(f"πŸ” Detected class ID: {class_id}")
40
+ if class_id == 0: # class 0 is damaged
41
+ is_damaged = True
42
+ print("🍎 Damage detected (class 0)")
43
+ break
44
+ except Exception as parse_error:
45
+ print("⚠️ Failed to parse line:", line, "Error:", parse_error)
46
+ else:
47
  print("⚠️ No label file found:", label_file)
48
 
49
+ print(f"πŸ§ͺ Final result: is_damaged = {is_damaged}")
50
  return is_damaged