def adapted_rand(self, segmentation): assert list(segmentation.data.shape) == list(self.groundtruth.data.shape) assert list(segmentation.resolution) == list(self.groundtruth.resolution) print "Computing RAND..." return adapted_rand(np.array(segmentation.data), self.gt)
def run(config): image_path, labels_path, raw_path = config['SAVE_PRED'], config[ 'LABELS_DENSE'], config['DATA'] seg, labels, raw = imread(image_path)[2:12], imread( labels_path)[-16:-6], imread(raw_path)[-16:-6, :, :, 0] pixel_error = np.mean(seg != labels) rand_error = adapted_rand(seg, labels) print("pixel error: {}, rand error {}".format(pixel_error, rand_error))
def adapted_rand(self, segmentation): assert list(segmentation.data.shape) == list( self.groundtruth.data.shape) assert list(segmentation.resolution) == list( self.groundtruth.resolution) print "Computing RAND..." return adapted_rand(np.array(segmentation.data), self.gt)
for tp in time_points: for st in seg_types: seg_path = f"{data_path}{dataset}{tp}{st}{seg_id}" gt_path = f"{data_path}{dataset}{tp}{st}{gt_id}" seg_path = glob.glob(seg_path) gt_path = glob.glob(gt_path) for _seg_path, _gt_path in zip(seg_path, gt_path): seg = np.load(_seg_path) gt = np.load(_gt_path) seg = np.where(gt == 0, 0, seg) _rand = adapted_rand(seg, gt) _voi = voi(seg, gt) print(" scores: ", _rand, _voi[0], _voi[1]) result = { "dataset": dataset, "time_point": tp, "segmentation_id": seg_id, "segmentation_path": seg_path, "groundtruth_path": gt_path, "adapted_rand": _rand, "voi": _voi, "voi_split": _voi[0], "voi_merge": _voi[1] }
from rand import adapted_rand if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-seg', '--segmentation', type=str, default='../inference/segmentation.hdf') parser.add_argument('-gt', '--groundtruth', type=str, default='../data/gt.hdf') args = parser.parse_args() test = h5py.File(args.segmentation, 'r') test = np.asarray(test['labels']).astype(np.int64) gt = h5py.File(args.groundtruth, 'r') gt = np.asarray(gt['labels']) # /volumes/labels/neuron_ids # no_gt = gt>=np.uint64(-10) # gt[no_gt] = 0 gt = gt.astype(np.int64) test = test[14:-14, 106:-106, 106:-106] gt = gt[14:-14, 106:-106, 106:-106] (voi_split, voi_merge) = voi(test, gt) rand = adapted_rand(test, gt) print('voi split: ' + str(voi_split)) print('voi merge: ' + str(voi_merge)) print('rand: ' + str(rand))