def test_PREPROCESSOR_postprocessing_(self): sample_list = self.data_io3D.get_indiceslist() pp = Preprocessor(self.data_io3D, batch_size=1, analysis="fullimage", data_aug=None) batches = pp.run(sample_list[0:3], training=True, validation=False) for i in range(0, 3): pred_postprec = pp.postprocessing(sample_list[i], batches[i][1]) self.assertEqual(pred_postprec.shape, (16, 16, 16)) sam = self.data_io3D.sample_loader(sample_list[i], load_seg=True) self.assertTrue( np.array_equal(pred_postprec, np.reshape(sam.seg_data, (16, 16, 16))))
def test_SUBFUNCTIONS_postprocessing(self): ds = dict() for i in range(0, 10): img = np.random.rand(16, 16, 16) * 255 img = img.astype(int) seg = np.random.rand(16, 16, 16) * 3 seg = seg.astype(int) sample = (img, seg) ds["TEST.sample_" + str(i)] = sample io_interface = Dictionary_interface(ds, classes=3, three_dim=True) self.tmp_dir = tempfile.TemporaryDirectory(prefix="tmp.miscnn.") tmp_batches = os.path.join(self.tmp_dir.name, "batches") dataio = Data_IO(io_interface, input_path="", output_path="", batch_path=tmp_batches, delete_batchDir=False) sf = [Resize((9, 9, 9)), Normalization(), Clipping(min=-1.0, max=0.0)] pp = Preprocessor(dataio, batch_size=1, prepare_subfunctions=False, analysis="patchwise-grid", subfunctions=sf, patch_shape=(4, 4, 4)) sample_list = dataio.get_indiceslist() for index in sample_list: sample = dataio.sample_loader(index) for sf in pp.subfunctions: sf.preprocessing(sample, training=False) pp.cache["shape_" + str(index)] = sample.img_data.shape sample.seg_data = np.random.rand(9, 9, 9) * 3 sample.seg_data = sample.seg_data.astype(int) sample.seg_data = to_categorical(sample.seg_data, num_classes=3) data_patches = pp.analysis_patchwise_grid(sample, training=True, data_aug=False) seg_list = [] for i in range(0, len(data_patches)): seg_list.append(data_patches[i][1]) seg = np.stack(seg_list, axis=0) self.assertEqual(seg.shape, (27, 4, 4, 4, 3)) pred = pp.postprocessing(sample, seg) self.assertEqual(pred.shape, (16, 16, 16)) self.tmp_dir.cleanup()