-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpipeline_test_command_params_just_tls.py
More file actions
129 lines (106 loc) · 4.45 KB
/
pipeline_test_command_params_just_tls.py
File metadata and controls
129 lines (106 loc) · 4.45 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import subprocess
import wandb
# local imports
from metrics.instance_segmentation_metrics_in_folder import \
InstanceSegmentationMetricsInFolder
# define a class to run the command with arguments
class RunCommand:
def __init__(self, cmd, args):
self.cmd = cmd
self.args = args
def __call__(self):
print("Running command: " + self.cmd + " " + " ".join(self.args))
subprocess.run([self.cmd, *self.args])
def main(
n_tiles,
slice_thickness,
find_stems_height,
find_stems_thickness,
graph_maximum_cumulative_gap,
add_leaves_voxel_length,
find_stems_min_points,
graph_edge_length,
add_leaves_edge_length
):
USE_WANDB = False
# initialize the sweep
if USE_WANDB:
run = wandb.init(project="paper-sweep-nibio-model-just-tls", entity="smart_forest")
# get files for the sweep
print("Getting files for the sweep")
cmd = "/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/bash_helper_scripts/get_val_corrected_after_sem_seg_selected_files.sh"
subprocess.run([cmd], shell=True)
# define the arguments for all the parameters from the sweep configuration
print("Defining arguments for all the parameters from the sweep configuration")
# print the arguments
print("N_TILES: " + str(n_tiles))
print("SLICE_THICKNESS: " + str(slice_thickness))
print("FIND_STEMS_HEIGHT: " + str(find_stems_height))
print("FIND_STEMS_THICKNESS: " + str(find_stems_thickness))
print("GRAPH_MAXIMUM_CUMULATIVE_GAP: " + str(graph_maximum_cumulative_gap))
print("ADD_LEAVES_VOXEL_LENGTH: " + str(add_leaves_voxel_length))
print("FIND_STEMS_MIN_POINTS: " + str(find_stems_min_points))
print("GRAPH_EDGE_LENGTH: " + str(graph_edge_length))
print("ADD_LEAVES_EDGE_LENGTH: " + str(add_leaves_edge_length))
# define the command
cmd = "./optimization_pipeline/tls.sh"
# define the arguments
args = [
"-d", "/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground"
]
print("Adding the arguments to the list of arguments")
args.extend([
"-n", str(n_tiles),
"-s", str(slice_thickness),
"-h", str(find_stems_height),
"-t", str(find_stems_thickness),
"-g", str(graph_maximum_cumulative_gap),
"-l", str(add_leaves_voxel_length),
"-m", str(find_stems_min_points),
"-o", str(graph_edge_length),
"-p", str(add_leaves_edge_length)
])
# run the command with the arguments
print("Running the command with the arguments")
RunCommand(cmd, args)()
# compute the metric
print("Computing the metric")
metric = InstanceSegmentationMetricsInFolder(
gt_las_folder_path = '/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/results/input_data',
target_las_folder_path = '/home/nibio/mutable-outside-world/code/gitlab_fsct/instance_segmentation_classic/sample_playground/results/instance_segmented_point_clouds',
remove_ground=True,
verbose=True
)
f1_score = metric.main()
print("F1 score: " + str(f1_score))
# log the metric
print("Logging the metric")
if USE_WANDB:
wandb.log({"f1_score": f1_score})
return f1_score
if __name__ == "__main__":
# use argparse to get the arguments
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--n_tiles", type=int, default=1)
parser.add_argument("--slice_thickness", type=float, default=0.1)
parser.add_argument("--find_stems_height", type=float, default=0.1)
parser.add_argument("--find_stems_thickness", type=float, default=0.1)
parser.add_argument("--graph_maximum_cumulative_gap", type=float, default=0.1)
parser.add_argument("--add_leaves_voxel_length", type=float, default=0.1)
parser.add_argument("--find_stems_min_points", type=int, default=1)
parser.add_argument("--graph_edge_length", type=float, default=0.1)
parser.add_argument("--add_leaves_edge_length", type=float, default=0.1)
args = parser.parse_args()
# run the main function
main(
args.n_tiles,
args.slice_thickness,
args.find_stems_height,
args.find_stems_thickness,
args.graph_maximum_cumulative_gap,
args.add_leaves_voxel_length,
args.find_stems_min_points,
args.graph_edge_length,
args.add_leaves_edge_length
)