def test_basic(self): class NS(object): def __init__(self, dict): self.__dict__.update(dict) segmentation_param=NS({'evaluation_units':'foreground,cc', 'num_classes':2, 'output_prob':False}) eval_param=NS({'evaluations':'Dice'}) mask = np.reshape(np.abs(np.linspace(0.,2.,64)-1)>.8,[4,4,4,1,1]) data_dict = {'label':mask,'inferred':mask} interp_orders = {'label':0,'inferred':0} image_folder = '.' e = SegmentationEvaluator(None, segmentation_param, eval_param) def generator(): yield ('test',data_dict,interp_orders) result_dict = e.evaluate_from_generator(generator()) self.assertIn(('subject_id', 'label'), result_dict) self.assertIn(('subject_id', 'cc_id'), result_dict) self.assertEqual(tuple(result_dict[('subject_id', 'label')].index.names), ('subject_id', 'label')) self.assertEqual(tuple(result_dict[('subject_id', 'cc_id')].index.names), ('subject_id', 'cc_id')) print(result_dict[('subject_id', 'cc_id')].to_dict('index')) self.assertEqual(result_dict[('subject_id', 'label')].to_dict('index'), {('test', 1): {'dice': 1.}}) self.assertEqual(result_dict[('subject_id', 'cc_id')].to_dict('index'), {('test', 'r1_s1'): {'dice': 1.}, ('test', 'r2_s2'): {'dice': 1.}})
def test_segmentation_evaluator(self): app_param = Namespace(evaluation_units='label,cc',output_prob=False, num_classes=2) eval_param = Namespace(evaluations='Dice,Jaccard,average_distance') evalu = SegmentationEvaluator(SegmentationEvaluatorTests.ReaderStub(), app_param, eval_param) result_dict = evalu.evaluate() self.assertIn(('subject_id', 'cc_id'), result_dict) self.assertIn(('subject_id', 'label'), result_dict) group_cc = result_dict[('subject_id', 'cc_id')] group_l = result_dict[('subject_id', 'label')] self.assertIn('jaccard', list(group_l.columns)) self.assertIn('dice', list(group_l.columns)) self.assertIn('jaccard', list(group_cc.columns)) self.assertIn('dice', list(group_cc.columns)) self.assertIn('average_distance', list(group_cc.columns)) self.assertIn(('foo','r1_s1'), list(group_cc.index)) self.assertIn(('bar','r1_s1'), list(group_cc.index)) self.assertIn(('foo',1), list(group_l.index)) self.assertIn(('bar',1), list(group_l.index))
def initialise_evaluator(self, eval_param): self.eval_param = eval_param self.evaluator = SegmentationEvaluator(self.readers[0], self.segmentation_param, eval_param)