コード例 #1
0
ファイル: PredPipeline.py プロジェクト: odysszis/AML
    def predictContours(self):

        '''
        Method for pushing images loaded by _read_all_dicom_images through full learned network
        to predict the resulting contour
           STEPS: 1) Feedforward through CNN, followed by through SA, followed by calling AC model, giving final result

        :return:
        '''

        #images are slice * time * height * width
        self.predROIs = np.array([CNNpred(inputimages = self.images[s,:], batch_size=1,
                                          fine_tuned_params_path = '/Users/Peadar/Documents/KagglePythonProjects/AML/DataScienceBowl/data/fine_tune_paramsXnew.pickle')
                                  for s in range(0, len(self.slices))])


        self.imagesROIs = np.array([crop_ROI(images=self.images[s,:], roi=self.predROIs[s,:],
                                             roi_dim=(100,100), newsize=(64, 64))
                              for s in range(0, len(self.slices))])

        self.predSAContours = np.array([SApred(self.imagesROIs[s,:],
                                               trained_SA_path ='/Users/Peadar/Documents/KagglePythonProjects/AML/DataScienceBowl/data/SA_XPHmodel')
                                        for s in range(0, len(self.slices))])

        self.predACContours = np.array([[AC.evolve_contour(lv = self.predSAContours[s,t], roi=self.imagesROIs[s,t],alpha3=0)
                                         for t in range(0, len(self.time))] for s in range(0, len(self.slices))])
コード例 #2
0
    def predictContours(self):
        '''
        Method for pushing images loaded by _read_all_dicom_images through full learned network
        to predict the resulting contour
           STEPS: 1) Feedforward through CNN, followed by through SA, followed by calling AC model, giving final result

        :return:
        '''

        #images are slice * time * height * width
        self.predROIs = np.array([
            CNNpred(
                inputimages=self.images[s, :],
                batch_size=1,
                fine_tuned_params_path=
                '/Users/Peadar/Documents/KagglePythonProjects/AML/DataScienceBowl/data/fine_tune_paramsXnew.pickle'
            ) for s in range(0, len(self.slices))
        ])

        self.imagesROIs = np.array([
            crop_ROI(images=self.images[s, :],
                     roi=self.predROIs[s, :],
                     roi_dim=(100, 100),
                     newsize=(64, 64)) for s in range(0, len(self.slices))
        ])

        self.predSAContours = np.array([
            SApred(
                self.imagesROIs[s, :],
                trained_SA_path=
                '/Users/Peadar/Documents/KagglePythonProjects/AML/DataScienceBowl/data/SA_XPHmodel'
            ) for s in range(0, len(self.slices))
        ])

        self.predACContours = np.array([[
            AC.evolve_contour(lv=self.predSAContours[s, t],
                              roi=self.imagesROIs[s, t],
                              alpha3=0) for t in range(0, len(self.time))
        ] for s in range(0, len(self.slices))])
コード例 #3
0
    def predictContours(self):

        '''
        Method for pushing images loaded by _read_all_dicom_images through full learned network
        to predict the resulting contour
           STEPS: 1) Feedforward through CNN, followed by through SA, followed by calling AC model, giving final result

        :return:
        '''

        #images are slice * time * height * width
        #############################################
        # PREDICT ROI MASKS
        # IMPORTANT: Change fine_tuned_params_path file to fine_tune_paramsX_big.pickle and .._small.pickle respectively

        # self.big_images and self.small_images are both lists of lists of arrays
        b = len(self.big_images)
        s = len(self.small_images)
        # CNN should return list of arrays
        self.pred_big_ROIs = [CNNpred(inputimages = self.big_images[s], batch_size=1,
                                      fine_tuned_params_path = '/home/odyss/Desktop/dsb/AML/DataScienceBowl/data/fine_tune_paramsXlarge.pickle')
                              for s in range(0, len(self.big_slices))]
        self.pred_small_ROIs = [CNNpred(inputimages = self.small_images[s], batch_size=1,
                                        fine_tuned_params_path = '/home/odyss/Desktop/dsb/AML/DataScienceBowl/data/fine_tune_paramsXsmall.pickle')
                                for s in range(0, len(self.small_slices))]

        """
        self.predROIs = np.array([CNNpred(inputimages = self.images[s,:], batch_size=1,
                                          fine_tuned_params_path = '/Users/mh/AML/DataScienceBowl/data/fine_tune_paramsXnew.pickle')
                                  for s in range(0, len(self.slices))])
        """
        #############################################
        # CROP IMAGES TO ROIs
        # crop ROI should return list of arrays
        self.imagesROIs_big = [crop_ROI(images=self.big_images[s], roi=self.pred_big_ROIs[s],
                                        roi_dim=(100,100), newsize=(64, 64))
                                        for s in range(0, len(self.big_slices))]
        self.imagesROIs_small = [crop_ROI(images=self.small_images[s], roi=self.pred_small_ROIs[s],
                                          roi_dim=(100,100), newsize=(64, 64))
                                        for s in range(0, len(self.small_slices))]

        """
        self.imagesROIs = np.array([crop_ROI(images=self.images[s,:], roi=self.predROIs[s,:],
                                             roi_dim=(100,100), newsize=(64, 64))
                              for s in range(0, len(self.slices))])
        """
        #############################################
        # PREDICT CONTOUR USING SA
        # IMPORTANT: Change trained_SA_path to ../SA_Xmodel_big and ../SA_Xmodel_small, respectively


        self.predSAbigContours = np.array([SApred(self.imagesROIs_big[s],
                                               trained_SA_path ='/home/odyss/Desktop/dsb/AML/DataScienceBowl/data/SA_RLUmodel_large')
                                        for s in range(0, len(self.big_slices))])
        self.predSAsmallContours = np.array([SApred(self.imagesROIs_small[s],
                                               trained_SA_path ='/home/odyss/Desktop/dsb/AML/DataScienceBowl/data/SA_RLUmodel_small')
                                        for s in range(0, len(self.small_slices))])

        """
        self.predSAContours = np.array([SApred(self.imagesROIs[s,:],
                                               trained_SA_path ='/Users/mh/AML/DataScienceBowl/data/SA_Xmodel')
                                        for s in range(0, len(self.slices))])
        """
        #############################################
        # ACTIVE CONTOUR

        self.predACContours_big = np.array([[AC.evolve_contour(lv = self.predSAbigContours[s][t], roi=self.imagesROIs_big[s][t]
                                                               , alpha1=2, alpha2=1.5, alpha3=0.002)
                                         for t in range(0, len(self.time))] for s in range(0, len(self.big_slices))])
        self.predACContours_small = np.array([[AC.evolve_contour(lv = self.predSAsmallContours[s][t], roi=self.imagesROIs_small[s][t]
                                                                 , alpha1=2, alpha2=1.5, alpha3=0.007)
                                         for t in range(0, len(self.time))] for s in range(0, len(self.small_slices))])

        """
コード例 #4
0
# original training image
train_large = np.load(LOCALDATAPATH + 'SBXtrainImage256_large')
train_small = np.load(LOCALDATAPATH + 'SBXtrainImage256_small')

# original training binary contour
mask_large = np.load(LOCALDATAPATH + 'SBXtrainMask256_large')
mask_small = np.load(LOCALDATAPATH + 'SBXtrainMask256_small')

# predictions from SA based on the above data
preds_Large = np.load(LOCALDATAPATH + 'SA_predictions_large')
preds_Small = np.load(LOCALDATAPATH + 'SA_predictions_small')

# crop original image and contour data to match the region of the predictions
train_roi_large = crop_ROI(images=train_large,
                           roi=roi_large,
                           roi_dim=(100, 100),
                           newsize=(64, 64))
train_roi_small = crop_ROI(images=train_small,
                           roi=roi_small,
                           roi_dim=(100, 100),
                           newsize=(64, 64))

mask_roi_large = crop_ROI(images=mask_large,
                          roi=roi_large,
                          roi_dim=(100, 100),
                          newsize=(64, 64))
mask_roi_small = crop_ROI(images=mask_small,
                          roi=roi_small,
                          roi_dim=(100, 100),
                          newsize=(64, 64))
コード例 #5
0
ファイル: SATest.py プロジェクト: odysszis/AML
    masks = np.array(mask_predictions)


    return masks


if __name__ == "__main__":

    # load required data

    roi = np.load('/Users/Peadar/Documents/KagglePythonProjects/AML/DataScienceBowl/data/SBXtrainBinaryMask32')
    train = np.load('/Users/Peadar/Documents/KagglePythonProjects/AML/DataScienceBowl/data/SBXtrainImage256')
    mask = np.load('/Users/Peadar/Documents/KagglePythonProjects/AML/DataScienceBowl/data/SBXtrainMask256')

    # crop data based on ROI
    train_roi =crop_ROI(images=train, roi=roi, roi_dim=(100,100), newsize=(64, 64))
    mask_roi =crop_ROI(images= mask, roi=roi, roi_dim=(100,100), newsize=(64, 64))

    # call predict function
    mask_predictions = predict_sa(train_roi, trained_SA_path = '/Users/Peadar/Documents/KagglePythonProjects/AML/DataScienceBowl/data/SA_RLUmodel')

    # store predictions

    mask_predictions.dump('/Users/Peadar/Documents/KagglePythonProjects/AML/DataScienceBowl/data/SA_predictions')

    # methods for plotting scatter of results

    for i in range(0,100):
        f, axarr = plt.subplots(3, 2)
        axarr[0, 1].imshow(train[i,:,:])
        axarr[0, 1].set_title('Original Image')
コード例 #6
0
ファイル: PredPipeline2Way.py プロジェクト: odysszis/AML
    def predictContours(self):

        '''
        Method for pushing images loaded by _read_all_dicom_images through full learned network
        to predict the resulting contour
           STEPS: 1) Feedforward through CNN, followed by through SA, followed by calling AC model, giving final result

        :return:
        '''

        #images are slice * time * height * width
        #############################################
        # PREDICT ROI MASKS
        # IMPORTANT: Change fine_tuned_params_path file to fine_tune_paramsX_big.pickle and .._small.pickle respectively

        # self.big_images and self.small_images are both lists of lists of arrays
        b = len(self.big_images)
        s = len(self.small_images)
        # CNN should return list of arrays
        self.pred_big_ROIs = [CNNpred(inputimages = self.big_images[s], batch_size=1,
                                      fine_tuned_params_path = '/home/odyss/Desktop/dsb/AML/DataScienceBowl/data/fine_tune_paramsXlarge.pickle')
                              for s in range(0, len(self.big_slices))]
        self.pred_small_ROIs = [CNNpred(inputimages = self.small_images[s], batch_size=1,
                                        fine_tuned_params_path = '/home/odyss/Desktop/dsb/AML/DataScienceBowl/data/fine_tune_paramsXsmall.pickle')
                                for s in range(0, len(self.small_slices))]

        """
        self.predROIs = np.array([CNNpred(inputimages = self.images[s,:], batch_size=1,
                                          fine_tuned_params_path = '/Users/mh/AML/DataScienceBowl/data/fine_tune_paramsXnew.pickle')
                                  for s in range(0, len(self.slices))])
        """
        #############################################
        # CROP IMAGES TO ROIs
        # crop ROI should return list of arrays
        self.imagesROIs_big = [crop_ROI(images=self.big_images[s], roi=self.pred_big_ROIs[s],
                                        roi_dim=(100,100), newsize=(64, 64))
                                        for s in range(0, len(self.big_slices))]
        self.imagesROIs_small = [crop_ROI(images=self.small_images[s], roi=self.pred_small_ROIs[s],
                                          roi_dim=(100,100), newsize=(64, 64))
                                        for s in range(0, len(self.small_slices))]

        """
        self.imagesROIs = np.array([crop_ROI(images=self.images[s,:], roi=self.predROIs[s,:],
                                             roi_dim=(100,100), newsize=(64, 64))
                              for s in range(0, len(self.slices))])
        """
        #############################################
        # PREDICT CONTOUR USING SA
        # IMPORTANT: Change trained_SA_path to ../SA_Xmodel_big and ../SA_Xmodel_small, respectively


        self.predSAbigContours = np.array([SApred(self.imagesROIs_big[s],
                                               trained_SA_path ='/home/odyss/Desktop/dsb/AML/DataScienceBowl/data/SA_RLUmodel_large')
                                        for s in range(0, len(self.big_slices))])
        self.predSAsmallContours = np.array([SApred(self.imagesROIs_small[s],
                                               trained_SA_path ='/home/odyss/Desktop/dsb/AML/DataScienceBowl/data/SA_RLUmodel_small')
                                        for s in range(0, len(self.small_slices))])

        """
        self.predSAContours = np.array([SApred(self.imagesROIs[s,:],
                                               trained_SA_path ='/Users/mh/AML/DataScienceBowl/data/SA_Xmodel')
                                        for s in range(0, len(self.slices))])
        """
        #############################################
        # ACTIVE CONTOUR

        self.predACContours_big = np.array([[AC.evolve_contour(lv = self.predSAbigContours[s][t], roi=self.imagesROIs_big[s][t]
                                                               , alpha1=2, alpha2=1.5, alpha3=0.002)
                                         for t in range(0, len(self.time))] for s in range(0, len(self.big_slices))])
        self.predACContours_small = np.array([[AC.evolve_contour(lv = self.predSAsmallContours[s][t], roi=self.imagesROIs_small[s][t]
                                                                 , alpha1=2, alpha2=1.5, alpha3=0.007)
                                         for t in range(0, len(self.time))] for s in range(0, len(self.small_slices))])

        """
コード例 #7
0
ファイル: ACVal.py プロジェクト: odysszis/AML
roi_small = np.load(LOCALDATAPATH + 'SBXtrainBinaryMask32_small')

# original training image
train_large = np.load(LOCALDATAPATH + 'SBXtrainImage256_large')
train_small = np.load(LOCALDATAPATH + 'SBXtrainImage256_small')

# original training binary contour
mask_large = np.load(LOCALDATAPATH + 'SBXtrainMask256_large')
mask_small = np.load(LOCALDATAPATH + 'SBXtrainMask256_small')

# predictions from SA based on the above data
preds_Large = np.load(LOCALDATAPATH + 'SA_predictions_large')
preds_Small = np.load(LOCALDATAPATH + 'SA_predictions_small')

# crop original image and contour data to match the region of the predictions
train_roi_large =crop_ROI(images=train_large, roi=roi_large, roi_dim=(100,100), newsize=(64, 64))
train_roi_small =crop_ROI(images=train_small, roi=roi_small, roi_dim=(100,100), newsize=(64, 64))

mask_roi_large =crop_ROI(images=mask_large, roi=roi_large, roi_dim=(100,100), newsize=(64, 64))
mask_roi_small =crop_ROI(images=mask_small, roi=roi_small, roi_dim=(100,100), newsize=(64, 64))


show_preds_large = [train_roi_large[i,:,:] + preds_Large[i,:,:] for i in range(np.shape(preds_Large)[0])]
show_preds_small = [train_roi_small[i,:,:] + preds_Small[i,:,:] for i in range(np.shape(preds_Small)[0])]

#pdb.set_trace()

"""
    Trial parameter ranges: alpha1{1, 1.5, 2}, alpha 2{1.5,2,2.5},  alpha 3 = {0, ..., 0.01} steps 0.001

"""