Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
SVivdich02 committed May 15, 2024
1 parent aa54a68 commit 0611992
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 42 deletions.
24 changes: 15 additions & 9 deletions experiment/hdbscan/main_kitti_processing_hdbscan_voxel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,30 @@

def segment_pcds_by_hdbscan(start_index, end_index):

file_name = "experiment_bin_0704_4_sem_voxel_offset0_T0l03/start{}_end{}.pickle".format(
start_index, end_index
file_name = (
"experiment_bin_0704_4_sem_voxel_offset0_T0l03/start{}_end{}.pickle".format(
start_index, end_index
)
)

with open(file_name, 'rb') as file:
with open(file_name, "rb") as file:
data = pickle.load(file)

pcd_hdbscan_voxel_down_points = np.asarray(data[2]["voxel_pcd_original_points"])
pcd_hdbscan_voxel_down = o3d.geometry.PointCloud()
pcd_hdbscan_voxel_down.points = o3d.utility.Vector3dVector(pcd_hdbscan_voxel_down_points)
pcd_hdbscan_voxel_down.points = o3d.utility.Vector3dVector(
pcd_hdbscan_voxel_down_points
)

clusterer = HDBSCAN()
clusters = clusterer.fit_predict(np.asarray(pcd_hdbscan_voxel_down.points))

return (
{"hdbscan_clustered_voxel_pcd_original_points": np.asarray(pcd_hdbscan_voxel_down.points)},
{
"hdbscan_clustered_voxel_pcd_original_points": np.asarray(
pcd_hdbscan_voxel_down.points
)
},
{"hdbscan_voxel_trace_original": data[3]["voxel_trace_original"]},
{"hdbscan_clusters": clusters},
{"inst_label_array_for_clustering": data[6]["inst_label_array_for_clustering"]},
Expand All @@ -54,10 +62,8 @@ def process_kitti_hdbscan(from_num, to_num):

result_tuple = segment_pcds_by_hdbscan(start_index, end_index)

file_name = (
"experiment_bin_0704_4_sem_voxel_offset0_T0l03_hdbscan/start{}_end{}.pickle".format(
start_index, end_index
)
file_name = "experiment_bin_0704_4_sem_voxel_offset0_T0l03_hdbscan/start{}_end{}.pickle".format(
start_index, end_index
)
new_file = open(file_name, "w")
new_file.close()
Expand Down
8 changes: 4 additions & 4 deletions experiment/hdbscan/main_kitti_processing_metrics_hdbscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ def main():
): # в облаке нет инстансов => пропускаем
skipped += 1
print(
"start_index={}, end_index={} skip".format(
start_index, end_index
)
"start_index={}, end_index={} skip".format(start_index, end_index)
)
current_from_num = end_index
continue

clusters_list_without_noise = convert_clusters_to_list_of_point_arrays(clusters_array)[1:]
clusters_list_without_noise = convert_clusters_to_list_of_point_arrays(
clusters_array
)[1:]

pred_inst_array = build_pred_inst_array(
copy.deepcopy(inst_label_array_for_clustering),
Expand Down
43 changes: 14 additions & 29 deletions experiment/main_calc_metrics_by_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
import csv


def calculate_sum_ones_zeros(values):
sum, ones, zeros = 0, 0, 0
for value in values:
sum += float(value)
if float(value) == 1.0:
ones += 1
elif float(value) == 0.0:
zeros += 1
return sum, ones, zeros


def calculate_metrics(file_name):
values_pres = []
values_recall = []
Expand All @@ -26,35 +37,9 @@ def calculate_metrics(file_name):
values_recall.append(row["recall"])
values_fScore.append(row["fScore"])

sum_pres = 0
pres1 = 0
pres0 = 0
for value in values_pres:
sum_pres += float(value)
if float(value) == 1.0:
pres1 += 1
if float(value) == 0.0:
pres0 += 1

sum_recall = 0
recall1 = 0
recall0 = 0
for value in values_recall:
sum_recall += float(value)
if float(value) == 1.0:
recall1 += 1
if float(value) == 0.0:
recall0 += 1

sum_fScore = 0
fscore1 = 0
fscore0 = 0
for value in values_fScore:
sum_fScore += float(value)
if float(value) == 1.0:
fscore1 += 1
if float(value) == 0.0:
fscore0 += 1
sum_pres, pres1, pres0 = calculate_sum_ones_zeros(values_pres)
sum_recall, recall1, recall0 = calculate_sum_ones_zeros(values_recall)
sum_fScore, fscore1, fscore0 = calculate_sum_ones_zeros(values_fScore)

print(
"precision={}, 1={}, 0={}".format(
Expand Down

0 comments on commit 0611992

Please sign in to comment.