How to use the miscnn.Preprocessor function in miscnn

To help you get started, we’ve selected a few miscnn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frankkramer-lab / MIScnn / tests / test_datagenerator.py View on Github external
def test_DATAGENERATOR_runTraining(self):
        pp_fi = Preprocessor(self.data_io, batch_size=4, data_aug=self.data_aug,
                             prepare_subfunctions=False, prepare_batches=False,
                             analysis="fullimage")
        data_gen = DataGenerator(self.sample_list, pp_fi, training=True,
                                 shuffle=False, iterations=None)
        self.assertEqual(len(data_gen), 3)
        for batch in data_gen:
            self.assertIsInstance(batch, tuple)
            self.assertEqual(batch[0].shape, (4,16,16,16,1))
            self.assertEqual(batch[1].shape, (4,16,16,16,3))
        pp_pc = Preprocessor(self.data_io, batch_size=3, data_aug=self.data_aug,
                             prepare_subfunctions=False, prepare_batches=False,
                             patch_shape=(5,5,5), analysis="patchwise-crop")
        data_gen = DataGenerator(self.sample_list, pp_pc, training=True,
                                 shuffle=False, iterations=None)
        self.assertEqual(len(data_gen), 4)
        for batch in data_gen:
github frankkramer-lab / MIScnn / tests / test_preprocessor.py View on Github external
def test_PREPROCESSOR_BASE_create(self):
        with self.assertRaises(Exception):
            Preprocessor()
        Preprocessor(self.data_io3D, batch_size=1, analysis="fullimage")
        Preprocessor(self.data_io3D, batch_size=1, analysis="patchwise-crop",
                     patch_shape=(16,16,16))
        Preprocessor(self.data_io3D, batch_size=1, analysis="patchwise-grid",
                     patch_shape=(16,16,16), data_aug=None)
github frankkramer-lab / MIScnn / tests / test_preprocessor.py View on Github external
def test_PREPROCESSOR_patchwisecrop_3D(self):
        sample_list = self.data_io3D.get_indiceslist()
        pp = Preprocessor(self.data_io3D, data_aug=None, batch_size=1,
                          analysis="patchwise-crop", patch_shape=(4,4,4))
        batches = pp.run(sample_list[0:3], training=True, validation=False)
        self.assertEqual(len(batches), 3)
        batches = pp.run(sample_list[0:1], training=False, validation=False)
        self.assertEqual(len(batches), 64)
        sample = self.data_io3D.sample_loader(sample_list[0], load_seg=True)
        sample.seg_data = to_categorical(sample.seg_data,
                                         num_classes=sample.classes)
        ready_data = pp.analysis_patchwise_crop(sample, data_aug=False)
        self.assertEqual(len(ready_data), 1)
        self.assertEqual(ready_data[0][0].shape, (4,4,4,1))
        self.assertEqual(ready_data[0][1].shape, (4,4,4,3))
github frankkramer-lab / MIScnn / tests / test_evaluations.py View on Github external
seg = np.random.rand(16, 16) * 2
            self.seg = seg.astype(int)
            self.dataset["TEST.sample_" + str(i)] = (self.img, self.seg)
        # Initialize Dictionary IO Interface
        io_interface = Dictionary_interface(self.dataset, classes=3,
                                              three_dim=False)
        # Initialize temporary directory
        self.tmp_dir = tempfile.TemporaryDirectory(prefix="tmp.miscnn.")
        tmp_batches = os.path.join(self.tmp_dir.name, "batches")
        # Initialize Data IO
        self.data_io = Data_IO(io_interface,
                               input_path=os.path.join(self.tmp_dir.name),
                               output_path=os.path.join(self.tmp_dir.name),
                               batch_path=tmp_batches, delete_batchDir=False)
        # Initialize Preprocessor
        self.pp = Preprocessor(self.data_io, batch_size=2,
                               data_aug=None, analysis="fullimage")
        # Initialize Neural Network
        self.model = Neural_Network(self.pp)
        # Get sample list
        self.sample_list = self.data_io.get_indiceslist()
github frankkramer-lab / MIScnn / tests / test_datagenerator.py View on Github external
def test_DATAGENERATOR_consistency(self):
        pp_fi = Preprocessor(self.data_io, batch_size=1, data_aug=None,
                             prepare_subfunctions=False, prepare_batches=False,
                             analysis="fullimage")
        data_gen = DataGenerator(self.sample_list, pp_fi,
                                 training=True, shuffle=False, iterations=None)
        i = 0
        for batch in data_gen:
            sample = self.data_io.sample_loader(self.sample_list[i],
                                                load_seg=True)
            self.assertTrue(np.array_equal(batch[0][0], sample.img_data))
            seg = to_categorical(sample.seg_data, num_classes=3)
            self.assertTrue(np.array_equal(batch[1][0], seg))
            i += 1
github frankkramer-lab / MIScnn / tests / test_preprocessor.py View on Github external
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))))
github frankkramer-lab / MIScnn / tests / test_preprocessor.py View on Github external
def test_PREPROCESSOR_patchwisecrop_skipBlanks(self):
        sample_list = self.data_io3D.get_indiceslist()
        pp = Preprocessor(self.data_io3D, data_aug=None, batch_size=1,
                          analysis="patchwise-crop", patch_shape=(4,4,4))
        pp.patchwise_skip_blanks = True
        batches = pp.run(sample_list[0:3], training=True, validation=False)
        sample = self.data_io3D.sample_loader(sample_list[0], load_seg=True)
        sample.seg_data = to_categorical(sample.seg_data,
                                         num_classes=sample.classes)
        ready_data = pp.analysis_patchwise_crop(sample, data_aug=False)
        self.assertEqual(len(ready_data), 1)
        self.assertEqual(ready_data[0][0].shape, (4,4,4,1))
        self.assertEqual(ready_data[0][1].shape, (4,4,4,3))
github frankkramer-lab / MIScnn / tests / test_preprocessor.py View on Github external
def test_PREPROCESSOR_fullimage_3D(self):
        sample_list = self.data_io3D.get_indiceslist()
        pp = Preprocessor(self.data_io3D, data_aug=None, batch_size=2,
                          analysis="fullimage")
        batches = pp.run(sample_list[0:3], training=True, validation=False)
        self.assertEqual(len(batches), 2)
        batches = pp.run(sample_list[0:1], training=False, validation=False)
        self.assertEqual(len(batches), 1)
        sample = self.data_io3D.sample_loader(sample_list[0], load_seg=True)
        sample.seg_data = to_categorical(sample.seg_data,
                                         num_classes=sample.classes)
        ready_data = pp.analysis_fullimage(sample, data_aug=False,
                                           training=True)
        self.assertEqual(len(ready_data), 1)
        self.assertEqual(ready_data[0][0].shape, (16,16,16,1))
        self.assertEqual(ready_data[0][1].shape, (16,16,16,3))
github frankkramer-lab / MIScnn / tests / test_preprocessor.py View on Github external
def test_PREPROCESSOR_BASE_dataaugmentation(self):
        sample_list = self.data_io3D.get_indiceslist()
        pp = Preprocessor(self.data_io3D, batch_size=1,  analysis="fullimage")
        batches = pp.run(sample_list[8:10], training=False, validation=False)
        self.assertEqual(len(batches), 2)
        self.assertEqual(batches[0][0].shape, (1,16,16,16,1))
        self.assertIsNone(batches[0][1])
        sample = self.data_io3D.sample_loader(sample_list[8], load_seg=False)
        self.assertFalse(np.array_equal(batches[0][0], sample.img_data))
github frankkramer-lab / MIScnn / tests / test_evaluations.py View on Github external
seg = np.random.rand(16, 16, 16) * 3
            self.seg = seg.astype(int)
            self.dataset3D["TEST.sample_" + str(i)] = (self.img, self.seg)
        # Initialize Dictionary IO Interface
        io_interface3D = Dictionary_interface(self.dataset3D, classes=3,
                                              three_dim=True)
        # Initialize temporary directory
        self.tmp_dir3D = tempfile.TemporaryDirectory(prefix="tmp.miscnn.")
        tmp_batches = os.path.join(self.tmp_dir3D.name, "batches")
        # Initialize Data IO
        self.data_io3D = Data_IO(io_interface3D,
                                 input_path=os.path.join(self.tmp_dir3D.name),
                                 output_path=os.path.join(self.tmp_dir3D.name),
                                 batch_path=tmp_batches, delete_batchDir=False)
        # Initialize Preprocessor
        self.pp3D = Preprocessor(self.data_io3D, batch_size=2,
                                 data_aug=None, analysis="fullimage")
        # Initialize Neural Network
        model = Neural_Network(self.pp3D)
        # Get sample list
        self.sample_list3D = self.data_io3D.get_indiceslist()

        eval_path = os.path.join(self.tmp_dir3D.name, "evaluation")
        leave_one_out(self.sample_list3D, model, epochs=3, iterations=None,
                      evaluation_path=eval_path, callbacks=[])
        self.assertTrue(os.path.exists(eval_path))
        # Cleanup stuff
        self.tmp_dir3D.cleanup()