Пример #1
0
 def preprocessing_valid(self):
      self.z_valid = z_calc(self.valid_pat, self.valid_sub_pat)
      self.z_startvalid, self.z_endvalid = calculating_slicesofinterest_segtrain(self.valid_pat, self.valid_sub_pat, self.z_valid, self.roi_interest)
      self.z_startvalid, self.z_endvalid = calculating_slicesofinterestfor3D(self.valid_pat,self.z_startvalid, self.z_endvalid)
      self.x_centvalid, self.y_centvalid = calculate_centroid_segvalid(self.valid_pat,
          self.valid_sub_pat, self.z_startvalid, self.z_endvalid, self.roi_interest)
      np.save(os.path.join(self.main_pred_dir, 'valid.npy'), self.valid_pat)
      np.save(os.path.join(self.main_pred_dir, 'valid_sub.npy'), self.valid_sub_pat)
      np.save(os.path.join(self.main_pred_dir, 'z_valid.npy'), self.z_valid)
      np.save(os.path.join(self.main_pred_dir, 'z_startvalid.npy'), self.z_startvalid)
      np.save(os.path.join(self.main_pred_dir, 'z_endvalid.npy'), self.z_endvalid)
      np.save(os.path.join(self.main_pred_dir, 'x_centvalid.npy'), self.x_centvalid)
      np.save(os.path.join(self.main_pred_dir, 'y_centvalid.npy'), self.y_centvalid)
Пример #2
0
 def preprocessing_train(self):
      self.z_TRAIN = z_calc(self.train_pat, self.train_pat_sublist)
      self.z_starttrain, self.z_endtrain = calculating_slicesofinterest_segtrain(self.train_pat, self.train_pat_sublist, self.z_TRAIN, self.roi_interest)
      self.z_starttrain, self.z_endtrain = calculating_slicesofinterestfor3D(self.train_pat,self.z_starttrain, self.z_endtrain)
      self.x_centtrain, self.y_centtrain = calculate_centroid_segtrain(self.train_pat,
          self.train_pat_sublist, self.z_starttrain, self.z_endtrain, self.roi_interest)
      np.save(os.path.join(self.main_pred_dir, 'train.npy'), self.train_pat)
      np.save(os.path.join(self.main_pred_dir, 'train_sub.npy'), self.train_pat_sublist)
      np.save(os.path.join(self.main_pred_dir, 'z_train.npy'), self.z_TRAIN)
      np.save(os.path.join(self.main_pred_dir, 'z_starttrain.npy'), self.z_startvalid)
      np.save(os.path.join(self.main_pred_dir, 'z_endtrain.npy'), self.z_endtrain)
      np.save(os.path.join(self.main_pred_dir, 'x_centtrain.npy'), self.x_centtrain)
      np.save(os.path.join(self.main_pred_dir, 'y_centtrain.npy'), self.y_centtrain)
Пример #3
0
    def predict(self):
        self.test_pat = np.load(os.path.join(self.data_dir, 'test.npy'))
        self.test_sub = np.load(os.path.join(self.data_dir, 'test_sub.npy'))
        self.z_test = z_calc(self.test_pat, self.test_sub)

        #localization
        self.test_imgs_in, self.test_imgs_roi = self.create_locnpys(
            self.test_pat, self.test_sub, self.z_test)
        cust = {
            'channel_RSDice': channel_RSDice,
            'channel_RSloss': channel_RSloss
        }
        self.loc_network = load_model('locnetwork_2.h5', cust)
        imgs_roi_pred = self.loc_network.predict(self.test_imgs_in,
                                                 batch_size=1,
                                                 verbose=1)
        save_coarse_predictions(self.loc_dir, imgs_roi_pred)

        #OAR segmentation
        oar_pred_dir = '/data/M1_FM2'
        self.preprocessing_test(oar_pred_dir, 2)
        cust = {
            'weighted_dice_loss3D': weighted_dice_loss3D,
            'dice_coef': dice_coef,
            'GroupNormalization': GroupNormalization,
            'DropBlock3D': DropBlock3D
        }
        self.loc_network = load_model('FM2_network.h5', cust)
        f = K.function([self.loc_network.layers[0].input,
                        K.learning_phase()],
                       [self.loc_network.layers[-1].output])
        self.predict_with_uncertainty(f,
                                      oar_pred_dir,
                                      5,
                                      self.test_imgs_in,
                                      1,
                                      n_iter=50)

        oar_pred_dir = '/data/M1_FM3'
        self.preprocessing_test(oar_pred_dir, 3)
        cust = {
            'weighted_dice_loss3D': weighted_dice_loss3D,
            'dice_coef': dice_coef,
            'GroupNormalization': GroupNormalization,
            'DropBlock3D': DropBlock3D
        }
        self.loc_network = load_model('FM3_network.h5', cust)
        f = K.function([self.loc_network.layers[0].input,
                        K.learning_phase()],
                       [self.loc_network.layers[-1].output])
        self.predict_with_uncertainty(f,
                                      oar_pred_dir,
                                      5,
                                      self.test_imgs_in,
                                      1,
                                      n_iter=50)
        oar_pred_dir = '/data/M1_PB'
        self.preprocessing_test(oar_pred_dir, 8)
        cust = {
            'weighted_dice_loss3D': weighted_dice_loss3D,
            'dice_coef': dice_coef,
            'GroupNormalization': GroupNormalization,
            'DropBlock3D': DropBlock3D
        }
        self.loc_network = load_model('PB_network.h5', cust)
        f = K.function([self.loc_network.layers[0].input,
                        K.learning_phase()],
                       [self.loc_network.layers[-1].output])
        self.predict_with_uncertainty(f,
                                      oar_pred_dir,
                                      5,
                                      self.test_imgs_in,
                                      1,
                                      n_iter=50)

        oar_pred_dir = '/data/M1_Bladder'
        self.preprocessing_test(oar_pred_dir, 5)
        cust = {
            'weighted_dice_loss3D': weighted_dice_loss3D,
            'dice_coef': dice_coef,
            'GroupNormalization': GroupNormalization,
            'DropBlock3D': DropBlock3D
        }
        self.loc_network = load_model('Bladder_network.h5', cust)
        f = K.function([self.loc_network.layers[0].input,
                        K.learning_phase()],
                       [self.loc_network.layers[-1].output])
        self.predict_with_uncertainty(f,
                                      oar_pred_dir,
                                      5,
                                      self.test_imgs_in,
                                      1,
                                      n_iter=50)
        oar_pred_dir = '/data/M1_Rectum'
        self.preprocessing_test(oar_pred_dir, 4)
        cust = {
            'weighted_dice_loss3D': weighted_dice_loss3D,
            'dice_coef': dice_coef,
            'GroupNormalization': GroupNormalization,
            'DropBlock3D': DropBlock3D
        }
        self.loc_network = load_model('Rectum_network.h5', cust)
        f = K.function([self.loc_network.layers[0].input,
                        K.learning_phase()],
                       [self.loc_network.layers[-1].output])
        self.predict_with_uncertainty(f,
                                      oar_pred_dir,
                                      4,
                                      self.test_imgs_in,
                                      1,
                                      n_iter=50)
        oar_pred_dir = '/data/M1_CTV'
        self.preprocessing_test(oar_pred_dir, 7)
        cust = {
            'weighted_dice_loss3D': weighted_dice_loss3D,
            'dice_coef': dice_coef,
            'GroupNormalization': GroupNormalization,
            'DropBlock3D': DropBlock3D
        }
        self.loc_network = load_model('Rectum_network.h5', cust)
        f = K.function([self.loc_network.layers[0].input,
                        K.learning_phase()],
                       [self.loc_network.layers[-4].output])
        self.predict_with_uncertainty(f,
                                      oar_pred_dir,
                                      7,
                                      self.test_imgs_in,
                                      1,
                                      n_iter=50)