@@ -70,6 +70,7 @@ def collect_results(input_folder, gt_folder, version, check=False):
7070 results = []
7171 seg_key = f"predictions/az/seg_v{ version } "
7272 gt_key = "/labels/az_merged"
73+ input_folder_name = os .path .basename (os .path .normpath (input_folder ))
7374
7475 for fname in tqdm (os .listdir (input_folder ), desc = "Processing segmentations" ):
7576 if not fname .endswith (".h5" ):
@@ -84,18 +85,36 @@ def collect_results(input_folder, gt_folder, version, check=False):
8485
8586 result = process_file (pred_path , gt_path , seg_key , gt_key , check )
8687 if result :
88+ result ["input_folder" ] = input_folder_name
8789 results .append (result )
8890
8991 return results
9092
9193
9294def save_results (results , output_file ):
93- """Save results as an Excel file."""
94- df = pd .DataFrame (results )
95- df .to_excel (output_file , index = False )
95+ """Append results to an Excel file, updating rows with matching tomo_name and input_folder."""
96+ new_df = pd .DataFrame (results )
97+
98+ if os .path .exists (output_file ):
99+ existing_df = pd .read_excel (output_file )
100+
101+ # Drop rows where tomo_name and input_folder match any in new_df
102+ combined_df = existing_df [
103+ ~ existing_df .set_index (["tomo_name" , "input_folder" ]).index .isin (
104+ new_df .set_index (["tomo_name" , "input_folder" ]).index
105+ )
106+ ]
107+
108+ # Append new data and reset index
109+ final_df = pd .concat ([combined_df , new_df ], ignore_index = True )
110+ else :
111+ final_df = new_df
112+
113+ final_df .to_excel (output_file , index = False )
96114 print (f"Results saved to { output_file } " )
97115
98116
117+
99118def main ():
100119 parser = argparse .ArgumentParser (description = "Compute surface dice for AZ segmentations." )
101120 parser .add_argument ("--input_folder" , "-i" , required = True , help = "Folder with predicted segmentations (.h5)" )
0 commit comments