@@ -71,6 +71,7 @@ def eval_all_sgn():
7171 for baseline in baselines :
7272 if "spiner" in baseline :
7373 eval_segmentation_spiner (os .path .join (seg_dir , baseline ), annotation_dir = annotation_dir )
74+ # eval_segmentation(os.path.join(seg_dir, baseline), annotation_dir=annotation_dir, filter=False)
7475 else :
7576 eval_segmentation (os .path .join (seg_dir , baseline ), annotation_dir = annotation_dir )
7677
@@ -92,7 +93,7 @@ def eval_all_ihc():
9293 eval_segmentation (os .path .join (seg_dir , baseline ), annotation_dir = annotation_dir )
9394
9495
95- def eval_segmentation (seg_dir , annotation_dir ):
96+ def eval_segmentation (seg_dir , annotation_dir , filter = True ):
9697 print (f"Evaluating segmentation in directory { seg_dir } " )
9798 segs = [entry .path for entry in os .scandir (seg_dir ) if entry .is_file () and ".tif" in entry .path ]
9899
@@ -109,20 +110,24 @@ def eval_segmentation(seg_dir, annotation_dir):
109110
110111 df_path = os .path .join (annotation_dir , f"{ basename } .csv" )
111112 df = pd .read_csv (df_path , sep = "," )
112- timer_file = os .path .join (seg_dir , f"{ basename } _timer.json" )
113- with open (timer_file ) as f :
114- timer_dic = json .load (f )
115113
116114 seg_arr = imageio .imread (seg )
117115 print (f"shape { seg_arr .shape } " )
118- seg_filtered = filter_seg (seg_arr = seg_arr )
116+ if filter :
117+ seg_arr = filter_seg (seg_arr = seg_arr )
119118
120- seg_dic = compute_matches_for_annotated_slice (segmentation = seg_filtered ,
119+ seg_dic = compute_matches_for_annotated_slice (segmentation = seg_arr ,
121120 annotations = df ,
122121 matching_tolerance = 5 )
123122 seg_dic ["annotation_length" ] = len (df )
124123 seg_dic ["crop_name" ] = basename
125- seg_dic ["time" ] = float (timer_dic ["total_duration[s]" ])
124+ timer_file = os .path .join (seg_dir , f"{ basename } _timer.json" )
125+ if os .path .isfile (timer_file ):
126+ with open (timer_file ) as f :
127+ timer_dic = json .load (f )
128+ seg_dic ["time" ] = float (timer_dic ["total_duration[s]" ])
129+ else :
130+ seg_dic ["time" ] = None
126131
127132 eval_seg_dict (seg_dic , dic_out )
128133
@@ -158,10 +163,10 @@ def eval_segmentation_spiner(seg_dir, annotation_dir):
158163
159164 df_annot = pd .read_csv (annot , sep = "," )
160165 for num , row in df_annot .iterrows ():
161- x1 = int (row ["x1 " ])
162- x2 = int (row ["x2 " ])
163- y1 = int (row ["y1 " ])
164- y2 = int (row ["y2 " ])
166+ x1 = int (row ["y1 " ])
167+ x2 = int (row ["y2 " ])
168+ y1 = int (row ["x1 " ])
169+ y2 = int (row ["x2 " ])
165170 seg_arr [x1 :x2 , y1 :y2 ] = num + 1
166171
167172 seg_dic = compute_matches_for_annotated_slice (segmentation = seg_arr ,
@@ -265,9 +270,9 @@ def print_accuracy_ihc():
265270
266271
267272def main ():
268- # eval_all_sgn()
273+ eval_all_sgn ()
269274 eval_all_ihc ()
270- # print_accuracy_sgn()
275+ print_accuracy_sgn ()
271276 print_accuracy_ihc ()
272277
273278
0 commit comments