-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_threshold_fix.py
More file actions
84 lines (71 loc) · 2.6 KB
/
Copy pathtest_threshold_fix.py
File metadata and controls
84 lines (71 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
"""
Test script to verify that the threshold iteration fix works correctly.
This script will test a single threshold combination to ensure the output directory structure is correct.
"""
import subprocess
import sys
import os
from typing import List
def test_single_threshold():
"""Test a single threshold combination to verify the fix works"""
# Test configuration
disk = "H:"
nifti_files = [
f"{disk}\\monailabel\\datasets\\soilcores\\test\\C1216.nii.gz",
] # Only test with one file for speed
model = "dataset_2adamw_100k_num_heads_2"
pixels_per_range = 2
num_ranges = 5
outputs_dir = "test_outputs"
view = "vertical"
gt_csv = f"{disk}\\monailabel\\soilcores3dsegmentation\\gt\\CoresGT.csv"
# Test threshold values
lower = 0
upper = 80
# Create unique output directory for this threshold combination
threshold_output_dir = os.path.join(outputs_dir, f"l{lower}_u{upper}")
cmd = [
sys.executable, "soilcore_cli.py",
"--nifti"
] + nifti_files + [
"--model", model,
"--lower", str(lower),
"--upper", str(upper),
"--pixels-per-range", str(pixels_per_range),
"--num-ranges", str(num_ranges),
"--outputs-dir", threshold_output_dir,
"--view", view,
"--gt-csv", gt_csv
]
print("Testing threshold iteration fix...")
print(f"Lower threshold: {lower}")
print(f"Upper threshold: {upper}")
print(f"Output directory: {threshold_output_dir}")
print(f"Command: {' '.join(cmd)}")
print()
try:
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
print("✓ Test successful!")
print("Output:")
print(result.stdout)
# Check if the output directory was created
if os.path.exists(threshold_output_dir):
print(f"✓ Output directory created: {threshold_output_dir}")
# List contents
contents = os.listdir(threshold_output_dir)
print(f"Directory contents: {contents}")
else:
print(f"✗ Output directory not found: {threshold_output_dir}")
return True
except subprocess.CalledProcessError as e:
print(f"✗ Test failed with exit code {e.returncode}")
print("Error output:")
print(e.stderr)
return False
if __name__ == "__main__":
success = test_single_threshold()
if success:
print("\n✓ Threshold iteration fix is working correctly!")
else:
print("\n✗ Threshold iteration fix needs more work.")