예제 #1
0
def main():
    print("Welcome to Organogenesis")
    print("------------------")

    #Keep a list of available structures for training/predicting
    OARs = [
        "Body", "Spinal Cord", "Oral Cavity", "Left Parotid", "Right Parotid"
    ]  #Later will add an "all" option

    #Need to get user input. Make a string to easily ask for a number corresponding to an OAR.
    ChooseOAR_string = "Please enter the number for the organ you wish to contour / train a model for \n>>"
    for i in range(len(OARs)):
        ChooseOAR_string += str(
            i + 1) + ": " + OARs[i] + "\n"  #create list of options

    while True:  #wait for user input
        try:
            chosenOAR = int(input(ChooseOAR_string)) - 1
            if chosenOAR < len(OARs):
                break
        except KeyboardInterrupt:
            quit()
        except:
            pass

    #Now determine if the goal is to train or to find contours, etc
    chooseTask_string = "Please enter the number for the desired task\n"
    chooseTask_string += "1. Train a UNet model for predicting " + str(
        OARs[chosenOAR])
    chooseTask_string += "\n2. Predict " + str(
        OARs[chosenOAR]) + " contours using an existing model"
    chooseTask_string += "\n3. Determine threshold accuracies for predictions of the " + str(
        OARs[chosenOAR])
    chooseTask_string += "\n4. Determine the evaulation data (F score and 95th percentile Haussdorf distance) for the validation set of the " + str(
        OARs[chosenOAR])
    chooseTask_string += "\n5. Plot predicted masks for the  " + str(
        OARs[chosenOAR])
    chooseTask_string += "\n6. Export model to ONNX"  #Not worrying about this anymore for now
    chooseTask_string += "\n7. predict using ONNX model \n>>"  #Not worrying about this anymore for now

    while True:  #get user input
        try:
            task = int(input(chooseTask_string))
            if (task in range(0, 8)):
                break
        except KeyboardInterrupt:
            quit()
        except:
            pass

    if (task == 1):
        Train.Train(OARs[chosenOAR],
                    7,
                    1e-3,
                    path=None,
                    processData=False,
                    loadModel=False,
                    preSorted=True)
        Test.BestThreshold(OARs[chosenOAR], 400)
        Test.TestPlot(OARs[chosenOAR], path=None, threshold=0.1)
    elif task == 2:
        contoursList, existingContoursList = Predict.GetContours(
            OARs[chosenOAR],
            "P85",
            path=None,
            threshold=0.72,
            withReal=True,
            tryLoad=False,
            plot=False)
        #print(contoursList)
        #print(len(contoursList))
    elif task == 3:
        Test.BestThreshold(OARs[chosenOAR],
                           path=None,
                           testSize=500,
                           onlyMasks=False,
                           onlyBackground=False)
    elif task == 4:
        F_Score, recall, precision, accuracy, haussdorffDistance = Test.GetEvalData(
            OARs[chosenOAR], path=None, threshold=0.7)
        print([F_Score, recall, precision, accuracy, haussdorffDistance])
    elif task == 5:
        array, y = Test.GetMasks(OARs[chosenOAR],
                                 "HN1046",
                                 path="/media/calebsample/Data/temp",
                                 threshold=0.1)
        import numpy as np
        print(np.amax(y))
        print(np.amax(array))
        Test.TestPlot(OARs[chosenOAR],
                      path="/media/calebsample/Data/temp",
                      threshold=0.1)
예제 #2
0
                            "\nPlease specify the number of epochs\n >")
                        numEpochs = int(numEpochs)
                        break
                    except KeyboardInterrupt:
                        quit()
                    except:
                        pass

            processData = args.processData
            loadModel = args.loadModel
            dataPath = args.dataPath  #If dataPath is None, then the program uses the data in the patient_files folder. If it is a path to a directory, data will be processed in this directory.
            preSorted = args.preSorted

            Train.Train(organ, numEpochs, lr, dataPath, processData, loadModel,
                        preSorted)
            bestThreshold = Test.BestThreshold(organ, dataPath, 400)

            Test.TestPlot(organ, dataPath, threshold=bestThreshold)

        elif args.function == "GetContours":
            patient = args.predictionPatientName
            if (patient == None):
                while True:
                    try:
                        patient = input(
                            "\nPlease specify the name of the patient folder that you are trying to get contours for\n >"
                        )
                        if patient != "":
                            break
                    except KeyboardInterrupt:
                        quit()