class metricTEST(unittest.TestCase): # Create random imaging and segmentation data @classmethod def setUpClass(self): np.random.seed(1234) # Create 2D imgaging and segmentation data set self.dataset = dict() for i in range(0, 2): img = np.random.rand(16, 16) * 255 self.img = img.astype(int) 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.CESP.") 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=1, 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() # Delete all temporary files @classmethod def tearDownClass(self): self.tmp_dir.cleanup() #-------------------------------------------------# # Standard DSC Metric # #-------------------------------------------------# def test_METRICS_DSC_standard(self): self.model.loss = dice_coefficient self.model.metrics = [dice_coefficient] self.model.train(self.sample_list, epochs=1) #-------------------------------------------------# # Standard DSC Loss # #-------------------------------------------------# def test_METRICS_DSC_standardLOSS(self): self.model.loss = dice_coefficient_loss self.model.metrics = [dice_coefficient_loss] self.model.train(self.sample_list, epochs=1) #-------------------------------------------------# # Soft DSC Metric # #-------------------------------------------------# def test_METRICS_DSC_soft(self): self.model.loss = dice_soft self.model.metrics = [dice_soft] self.model.train(self.sample_list, epochs=1) #-------------------------------------------------# # Soft DSC Loss # #-------------------------------------------------# def test_METRICS_DSC_softLOSS(self): self.model.loss = dice_soft_loss self.model.metrics = [dice_soft_loss] self.model.train(self.sample_list, epochs=1) #-------------------------------------------------# # Weighted DSC # #-------------------------------------------------# def test_METRICS_DSC_weighted(self): self.model.loss = dice_weighted([1,1,4]) self.model.metrics = [dice_weighted([1,1,4])] self.model.train(self.sample_list, epochs=1) #-------------------------------------------------# # Dice & Crossentropy loss # #-------------------------------------------------# def test_METRICS_DSC_CrossEntropy(self): self.model.loss = dice_crossentropy self.model.metrics = [dice_crossentropy] self.model.train(self.sample_list, epochs=1) #-------------------------------------------------# # Tversky loss # #-------------------------------------------------# def test_METRICS_Tversky(self): self.model.loss = tversky_loss self.model.metrics = [tversky_loss] self.model.train(self.sample_list, epochs=1) #-------------------------------------------------# # Tversky & Crossentropy loss # #-------------------------------------------------# def test_METRICS_Tversky_CrossEntropy(self): self.model.loss = tversky_crossentropy self.model.metrics = [tversky_crossentropy] self.model.train(self.sample_list, epochs=1)
def test_MODEL_training3D(self): nn = Neural_Network(preprocessor=self.pp3D) nn.train(self.sample_list3D, epochs=3)